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"`
|
ID uint `json:"id" gorm:"primaryKey;type:int4;autoIncrement"`
|
||||||
Title string `json:"title" gorm:"type:varchar"`
|
Title string `json:"title" gorm:"type:varchar"`
|
||||||
Description string `json:"description" 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"`
|
CategoryId uint `json:"category_id" gorm:"type:int4"`
|
||||||
CreatedById *uint `json:"created_by_id" gorm:"type:int4"`
|
CreatedById *uint `json:"created_by_id" gorm:"type:int4"`
|
||||||
LevelGroupId *int `json:"level_group_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
|
// @Description API for getting one PpidDatas
|
||||||
// @Tags PPID Data
|
// @Tags PPID Data
|
||||||
// @Security Bearer
|
// @Security Bearer
|
||||||
// @Param id path int true "PpidDatas ID"
|
// @Param id path string true "PpidDatas [ ID / Slug ]"
|
||||||
// @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 /ppid-datas/{id} [get]
|
// @Router /ppid-datas/{id} [get]
|
||||||
func (_i *ppidDatasController) Show(c *fiber.Ctx) error {
|
func (_i *ppidDatasController) Show(c *fiber.Ctx) error {
|
||||||
id, err := strconv.ParseUint(c.Params("id"), 10, 0)
|
id := c.Params("id")
|
||||||
if err != nil {
|
ppidDatasData, err := _i.ppidDatasService.Show(id)
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
ppidDatasData, err := _i.ppidDatasService.Show(uint(id))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,7 @@ func PpidDatasResponseMapper(
|
||||||
ID: ppidDatasReq.ID,
|
ID: ppidDatasReq.ID,
|
||||||
Title: ppidDatasReq.Title,
|
Title: ppidDatasReq.Title,
|
||||||
Description: ppidDatasReq.Description,
|
Description: ppidDatasReq.Description,
|
||||||
|
Slug: ppidDatasReq.Slug,
|
||||||
CategoryId: ppidDatasReq.CategoryId,
|
CategoryId: ppidDatasReq.CategoryId,
|
||||||
CategoryName: &categoryName,
|
CategoryName: &categoryName,
|
||||||
CreatedById: ppidDatasReq.CreatedById,
|
CreatedById: ppidDatasReq.CreatedById,
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ type ppidDatasRepository struct {
|
||||||
type PpidDatasRepository interface {
|
type PpidDatasRepository interface {
|
||||||
GetAll(req request.PpidDatasQueryRequest) (ppidDatass []*entity.PpidDatas, paging paginator.Pagination, err error)
|
GetAll(req request.PpidDatasQueryRequest) (ppidDatass []*entity.PpidDatas, paging paginator.Pagination, err error)
|
||||||
FindOne(id uint) (ppidDatas *entity.PpidDatas, 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)
|
Create(ppidDatas *entity.PpidDatas) (ppidDataReturn *entity.PpidDatas, err error)
|
||||||
Update(id uint, ppidDatas *entity.PpidDatas) (err error)
|
Update(id uint, ppidDatas *entity.PpidDatas) (err error)
|
||||||
Delete(id uint) (err error)
|
Delete(id uint) (err error)
|
||||||
|
|
@ -94,6 +95,14 @@ func (_i *ppidDatasRepository) FindOne(id uint) (ppidDatas *entity.PpidDatas, er
|
||||||
return ppidDatas, nil
|
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) {
|
func (_i *ppidDatasRepository) Create(ppidDatas *entity.PpidDatas) (ppidDataReturn *entity.PpidDatas, err error) {
|
||||||
result := _i.DB.DB.Create(ppidDatas)
|
result := _i.DB.DB.Create(ppidDatas)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ type PpidDatasQueryRequest struct {
|
||||||
type PpidDatasCreateRequest struct {
|
type PpidDatasCreateRequest struct {
|
||||||
Title string `json:"title" validate:"required"`
|
Title string `json:"title" validate:"required"`
|
||||||
Description string `json:"description" validate:"required"`
|
Description string `json:"description" validate:"required"`
|
||||||
|
Slug string `json:"slug" validate:"required"`
|
||||||
CategoryId uint `json:"categoryId" validate:"required"`
|
CategoryId uint `json:"categoryId" validate:"required"`
|
||||||
StatusId int `json:"statusId" validate:"required"`
|
StatusId int `json:"statusId" validate:"required"`
|
||||||
CreatedById *uint `json:"createdById"`
|
CreatedById *uint `json:"createdById"`
|
||||||
|
|
@ -37,6 +38,7 @@ func (req PpidDatasCreateRequest) ToEntity() *entity.PpidDatas {
|
||||||
return &entity.PpidDatas{
|
return &entity.PpidDatas{
|
||||||
Title: req.Title,
|
Title: req.Title,
|
||||||
Description: req.Description,
|
Description: req.Description,
|
||||||
|
Slug: req.Slug,
|
||||||
CategoryId: req.CategoryId,
|
CategoryId: req.CategoryId,
|
||||||
CreatedById: req.CreatedById,
|
CreatedById: req.CreatedById,
|
||||||
StatusId: req.StatusId,
|
StatusId: req.StatusId,
|
||||||
|
|
@ -49,6 +51,7 @@ type PpidDatasUpdateRequest struct {
|
||||||
ID uint `json:"id" validate:"required"`
|
ID uint `json:"id" validate:"required"`
|
||||||
Title string `json:"title" validate:"required"`
|
Title string `json:"title" validate:"required"`
|
||||||
Description string `json:"description" validate:"required"`
|
Description string `json:"description" validate:"required"`
|
||||||
|
Slug string `json:"slug" validate:"required"`
|
||||||
CategoryId uint `json:"category_id" validate:"required"`
|
CategoryId uint `json:"category_id" validate:"required"`
|
||||||
StatusId int `json:"status_id" validate:"required"`
|
StatusId int `json:"status_id" validate:"required"`
|
||||||
CreatedById *uint `json:"created_by_id"`
|
CreatedById *uint `json:"created_by_id"`
|
||||||
|
|
@ -63,6 +66,7 @@ func (req PpidDatasUpdateRequest) ToEntity() *entity.PpidDatas {
|
||||||
ID: req.ID,
|
ID: req.ID,
|
||||||
Title: req.Title,
|
Title: req.Title,
|
||||||
Description: req.Description,
|
Description: req.Description,
|
||||||
|
Slug: req.Slug,
|
||||||
CategoryId: req.CategoryId,
|
CategoryId: req.CategoryId,
|
||||||
CreatedById: req.CreatedById,
|
CreatedById: req.CreatedById,
|
||||||
StatusId: req.StatusId,
|
StatusId: req.StatusId,
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ type PpidDatasResponse struct {
|
||||||
ID uint `json:"id"`
|
ID uint `json:"id"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
|
Slug string `json:"slug"`
|
||||||
CategoryId uint `json:"categoryId"`
|
CategoryId uint `json:"categoryId"`
|
||||||
CategoryName *string `json:"categoryName"`
|
CategoryName *string `json:"categoryName"`
|
||||||
CreatedById *uint `json:"createdById"`
|
CreatedById *uint `json:"createdById"`
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ import (
|
||||||
usersRepository "go-humas-be/app/module/users/repository"
|
usersRepository "go-humas-be/app/module/users/repository"
|
||||||
"go-humas-be/utils/paginator"
|
"go-humas-be/utils/paginator"
|
||||||
utilSvc "go-humas-be/utils/service"
|
utilSvc "go-humas-be/utils/service"
|
||||||
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
// PpidDatasService
|
// PpidDatasService
|
||||||
|
|
@ -28,7 +29,7 @@ type ppidDatasService struct {
|
||||||
// PpidDatasService define interface of IPpidDatasService
|
// PpidDatasService define interface of IPpidDatasService
|
||||||
type PpidDatasService interface {
|
type PpidDatasService interface {
|
||||||
All(req request.PpidDatasQueryRequest) (ppidDatas []*response.PpidDatasResponse, paging paginator.Pagination, err error)
|
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)
|
Save(req request.PpidDatasCreateRequest, authToken string) (ppidDatas *entity.PpidDatas, err error)
|
||||||
Update(id uint, req request.PpidDatasUpdateRequest) (err error)
|
Update(id uint, req request.PpidDatasUpdateRequest) (err error)
|
||||||
Delete(id uint) error
|
Delete(id uint) error
|
||||||
|
|
@ -68,10 +69,21 @@ func (_i *ppidDatasService) All(req request.PpidDatasQueryRequest) (ppidDatass [
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_i *ppidDatasService) Show(id uint) (ppidDatas *response.PpidDatasResponse, err error) {
|
func (_i *ppidDatasService) Show(id string) (ppidDatas *response.PpidDatasResponse, err error) {
|
||||||
result, err := _i.Repo.FindOne(id)
|
|
||||||
if err != nil {
|
var result *entity.PpidDatas
|
||||||
return nil, err
|
|
||||||
|
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
|
return mapper.PpidDatasResponseMapper(_i.Log, _i.PpidDataCategoriesRepo, _i.PpidDataFilesRepo, _i.UsersRepo, result), nil
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ production = false
|
||||||
|
|
||||||
[db.postgres]
|
[db.postgres]
|
||||||
dsn = "postgresql://humas_polri:P@ssw0rd.1@103.82.242.92:5432/humas_polri" # <driver>://<username>:<password>@<host>:<port>/<database>
|
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
|
seed = false
|
||||||
|
|
||||||
[logger]
|
[logger]
|
||||||
|
|
|
||||||
|
|
@ -4011,8 +4011,8 @@ const docTemplate = `{
|
||||||
"summary": "Get one PpidDatas",
|
"summary": "Get one PpidDatas",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
"type": "integer",
|
"type": "string",
|
||||||
"description": "PpidDatas ID",
|
"description": "PpidDatas [ ID / Slug ]",
|
||||||
"name": "id",
|
"name": "id",
|
||||||
"in": "path",
|
"in": "path",
|
||||||
"required": true
|
"required": true
|
||||||
|
|
@ -6046,6 +6046,7 @@ const docTemplate = `{
|
||||||
"required": [
|
"required": [
|
||||||
"categoryId",
|
"categoryId",
|
||||||
"description",
|
"description",
|
||||||
|
"slug",
|
||||||
"statusId",
|
"statusId",
|
||||||
"title"
|
"title"
|
||||||
],
|
],
|
||||||
|
|
@ -6065,6 +6066,9 @@ const docTemplate = `{
|
||||||
"levelGroupId": {
|
"levelGroupId": {
|
||||||
"type": "integer"
|
"type": "integer"
|
||||||
},
|
},
|
||||||
|
"slug": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
"statusId": {
|
"statusId": {
|
||||||
"type": "integer"
|
"type": "integer"
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -4000,8 +4000,8 @@
|
||||||
"summary": "Get one PpidDatas",
|
"summary": "Get one PpidDatas",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
"type": "integer",
|
"type": "string",
|
||||||
"description": "PpidDatas ID",
|
"description": "PpidDatas [ ID / Slug ]",
|
||||||
"name": "id",
|
"name": "id",
|
||||||
"in": "path",
|
"in": "path",
|
||||||
"required": true
|
"required": true
|
||||||
|
|
@ -6035,6 +6035,7 @@
|
||||||
"required": [
|
"required": [
|
||||||
"categoryId",
|
"categoryId",
|
||||||
"description",
|
"description",
|
||||||
|
"slug",
|
||||||
"statusId",
|
"statusId",
|
||||||
"title"
|
"title"
|
||||||
],
|
],
|
||||||
|
|
@ -6054,6 +6055,9 @@
|
||||||
"levelGroupId": {
|
"levelGroupId": {
|
||||||
"type": "integer"
|
"type": "integer"
|
||||||
},
|
},
|
||||||
|
"slug": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
"statusId": {
|
"statusId": {
|
||||||
"type": "integer"
|
"type": "integer"
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -309,6 +309,8 @@ definitions:
|
||||||
type: string
|
type: string
|
||||||
levelGroupId:
|
levelGroupId:
|
||||||
type: integer
|
type: integer
|
||||||
|
slug:
|
||||||
|
type: string
|
||||||
statusId:
|
statusId:
|
||||||
type: integer
|
type: integer
|
||||||
title:
|
title:
|
||||||
|
|
@ -316,6 +318,7 @@ definitions:
|
||||||
required:
|
required:
|
||||||
- categoryId
|
- categoryId
|
||||||
- description
|
- description
|
||||||
|
- slug
|
||||||
- statusId
|
- statusId
|
||||||
- title
|
- title
|
||||||
type: object
|
type: object
|
||||||
|
|
@ -3144,11 +3147,11 @@ paths:
|
||||||
get:
|
get:
|
||||||
description: API for getting one PpidDatas
|
description: API for getting one PpidDatas
|
||||||
parameters:
|
parameters:
|
||||||
- description: PpidDatas ID
|
- description: PpidDatas [ ID / Slug ]
|
||||||
in: path
|
in: path
|
||||||
name: id
|
name: id
|
||||||
required: true
|
required: true
|
||||||
type: integer
|
type: string
|
||||||
responses:
|
responses:
|
||||||
"200":
|
"200":
|
||||||
description: OK
|
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