From 324a91489c83a48ab88758e9982b954515b13edf Mon Sep 17 00:00:00 2001 From: AzenKain Date: Fri, 17 Apr 2026 15:44:34 +0700 Subject: [PATCH] UPDATE: fix bug --- docs/docs.go | 234 +++++++++++------------ docs/swagger.json | 234 +++++++++++------------ docs/swagger.yaml | 149 +++++++-------- internal/services/verificationService.go | 8 +- 4 files changed, 309 insertions(+), 316 deletions(-) diff --git a/docs/docs.go b/docs/docs.go index 4f68cc2..c1ba207 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -1503,6 +1503,62 @@ const docTemplate = `{ } } } + }, + "put": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "Update the profile details of the currently authenticated user", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Users" + ], + "summary": "Update user profile", + "parameters": [ + { + "type": "string", + "description": "User ID", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "Update Profile request", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/history-api_internal_dtos_request.UpdateProfileDto" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/history-api_internal_dtos_response.CommonResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/history-api_internal_dtos_response.CommonResponse" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/history-api_internal_dtos_response.CommonResponse" + } + } + } } }, "/users/current/application": { @@ -1573,6 +1629,64 @@ const docTemplate = `{ } } }, + "/users/current/password": { + "patch": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "Update the password for the currently authenticated user", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Users" + ], + "summary": "Change user password", + "parameters": [ + { + "type": "string", + "description": "User ID", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "Change Password request", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/history-api_internal_dtos_request.ChangePasswordDto" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/history-api_internal_dtos_response.CommonResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/history-api_internal_dtos_response.CommonResponse" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/history-api_internal_dtos_response.CommonResponse" + } + } + } + } + }, "/users/{id}": { "get": { "security": [ @@ -1615,62 +1729,6 @@ const docTemplate = `{ } } }, - "put": { - "security": [ - { - "BearerAuth": [] - } - ], - "description": "Update the profile details of the currently authenticated user", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "Users" - ], - "summary": "Update user profile", - "parameters": [ - { - "type": "string", - "description": "User ID", - "name": "id", - "in": "path", - "required": true - }, - { - "description": "Update Profile request", - "name": "request", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/history-api_internal_dtos_request.UpdateProfileDto" - } - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/history-api_internal_dtos_response.CommonResponse" - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/history-api_internal_dtos_response.CommonResponse" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/history-api_internal_dtos_response.CommonResponse" - } - } - } - }, "delete": { "security": [ { @@ -1789,64 +1847,6 @@ const docTemplate = `{ } } }, - "/users/{id}/password": { - "patch": { - "security": [ - { - "BearerAuth": [] - } - ], - "description": "Update the password for the currently authenticated user", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "Users" - ], - "summary": "Change user password", - "parameters": [ - { - "type": "string", - "description": "User ID", - "name": "id", - "in": "path", - "required": true - }, - { - "description": "Change Password request", - "name": "request", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/history-api_internal_dtos_request.ChangePasswordDto" - } - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/history-api_internal_dtos_response.CommonResponse" - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/history-api_internal_dtos_response.CommonResponse" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/history-api_internal_dtos_response.CommonResponse" - } - } - } - } - }, "/users/{id}/restore": { "patch": { "security": [ @@ -1972,8 +1972,7 @@ const docTemplate = `{ "history-api_internal_dtos_request.ChangeRoleDto": { "type": "object", "required": [ - "role_ids", - "user_id" + "role_ids" ], "properties": { "role_ids": { @@ -1982,9 +1981,6 @@ const docTemplate = `{ "items": { "type": "string" } - }, - "user_id": { - "type": "string" } } }, diff --git a/docs/swagger.json b/docs/swagger.json index 29b1626..1ca6d99 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -1496,6 +1496,62 @@ } } } + }, + "put": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "Update the profile details of the currently authenticated user", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Users" + ], + "summary": "Update user profile", + "parameters": [ + { + "type": "string", + "description": "User ID", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "Update Profile request", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/history-api_internal_dtos_request.UpdateProfileDto" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/history-api_internal_dtos_response.CommonResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/history-api_internal_dtos_response.CommonResponse" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/history-api_internal_dtos_response.CommonResponse" + } + } + } } }, "/users/current/application": { @@ -1566,6 +1622,64 @@ } } }, + "/users/current/password": { + "patch": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "Update the password for the currently authenticated user", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Users" + ], + "summary": "Change user password", + "parameters": [ + { + "type": "string", + "description": "User ID", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "Change Password request", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/history-api_internal_dtos_request.ChangePasswordDto" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/history-api_internal_dtos_response.CommonResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/history-api_internal_dtos_response.CommonResponse" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/history-api_internal_dtos_response.CommonResponse" + } + } + } + } + }, "/users/{id}": { "get": { "security": [ @@ -1608,62 +1722,6 @@ } } }, - "put": { - "security": [ - { - "BearerAuth": [] - } - ], - "description": "Update the profile details of the currently authenticated user", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "Users" - ], - "summary": "Update user profile", - "parameters": [ - { - "type": "string", - "description": "User ID", - "name": "id", - "in": "path", - "required": true - }, - { - "description": "Update Profile request", - "name": "request", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/history-api_internal_dtos_request.UpdateProfileDto" - } - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/history-api_internal_dtos_response.CommonResponse" - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/history-api_internal_dtos_response.CommonResponse" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/history-api_internal_dtos_response.CommonResponse" - } - } - } - }, "delete": { "security": [ { @@ -1782,64 +1840,6 @@ } } }, - "/users/{id}/password": { - "patch": { - "security": [ - { - "BearerAuth": [] - } - ], - "description": "Update the password for the currently authenticated user", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "Users" - ], - "summary": "Change user password", - "parameters": [ - { - "type": "string", - "description": "User ID", - "name": "id", - "in": "path", - "required": true - }, - { - "description": "Change Password request", - "name": "request", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/history-api_internal_dtos_request.ChangePasswordDto" - } - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/history-api_internal_dtos_response.CommonResponse" - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/history-api_internal_dtos_response.CommonResponse" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/history-api_internal_dtos_response.CommonResponse" - } - } - } - } - }, "/users/{id}/restore": { "patch": { "security": [ @@ -1965,8 +1965,7 @@ "history-api_internal_dtos_request.ChangeRoleDto": { "type": "object", "required": [ - "role_ids", - "user_id" + "role_ids" ], "properties": { "role_ids": { @@ -1975,9 +1974,6 @@ "items": { "type": "string" } - }, - "user_id": { - "type": "string" } } }, diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 0646476..a3a4dca 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -21,11 +21,8 @@ definitions: type: string minItems: 1 type: array - user_id: - type: string required: - role_ids - - user_id type: object history-api_internal_dtos_request.CreateTokenDto: properties: @@ -1242,42 +1239,6 @@ paths: summary: Get user by ID tags: - Users - put: - consumes: - - application/json - description: Update the profile details of the currently authenticated user - parameters: - - description: User ID - in: path - name: id - required: true - type: string - - description: Update Profile request - in: body - name: request - required: true - schema: - $ref: '#/definitions/history-api_internal_dtos_request.UpdateProfileDto' - produces: - - application/json - responses: - "200": - description: OK - schema: - $ref: '#/definitions/history-api_internal_dtos_response.CommonResponse' - "400": - description: Bad Request - schema: - $ref: '#/definitions/history-api_internal_dtos_response.CommonResponse' - "500": - description: Internal Server Error - schema: - $ref: '#/definitions/history-api_internal_dtos_response.CommonResponse' - security: - - BearerAuth: [] - summary: Update user profile - tags: - - Users /users/{id}/application: get: consumes: @@ -1328,43 +1289,6 @@ paths: summary: Get user's media by user ID tags: - Users - /users/{id}/password: - patch: - consumes: - - application/json - description: Update the password for the currently authenticated user - parameters: - - description: User ID - in: path - name: id - required: true - type: string - - description: Change Password request - in: body - name: request - required: true - schema: - $ref: '#/definitions/history-api_internal_dtos_request.ChangePasswordDto' - produces: - - application/json - responses: - "200": - description: OK - schema: - $ref: '#/definitions/history-api_internal_dtos_response.CommonResponse' - "400": - description: Bad Request - schema: - $ref: '#/definitions/history-api_internal_dtos_response.CommonResponse' - "500": - description: Internal Server Error - schema: - $ref: '#/definitions/history-api_internal_dtos_response.CommonResponse' - security: - - BearerAuth: [] - summary: Change user password - tags: - - Users /users/{id}/restore: patch: consumes: @@ -1451,6 +1375,42 @@ paths: summary: Get current user profile tags: - Users + put: + consumes: + - application/json + description: Update the profile details of the currently authenticated user + parameters: + - description: User ID + in: path + name: id + required: true + type: string + - description: Update Profile request + in: body + name: request + required: true + schema: + $ref: '#/definitions/history-api_internal_dtos_request.UpdateProfileDto' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/history-api_internal_dtos_response.CommonResponse' + "400": + description: Bad Request + schema: + $ref: '#/definitions/history-api_internal_dtos_response.CommonResponse' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/history-api_internal_dtos_response.CommonResponse' + security: + - BearerAuth: [] + summary: Update user profile + tags: + - Users /users/current/application: get: consumes: @@ -1493,6 +1453,43 @@ paths: summary: Get current user's media tags: - Users + /users/current/password: + patch: + consumes: + - application/json + description: Update the password for the currently authenticated user + parameters: + - description: User ID + in: path + name: id + required: true + type: string + - description: Change Password request + in: body + name: request + required: true + schema: + $ref: '#/definitions/history-api_internal_dtos_request.ChangePasswordDto' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/history-api_internal_dtos_response.CommonResponse' + "400": + description: Bad Request + schema: + $ref: '#/definitions/history-api_internal_dtos_response.CommonResponse' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/history-api_internal_dtos_response.CommonResponse' + security: + - BearerAuth: [] + summary: Change user password + tags: + - Users securityDefinitions: BearerAuth: description: Type "Bearer " followed by a space and JWT token. diff --git a/internal/services/verificationService.go b/internal/services/verificationService.go index e1e0a06..682bc40 100644 --- a/internal/services/verificationService.go +++ b/internal/services/verificationService.go @@ -124,7 +124,11 @@ func (v *verificationService) DeleteVerification(ctx context.Context, claims *re } shoudDelete := false - if slices.Contains(claims.Roles, constants.ADMIN) || slices.Contains(claims.Roles, constants.MOD) || verification.User.ID == claims.UId { + if slices.Contains(claims.Roles, constants.ADMIN) || slices.Contains(claims.Roles, constants.MOD) { + shoudDelete = true + } + + if verification.User.ID == claims.UId && verification.Status == constants.StatusPending { shoudDelete = true } @@ -132,7 +136,7 @@ func (v *verificationService) DeleteVerification(ctx context.Context, claims *re return fiber.NewError(fiber.StatusForbidden, "You don't have permission to delete this verification") } - err = v.mediaRepo.Delete(ctx, verificationIdUUID) + err = v.verificationRepo.Delete(ctx, verificationIdUUID) if err != nil { return fiber.NewError(fiber.StatusInternalServerError, err.Error()) }