feat: update user levels, articles, and magazine files

This commit is contained in:
hanif salafi 2025-02-07 04:14:25 +07:00
parent cd09dae524
commit 0fa899424c
15 changed files with 117 additions and 27 deletions

View File

@ -23,6 +23,8 @@ type Articles struct {
OldId *uint `json:"old_id" gorm:"type:int4"`
IsPublish *bool `json:"is_publish" gorm:"type:bool;default:false"`
PublishedAt *time.Time `json:"published_at" gorm:"type:timestamp"`
IsDraft *bool `json:"is_draft" gorm:"type:bool;default:false"`
DraftedAt *time.Time `json:"drafted_at" gorm:"type:timestamp"`
IsActive *bool `json:"is_active" gorm:"type:bool;default:true"`
CreatedAt time.Time `json:"created_at" gorm:"default:now()"`
UpdatedAt time.Time `json:"updated_at" gorm:"default:now()"`

View File

@ -7,7 +7,7 @@ type UserLevels struct {
Name string `json:"name" gorm:"type:varchar"`
AliasName string `json:"alias_name" gorm:"type:varchar"`
LevelNumber int `json:"level_number" gorm:"type:int4"`
ParentLevelId int `json:"parent_level_id" gorm:"type:int4"`
ParentLevelId *int `json:"parent_level_id" gorm:"type:int4"`
ProvinceId *int `json:"province_id" gorm:"type:int4"`
Group *string `json:"group" gorm:"type:varchar"`
IsActive *bool `json:"is_active" gorm:"type:bool"`

View File

@ -57,6 +57,7 @@ func (_i *articlesController) All(c *fiber.Ctx) error {
TypeId: c.Query("typeId"),
StatusId: c.Query("statusId"),
IsPublish: c.Query("isPublish"),
IsDraft: c.Query("isDraft"),
}
req := reqContext.ToParamRequest()
req.Pagination = paginate

View File

@ -60,6 +60,9 @@ func (_i *articlesRepository) GetAll(req request.ArticlesQueryRequest) (articles
if req.IsPublish != nil {
query = query.Where("is_publish = ?", req.IsPublish)
}
if req.IsDraft != nil {
query = query.Where("is_draft = ?", req.IsDraft)
}
if req.StatusId != nil {
query = query.Where("status_id = ?", req.StatusId)
}

View File

@ -20,6 +20,7 @@ type ArticlesQueryRequest struct {
CreatedById *int `json:"createdById"`
StatusId *int `json:"statusId"`
IsPublish *bool `json:"isPublish"`
IsDraft *bool `json:"isDraft"`
Pagination *paginator.Pagination `json:"pagination"`
}
@ -32,6 +33,8 @@ type ArticlesCreateRequest struct {
TypeId int `json:"typeId" validate:"required"`
Tags string `json:"tags" validate:"required"`
AiArticleId *int `json:"aiArticleId"`
IsPublish *bool `json:"isPublish"`
IsDraft *bool `json:"isDraft"`
OldId *uint `json:"oldId"`
}
@ -44,6 +47,8 @@ func (req ArticlesCreateRequest) ToEntity() *entity.Articles {
TypeId: req.TypeId,
Tags: req.Tags,
AiArticleId: req.AiArticleId,
IsPublish: req.IsPublish,
IsDraft: req.IsDraft,
OldId: req.OldId,
}
}
@ -58,6 +63,8 @@ type ArticlesUpdateRequest struct {
Tags string `json:"tags" validate:"required"`
CreatedById *uint `json:"createdById"`
AiArticleId *int `json:"aiArticleId"`
IsPublish *bool `json:"isPublish"`
IsDraft *bool `json:"isDraft"`
StatusId *int `json:"statusId"`
}
@ -72,6 +79,8 @@ func (req ArticlesUpdateRequest) ToEntity() *entity.Articles {
Tags: req.Tags,
StatusId: req.StatusId,
AiArticleId: req.AiArticleId,
IsPublish: req.IsPublish,
IsDraft: req.IsDraft,
UpdatedAt: time.Now(),
}
} else {
@ -85,6 +94,8 @@ func (req ArticlesUpdateRequest) ToEntity() *entity.Articles {
StatusId: req.StatusId,
CreatedById: req.CreatedById,
AiArticleId: req.AiArticleId,
IsPublish: req.IsPublish,
IsDraft: req.IsDraft,
UpdatedAt: time.Now(),
}
}
@ -98,6 +109,7 @@ type ArticlesQueryRequestContext struct {
Tags string `json:"tags"`
CreatedById string `json:"createdById"`
IsPublish string `json:"isPublish"`
IsDraft string `json:"isDraft"`
StatusId string `json:"statusId"`
}
@ -131,6 +143,12 @@ func (req ArticlesQueryRequestContext) ToParamRequest() ArticlesQueryRequest {
request.IsPublish = &isPublish
}
}
if isDraftStr := req.IsDraft; isDraftStr != "" {
isDraft, err := strconv.ParseBool(isDraftStr)
if err == nil {
request.IsDraft = &isDraft
}
}
if statusIdStr := req.StatusId; statusIdStr != "" {
statusId, err := strconv.Atoi(statusIdStr)
if err == nil {

View File

@ -116,6 +116,26 @@ func (_i *articlesService) Save(req request.ArticlesCreateRequest, authToken str
createdBy := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken)
newReq.CreatedById = &createdBy.ID
isDraft := true
if req.IsDraft == &isDraft {
draftedAt := time.Now()
newReq.IsDraft = &isDraft
newReq.DraftedAt = &draftedAt
isPublishFalse := false
newReq.IsPublish = &isPublishFalse
newReq.PublishedAt = nil
}
isPublish := true
if req.IsPublish == &isPublish {
publishedAt := time.Now()
newReq.IsPublish = &isPublish
newReq.PublishedAt = &publishedAt
isDraftFalse := false
newReq.IsDraft = &isDraftFalse
newReq.DraftedAt = nil
}
saveArticleRes, err := _i.Repo.Create(newReq)
if err != nil {
return nil, err

View File

@ -5,7 +5,12 @@ import (
res "go-humas-be/app/module/magazine_files/response"
)
func MagazineFilesResponseMapper(magazineFilesReq *entity.MagazineFiles) (magazineFilesRes *res.MagazineFilesResponse) {
func MagazineFilesResponseMapper(magazineFilesReq *entity.MagazineFiles, host string) (magazineFilesRes *res.MagazineFilesResponse) {
fileUrl := host + "/magazine-files/viewer/"
if magazineFilesReq.FileName != nil {
fileUrl += *magazineFilesReq.FileName
}
if magazineFilesReq != nil {
magazineFilesRes = &res.MagazineFilesResponse{
ID: magazineFilesReq.ID,
@ -14,7 +19,7 @@ func MagazineFilesResponseMapper(magazineFilesReq *entity.MagazineFiles) (magazi
MagazineId: magazineFilesReq.MagazineId,
DownloadCount: magazineFilesReq.DownloadCount,
FilePath: magazineFilesReq.FilePath,
FileUrl: magazineFilesReq.FileUrl,
FileUrl: &fileUrl,
FileName: magazineFilesReq.FileName,
FileAlt: magazineFilesReq.FileAlt,
WidthPixel: magazineFilesReq.WidthPixel,

View File

@ -9,6 +9,7 @@ import (
"go-humas-be/app/module/magazine_files/repository"
"go-humas-be/app/module/magazine_files/request"
"go-humas-be/app/module/magazine_files/response"
config "go-humas-be/config/config"
minioStorage "go-humas-be/config/config"
"go-humas-be/utils/paginator"
"io"
@ -25,6 +26,7 @@ import (
type magazineFilesService struct {
Repo repository.MagazineFilesRepository
Log zerolog.Logger
Cfg *config.Config
MinioStorage *minioStorage.MinioStorage
}
@ -39,11 +41,12 @@ type MagazineFilesService interface {
}
// NewMagazineFilesService init MagazineFilesService
func NewMagazineFilesService(repo repository.MagazineFilesRepository, log zerolog.Logger, minioStorage *minioStorage.MinioStorage) MagazineFilesService {
func NewMagazineFilesService(repo repository.MagazineFilesRepository, log zerolog.Logger, cfg *config.Config, minioStorage *minioStorage.MinioStorage) MagazineFilesService {
return &magazineFilesService{
Repo: repo,
Log: log,
Cfg: cfg,
MinioStorage: minioStorage,
}
}
@ -54,11 +57,10 @@ func (_i *magazineFilesService) All(req request.MagazineFilesQueryRequest) (maga
if err != nil {
return
}
host := _i.Cfg.App.Domain
for _, result := range results {
magazineFiless = append(magazineFiless, mapper.MagazineFilesResponseMapper(result))
magazineFiless = append(magazineFiless, mapper.MagazineFilesResponseMapper(result, host))
}
return
}
@ -67,8 +69,8 @@ func (_i *magazineFilesService) Show(id uint) (magazineFiles *response.MagazineF
if err != nil {
return nil, err
}
return mapper.MagazineFilesResponseMapper(result), nil
host := _i.Cfg.App.Domain
return mapper.MagazineFilesResponseMapper(result, host), nil
}
func (_i *magazineFilesService) Save(c *fiber.Ctx, id uint, title string, description string) (err error) {

View File

@ -13,7 +13,7 @@ func MagazinesResponseMapper(magazinesReq *entity.Magazines, magazineFilesRepo m
var magazineFilesArr []*magazineFilesResponse.MagazineFilesResponse
if magazineFiles != nil && len(magazineFiles) > 0 {
for _, result := range magazineFiles {
magazineFilesArr = append(magazineFilesArr, magazineFilesMapper.MagazineFilesResponseMapper(result))
magazineFilesArr = append(magazineFilesArr, magazineFilesMapper.MagazineFilesResponseMapper(result, host))
}
}

View File

@ -23,7 +23,7 @@ type UserLevelsCreateRequest struct {
Name string `json:"name" validate:"required"`
AliasName string `json:"aliasName" validate:"required"`
LevelNumber int `json:"levelNumber" validate:"required"`
ParentLevelId int `json:"parentLevelId" validate:"required"`
ParentLevelId *int `json:"parentLevelId"`
ProvinceId *int `json:"provinceId"`
IsActive *bool `json:"isActive"`
}
@ -43,7 +43,7 @@ type UserLevelsUpdateRequest struct {
Name string `json:"name" validate:"required"`
AliasName string `json:"aliasName" validate:"required"`
LevelNumber int `json:"levelNumber" validate:"required"`
ParentLevelId int `json:"parentLevelId" validate:"required"`
ParentLevelId *int `json:"parentLevelId"`
ProvinceId *int `json:"provinceId"`
}

View File

@ -7,7 +7,7 @@ type UserLevelsResponse struct {
Name string `json:"name"`
AliasName string `json:"aliasName"`
LevelNumber int `json:"levelNumber"`
ParentLevelId int `json:"parentLevelId"`
ParentLevelId *int `json:"parentLevelId"`
ProvinceId *int `json:"provinceId"`
IsActive *bool `json:"isActive"`
CreatedAt time.Time `json:"createdAt"`

View File

@ -63,7 +63,7 @@ admin-password = "P@ssw0rd.1"
[smtp]
host = "smtp-app.polri.go.id"
port = 465
username = "multipool.divhumas@polri.go.id"
password = "wkjs0XzoCQ0axsYW"
from-address = "multipool.divhumas@polri.go.id"
from-name = "APLIKASI MULTIPOOL DIVHUMAS POLRI"
username = "webhumas.divhumas@polri.go.id"
password = "z0VfYLbaghPc"
from-address = "webhumas.divhumas@polri.go.id"
from-name = "APLIKASI WEB HUMAS DIVHUMAS POLRI"

View File

@ -1819,6 +1819,11 @@ const docTemplate = `{
"name": "description",
"in": "query"
},
{
"type": "boolean",
"name": "isDraft",
"in": "query"
},
{
"type": "boolean",
"name": "isPublish",
@ -7157,6 +7162,12 @@ const docTemplate = `{
"htmlDescription": {
"type": "string"
},
"isDraft": {
"type": "boolean"
},
"isPublish": {
"type": "boolean"
},
"oldId": {
"type": "integer"
},
@ -7201,6 +7212,12 @@ const docTemplate = `{
"htmlDescription": {
"type": "string"
},
"isDraft": {
"type": "boolean"
},
"isPublish": {
"type": "boolean"
},
"slug": {
"type": "string"
},
@ -7477,8 +7494,7 @@ const docTemplate = `{
"required": [
"aliasName",
"levelNumber",
"name",
"parentLevelId"
"name"
],
"properties": {
"aliasName": {
@ -7506,8 +7522,7 @@ const docTemplate = `{
"required": [
"aliasName",
"levelNumber",
"name",
"parentLevelId"
"name"
],
"properties": {
"aliasName": {

View File

@ -1808,6 +1808,11 @@
"name": "description",
"in": "query"
},
{
"type": "boolean",
"name": "isDraft",
"in": "query"
},
{
"type": "boolean",
"name": "isPublish",
@ -7146,6 +7151,12 @@
"htmlDescription": {
"type": "string"
},
"isDraft": {
"type": "boolean"
},
"isPublish": {
"type": "boolean"
},
"oldId": {
"type": "integer"
},
@ -7190,6 +7201,12 @@
"htmlDescription": {
"type": "string"
},
"isDraft": {
"type": "boolean"
},
"isPublish": {
"type": "boolean"
},
"slug": {
"type": "string"
},
@ -7466,8 +7483,7 @@
"required": [
"aliasName",
"levelNumber",
"name",
"parentLevelId"
"name"
],
"properties": {
"aliasName": {
@ -7495,8 +7511,7 @@
"required": [
"aliasName",
"levelNumber",
"name",
"parentLevelId"
"name"
],
"properties": {
"aliasName": {

View File

@ -196,6 +196,10 @@ definitions:
type: string
htmlDescription:
type: string
isDraft:
type: boolean
isPublish:
type: boolean
oldId:
type: integer
slug:
@ -227,6 +231,10 @@ definitions:
type: string
htmlDescription:
type: string
isDraft:
type: boolean
isPublish:
type: boolean
slug:
type: string
statusId:
@ -438,7 +446,6 @@ definitions:
- aliasName
- levelNumber
- name
- parentLevelId
type: object
request.UserLevelsUpdateRequest:
properties:
@ -456,7 +463,6 @@ definitions:
- aliasName
- levelNumber
- name
- parentLevelId
type: object
request.UserLogin:
properties:
@ -1876,6 +1882,9 @@ paths:
- in: query
name: description
type: string
- in: query
name: isDraft
type: boolean
- in: query
name: isPublish
type: boolean