feat: update user levels

This commit is contained in:
hanif salafi 2025-04-14 14:17:41 +07:00
parent e4da5dc9f4
commit 518c779b5c
6 changed files with 263 additions and 173 deletions

View File

@ -15,6 +15,8 @@ type FeedbacksQueryRequest struct {
Message *string `json:"message"` Message *string `json:"message"`
CommentFromName *string `json:"commentFromName"` CommentFromName *string `json:"commentFromName"`
CommentFromEmail *string `json:"commentFromEmail"` CommentFromEmail *string `json:"commentFromEmail"`
StartDate *string `json:"startDate"`
EndDate *string `json:"endDate"`
StatusId *int `json:"statusId"` StatusId *int `json:"statusId"`
Pagination *paginator.Pagination `json:"pagination"` Pagination *paginator.Pagination `json:"pagination"`
} }

View File

@ -6,6 +6,7 @@ import (
"go-humas-be/app/module/user_levels/service" "go-humas-be/app/module/user_levels/service"
"go-humas-be/utils/paginator" "go-humas-be/utils/paginator"
"strconv" "strconv"
"strings"
utilRes "go-humas-be/utils/response" utilRes "go-humas-be/utils/response"
utilVal "go-humas-be/utils/validator" utilVal "go-humas-be/utils/validator"
@ -220,27 +221,29 @@ func (_i *userLevelsController) Delete(c *fiber.Ctx) error {
// @Tags UserLevels // @Tags UserLevels
// @Security Bearer // @Security Bearer
// @Param Authorization header string false "Insert your access token" default(Bearer <Add access token here>) // @Param Authorization header string false "Insert your access token" default(Bearer <Add access token here>)
// @Param id query int false "user level id" // @Param payload body request.UserLevelsApprovalRequest true "Required payload"
// @Param isApprovalActive query string false "approval status"
// @Success 200 {object} response.Response // @Success 200 {object} response.Response
// @Failure 400 {object} response.BadRequestError // @Failure 400 {object} response.BadRequestError
// @Failure 401 {object} response.UnauthorizedError // @Failure 401 {object} response.UnauthorizedError
// @Failure 500 {object} response.InternalServerError // @Failure 500 {object} response.InternalServerError
// @Router /articles/enable-approval [post] // @Router /user-levels/enable-approval [post]
func (_i *userLevelsController) EnableApproval(c *fiber.Ctx) error { func (_i *userLevelsController) EnableApproval(c *fiber.Ctx) error {
id, err := strconv.ParseUint(c.Query("id"), 10, 0) req := new(request.UserLevelsApprovalRequest)
if err != nil { if err := utilVal.ParseAndValidate(c, req); err != nil {
return err
}
isApprovalActive, err := strconv.ParseBool(c.Query("isPublish"))
if err != nil {
return err return err
} }
err = _i.userLevelsService.EnableApproval(uint(id), isApprovalActive) ids := strings.Split(req.Ids, ",")
for _, id := range ids {
idUint, err := strconv.ParseUint(id, 10, 64)
if err != nil { if err != nil {
return err return err
} }
err = _i.userLevelsService.EnableApproval(uint(idUint), req.IsApprovalActive)
if err != nil {
return err
}
}
return utilRes.Resp(c, utilRes.Response{ return utilRes.Resp(c, utilRes.Response{
Success: true, Success: true,

View File

@ -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 { type UserLevelsQueryRequestContext struct {
Name string `json:"name"` Name string `json:"name"`
LevelNumber string `json:"levelNumber"` LevelNumber string `json:"levelNumber"`

View File

@ -507,6 +507,14 @@ const docTemplate = `{
], ],
"summary": "Update Publish Advertisement", "summary": "Update Publish Advertisement",
"parameters": [ "parameters": [
{
"type": "string",
"default": "Bearer \u003cAdd access token here\u003e",
"description": "Insert your access token",
"name": "Authorization",
"in": "header",
"required": true
},
{ {
"type": "integer", "type": "integer",
"description": "Advertisement ID", "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": { "/articles/publish-scheduling": {
"post": { "post": {
"security": [ "security": [
@ -4773,11 +4720,21 @@ const docTemplate = `{
"name": "commentFromName", "name": "commentFromName",
"in": "query" "in": "query"
}, },
{
"type": "string",
"name": "endDate",
"in": "query"
},
{ {
"type": "string", "type": "string",
"name": "message", "name": "message",
"in": "query" "in": "query"
}, },
{
"type": "string",
"name": "startDate",
"in": "query"
},
{ {
"type": "integer", "type": "integer",
"name": "statusId", "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}": { "/user-levels/{id}": {
"get": { "get": {
"security": [ "security": [
@ -9927,6 +9942,21 @@ const docTemplate = `{
} }
} }
}, },
"request.UserLevelsApprovalRequest": {
"type": "object",
"required": [
"ids",
"isApprovalActive"
],
"properties": {
"ids": {
"type": "string"
},
"isApprovalActive": {
"type": "boolean"
}
}
},
"request.UserLevelsCreateRequest": { "request.UserLevelsCreateRequest": {
"type": "object", "type": "object",
"required": [ "required": [

View File

@ -496,6 +496,14 @@
], ],
"summary": "Update Publish Advertisement", "summary": "Update Publish Advertisement",
"parameters": [ "parameters": [
{
"type": "string",
"default": "Bearer \u003cAdd access token here\u003e",
"description": "Insert your access token",
"name": "Authorization",
"in": "header",
"required": true
},
{ {
"type": "integer", "type": "integer",
"description": "Advertisement ID", "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": { "/articles/publish-scheduling": {
"post": { "post": {
"security": [ "security": [
@ -4762,11 +4709,21 @@
"name": "commentFromName", "name": "commentFromName",
"in": "query" "in": "query"
}, },
{
"type": "string",
"name": "endDate",
"in": "query"
},
{ {
"type": "string", "type": "string",
"name": "message", "name": "message",
"in": "query" "in": "query"
}, },
{
"type": "string",
"name": "startDate",
"in": "query"
},
{ {
"type": "integer", "type": "integer",
"name": "statusId", "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}": { "/user-levels/{id}": {
"get": { "get": {
"security": [ "security": [
@ -9916,6 +9931,21 @@
} }
} }
}, },
"request.UserLevelsApprovalRequest": {
"type": "object",
"required": [
"ids",
"isApprovalActive"
],
"properties": {
"ids": {
"type": "string"
},
"isApprovalActive": {
"type": "boolean"
}
}
},
"request.UserLevelsCreateRequest": { "request.UserLevelsCreateRequest": {
"type": "object", "type": "object",
"required": [ "required": [

View File

@ -589,6 +589,16 @@ definitions:
username: username:
type: string type: string
type: object type: object
request.UserLevelsApprovalRequest:
properties:
ids:
type: string
isApprovalActive:
type: boolean
required:
- ids
- isApprovalActive
type: object
request.UserLevelsCreateRequest: request.UserLevelsCreateRequest:
properties: properties:
aliasName: aliasName:
@ -1321,6 +1331,12 @@ paths:
put: put:
description: API for Update Publish Advertisement description: API for Update Publish Advertisement
parameters: parameters:
- default: Bearer <Add access token here>
description: Insert your access token
in: header
name: Authorization
required: true
type: string
- description: Advertisement ID - description: Advertisement ID
in: path in: path
name: id name: id
@ -3100,45 +3116,6 @@ paths:
summary: Update Banner Articles summary: Update Banner Articles
tags: tags:
- Articles - Articles
/articles/enable-approval:
post:
description: API for Enable Approval of Article
parameters:
- default: Bearer <Add access token here>
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: /articles/publish-scheduling:
post: post:
description: API for Publish Schedule of Article description: API for Publish Schedule of Article
@ -3924,9 +3901,15 @@ paths:
- in: query - in: query
name: commentFromName name: commentFromName
type: string type: string
- in: query
name: endDate
type: string
- in: query - in: query
name: message name: message
type: string type: string
- in: query
name: startDate
type: string
- in: query - in: query
name: statusId name: statusId
type: integer type: integer
@ -5539,6 +5522,43 @@ paths:
summary: Get one UserLevels summary: Get one UserLevels
tags: tags:
- UserLevels - UserLevels
/user-levels/enable-approval:
post:
description: API for Enable Approval of Article
parameters:
- default: Bearer <Add access token here>
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: /user-role-accesses:
get: get:
description: API for getting all UserRoleAccesses description: API for getting all UserRoleAccesses