feat: update schedule response and request
This commit is contained in:
parent
20445fa5c9
commit
928312f600
|
|
@ -65,6 +65,7 @@ func (_i *schedulesController) All(c *fiber.Ctx) error {
|
|||
Speakers: c.Query("speakers"),
|
||||
StatusId: c.Query("statusId"),
|
||||
CreatedById: c.Query("createdById"),
|
||||
ClientSlug: c.Query("clientSlug"),
|
||||
}
|
||||
req := reqContext.ToParamRequest()
|
||||
req.Pagination = paginate
|
||||
|
|
|
|||
|
|
@ -2,10 +2,22 @@ package mapper
|
|||
|
||||
import (
|
||||
"netidhub-saas-be/app/database/entity"
|
||||
clientsRepository "netidhub-saas-be/app/module/clients/repository"
|
||||
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{
|
||||
ID: schedule.ID,
|
||||
Title: schedule.Title,
|
||||
|
|
@ -22,16 +34,18 @@ func ToSchedulesResponse(schedule *entity.Schedules) *schedulesResponse.Schedule
|
|||
PosterImagePath: schedule.PosterImagePath,
|
||||
CreatedById: schedule.CreatedById,
|
||||
StatusId: schedule.StatusId,
|
||||
ClientName: clientName,
|
||||
ClientSlug: clientSlug,
|
||||
IsActive: schedule.IsActive,
|
||||
CreatedAt: schedule.CreatedAt,
|
||||
UpdatedAt: schedule.UpdatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
func ToSchedulesResponseList(schedules []*entity.Schedules) []*schedulesResponse.SchedulesResponse {
|
||||
func ToSchedulesResponseList(schedules []*entity.Schedules, clientsRepo clientsRepository.ClientsRepository) []*schedulesResponse.SchedulesResponse {
|
||||
var responses []*schedulesResponse.SchedulesResponse
|
||||
for _, schedule := range schedules {
|
||||
responses = append(responses, ToSchedulesResponse(schedule))
|
||||
responses = append(responses, ToSchedulesResponse(schedule, clientsRepo))
|
||||
}
|
||||
return responses
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ type SchedulesQueryRequest struct {
|
|||
Speakers *string `json:"speakers"`
|
||||
StatusId *int `json:"statusId"`
|
||||
CreatedById *uint `json:"createdById"`
|
||||
ClientSlug *string `json:"clientSlug"`
|
||||
Pagination *paginator.Pagination `json:"pagination"`
|
||||
}
|
||||
|
||||
|
|
@ -105,6 +106,7 @@ type SchedulesQueryRequestContext struct {
|
|||
Speakers string `json:"speakers"`
|
||||
StatusId string `json:"statusId"`
|
||||
CreatedById string `json:"createdById"`
|
||||
ClientSlug string `json:"clientSlug"`
|
||||
}
|
||||
|
||||
func (req SchedulesQueryRequestContext) ToParamRequest() SchedulesQueryRequest {
|
||||
|
|
@ -157,6 +159,9 @@ func (req SchedulesQueryRequestContext) ToParamRequest() SchedulesQueryRequest {
|
|||
request.CreatedById = &createdByIdUint
|
||||
}
|
||||
}
|
||||
if clientSlug := req.ClientSlug; clientSlug != "" {
|
||||
request.ClientSlug = &clientSlug
|
||||
}
|
||||
|
||||
return request
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,8 @@ type SchedulesResponse struct {
|
|||
CreatedByName *string `json:"createdByName"`
|
||||
StatusId *int `json:"statusId"`
|
||||
StatusName *string `json:"statusName"`
|
||||
ClientName *string `json:"clientName"`
|
||||
ClientSlug *string `json:"clientSlug"`
|
||||
IsActive *bool `json:"isActive"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package service
|
||||
|
||||
import (
|
||||
clientsRepository "netidhub-saas-be/app/module/clients/repository"
|
||||
"netidhub-saas-be/app/module/schedules/mapper"
|
||||
"netidhub-saas-be/app/module/schedules/repository"
|
||||
"netidhub-saas-be/app/module/schedules/request"
|
||||
|
|
@ -8,6 +9,7 @@ import (
|
|||
"netidhub-saas-be/utils/paginator"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/rs/zerolog"
|
||||
)
|
||||
|
||||
type SchedulesService interface {
|
||||
|
|
@ -21,21 +23,38 @@ type SchedulesService interface {
|
|||
|
||||
type schedulesService struct {
|
||||
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{
|
||||
schedulesRepository: schedulesRepository,
|
||||
clientsRepository: clientsRepository,
|
||||
log: log,
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
responses := mapper.ToSchedulesResponseList(schedules)
|
||||
responses := mapper.ToSchedulesResponseList(schedules, _i.clientsRepository)
|
||||
return responses, pagination, nil
|
||||
}
|
||||
|
||||
|
|
@ -45,7 +64,7 @@ func (_i *schedulesService) Show(clientId *uuid.UUID, id uint) (*schedulesRespon
|
|||
return nil, err
|
||||
}
|
||||
|
||||
response := mapper.ToSchedulesResponse(schedule)
|
||||
response := mapper.ToSchedulesResponse(schedule, _i.clientsRepository)
|
||||
return response, nil
|
||||
}
|
||||
|
||||
|
|
@ -57,7 +76,7 @@ func (_i *schedulesService) Save(clientId *uuid.UUID, req request.SchedulesCreat
|
|||
return nil, err
|
||||
}
|
||||
|
||||
response := mapper.ToSchedulesResponse(savedSchedule)
|
||||
response := mapper.ToSchedulesResponse(savedSchedule, _i.clientsRepository)
|
||||
return response, nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13777,6 +13777,11 @@ const docTemplate = `{
|
|||
"name": "Authorization",
|
||||
"in": "header"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"name": "clientSlug",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"name": "createdById",
|
||||
|
|
|
|||
|
|
@ -13766,6 +13766,11 @@
|
|||
"name": "Authorization",
|
||||
"in": "header"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"name": "clientSlug",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"name": "createdById",
|
||||
|
|
|
|||
|
|
@ -10479,6 +10479,9 @@ paths:
|
|||
in: header
|
||||
name: Authorization
|
||||
type: string
|
||||
- in: query
|
||||
name: clientSlug
|
||||
type: string
|
||||
- in: query
|
||||
name: createdById
|
||||
type: integer
|
||||
|
|
|
|||
Loading…
Reference in New Issue