From 518c779b5c00c5161f2d0bc5d911de62a1b0ae68 Mon Sep 17 00:00:00 2001 From: hanif salafi Date: Mon, 14 Apr 2025 14:17:41 +0700 Subject: [PATCH] feat: update user levels --- .../feedbacks/request/feedbacks.request.go | 2 + .../controller/user_levels.controller.go | 27 ++-- .../request/user_levels.request.go | 5 + docs/swagger/docs.go | 152 +++++++++++------- docs/swagger/swagger.json | 152 +++++++++++------- docs/swagger/swagger.yaml | 98 ++++++----- 6 files changed, 263 insertions(+), 173 deletions(-) diff --git a/app/module/feedbacks/request/feedbacks.request.go b/app/module/feedbacks/request/feedbacks.request.go index 874e0f4..653d43c 100644 --- a/app/module/feedbacks/request/feedbacks.request.go +++ b/app/module/feedbacks/request/feedbacks.request.go @@ -15,6 +15,8 @@ type FeedbacksQueryRequest struct { Message *string `json:"message"` CommentFromName *string `json:"commentFromName"` CommentFromEmail *string `json:"commentFromEmail"` + StartDate *string `json:"startDate"` + EndDate *string `json:"endDate"` StatusId *int `json:"statusId"` Pagination *paginator.Pagination `json:"pagination"` } diff --git a/app/module/user_levels/controller/user_levels.controller.go b/app/module/user_levels/controller/user_levels.controller.go index 6862929..291fd1f 100644 --- a/app/module/user_levels/controller/user_levels.controller.go +++ b/app/module/user_levels/controller/user_levels.controller.go @@ -6,6 +6,7 @@ import ( "go-humas-be/app/module/user_levels/service" "go-humas-be/utils/paginator" "strconv" + "strings" utilRes "go-humas-be/utils/response" utilVal "go-humas-be/utils/validator" @@ -220,26 +221,28 @@ func (_i *userLevelsController) Delete(c *fiber.Ctx) error { // @Tags UserLevels // @Security Bearer // @Param Authorization header string false "Insert your access token" default(Bearer ) -// @Param id query int false "user level id" -// @Param isApprovalActive query string false "approval status" +// @Param payload body request.UserLevelsApprovalRequest true "Required payload" // @Success 200 {object} response.Response // @Failure 400 {object} response.BadRequestError // @Failure 401 {object} response.UnauthorizedError // @Failure 500 {object} response.InternalServerError -// @Router /articles/enable-approval [post] +// @Router /user-levels/enable-approval [post] func (_i *userLevelsController) EnableApproval(c *fiber.Ctx) error { - id, err := strconv.ParseUint(c.Query("id"), 10, 0) - if err != nil { - return err - } - isApprovalActive, err := strconv.ParseBool(c.Query("isPublish")) - if err != nil { + req := new(request.UserLevelsApprovalRequest) + if err := utilVal.ParseAndValidate(c, req); err != nil { return err } - err = _i.userLevelsService.EnableApproval(uint(id), isApprovalActive) - if err != nil { - return err + ids := strings.Split(req.Ids, ",") + for _, id := range ids { + idUint, err := strconv.ParseUint(id, 10, 64) + if err != nil { + return err + } + err = _i.userLevelsService.EnableApproval(uint(idUint), req.IsApprovalActive) + if err != nil { + return err + } } return utilRes.Resp(c, utilRes.Response{ diff --git a/app/module/user_levels/request/user_levels.request.go b/app/module/user_levels/request/user_levels.request.go index c55cbe4..4c715c0 100644 --- a/app/module/user_levels/request/user_levels.request.go +++ b/app/module/user_levels/request/user_levels.request.go @@ -66,6 +66,11 @@ func (req UserLevelsUpdateRequest) ToEntity() *entity.UserLevels { } } +type UserLevelsApprovalRequest struct { + Ids string `json:"ids" validate:"required"` + IsApprovalActive bool `json:"isApprovalActive" validate:"required"` +} + type UserLevelsQueryRequestContext struct { Name string `json:"name"` LevelNumber string `json:"levelNumber"` diff --git a/docs/swagger/docs.go b/docs/swagger/docs.go index 7746657..93ac0bd 100644 --- a/docs/swagger/docs.go +++ b/docs/swagger/docs.go @@ -507,6 +507,14 @@ const docTemplate = `{ ], "summary": "Update Publish Advertisement", "parameters": [ + { + "type": "string", + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", + "in": "header", + "required": true + }, { "type": "integer", "description": "Advertisement ID", @@ -3319,67 +3327,6 @@ const docTemplate = `{ } } }, - "/articles/enable-approval": { - "post": { - "security": [ - { - "Bearer": [] - } - ], - "description": "API for Enable Approval of Article", - "tags": [ - "UserLevels" - ], - "summary": "EnableApproval Articles", - "parameters": [ - { - "type": "string", - "default": "Bearer \u003cAdd access token here\u003e", - "description": "Insert your access token", - "name": "Authorization", - "in": "header" - }, - { - "type": "integer", - "description": "user level id", - "name": "id", - "in": "query" - }, - { - "type": "string", - "description": "approval status", - "name": "isApprovalActive", - "in": "query" - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/response.Response" - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/response.BadRequestError" - } - }, - "401": { - "description": "Unauthorized", - "schema": { - "$ref": "#/definitions/response.UnauthorizedError" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/response.InternalServerError" - } - } - } - } - }, "/articles/publish-scheduling": { "post": { "security": [ @@ -4773,11 +4720,21 @@ const docTemplate = `{ "name": "commentFromName", "in": "query" }, + { + "type": "string", + "name": "endDate", + "in": "query" + }, { "type": "string", "name": "message", "in": "query" }, + { + "type": "string", + "name": "startDate", + "in": "query" + }, { "type": "integer", "name": "statusId", @@ -7163,6 +7120,64 @@ const docTemplate = `{ } } }, + "/user-levels/enable-approval": { + "post": { + "security": [ + { + "Bearer": [] + } + ], + "description": "API for Enable Approval of Article", + "tags": [ + "UserLevels" + ], + "summary": "EnableApproval Articles", + "parameters": [ + { + "type": "string", + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", + "in": "header" + }, + { + "description": "Required payload", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.UserLevelsApprovalRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/response.Response" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/response.BadRequestError" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/response.UnauthorizedError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/response.InternalServerError" + } + } + } + } + }, "/user-levels/{id}": { "get": { "security": [ @@ -9927,6 +9942,21 @@ const docTemplate = `{ } } }, + "request.UserLevelsApprovalRequest": { + "type": "object", + "required": [ + "ids", + "isApprovalActive" + ], + "properties": { + "ids": { + "type": "string" + }, + "isApprovalActive": { + "type": "boolean" + } + } + }, "request.UserLevelsCreateRequest": { "type": "object", "required": [ diff --git a/docs/swagger/swagger.json b/docs/swagger/swagger.json index f10b7aa..f211eae 100644 --- a/docs/swagger/swagger.json +++ b/docs/swagger/swagger.json @@ -496,6 +496,14 @@ ], "summary": "Update Publish Advertisement", "parameters": [ + { + "type": "string", + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", + "in": "header", + "required": true + }, { "type": "integer", "description": "Advertisement ID", @@ -3308,67 +3316,6 @@ } } }, - "/articles/enable-approval": { - "post": { - "security": [ - { - "Bearer": [] - } - ], - "description": "API for Enable Approval of Article", - "tags": [ - "UserLevels" - ], - "summary": "EnableApproval Articles", - "parameters": [ - { - "type": "string", - "default": "Bearer \u003cAdd access token here\u003e", - "description": "Insert your access token", - "name": "Authorization", - "in": "header" - }, - { - "type": "integer", - "description": "user level id", - "name": "id", - "in": "query" - }, - { - "type": "string", - "description": "approval status", - "name": "isApprovalActive", - "in": "query" - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/response.Response" - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/response.BadRequestError" - } - }, - "401": { - "description": "Unauthorized", - "schema": { - "$ref": "#/definitions/response.UnauthorizedError" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/response.InternalServerError" - } - } - } - } - }, "/articles/publish-scheduling": { "post": { "security": [ @@ -4762,11 +4709,21 @@ "name": "commentFromName", "in": "query" }, + { + "type": "string", + "name": "endDate", + "in": "query" + }, { "type": "string", "name": "message", "in": "query" }, + { + "type": "string", + "name": "startDate", + "in": "query" + }, { "type": "integer", "name": "statusId", @@ -7152,6 +7109,64 @@ } } }, + "/user-levels/enable-approval": { + "post": { + "security": [ + { + "Bearer": [] + } + ], + "description": "API for Enable Approval of Article", + "tags": [ + "UserLevels" + ], + "summary": "EnableApproval Articles", + "parameters": [ + { + "type": "string", + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", + "in": "header" + }, + { + "description": "Required payload", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.UserLevelsApprovalRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/response.Response" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/response.BadRequestError" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/response.UnauthorizedError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/response.InternalServerError" + } + } + } + } + }, "/user-levels/{id}": { "get": { "security": [ @@ -9916,6 +9931,21 @@ } } }, + "request.UserLevelsApprovalRequest": { + "type": "object", + "required": [ + "ids", + "isApprovalActive" + ], + "properties": { + "ids": { + "type": "string" + }, + "isApprovalActive": { + "type": "boolean" + } + } + }, "request.UserLevelsCreateRequest": { "type": "object", "required": [ diff --git a/docs/swagger/swagger.yaml b/docs/swagger/swagger.yaml index 215e53e..e438202 100644 --- a/docs/swagger/swagger.yaml +++ b/docs/swagger/swagger.yaml @@ -589,6 +589,16 @@ definitions: username: type: string type: object + request.UserLevelsApprovalRequest: + properties: + ids: + type: string + isApprovalActive: + type: boolean + required: + - ids + - isApprovalActive + type: object request.UserLevelsCreateRequest: properties: aliasName: @@ -1321,6 +1331,12 @@ paths: put: description: API for Update Publish Advertisement parameters: + - default: Bearer + description: Insert your access token + in: header + name: Authorization + required: true + type: string - description: Advertisement ID in: path name: id @@ -3100,45 +3116,6 @@ paths: summary: Update Banner Articles tags: - Articles - /articles/enable-approval: - post: - description: API for Enable Approval of Article - parameters: - - default: Bearer - description: Insert your access token - in: header - name: Authorization - type: string - - description: user level id - in: query - name: id - type: integer - - description: approval status - in: query - name: isApprovalActive - type: string - responses: - "200": - description: OK - schema: - $ref: '#/definitions/response.Response' - "400": - description: Bad Request - schema: - $ref: '#/definitions/response.BadRequestError' - "401": - description: Unauthorized - schema: - $ref: '#/definitions/response.UnauthorizedError' - "500": - description: Internal Server Error - schema: - $ref: '#/definitions/response.InternalServerError' - security: - - Bearer: [] - summary: EnableApproval Articles - tags: - - UserLevels /articles/publish-scheduling: post: description: API for Publish Schedule of Article @@ -3924,9 +3901,15 @@ paths: - in: query name: commentFromName type: string + - in: query + name: endDate + type: string - in: query name: message type: string + - in: query + name: startDate + type: string - in: query name: statusId type: integer @@ -5539,6 +5522,43 @@ paths: summary: Get one UserLevels tags: - UserLevels + /user-levels/enable-approval: + post: + description: API for Enable Approval of Article + parameters: + - default: Bearer + description: Insert your access token + in: header + name: Authorization + type: string + - description: Required payload + in: body + name: payload + required: true + schema: + $ref: '#/definitions/request.UserLevelsApprovalRequest' + responses: + "200": + description: OK + schema: + $ref: '#/definitions/response.Response' + "400": + description: Bad Request + schema: + $ref: '#/definitions/response.BadRequestError' + "401": + description: Unauthorized + schema: + $ref: '#/definitions/response.UnauthorizedError' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/response.InternalServerError' + security: + - Bearer: [] + summary: EnableApproval Articles + tags: + - UserLevels /user-role-accesses: get: description: API for getting all UserRoleAccesses