Skip to content

Commit

Permalink
docs: create delete user by id doc (#210)
Browse files Browse the repository at this point in the history
* docs: create delete user by id doc

* fix: update param to userID

* docs: exec make swag

* docs: update param
  • Loading branch information
davidambz authored Oct 1, 2024
1 parent b81e895 commit 42b37eb
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 3 deletions.
15 changes: 13 additions & 2 deletions api/controllers/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,16 @@ func (uc *UserController) FindByID(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
}

// Delete user
// @Summary Delete user
// @Description Marks a user as deleted (soft delete) without removing them from the database
// @Tags User
// @Param userID path string true "User ID"
// @Success 204 "No Content"
// @Failure 400 "Bad request"
// @Failure 401 "Unauthorized"
// @Failure 500 "Internal server error"
// @Router /user/{userID} [delete]
func (uc *UserController) Delete(w http.ResponseWriter, r *http.Request) {
userIDFromTokenStr := r.Header.Get("UserId")
userIDFromToken, err := uniqueEntityId.ParseID(userIDFromTokenStr)
Expand All @@ -195,7 +205,7 @@ func (uc *UserController) Delete(w http.ResponseWriter, r *http.Request) {
return
}

IDStr := chi.URLParam(r, "id")
IDStr := chi.URLParam(r, "userID")
ID, err := uniqueEntityId.ParseID(IDStr)
if err != nil {
uc.logger.Error("[#UserController.Delete] Erro ao tentar converter o body da requisição -> Erro: ", err)
Expand All @@ -212,10 +222,11 @@ func (uc *UserController) Delete(w http.ResponseWriter, r *http.Request) {
err = uc.usecase.Delete(ID)
if err != nil {
uc.logger.Error("[#UserController.Delete] Erro ao tentar deletar o usuário -> Erro: ", err)
http.Error(w, "Erro ao tentar atualizar o usuário ", http.StatusBadRequest)
http.Error(w, "Erro ao tentar atualizar o usuário ", http.StatusInternalServerError)
return
}

w.WriteHeader(http.StatusNoContent)
}

// Enable push notifications
Expand Down
2 changes: 1 addition & 1 deletion api/routes/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func InitRoutes(controllers Controllers, c *chi.Mux) {
r.Patch("/{userID}/pets/{petID}", controllers.PetController.Update)
r.Patch("/{userID}", controllers.UserController.Update)
r.Get("/{userID}", controllers.UserController.FindByID)
r.Delete("/{id}", controllers.UserController.Delete)
r.Delete("/{userID}", controllers.UserController.Delete)
})
private.Route("/settings", func(r chi.Router) {
r.Patch("/push-notifications", controllers.UserController.UpdatePushNotificationSettings)
Expand Down
30 changes: 30 additions & 0 deletions swagger/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,36 @@ const docTemplate = `{
}
}
},
"delete": {
"description": "Marks a user as deleted (soft delete) without removing them from the database",
"tags": [
"User"
],
"summary": "Delete user",
"parameters": [
{
"type": "string",
"description": "User ID",
"name": "userID",
"in": "path",
"required": true
}
],
"responses": {
"204": {
"description": "No Content"
},
"400": {
"description": "Bad request"
},
"401": {
"description": "Unauthorized"
},
"500": {
"description": "Internal server error"
}
}
},
"patch": {
"description": "Updates the details of an existing user based on the provided user ID and payload",
"consumes": [
Expand Down
30 changes: 30 additions & 0 deletions swagger/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,36 @@
}
}
},
"delete": {
"description": "Marks a user as deleted (soft delete) without removing them from the database",
"tags": [
"User"
],
"summary": "Delete user",
"parameters": [
{
"type": "string",
"description": "User ID",
"name": "userID",
"in": "path",
"required": true
}
],
"responses": {
"204": {
"description": "No Content"
},
"400": {
"description": "Bad request"
},
"401": {
"description": "Unauthorized"
},
"500": {
"description": "Internal server error"
}
}
},
"patch": {
"description": "Updates the details of an existing user based on the provided user ID and payload",
"consumes": [
Expand Down
21 changes: 21 additions & 0 deletions swagger/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,27 @@ paths:
tags:
- User
/user/{userID}:
delete:
description: Marks a user as deleted (soft delete) without removing them from
the database
parameters:
- description: User ID
in: path
name: userID
required: true
type: string
responses:
"204":
description: No Content
"400":
description: Bad request
"401":
description: Unauthorized
"500":
description: Internal server error
summary: Delete user
tags:
- User
get:
consumes:
- application/json
Expand Down

0 comments on commit 42b37eb

Please sign in to comment.