feat: update ppid data
This commit is contained in:
parent
147ec09ebf
commit
88eee0f411
|
|
@ -6,6 +6,7 @@ type PpidDatas struct {
|
|||
ID uint `json:"id" gorm:"primaryKey;type:int4;autoIncrement"`
|
||||
Title string `json:"title" gorm:"type:varchar"`
|
||||
Description string `json:"description" gorm:"type:varchar"`
|
||||
Slug string `json:"slug" gorm:"type:varchar"`
|
||||
CategoryId uint `json:"category_id" gorm:"type:int4"`
|
||||
CreatedById *uint `json:"created_by_id" gorm:"type:int4"`
|
||||
LevelGroupId *int `json:"level_group_id" gorm:"type:int4"`
|
||||
|
|
|
|||
|
|
@ -77,19 +77,15 @@ func (_i *ppidDatasController) All(c *fiber.Ctx) error {
|
|||
// @Description API for getting one PpidDatas
|
||||
// @Tags PPID Data
|
||||
// @Security Bearer
|
||||
// @Param id path int true "PpidDatas ID"
|
||||
// @Param id path string true "PpidDatas [ ID / Slug ]"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
// @Failure 401 {object} response.UnauthorizedError
|
||||
// @Failure 500 {object} response.InternalServerError
|
||||
// @Router /ppid-datas/{id} [get]
|
||||
func (_i *ppidDatasController) Show(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseUint(c.Params("id"), 10, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ppidDatasData, err := _i.ppidDatasService.Show(uint(id))
|
||||
id := c.Params("id")
|
||||
ppidDatasData, err := _i.ppidDatasService.Show(id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@ func PpidDatasResponseMapper(
|
|||
ID: ppidDatasReq.ID,
|
||||
Title: ppidDatasReq.Title,
|
||||
Description: ppidDatasReq.Description,
|
||||
Slug: ppidDatasReq.Slug,
|
||||
CategoryId: ppidDatasReq.CategoryId,
|
||||
CategoryName: &categoryName,
|
||||
CreatedById: ppidDatasReq.CreatedById,
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ type ppidDatasRepository struct {
|
|||
type PpidDatasRepository interface {
|
||||
GetAll(req request.PpidDatasQueryRequest) (ppidDatass []*entity.PpidDatas, paging paginator.Pagination, err error)
|
||||
FindOne(id uint) (ppidDatas *entity.PpidDatas, err error)
|
||||
FindOneUsingSlug(slug string) (ppidDatas *entity.PpidDatas, err error)
|
||||
Create(ppidDatas *entity.PpidDatas) (ppidDataReturn *entity.PpidDatas, err error)
|
||||
Update(id uint, ppidDatas *entity.PpidDatas) (err error)
|
||||
Delete(id uint) (err error)
|
||||
|
|
@ -94,6 +95,14 @@ func (_i *ppidDatasRepository) FindOne(id uint) (ppidDatas *entity.PpidDatas, er
|
|||
return ppidDatas, nil
|
||||
}
|
||||
|
||||
func (_i *ppidDatasRepository) FindOneUsingSlug(slug string) (ppidDatas *entity.PpidDatas, err error) {
|
||||
if err := _i.DB.DB.Where("slug = ?", slug).First(&ppidDatas).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return ppidDatas, nil
|
||||
}
|
||||
|
||||
func (_i *ppidDatasRepository) Create(ppidDatas *entity.PpidDatas) (ppidDataReturn *entity.PpidDatas, err error) {
|
||||
result := _i.DB.DB.Create(ppidDatas)
|
||||
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ type PpidDatasQueryRequest struct {
|
|||
type PpidDatasCreateRequest struct {
|
||||
Title string `json:"title" validate:"required"`
|
||||
Description string `json:"description" validate:"required"`
|
||||
Slug string `json:"slug" validate:"required"`
|
||||
CategoryId uint `json:"categoryId" validate:"required"`
|
||||
StatusId int `json:"statusId" validate:"required"`
|
||||
CreatedById *uint `json:"createdById"`
|
||||
|
|
@ -37,6 +38,7 @@ func (req PpidDatasCreateRequest) ToEntity() *entity.PpidDatas {
|
|||
return &entity.PpidDatas{
|
||||
Title: req.Title,
|
||||
Description: req.Description,
|
||||
Slug: req.Slug,
|
||||
CategoryId: req.CategoryId,
|
||||
CreatedById: req.CreatedById,
|
||||
StatusId: req.StatusId,
|
||||
|
|
@ -49,6 +51,7 @@ type PpidDatasUpdateRequest struct {
|
|||
ID uint `json:"id" validate:"required"`
|
||||
Title string `json:"title" validate:"required"`
|
||||
Description string `json:"description" validate:"required"`
|
||||
Slug string `json:"slug" validate:"required"`
|
||||
CategoryId uint `json:"category_id" validate:"required"`
|
||||
StatusId int `json:"status_id" validate:"required"`
|
||||
CreatedById *uint `json:"created_by_id"`
|
||||
|
|
@ -63,6 +66,7 @@ func (req PpidDatasUpdateRequest) ToEntity() *entity.PpidDatas {
|
|||
ID: req.ID,
|
||||
Title: req.Title,
|
||||
Description: req.Description,
|
||||
Slug: req.Slug,
|
||||
CategoryId: req.CategoryId,
|
||||
CreatedById: req.CreatedById,
|
||||
StatusId: req.StatusId,
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ type PpidDatasResponse struct {
|
|||
ID uint `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
Slug string `json:"slug"`
|
||||
CategoryId uint `json:"categoryId"`
|
||||
CategoryName *string `json:"categoryName"`
|
||||
CreatedById *uint `json:"createdById"`
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import (
|
|||
usersRepository "go-humas-be/app/module/users/repository"
|
||||
"go-humas-be/utils/paginator"
|
||||
utilSvc "go-humas-be/utils/service"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// PpidDatasService
|
||||
|
|
@ -28,7 +29,7 @@ type ppidDatasService struct {
|
|||
// PpidDatasService define interface of IPpidDatasService
|
||||
type PpidDatasService interface {
|
||||
All(req request.PpidDatasQueryRequest) (ppidDatas []*response.PpidDatasResponse, paging paginator.Pagination, err error)
|
||||
Show(id uint) (ppidDatas *response.PpidDatasResponse, err error)
|
||||
Show(id string) (ppidDatas *response.PpidDatasResponse, err error)
|
||||
Save(req request.PpidDatasCreateRequest, authToken string) (ppidDatas *entity.PpidDatas, err error)
|
||||
Update(id uint, req request.PpidDatasUpdateRequest) (err error)
|
||||
Delete(id uint) error
|
||||
|
|
@ -68,11 +69,22 @@ func (_i *ppidDatasService) All(req request.PpidDatasQueryRequest) (ppidDatass [
|
|||
return
|
||||
}
|
||||
|
||||
func (_i *ppidDatasService) Show(id uint) (ppidDatas *response.PpidDatasResponse, err error) {
|
||||
result, err := _i.Repo.FindOne(id)
|
||||
func (_i *ppidDatasService) Show(id string) (ppidDatas *response.PpidDatasResponse, err error) {
|
||||
|
||||
var result *entity.PpidDatas
|
||||
|
||||
if utilSvc.IsNumeric(id) {
|
||||
idInt, _ := strconv.Atoi(id)
|
||||
result, err = _i.Repo.FindOne(uint(idInt))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
result, err = _i.Repo.FindOneUsingSlug(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return mapper.PpidDatasResponseMapper(_i.Log, _i.PpidDataCategoriesRepo, _i.PpidDataFilesRepo, _i.UsersRepo, result), nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ production = false
|
|||
|
||||
[db.postgres]
|
||||
dsn = "postgresql://humas_polri:P@ssw0rd.1@103.82.242.92:5432/humas_polri" # <driver>://<username>:<password>@<host>:<port>/<database>
|
||||
migrate = false
|
||||
migrate = true
|
||||
seed = false
|
||||
|
||||
[logger]
|
||||
|
|
|
|||
|
|
@ -4011,8 +4011,8 @@ const docTemplate = `{
|
|||
"summary": "Get one PpidDatas",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "PpidDatas ID",
|
||||
"type": "string",
|
||||
"description": "PpidDatas [ ID / Slug ]",
|
||||
"name": "id",
|
||||
"in": "path",
|
||||
"required": true
|
||||
|
|
@ -6046,6 +6046,7 @@ const docTemplate = `{
|
|||
"required": [
|
||||
"categoryId",
|
||||
"description",
|
||||
"slug",
|
||||
"statusId",
|
||||
"title"
|
||||
],
|
||||
|
|
@ -6065,6 +6066,9 @@ const docTemplate = `{
|
|||
"levelGroupId": {
|
||||
"type": "integer"
|
||||
},
|
||||
"slug": {
|
||||
"type": "string"
|
||||
},
|
||||
"statusId": {
|
||||
"type": "integer"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -4000,8 +4000,8 @@
|
|||
"summary": "Get one PpidDatas",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "PpidDatas ID",
|
||||
"type": "string",
|
||||
"description": "PpidDatas [ ID / Slug ]",
|
||||
"name": "id",
|
||||
"in": "path",
|
||||
"required": true
|
||||
|
|
@ -6035,6 +6035,7 @@
|
|||
"required": [
|
||||
"categoryId",
|
||||
"description",
|
||||
"slug",
|
||||
"statusId",
|
||||
"title"
|
||||
],
|
||||
|
|
@ -6054,6 +6055,9 @@
|
|||
"levelGroupId": {
|
||||
"type": "integer"
|
||||
},
|
||||
"slug": {
|
||||
"type": "string"
|
||||
},
|
||||
"statusId": {
|
||||
"type": "integer"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -309,6 +309,8 @@ definitions:
|
|||
type: string
|
||||
levelGroupId:
|
||||
type: integer
|
||||
slug:
|
||||
type: string
|
||||
statusId:
|
||||
type: integer
|
||||
title:
|
||||
|
|
@ -316,6 +318,7 @@ definitions:
|
|||
required:
|
||||
- categoryId
|
||||
- description
|
||||
- slug
|
||||
- statusId
|
||||
- title
|
||||
type: object
|
||||
|
|
@ -3144,11 +3147,11 @@ paths:
|
|||
get:
|
||||
description: API for getting one PpidDatas
|
||||
parameters:
|
||||
- description: PpidDatas ID
|
||||
- description: PpidDatas [ ID / Slug ]
|
||||
in: path
|
||||
name: id
|
||||
required: true
|
||||
type: integer
|
||||
type: string
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
|
|
|
|||
|
|
@ -0,0 +1,12 @@
|
|||
package service
|
||||
|
||||
import "unicode"
|
||||
|
||||
func IsNumeric(str string) bool {
|
||||
for _, char := range str {
|
||||
if !unicode.IsDigit(char) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
Loading…
Reference in New Issue