Skip to content

Commit

Permalink
FEAT: ASYNCRONOUS COMUNICATIONS AND SWAGGER UPDATES
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-GF authored Jan 23, 2024
2 parents 8faf557 + ad9767a commit ab0703f
Show file tree
Hide file tree
Showing 10 changed files with 472 additions and 289 deletions.
11 changes: 7 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ jobs:

- name: Decrypt Google credentials.json
env:
GOOGLE_API_PW: ${{ secrets.GCP_CREDENTIALS_PK }}
GCP_CREDENTIALS: ${{ secrets.ENCODED_GCP_CREDENTIALS }}
run: |
gpg --quiet --batch --yes --decrypt --passphrase="$GOOGLE_API_PW" \
--output $GITHUB_WORKSPACE/GoogleCloudKey.json GoogleCloudKey.json.gpg
echo "$GCP_CREDENTIALS" | base64 --decode > GoogleCloudKey.json
- name: Make envfile
uses: SpicyPizza/[email protected]
Expand Down Expand Up @@ -50,12 +49,16 @@ jobs:
envkey_GCF_VERIFY_TOKEN_ENDPOINT: ${{ vars.GCF_VERIFY_TOKEN_ENDPOINT }}
envkey_GCF_GET_PAYLOAD_FROM_TOKEN_ENDPOINT: ${{ vars.GCF_GET_PAYLOAD_FROM_TOKEN_ENDPOINT }}
envkey_SENDINBLUE_API_KEY: ${{ secrets.CI_SENDINBLUE_API_KEY }}
envkey_COURSES_SERVICE_USERNAME: ${{ secrets.CI_COURSES_SERVICE_USERNAME }}
envkey_COURSES_SERVICE_PASSWORD: ${{ secrets.CI_COURSES_SERVICE_PASSWORD }}
envkey_PAYMENT_SERVICE_USERNAME: ${{ secrets.CI_PAYMENT_SERVICE_USERNAME }}
envkey_PAYMENT_SERVICE_PASSWORD: ${{ secrets.CI_PAYMENT_SERVICE_PASSWORD }}
directory: ./server
file_name: .env
fail_on_empty: false
sort_keys: false

- name: Start MongoDB
- name: Start MongoDBs
uses: supercharge/[email protected]
with:
mongodb-version: ${{ vars.CI_MONGODB_VERSION }}
Expand Down
176 changes: 111 additions & 65 deletions server/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,27 +59,12 @@ components:
type: string
description: The email of the user
format: email
plan:
type: string
description: The plan of the user
enum:
- BASIC
- ADVANCED
- PRO
role:
type: string
description: The role of the user
enum:
- USER
- ADMIN
example:
firstName: John
lastName: Doe
username: johndoe
password: johnpassword
email: [email protected]
plan: BASIC
role: USER
UserPut:
type: object
properties:
Expand All @@ -89,37 +74,27 @@ components:
lastName:
type: string
description: The last name of the user
username:
type: string
description: The username of the user
password:
currentPassword:
type: string
description: The password of the user
newPassword:
type: string
description: The new password of the user
email:
type: string
description: The email of the user
format: email
plan:
profilePicture:
type: string
description: The plan of the user
enum:
- BASIC
- ADVANCED
- PRO
role:
type: string
description: The role of the user
enum:
- USER
- ADMIN
description: The profile picture of the user
format: url
example:
firstName: John
lastName: Doe
username: johndoe
password: johnpassword
currentPassword: johnpassword
newPassword: newpassword
email: [email protected]
plan: BASIC
role: USER
profilePicture: https://storage.googleapis.com/fisg4-bucket/default-user.jpg
User:
type: object
required:
Expand All @@ -129,6 +104,8 @@ components:
- email
- plan
- role
- profilePicture
- coinsAmount
properties:
id:
type: string
Expand Down Expand Up @@ -159,6 +136,13 @@ components:
enum:
- USER
- ADMIN
profilePicture:
type: string
description: The profile picture of the user
format: url
coinsAmount:
type: number
description: The coins amount of the user
example:
id: 60b0a1b7c9e8a1b9c8a1b9c8
firstName: John
Expand All @@ -167,6 +151,24 @@ components:
email: [email protected]
plan: BASIC
role: USER
profilePicture: https://storage.googleapis.com/fisg4-bucket/default-user.jpg
coinsAmount: 0
UserMinimal:
type: object
required:
- username
- profilePicture
properties:
username:
type: string
description: The username of the user
profilePicture:
type: string
description: The profile picture of the user
format: url
example:
username: johndoe
profilePicture: https://storage.googleapis.com/fisg4-bucket/default-user.jpg
UserList:
type: object
required:
Expand All @@ -176,15 +178,33 @@ components:
type: object
description: The user
$ref: "#/components/schemas/User"
UserAllList:
type: object
required:
- data
properties:
data:
type: list
description: The user list
items:
$ref: "#/components/schemas/UserMinimal"
JWTList:
type: object
required:
- data
properties:
data:
type: string
description: The JWT token
example: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2Vybm...
type: object
required:
- token
- user
properties:
token:
description: The JWT token
example: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2Vybm...
user:
description: The user
$ref: "#/components/schemas/User"
MessagePost:
type: object
required:
Expand Down Expand Up @@ -493,26 +513,63 @@ paths:
application/json:
schema:
$ref: "#/components/schemas/Error500"
"/{username}":
/reset?username={username}:
get:
summary: Returns the info of the user that has the username passed as parameter
summary: Sends an email with the new credentials
tags:
- Users
parameters:
- in: path
- in: query
name: username
description: The username of the user to reset the password
required: true
schema:
type: string
required: true
description: The username of the user to get
example: johndoe
example: johndoe
security: []
responses:
"200":
description: The user was successfully alerted
content:
application/json:
schema:
$ref: "#/components/schemas/OK2XX"
"400":
description: There was an error with the request
content:
application/json:
schema:
$ref: "#/components/schemas/Error400"
"401":
description: The request was not authorized
content:
application/json:
schema:
$ref: "#/components/schemas/Error401"
"404":
description: The item was not found
content:
application/json:
schema:
$ref: "#/components/schemas/Error404"
"500":
description: Some server error
content:
application/json:
schema:
$ref: "#/components/schemas/Error500"
/all:
get:
summary: Returns minimal info of all users
tags:
- Users
responses:
"200":
description: The info was successfully retrieved
content:
application/json:
schema:
$ref: "#/components/schemas/UserList"
$ref: "#/components/schemas/UserAllList"
"400":
description: There was an error with the request
content:
Expand All @@ -537,8 +594,9 @@ paths:
application/json:
schema:
$ref: "#/components/schemas/Error500"
put:
summary: Updates the info of the user that has the username passed as parameter
/{username}:
get:
summary: Returns the info of the user that has the username passed as parameter
tags:
- Users
parameters:
Expand All @@ -547,21 +605,15 @@ paths:
schema:
type: string
required: true
description: The username of the user to update
description: The username of the user to get
example: johndoe
requestBody:
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/UserPut"
responses:
"200":
description: The info was successfully updated
description: The info was successfully retrieved
content:
application/json:
schema:
$ref: "#/components/schemas/OK2XX"
$ref: "#/components/schemas/UserList"
"400":
description: There was an error with the request
content:
Expand All @@ -574,12 +626,6 @@ paths:
application/json:
schema:
$ref: "#/components/schemas/Error401"
"403":
description: The user that made the request has not enough privileges
content:
application/json:
schema:
$ref: "#/components/schemas/Error403"
"404":
description: The item was not found
content:
Expand Down Expand Up @@ -678,7 +724,7 @@ paths:
application/json:
schema:
$ref: "#/components/schemas/Error500"
"/me/messages?filter={filter}&sort={sort}&offset={offset}&limit={limit}":
/me/messages?filter={filter}&sort={sort}&offset={offset}&limit={limit}:
get:
summary: Get all the messages of the user
tags:
Expand Down Expand Up @@ -789,7 +835,7 @@ paths:
application/json:
schema:
$ref: "#/components/schemas/Error500"
"/me/messages/{messageId}/open":
/me/messages/{messageId}/open:
patch:
summary: Checks a message as opened
tags:
Expand Down Expand Up @@ -833,7 +879,7 @@ paths:
application/json:
schema:
$ref: "#/components/schemas/Error500"
"/me/messages/{messageId}":
/me/messages/{messageId}:
patch:
summary: Enables to change the subject or the message of a message already sent
tags:
Expand Down
4 changes: 4 additions & 0 deletions server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import swaggerui from 'swagger-ui-express'
import bodyParser, { BodyParser } from 'body-parser'
import yaml from 'yaml'
import fs from 'fs';
import { receiveMessages } from './rabbitmq/operations'

const app: Express = express()

Expand Down Expand Up @@ -95,6 +96,9 @@ app.use((req, res, next) => {

})

const MICROSERVICE_QUEUE = 'users_microservice'
receiveMessages(MICROSERVICE_QUEUE)

const port = process.env.PORT ?? 8000

app.listen(port, () => {
Expand Down
Loading

0 comments on commit ab0703f

Please sign in to comment.