From 1036448251c70f479ea65e7f87f19f9a9319d63c Mon Sep 17 00:00:00 2001 From: Melanie Sarrouy Date: Fri, 5 Nov 2021 14:26:38 +0100 Subject: [PATCH] update swagger --- src/actions/actionGetToken.js | 2 +- src/actions/actionGetUser.js | 4 +- src/pages/SignIn.jsx | 6 +- src/pages/User.jsx | 1 - src/swagger/swagger.json | 171 +++++++++++++++++++++++++++------- src/swagger/swagger.yaml | 115 ++++++++++++++++++----- 6 files changed, 235 insertions(+), 64 deletions(-) diff --git a/src/actions/actionGetToken.js b/src/actions/actionGetToken.js index 98844e8..b789792 100644 --- a/src/actions/actionGetToken.js +++ b/src/actions/actionGetToken.js @@ -40,7 +40,7 @@ export const getToken = (email, password) => { dispatch(loadApiTokenSuccess(response.data.body.token)) localStorage.setItem('token', response.data.body.token) const token = localStorage.getItem('token') - dispatch(getUser(token, password)) + dispatch(getUser(token)) }) .catch((error) => { dispatch(loadApiTokenError(error.message)) diff --git a/src/actions/actionGetUser.js b/src/actions/actionGetUser.js index fb20fe2..6670e6e 100644 --- a/src/actions/actionGetUser.js +++ b/src/actions/actionGetUser.js @@ -24,7 +24,7 @@ const loadApiUserError = (error) => { } } -export const getUser = (token, password) => { +export const getUser = (token) => { return (dispatch) => { dispatch(loadApiUser()) axios({ @@ -34,8 +34,6 @@ export const getUser = (token, password) => { }) .then((response) => { dispatch(loadApiUserSuccess(response.data)) - localStorage.setItem('email', response.data.body.email) - localStorage.setItem('password', password) }) .catch((error) => { dispatch(loadApiUserError(error.message)) diff --git a/src/pages/SignIn.jsx b/src/pages/SignIn.jsx index 7d6bb47..7f86884 100644 --- a/src/pages/SignIn.jsx +++ b/src/pages/SignIn.jsx @@ -20,6 +20,7 @@ const SignIn = () => { const [email, setEmail] = useState('') const [password, setPassword] = useState('') + const [isLogged, setIsLogged] = useState(false) const dispatch = useDispatch() const selectMessage = (state) => state.getUser.user.status const message = useSelector(selectMessage) @@ -27,11 +28,12 @@ const SignIn = () => { const handleSubmit = (e) => { e.preventDefault() - if (email.length === 0 || password.length === 0) { + if (email === '' || password === '') { setInvalidFields('Please fill fields correctly') } else { dispatch(getToken(email, password)) - if (message === undefined) { + setIsLogged(true) + if (isLogged && message === undefined) { setInvalidFields('Email or password invalid') } } diff --git a/src/pages/User.jsx b/src/pages/User.jsx index 8e2e63b..59027de 100644 --- a/src/pages/User.jsx +++ b/src/pages/User.jsx @@ -27,7 +27,6 @@ const User = () => { const selectUser = (state) => state.getUser.user.body const user = useSelector(selectUser) const dispatch = useDispatch() - console.log(user) if (user === undefined) { return diff --git a/src/swagger/swagger.json b/src/swagger/swagger.json index d1c93d3..9a864ca 100644 --- a/src/swagger/swagger.json +++ b/src/swagger/swagger.json @@ -16,6 +16,10 @@ { "name": "Transaction", "description": "Everything about a transaction" + }, + { + "name": "Categories", + "description": "All transactions categories" } ], "schemes": [ @@ -29,7 +33,7 @@ "Transactions" ], "summary": "User's transactions of current month", - "description": "get user's transactions", + "description": "Get user's transactions", "consumes": [ "application/json" ], @@ -65,7 +69,50 @@ "200": { "description": "successful operation", "schema": { - "$ref": "#/definitions/Transactions" + "$ref": "#/definitions/ResponseTransactions" + } + }, + "400": { + "description": "Invalid values" + }, + "500": { + "description": "Internal Server Error" + } + }, + "security": [ + { + "Bearer": [] + } + ] + } + }, + "/user/categories": { + "get": { + "tags": [ + "Categories" + ], + "summary": "Transaction categories", + "description": "Get transactions categories", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "parameters": [ + { + "name": "Autorization", + "in": "header", + "description": "Attach Bearer JWT token", + "required": true, + "type": "string" + } + ], + "responses": { + "200": { + "description": "successful operation", + "schema": { + "$ref": "#/definitions/ResponseCategories" } }, "400": { @@ -87,8 +134,8 @@ "tags": [ "Transaction" ], - "summary": "transaction details", - "description": "Transaction details: type, category and notes", + "summary": "Transaction details", + "description": "Get transaction details", "operationId": "getTransactionId", "consumes": [ "application/json" @@ -116,7 +163,7 @@ "200": { "description": "successful operation", "schema": { - "$ref": "#/definitions/Transaction" + "$ref": "#/definitions/ResponseDetails" } }, "400": { @@ -136,8 +183,8 @@ "tags": [ "Transaction" ], - "summary": "Update transaction details", - "description": "Update transaction details", + "summary": "Update transaction's details", + "description": "Update transaction's details", "operationId": "upDateTransactionId", "consumes": [ "application/json" @@ -163,10 +210,10 @@ { "name": "Details", "in": "body", - "description": "Update transaction's details", + "description": "Update transaction's category", "required": true, "schema": { - "$ref": "#/definitions/Details" + "$ref": "#/definitions/EditableDetails" } } ], @@ -174,7 +221,7 @@ "200": { "description": "successful operation", "schema": { - "$ref": "#/definitions/TransactionDetails" + "$ref": "#/definitions/ResponseDetails" } }, "400": { @@ -200,16 +247,18 @@ } }, "definitions": { - "Transactions": { + "ResponseTransactions": { "type": "object", "properties": { "status": { "type": "integer", - "format": "int64" + "format": "int64", + "example": 200 }, "message": { "type": "string", - "format": "string" + "format": "string", + "example": "transactions successfully recovered" }, "body": { "type": "array", @@ -222,38 +271,42 @@ "name": "Transactions" } }, - "Transaction": { + "ResponseDetails": { "type": "object", "properties": { "status": { "type": "integer", - "format": "int64" + "format": "int64", + "example": 200 }, "message": { "type": "string", - "format": "string" + "format": "string", + "example": "details successfully recovered" }, "schema": { - "$ref": "#/definitions/Informations" + "$ref": "#/definitions/Details" } }, "xml": { - "name": "Transactions" + "name": "Details" } }, - "TransactionDetails": { + "ResponseCategories": { "type": "object", "properties": { "status": { "type": "integer", - "format": "int64" + "format": "int64", + "example": 200 }, "message": { "type": "string", - "format": "string" + "format": "string", + "example": "categories successfully recovered" }, "schema": { - "$ref": "#/definitions/Details" + "$ref": "#/definitions/Categories" } }, "xml": { @@ -264,46 +317,78 @@ "type": "object", "properties": { "transactionId": { - "type": "integer", - "format": "int64", - "description": "transaction ID" + "type": "string", + "description": "transaction ID", + "example": "uT20211105df8" }, "date": { "type": "string", - "format": "Date-time", - "description": "transaction date" + "format": "date-time", + "description": "transaction date", + "example": "2020-06-20T12:57:19.005Z" }, "description": { "type": "string", - "description": "transaction description" + "description": "transaction description", + "example": "Golden Sun Bakery" }, "amount": { "type": "integer", "format": "int64", - "description": "transaction amount" + "description": "transaction amount", + "example": 5 }, "balance": { "type": "integer", "format": "int64", - "description": "account balance after transaction" + "description": "account balance after transaction", + "example": 2082.79 } }, "xml": { "name": "Transaction" } }, + "Categories": { + "type": "array", + "items": { + "$ref": "#/definitions/Category" + }, + "xml": { + "name": "Categories" + } + }, "Details": { "type": "object", "properties": { "transactionId": { - "type": "integer", - "format": "int64", - "description": "transaction ID" + "type": "string", + "description": "transaction ID", + "example": "uT20211105df8" }, "type": { "type": "string", - "description": "transaction type" + "description": "transaction type", + "example": "Electronic" }, + "category": { + "type": "string", + "description": "transaction category", + "example": "Food" + }, + "notes": { + "type": "string", + "description": "transaction notes", + "example": "Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit..." + } + }, + "xml": { + "name": "Details" + } + }, + "EditableDetails": { + "type": "object", + "properties": { "category": { "type": "string", "description": "transaction category" @@ -323,17 +408,31 @@ "from": { "type": "string", "format": "date", - "description": "start date of transactions recovery (one month ago)" + "description": "start date of transactions recovery (one month ago)", + "example": "2021-10-12" }, "to": { "type": "string", "format": "date", - "description": "end date of transaction recovery (today)" + "description": "end date of transaction recovery (today)", + "example": "2021-11-12" } }, "xml": { "name": "TransactionsDate" } + }, + "Category": { + "type": "string", + "enum": [ + "Food", + "Clothes", + "Charges", + "Fuel", + "Supplies", + "Equipment", + "Other" + ] } } } \ No newline at end of file diff --git a/src/swagger/swagger.yaml b/src/swagger/swagger.yaml index f360694..5a71722 100644 --- a/src/swagger/swagger.yaml +++ b/src/swagger/swagger.yaml @@ -11,6 +11,8 @@ tags: description: Everything about user's transactions - name: Transaction description: Everything about a transaction + - name: Categories + description: All transactions categories schemes: - https - http @@ -20,7 +22,7 @@ paths: tags: - Transactions summary: User's transactions of current month - description: get user's transactions + description: Get user's transactions consumes: - application/json produces: @@ -46,7 +48,34 @@ paths: '200': description: successful operation schema: - $ref: '#/definitions/Transactions' + $ref: '#/definitions/ResponseTransactions' + '400': + description: Invalid values + '500': + description: Internal Server Error + security: + - Bearer: [] + /user/categories: + get: + tags: + - Categories + summary: Transaction categories + description: Get transactions categories + consumes: + - application/json + produces: + - application/json + parameters: + - name: Autorization + in: header + description: Attach Bearer JWT token + required: true + type: string + responses: + '200': + description: successful operation + schema: + $ref: '#/definitions/ResponseCategories' '400': description: Invalid values '500': @@ -57,8 +86,8 @@ paths: get: tags: - Transaction - summary: transaction details - description: 'Transaction details: type, category and notes' + summary: Transaction details + description: Get transaction details operationId: getTransactionId consumes: - application/json @@ -79,7 +108,7 @@ paths: '200': description: successful operation schema: - $ref: '#/definitions/Transaction' + $ref: '#/definitions/ResponseDetails' '400': description: Invalid values '500': @@ -89,8 +118,8 @@ paths: put: tags: - Transaction - summary: Update transaction details - description: Update transaction details + summary: Update transaction's details + description: Update transaction's details operationId: upDateTransactionId consumes: - application/json @@ -109,15 +138,15 @@ paths: type: string - name: Details in: body - description: Update transaction's details + description: Update transaction's category required: true schema: - $ref: '#/definitions/Details' + $ref: '#/definitions/EditableDetails' responses: '200': description: successful operation schema: - $ref: '#/definitions/TransactionDetails' + $ref: '#/definitions/ResponseDetails' '400': description: Invalid values '500': @@ -130,81 +159,113 @@ securityDefinitions: name: Authorization in: header definitions: - Transactions: + ResponseTransactions: type: object properties: status: type: integer format: int64 + example: 200 message: type: string format: string + example: transactions successfully recovered body: type: array items: $ref: '#/definitions/Informations' xml: name: Transactions - Transaction: + ResponseDetails: type: object properties: status: type: integer format: int64 + example: 200 message: type: string format: string + example: details successfully recovered schema: - $ref: '#/definitions/Informations' + $ref: '#/definitions/Details' xml: - name: Transactions - TransactionDetails: + name: Details + ResponseCategories: type: object properties: status: type: integer format: int64 + example: 200 message: type: string format: string + example: categories successfully recovered schema: - $ref: '#/definitions/Details' + $ref: '#/definitions/Categories' xml: name: Details Informations: type: object properties: transactionId: - type: integer - format: int64 + type: string description: transaction ID + example: uT20211105df8 date: type: string - format: Date-time + format: date-time description: transaction date + example: '2020-06-20T12:57:19.005Z' description: type: string description: transaction description + example: Golden Sun Bakery amount: type: integer format: int64 description: transaction amount + example: 5 balance: type: integer format: int64 description: account balance after transaction + example: 2082.79 xml: name: Transaction + Categories: + type: array + items: + $ref: '#/definitions/Category' + xml: + name: Categories Details: type: object properties: transactionId: - type: integer - format: int64 + type: string description: transaction ID + example: uT20211105df8 type: type: string description: transaction type + example: Electronic + category: + type: string + description: transaction category + example: Food + notes: + type: string + description: transaction notes + example: >- + Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, + consectetur, adipisci velit... + xml: + name: Details + EditableDetails: + type: object + properties: category: type: string description: transaction category @@ -220,9 +281,21 @@ definitions: type: string format: date description: start date of transactions recovery (one month ago) + example: '2021-10-12' to: type: string format: date description: end date of transaction recovery (today) + example: '2021-11-12' xml: name: TransactionsDate + Category: + type: string + enum: + - Food + - Clothes + - Charges + - Fuel + - Supplies + - Equipment + - Other