feat: update article and user levels
This commit is contained in:
parent
ff67b72483
commit
95d09c78bd
|
|
@ -34,6 +34,7 @@ type ArticlesCreateRequest struct {
|
|||
Tags string `json:"tags" validate:"required"`
|
||||
AiArticleId *int `json:"aiArticleId"`
|
||||
CreatedAt *string `json:"createdAt"`
|
||||
CreatedById *uint `json:"createdById"`
|
||||
IsPublish *bool `json:"isPublish"`
|
||||
IsDraft *bool `json:"isDraft"`
|
||||
OldId *uint `json:"oldId"`
|
||||
|
|
|
|||
|
|
@ -114,8 +114,16 @@ func (_i *articlesService) Save(req request.ArticlesCreateRequest, authToken str
|
|||
_i.Log.Info().Interface("data", req).Msg("")
|
||||
newReq := req.ToEntity()
|
||||
|
||||
createdBy := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken)
|
||||
newReq.CreatedById = &createdBy.ID
|
||||
if req.CreatedById != nil {
|
||||
createdBy, err := _i.UsersRepo.FindOne(*req.CreatedById)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("User not found")
|
||||
}
|
||||
newReq.CreatedById = &createdBy.ID
|
||||
} else {
|
||||
createdBy := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken)
|
||||
newReq.CreatedById = &createdBy.ID
|
||||
}
|
||||
|
||||
isDraft := true
|
||||
if req.IsDraft == &isDraft {
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ type userLevelsController struct {
|
|||
type UserLevelsController interface {
|
||||
All(c *fiber.Ctx) error
|
||||
Show(c *fiber.Ctx) error
|
||||
ShowByAlias(c *fiber.Ctx) error
|
||||
Save(c *fiber.Ctx) error
|
||||
Update(c *fiber.Ctx) error
|
||||
Delete(c *fiber.Ctx) error
|
||||
|
|
@ -97,6 +98,29 @@ func (_i *userLevelsController) Show(c *fiber.Ctx) error {
|
|||
})
|
||||
}
|
||||
|
||||
// ShowByAlias UserLevels
|
||||
// @Summary Get one UserLevels
|
||||
// @Description API for getting one UserLevels
|
||||
// @Tags UserLevels
|
||||
// @Security Bearer
|
||||
// @Param alias path string true "UserLevels Alias"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
// @Failure 401 {object} response.UnauthorizedError
|
||||
// @Failure 500 {object} response.InternalServerError
|
||||
// @Router /user-levels/alias/{alias} [get]
|
||||
func (_i *userLevelsController) ShowByAlias(c *fiber.Ctx) error {
|
||||
alias := c.Params("alias")
|
||||
userLevelsData, err := _i.userLevelsService.ShowByAlias(alias)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return utilRes.Resp(c, utilRes.Response{
|
||||
Messages: utilRes.Messages{"UserLevels successfully retrieved"},
|
||||
Data: userLevelsData,
|
||||
})
|
||||
}
|
||||
|
||||
// Save UserLevels
|
||||
// @Summary Create UserLevels
|
||||
// @Description API for create UserLevels
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ func (_i *userLevelsRepository) FindOne(id uint) (userLevels *entity.UserLevels,
|
|||
}
|
||||
|
||||
func (_i *userLevelsRepository) FindOneByAlias(alias string) (userLevels *entity.UserLevels, err error) {
|
||||
if err := _i.DB.DB.Where("alias_name = ?", strings.ToUpper(alias)).First(&userLevels).Error; err != nil {
|
||||
if err := _i.DB.DB.Where("alias_name = ?", strings.ToLower(alias)).First(&userLevels).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ type userLevelsService struct {
|
|||
type UserLevelsService interface {
|
||||
All(req request.UserLevelsQueryRequest) (userLevels []*response.UserLevelsResponse, paging paginator.Pagination, err error)
|
||||
Show(id uint) (userLevels *response.UserLevelsResponse, err error)
|
||||
ShowByAlias(alias string) (userLevels *response.UserLevelsResponse, err error)
|
||||
Save(req request.UserLevelsCreateRequest) (userLevels *entity.UserLevels, err error)
|
||||
Update(id uint, req request.UserLevelsUpdateRequest) (err error)
|
||||
Delete(id uint) error
|
||||
|
|
@ -57,6 +58,15 @@ func (_i *userLevelsService) Show(id uint) (userLevels *response.UserLevelsRespo
|
|||
return mapper.UserLevelsResponseMapper(result), nil
|
||||
}
|
||||
|
||||
func (_i *userLevelsService) ShowByAlias(alias string) (userLevels *response.UserLevelsResponse, err error) {
|
||||
result, err := _i.Repo.FindOneByAlias(alias)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return mapper.UserLevelsResponseMapper(result), nil
|
||||
}
|
||||
|
||||
func (_i *userLevelsService) Save(req request.UserLevelsCreateRequest) (userLevels *entity.UserLevels, err error) {
|
||||
_i.Log.Info().Interface("data", req).Msg("")
|
||||
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@ func (_i *UserLevelsRouter) RegisterUserLevelsRoutes() {
|
|||
_i.App.Route("/user-levels", func(router fiber.Router) {
|
||||
router.Get("/", userLevelsController.All)
|
||||
router.Get("/:id", userLevelsController.Show)
|
||||
router.Get("/alias/:alias", userLevelsController.ShowByAlias)
|
||||
router.Post("/", userLevelsController.Save)
|
||||
router.Put("/:id", userLevelsController.Update)
|
||||
router.Delete("/:id", userLevelsController.Delete)
|
||||
|
|
|
|||
|
|
@ -5471,6 +5471,55 @@ const docTemplate = `{
|
|||
}
|
||||
}
|
||||
},
|
||||
"/user-levels/alias/{alias}": {
|
||||
"get": {
|
||||
"security": [
|
||||
{
|
||||
"Bearer": []
|
||||
}
|
||||
],
|
||||
"description": "API for getting one UserLevels",
|
||||
"tags": [
|
||||
"UserLevels"
|
||||
],
|
||||
"summary": "Get one UserLevels",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "UserLevels Alias",
|
||||
"name": "alias",
|
||||
"in": "path",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"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": [
|
||||
|
|
@ -7567,6 +7616,9 @@ const docTemplate = `{
|
|||
"createdAt": {
|
||||
"type": "string"
|
||||
},
|
||||
"createdById": {
|
||||
"type": "integer"
|
||||
},
|
||||
"description": {
|
||||
"type": "string"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -5460,6 +5460,55 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"/user-levels/alias/{alias}": {
|
||||
"get": {
|
||||
"security": [
|
||||
{
|
||||
"Bearer": []
|
||||
}
|
||||
],
|
||||
"description": "API for getting one UserLevels",
|
||||
"tags": [
|
||||
"UserLevels"
|
||||
],
|
||||
"summary": "Get one UserLevels",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "UserLevels Alias",
|
||||
"name": "alias",
|
||||
"in": "path",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"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": [
|
||||
|
|
@ -7556,6 +7605,9 @@
|
|||
"createdAt": {
|
||||
"type": "string"
|
||||
},
|
||||
"createdById": {
|
||||
"type": "integer"
|
||||
},
|
||||
"description": {
|
||||
"type": "string"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -227,6 +227,8 @@ definitions:
|
|||
type: string
|
||||
createdAt:
|
||||
type: string
|
||||
createdById:
|
||||
type: integer
|
||||
description:
|
||||
type: string
|
||||
htmlDescription:
|
||||
|
|
@ -4334,6 +4336,37 @@ paths:
|
|||
summary: update UserLevels
|
||||
tags:
|
||||
- UserLevels
|
||||
/user-levels/alias/{alias}:
|
||||
get:
|
||||
description: API for getting one UserLevels
|
||||
parameters:
|
||||
- description: UserLevels Alias
|
||||
in: path
|
||||
name: alias
|
||||
required: true
|
||||
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: Get one UserLevels
|
||||
tags:
|
||||
- UserLevels
|
||||
/user-role-accesses:
|
||||
get:
|
||||
description: API for getting all UserRoleAccesses
|
||||
|
|
|
|||
Loading…
Reference in New Issue