Skip to content

Commit

Permalink
update swagger
Browse files Browse the repository at this point in the history
  • Loading branch information
MelanieSarrouy committed Nov 5, 2021
1 parent 6f96b4f commit 1036448
Show file tree
Hide file tree
Showing 6 changed files with 235 additions and 64 deletions.
2 changes: 1 addition & 1 deletion src/actions/actionGetToken.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 1 addition & 3 deletions src/actions/actionGetUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const loadApiUserError = (error) => {
}
}

export const getUser = (token, password) => {
export const getUser = (token) => {
return (dispatch) => {
dispatch(loadApiUser())
axios({
Expand All @@ -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))
Expand Down
6 changes: 4 additions & 2 deletions src/pages/SignIn.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,20 @@ 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)
const [invalidFields, setInvalidFields] = useState('')

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')
}
}
Expand Down
1 change: 0 additions & 1 deletion src/pages/User.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Redirect to="/" />
Expand Down
171 changes: 135 additions & 36 deletions src/swagger/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
{
"name": "Transaction",
"description": "Everything about a transaction"
},
{
"name": "Categories",
"description": "All transactions categories"
}
],
"schemes": [
Expand All @@ -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"
],
Expand Down Expand Up @@ -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": {
Expand All @@ -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"
Expand Down Expand Up @@ -116,7 +163,7 @@
"200": {
"description": "successful operation",
"schema": {
"$ref": "#/definitions/Transaction"
"$ref": "#/definitions/ResponseDetails"
}
},
"400": {
Expand All @@ -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"
Expand All @@ -163,18 +210,18 @@
{
"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": {
Expand All @@ -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",
Expand All @@ -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": {
Expand All @@ -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"
Expand All @@ -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"
]
}
}
}
Loading

0 comments on commit 1036448

Please sign in to comment.