feat: update schedule response and request

This commit is contained in:
hanif salafi 2025-11-03 13:06:38 +07:00
parent 20445fa5c9
commit 928312f600
8 changed files with 61 additions and 7 deletions

View File

@ -65,6 +65,7 @@ func (_i *schedulesController) All(c *fiber.Ctx) error {
Speakers: c.Query("speakers"), Speakers: c.Query("speakers"),
StatusId: c.Query("statusId"), StatusId: c.Query("statusId"),
CreatedById: c.Query("createdById"), CreatedById: c.Query("createdById"),
ClientSlug: c.Query("clientSlug"),
} }
req := reqContext.ToParamRequest() req := reqContext.ToParamRequest()
req.Pagination = paginate req.Pagination = paginate

View File

@ -2,10 +2,22 @@ package mapper
import ( import (
"netidhub-saas-be/app/database/entity" "netidhub-saas-be/app/database/entity"
clientsRepository "netidhub-saas-be/app/module/clients/repository"
schedulesResponse "netidhub-saas-be/app/module/schedules/response" schedulesResponse "netidhub-saas-be/app/module/schedules/response"
) )
func ToSchedulesResponse(schedule *entity.Schedules) *schedulesResponse.SchedulesResponse { func ToSchedulesResponse(schedule *entity.Schedules, clientsRepo clientsRepository.ClientsRepository) *schedulesResponse.SchedulesResponse {
var clientName *string
var clientSlug *string
if schedule.ClientId != nil {
findClient, _ := clientsRepo.FindOneByClientId(schedule.ClientId)
if findClient != nil {
clientName = &findClient.Name
clientSlug = &findClient.Slug
}
}
return &schedulesResponse.SchedulesResponse{ return &schedulesResponse.SchedulesResponse{
ID: schedule.ID, ID: schedule.ID,
Title: schedule.Title, Title: schedule.Title,
@ -22,16 +34,18 @@ func ToSchedulesResponse(schedule *entity.Schedules) *schedulesResponse.Schedule
PosterImagePath: schedule.PosterImagePath, PosterImagePath: schedule.PosterImagePath,
CreatedById: schedule.CreatedById, CreatedById: schedule.CreatedById,
StatusId: schedule.StatusId, StatusId: schedule.StatusId,
ClientName: clientName,
ClientSlug: clientSlug,
IsActive: schedule.IsActive, IsActive: schedule.IsActive,
CreatedAt: schedule.CreatedAt, CreatedAt: schedule.CreatedAt,
UpdatedAt: schedule.UpdatedAt, UpdatedAt: schedule.UpdatedAt,
} }
} }
func ToSchedulesResponseList(schedules []*entity.Schedules) []*schedulesResponse.SchedulesResponse { func ToSchedulesResponseList(schedules []*entity.Schedules, clientsRepo clientsRepository.ClientsRepository) []*schedulesResponse.SchedulesResponse {
var responses []*schedulesResponse.SchedulesResponse var responses []*schedulesResponse.SchedulesResponse
for _, schedule := range schedules { for _, schedule := range schedules {
responses = append(responses, ToSchedulesResponse(schedule)) responses = append(responses, ToSchedulesResponse(schedule, clientsRepo))
} }
return responses return responses
} }

View File

@ -22,6 +22,7 @@ type SchedulesQueryRequest struct {
Speakers *string `json:"speakers"` Speakers *string `json:"speakers"`
StatusId *int `json:"statusId"` StatusId *int `json:"statusId"`
CreatedById *uint `json:"createdById"` CreatedById *uint `json:"createdById"`
ClientSlug *string `json:"clientSlug"`
Pagination *paginator.Pagination `json:"pagination"` Pagination *paginator.Pagination `json:"pagination"`
} }
@ -105,6 +106,7 @@ type SchedulesQueryRequestContext struct {
Speakers string `json:"speakers"` Speakers string `json:"speakers"`
StatusId string `json:"statusId"` StatusId string `json:"statusId"`
CreatedById string `json:"createdById"` CreatedById string `json:"createdById"`
ClientSlug string `json:"clientSlug"`
} }
func (req SchedulesQueryRequestContext) ToParamRequest() SchedulesQueryRequest { func (req SchedulesQueryRequestContext) ToParamRequest() SchedulesQueryRequest {
@ -157,6 +159,9 @@ func (req SchedulesQueryRequestContext) ToParamRequest() SchedulesQueryRequest {
request.CreatedById = &createdByIdUint request.CreatedById = &createdByIdUint
} }
} }
if clientSlug := req.ClientSlug; clientSlug != "" {
request.ClientSlug = &clientSlug
}
return request return request
} }

View File

@ -23,6 +23,8 @@ type SchedulesResponse struct {
CreatedByName *string `json:"createdByName"` CreatedByName *string `json:"createdByName"`
StatusId *int `json:"statusId"` StatusId *int `json:"statusId"`
StatusName *string `json:"statusName"` StatusName *string `json:"statusName"`
ClientName *string `json:"clientName"`
ClientSlug *string `json:"clientSlug"`
IsActive *bool `json:"isActive"` IsActive *bool `json:"isActive"`
CreatedAt time.Time `json:"createdAt"` CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"` UpdatedAt time.Time `json:"updatedAt"`

View File

@ -1,6 +1,7 @@
package service package service
import ( import (
clientsRepository "netidhub-saas-be/app/module/clients/repository"
"netidhub-saas-be/app/module/schedules/mapper" "netidhub-saas-be/app/module/schedules/mapper"
"netidhub-saas-be/app/module/schedules/repository" "netidhub-saas-be/app/module/schedules/repository"
"netidhub-saas-be/app/module/schedules/request" "netidhub-saas-be/app/module/schedules/request"
@ -8,6 +9,7 @@ import (
"netidhub-saas-be/utils/paginator" "netidhub-saas-be/utils/paginator"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/rs/zerolog"
) )
type SchedulesService interface { type SchedulesService interface {
@ -21,21 +23,38 @@ type SchedulesService interface {
type schedulesService struct { type schedulesService struct {
schedulesRepository repository.SchedulesRepository schedulesRepository repository.SchedulesRepository
clientsRepository clientsRepository.ClientsRepository
log zerolog.Logger
} }
func NewSchedulesService(schedulesRepository repository.SchedulesRepository) SchedulesService { func NewSchedulesService(schedulesRepository repository.SchedulesRepository, clientsRepository clientsRepository.ClientsRepository, log zerolog.Logger) SchedulesService {
return &schedulesService{ return &schedulesService{
schedulesRepository: schedulesRepository, schedulesRepository: schedulesRepository,
clientsRepository: clientsRepository,
log: log,
} }
} }
func (_i *schedulesService) All(clientId *uuid.UUID, req request.SchedulesQueryRequest) ([]*schedulesResponse.SchedulesResponse, *paginator.Pagination, error) { func (_i *schedulesService) All(clientId *uuid.UUID, req request.SchedulesQueryRequest) ([]*schedulesResponse.SchedulesResponse, *paginator.Pagination, error) {
// Handle clientSlug filter - find client by slug and set clientId
if req.ClientSlug != nil {
findClient, err := _i.clientsRepository.FindBySlug(*req.ClientSlug)
if err != nil {
_i.log.Error().Err(err).Str("clientSlug", *req.ClientSlug).Msg("Failed to find client by slug")
return nil, nil, err
}
if findClient != nil {
clientId = &findClient.ID
_i.log.Info().Str("clientSlug", *req.ClientSlug).Str("clientId", findClient.ID.String()).Msg("Found client by slug")
}
}
schedules, pagination, err := _i.schedulesRepository.All(clientId, req) schedules, pagination, err := _i.schedulesRepository.All(clientId, req)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
responses := mapper.ToSchedulesResponseList(schedules) responses := mapper.ToSchedulesResponseList(schedules, _i.clientsRepository)
return responses, pagination, nil return responses, pagination, nil
} }
@ -45,7 +64,7 @@ func (_i *schedulesService) Show(clientId *uuid.UUID, id uint) (*schedulesRespon
return nil, err return nil, err
} }
response := mapper.ToSchedulesResponse(schedule) response := mapper.ToSchedulesResponse(schedule, _i.clientsRepository)
return response, nil return response, nil
} }
@ -57,7 +76,7 @@ func (_i *schedulesService) Save(clientId *uuid.UUID, req request.SchedulesCreat
return nil, err return nil, err
} }
response := mapper.ToSchedulesResponse(savedSchedule) response := mapper.ToSchedulesResponse(savedSchedule, _i.clientsRepository)
return response, nil return response, nil
} }

View File

@ -13777,6 +13777,11 @@ const docTemplate = `{
"name": "Authorization", "name": "Authorization",
"in": "header" "in": "header"
}, },
{
"type": "string",
"name": "clientSlug",
"in": "query"
},
{ {
"type": "integer", "type": "integer",
"name": "createdById", "name": "createdById",

View File

@ -13766,6 +13766,11 @@
"name": "Authorization", "name": "Authorization",
"in": "header" "in": "header"
}, },
{
"type": "string",
"name": "clientSlug",
"in": "query"
},
{ {
"type": "integer", "type": "integer",
"name": "createdById", "name": "createdById",

View File

@ -10479,6 +10479,9 @@ paths:
in: header in: header
name: Authorization name: Authorization
type: string type: string
- in: query
name: clientSlug
type: string
- in: query - in: query
name: createdById name: createdById
type: integer type: integer