Skip to content

Commit

Permalink
Merge pull request #79 from Arquisoft/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
uo277301 authored Apr 10, 2023
2 parents c015633 + d37002d commit 0ebb491
Show file tree
Hide file tree
Showing 39 changed files with 6,901 additions and 4,395 deletions.
37 changes: 11 additions & 26 deletions .github/workflows/lomap_es3b.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,29 @@ name: CI for LOMAP ES3B
on:
release:
types: [published]
push:
branches: [develop]
pull_request:
branches: [develop]

jobs:
unit-test-webapp:
unit-tests:
runs-on: ubuntu-latest
defaults:
run:
working-directory: webapp
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
- run: npm ci
- run: npm test --coverage --watchAll
- name: Analyze with SonarCloud
uses: sonarsource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
unit-test-restapi:
runs-on: ubuntu-latest
defaults:
run:
working-directory: restapi
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
- run: npm ci
- run: npm test --coverage --watchAll
with:
node-version: 18
- run: npm --prefix webapp ci
- run: npm --prefix restapi ci
- run: npm --prefix webapp test --coverage --watchAll
- name: Analyze with SonarCloud
uses: sonarsource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
e2e-tests:
needs: [unit-test-webapp, unit-test-restapi]
needs: [unit-tests]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down
Binary file modified docs/images/03_business_context.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/03_technical_context.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/07_deployment_view.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 0 additions & 50 deletions restapi/api.ts

This file was deleted.

123 changes: 118 additions & 5 deletions restapi/database/config.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
const mongoose = require('mongoose')
import { MongoClient } from 'mongodb';
import {Place} from '../../webapp/src/shared/shareddtypes';


const mongoose = require('mongoose')
const { MONGODB, MONGODB_ATLAS_TEST, NODE_ENV } = process.env // saca del .env la ruta a la base de datos

//const connectionString = NODE_ENV === 'test' ? MONGODB_ATLAS_TEST : MONGODB_ATLAS
let connectionURL: string; // coge del .env el enlace a la base de datos y lo transforma en string
connectionURL = MONGODB!; // esto falla otra vez

const client = new MongoClient("mongodb+srv://lomap:[email protected]/Lomap-es3b?retryWrites=true&w=majority"); //Para conectarse a la base

const connectionString = MONGODB // el enlace a la base de datos
var db: any;
var cliente: any;

if (!connectionString) {
if (!connectionURL) { // en caso de que falle el .env
console.error('Yoy must define your connection string')
}

// Realiza la conexion con la base de datos
/**
const dbConnection = async () => {
try {
mongoose.set("strictQuery", false)
Expand All @@ -32,4 +40,109 @@ const dbConnection = async () => {
mongoose.disconnect()
})
}
module.exports = { dbConnection }
module.exports = { dbConnection } */


export async function connectToDatabase() {
try {
await client.connect();
console.log('Connected to database!');
db = client.db();

} catch (error) {
console.error(error);
throw new Error('Failed to connect to database');
}
}

export async function guardarLugar(lugar:Place) {
await connectToDatabase();

const tablaDB = db.collection('places');

await tablaDB.insertOne(lugar);

console.log('Lugar guardado con exito! Nombre: ', lugar.name );

client.close();
}

export async function cogerLugar(lugarID:number) {
await connectToDatabase();

const tablaDB = db.collection('places');

const lugar = await tablaDB.findOne({_id:lugarID});

client.close();

return lugar;
}

export async function cogerLugares(): Promise<Place[]> {
await connectToDatabase();

const tablaDB = db.collection('places');

const lugares = await tablaDB.find().toArray();

console.log(lugares);

client.close();

return lugares;
}

export async function borrarLugar(lugarID:number) {
await connectToDatabase();

const tablaDB = db.collection('places');

const filtro = {id:lugarID};

await tablaDB.deleteOne(filtro);

console.log('Lugar borrado con exito! Nombre: ', lugarID );

client.close();
}

export async function borrarLugar2(lugar:Place) {
await connectToDatabase();

const tablaDB = db.collection('places');

await tablaDB.deleteOne(lugar);

console.log('Lugar borrado con exito! Nombre: ', lugar.name );

client.close();
}

export async function nuevoComentario(lugarID:number, comment: string) {
await connectToDatabase();

const tablaDB = db.collection('places');

const addComment = { $set: { comment: comment}};

await tablaDB.updateOne({_id:lugarID}, addComment);

console.log('Comentario añadido con exito! ID: ', lugarID );

client.close();
}

export async function nuevoComentario2(lugar:Place, comment: string) {
await connectToDatabase();

const tablaDB = db.collection('places');

const addComment = { $set: { comment: comment}};

await tablaDB.updateOne(lugar, addComment);

console.log('Comentario añadido con exito! Comentario: ', lugar.comments );

client.close();
}
2 changes: 1 addition & 1 deletion restapi/tests/jest.config.ts → restapi/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ export default {
"^.+\\.tsx?$": "ts-jest"
},
collectCoverage: true,
collectCoverageFrom:["api.ts","./routes/rplaces.ts"]
collectCoverageFrom:["api.ts"]
}
10 changes: 7 additions & 3 deletions restapi/models/place.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,21 @@ const PlaceSchema = Schema(
type: Number,
required: true
},
longitud: {
type: Number,
longitude: {
type: Number,
required: true
},
} ,
comments: { // Los comentarios igual conviene sacarlos de otro apartado de la base de datos
type: String,
required: true
},
photoLink: {
type: [String],
reguired: true
},
category: {
type: String,
reguired: true
}
},

Expand Down
Loading

0 comments on commit 0ebb491

Please sign in to comment.