Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Utilizzo buoni e validazione dell'azienda #59

Merged
merged 14 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:

- name: Run backend tests
working-directory: ./backend
run: npm run seqtest
run: npm test

- name: Trigger deploy Backend to Render
uses: JorgeLNJunior/render-deploy@v1.4.4
Expand Down Expand Up @@ -83,7 +83,7 @@ jobs:
env:
MAPBOX_ACCESS_TOKEN: ${{ secrets.MAPBOX_ACCESS_TOKEN }}
JWT_SECRET: ${{ secrets.JWT_SECRET }}
run: flutter build apk --dart-define PUBLIC_ACCESS_TOKEN="$MAPBOX_ACCESS_TOKEN" --dart-define BACKEND_BASE_URL=https://walkaware.onrender.com --dart-define JWT_SECRET="$JWT_SECRET"
run: flutter build apk --dart-define PUBLIC_ACCESS_TOKEN="$MAPBOX_ACCESS_TOKEN" --dart-define BACKEND_BASE_URL=https://walkaware.onrender.com --dart-define JWT_SECRET="$JWT_SECRET" --dart-define FRONTEND_BASE_URL=https://walkaware-frontend.onrender.com

- name: Archive build result
uses: actions/upload-artifact@v4
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:

- name: Run backend tests
working-directory: ./backend
run: npm run seqtest
run: npm test

# Mobile
- name: Setup java
Expand Down Expand Up @@ -62,7 +62,7 @@ jobs:
env:
MAPBOX_ACCESS_TOKEN: ${{ secrets.MAPBOX_ACCESS_TOKEN }}
JWT_SECRET: ${{ secrets.JWT_SECRET }}
run: flutter build apk --dart-define PUBLIC_ACCESS_TOKEN="$MAPBOX_ACCESS_TOKEN" --dart-define BACKEND_BASE_URL=https://walkaware.onrender.com --dart-define JWT_SECRET="$JWT_SECRET"
run: flutter build apk --dart-define PUBLIC_ACCESS_TOKEN="$MAPBOX_ACCESS_TOKEN" --dart-define BACKEND_BASE_URL=https://walkaware.onrender.com --dart-define JWT_SECRET="$JWT_SECRET" --dart-define FRONTEND_BASE_URL=https://walkaware-frontend.onrender.com

- name: Archive build result
uses: actions/upload-artifact@v4
Expand Down
5 changes: 3 additions & 2 deletions backend/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const utenteWeb = require('./routes/utente_web.js');
const segnalazioni = require('./routes/segnalazioni.js');
const aziende = require('./routes/aziende.js');
const premi = require('./routes/premi.js');
const buoni = require('./routes/buoni.js');

// Express settings
var app = express();
Expand All @@ -33,9 +34,9 @@ app.use(tokenChecker);
// Routes
app.use('/api/v1/utente/mobile', utenteMobile);
app.use('/api/v1/utente/web', utenteWeb);
app.use('/api/v1/segnalazioni', segnalazioni)
app.use('/api/v1/segnalazioni', segnalazioni);
app.use('/api/v1/aziende', aziende);
app.use('/api/v1/premi', premi);

app.use('/api/v1/buoni', buoni);

module.exports = app;
1 change: 1 addition & 0 deletions backend/auth/tokenChecker.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const tokenChecker = function (req, res, next) {
if (req.path === '/api/v1/utente/mobile' ||
req.path === '/api/v1/utente/mobile/login' ||
req.path === "/api/v1/utente/web/login" ||
req.path === "/api/v1/aziende/login" ||
req.path === "/api-docs") {
return next();
}
Expand Down
16 changes: 16 additions & 0 deletions backend/models/buono.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const mongoose = require("mongoose");

const buonoSchema = new mongoose.Schema({
nome: { type: String, required: true },
valore: { type: Number, required: true },
tipo: { type: String, enum: ["percentuale", "contante", "omaggio", "quantita"] },
descrizione: { type: String, required: true },
costo_punti: { type: Number, required: true },
idAzienda: { type: String, required: true },
validitaBuono: { type: Number, required: true }, // Numero di giorni di validità del buono
data_riscatto: { type: Date, default: Date.now },
usato: { type: Boolean, default: false },
});

module.exports = mongoose.model("buono", buonoSchema);

3 changes: 2 additions & 1 deletion backend/models/utente_mobile.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ const utenteMobileSchema = new mongoose.Schema({
});

module.exports.utenteMobileModel = mongoose.model("UtenteMobile", utenteMobileSchema);
module.exports.segnalazioneUtenteMobileModel = mongoose.model("SegnalazioneUtenteMobile", segnalazioneSchema);
module.exports.segnalazioneUtenteMobileModel = mongoose.model("SegnalazioneUtenteMobile", segnalazioneSchema);
module.exports.buonoUtenteMobileModel = mongoose.model("BuonoUtenteMobile", buonoSchema);
210 changes: 207 additions & 3 deletions backend/oas3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,38 @@ paths:
application/json:
schema:
$ref: "#/components/schemas/Error"

/aziende/login:
post:
summary: Login aziende
description: Endpoint per il login di una azienda.
tags:
- Aziende
requestBody:
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/LoginRequest"
responses:
"200":
description: OK. Login con successo.
content:
application/json:
schema:
$ref: "#/components/schemas/AziendaLoginResponse"
"400":
description: Bad Request. Richiesta errata, vedi errore nel corpo della risposta.
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
"401":
description: Not Authorized. Credenziali non valide.
content:
application/json:
schema:
$ref: "#/components/schemas/AuthError"

/aziende/{id}:
get:
Expand Down Expand Up @@ -778,9 +810,72 @@ paths:
schema:
$ref: "#/components/schemas/Error"

/buoni/{id}:
get:
summary: Restituisce ii buono specificato
description: Endpoint per restituire il buono specificato
tags:
- Buoni
security:
- apiKeyAuth: []
parameters:
- in: path
name: id
required: true
schema:
type: string
description: ID del buono
responses:
"200":
description: OK. Buono trovato.
content:
application/json:
schema:
$ref: "#/components/schemas/BuonoGetResponse"
"404":
description: Not Found. Buono con l'id specificato non trovato
content:
application/json:
schema:
$ref: "#/components/schemas/Error"

/buoni/{id}/valida:
put:
summary: Aggiorna lo stato del buono utilizzato
description: Endpoint per aggiornare lo stato del buono
tags:
- Buoni
security:
- apiKeyAuth: []
parameters:
- in: path
name: id
required: true
schema:
type: string
description: ID dell'utente mobile
responses:
"200":
description: OK. Buono utilizzato con successo
content:
application/json:
schema:
$ref: "#/components/schemas/ValidaBuonoResponse"
"404":
description: Buono con l'id specificato non trovato.
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
"400":
description: Bad Request. Richiesta errata, vedi errore nel corpo della risposta.
content:
application/json:
schema:
$ref: "#/components/schemas/Error"



components:
# Security schemas
securitySchemes:
Expand Down Expand Up @@ -960,6 +1055,32 @@ components:
description: Nome dell'utente

# Aziende responses and requests schemas
AziendaLoginResponse:
type: object
properties:
success:
type: boolean
description: Indica se il login è stato effettuato con successo
message:
type: string
description: Messaggio di risposta
token:
type: string
description: Token di autenticazione
self:
type: string
description: Link all'azienda
email:
type: string
format: email
description: Email dell'azienda
userId:
type: string
description: ID dell'azienda
name:
type: string
description: Nome dell'azienda

AziendeGetResponse:
type: object
properties:
Expand Down Expand Up @@ -1023,6 +1144,43 @@ components:
items:
$ref: "#/components/schemas/Premio"

#Premi responses and requests schemas
UtenteMobileBuoniGetResponse:
type: object
properties:
success:
type: boolean
description: Indica se la richiesta è andata a buon fine
UtenteMobile:
type: object
description: buoni di un utente mobile specifico
properties:
buoni:
type: array
description: lista di buoni
items:
$ref: "#/components/schemas/Buono"

BuonoGetResponse:
type: object
properties:
success:
type: boolean
description: Indica se la richiesta è andata a buon fine
buono:
$ref: "#/components/schemas/Buono"

ValidaBuonoResponse:
type: object
properties:
success:
type: boolean
description: Indica se la richiesta è andata a buon fine o no
usato:
type: boolean
description: indica che il buono è stato usato
default: true

# Database models schemas
Segnalazione:
type: object
Expand Down Expand Up @@ -1202,6 +1360,54 @@ components:
- costo_punti
- validitaBuono
- idAzienda

Buono:
type: object
properties:
nome:
type: string
description: nome del buono
valore:
type: number
description: valore del buono
tipo:
type: string
description: tipo di buono
format: enum
enum:
- percentuale
- contante
- omaggio
- quantita
descrizione:
type: string
description: descrizione del buono
costo_punti:
type: number
description: punti necessari per il riscatto del buono
idAzienda:
type: string
description: id dell'azienda
validitaBuono:
type: number
description: giorni di validità del buono
data_riscatto:
type: string
format: date-time
description: data riscatto del buono
usato:
type: boolean
description: se il buono è stato usato
default: false
required:
- nome
- valore
- tipo
- descrizione
- costo_punti
- idAzienda
- validitaBuono


# Errors schemas
Error:
Expand Down Expand Up @@ -1240,8 +1446,6 @@ components:
required:
- password
- email
- nome
- p_iva

PostSuccessfulResponse:
type: object
Expand Down
5 changes: 2 additions & 3 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
"main": "index.js",
"scripts": {
"run-dev": "nodemon ./index.js",
"test": "jest --setupFiles dotenv/config",
"seqtest": "jest --runInBand --testPathPattern='app.test.js|utente_mobile.test.js|aziende.test.js|segnalazioni.test.js|utente_web.test.js|aziende.test.js' --verbose=true"
"test": "jest --setupFiles dotenv/config --verbose"
},
"author": "",
"license": "ISC",
Expand All @@ -33,4 +32,4 @@
"nodemon": "^3.1.0",
"supertest": "^7.0.0"
}
}
}
Loading
Loading