diff --git a/app/database/entity/schedules.entity.go b/app/database/entity/schedules.entity.go new file mode 100644 index 0000000..57838d3 --- /dev/null +++ b/app/database/entity/schedules.entity.go @@ -0,0 +1,29 @@ +package entity + +import ( + "time" + + "github.com/google/uuid" +) + +type Schedules struct { + ID uint `json:"id" gorm:"primaryKey;type:int4;autoIncrement"` + Title string `json:"title" gorm:"type:varchar"` + Description string `json:"description" gorm:"type:varchar"` + Location string `json:"location" gorm:"type:varchar"` + IsLiveStreaming *bool `json:"is_live_streaming" gorm:"type:bool;default:false"` + LiveStreamingUrl *string `json:"live_streaming_url" gorm:"type:varchar"` + TypeId int `json:"type_id" gorm:"type:int4"` + StartDate *time.Time `json:"start_date" gorm:"type:date"` + EndDate *time.Time `json:"end_date" gorm:"type:date"` + StartTime *string `json:"start_time" gorm:"type:varchar"` + EndTime *string `json:"end_time" gorm:"type:varchar"` + Speakers string `json:"speakers" gorm:"type:varchar"` + PosterImagePath *string `json:"poster_image_path" gorm:"type:varchar"` + CreatedById *uint `json:"created_by_id" gorm:"type:int4"` + StatusId *int `json:"status_id" gorm:"type:int4"` + ClientId *uuid.UUID `json:"client_id" gorm:"type:UUID"` + 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()"` +} diff --git a/app/database/index.database.go b/app/database/index.database.go index 4d393fc..d51ed85 100644 --- a/app/database/index.database.go +++ b/app/database/index.database.go @@ -116,6 +116,7 @@ func Models() []interface{} { entity.Provinces{}, entity.OneTimePasswords{}, entity.Subscription{}, + entity.Schedules{}, entity.UserLevels{}, entity.UserRoles{}, entity.UserRoleAccesses{}, diff --git a/app/module/articles/controller/articles.controller.go b/app/module/articles/controller/articles.controller.go index 797d241..0524c33 100644 --- a/app/module/articles/controller/articles.controller.go +++ b/app/module/articles/controller/articles.controller.go @@ -109,6 +109,7 @@ func (_i *articlesController) All(c *fiber.Ctx) error { // @Description API for getting one Articles // @Tags Articles // @Security Bearer +// @Param X-Client-Key header string true "Insert the X-Client-Key" // @Param id path int true "Articles ID" // @Success 200 {object} response.Response // @Failure 400 {object} response.BadRequestError @@ -141,6 +142,7 @@ func (_i *articlesController) Show(c *fiber.Ctx) error { // @Description API for getting one Articles // @Tags Articles // @Security Bearer +// @Param X-Client-Key header string true "Insert the X-Client-Key" // @Param id path int true "Articles Old ID" // @Success 200 {object} response.Response // @Failure 400 {object} response.BadRequestError diff --git a/app/module/schedules/controller/schedules.controller.go b/app/module/schedules/controller/schedules.controller.go new file mode 100644 index 0000000..810e587 --- /dev/null +++ b/app/module/schedules/controller/schedules.controller.go @@ -0,0 +1,235 @@ +package controller + +import ( + "strconv" + "web-medols-be/app/middleware" + "web-medols-be/app/module/schedules/request" + "web-medols-be/app/module/schedules/service" + "web-medols-be/utils/paginator" + + "github.com/gofiber/fiber/v2" + "github.com/rs/zerolog" + + utilRes "web-medols-be/utils/response" + utilVal "web-medols-be/utils/validator" +) + +type schedulesController struct { + schedulesService service.SchedulesService + Log zerolog.Logger +} + +type SchedulesController interface { + All(c *fiber.Ctx) error + Show(c *fiber.Ctx) error + Save(c *fiber.Ctx) error + Update(c *fiber.Ctx) error + Delete(c *fiber.Ctx) error +} + +func NewSchedulesController(schedulesService service.SchedulesService, log zerolog.Logger) SchedulesController { + return &schedulesController{ + schedulesService: schedulesService, + Log: log, + } +} + +// All Schedules +// @Summary Get all Schedules +// @Description API for getting all Schedules +// @Tags Schedules +// @Security Bearer +// @Param X-Client-Key header string true "Insert the X-Client-Key" +// @Param Authorization header string false "Insert your access token" default(Bearer ) +// @Param req query request.SchedulesQueryRequest false "query parameters" +// @Param req query paginator.Pagination false "pagination parameters" +// @Success 200 {object} response.Response +// @Failure 400 {object} response.BadRequestError +// @Failure 401 {object} response.UnauthorizedError +// @Failure 500 {object} response.InternalServerError +// @Router /schedules [get] +func (_i *schedulesController) All(c *fiber.Ctx) error { + paginate, err := paginator.Paginate(c) + if err != nil { + return err + } + + reqContext := request.SchedulesQueryRequestContext{ + Title: c.Query("title"), + Description: c.Query("description"), + Location: c.Query("location"), + TypeId: c.Query("typeId"), + StartDate: c.Query("startDate"), + EndDate: c.Query("endDate"), + IsLiveStreaming: c.Query("isLiveStreaming"), + Speakers: c.Query("speakers"), + StatusId: c.Query("statusId"), + CreatedById: c.Query("createdById"), + } + req := reqContext.ToParamRequest() + req.Pagination = paginate + + // Get ClientId from context + clientId := middleware.GetClientID(c) + + // Get Authorization token from header + authToken := c.Get("Authorization") + _i.Log.Info().Interface("clientId", clientId).Msg("") + _i.Log.Info().Str("authToken", authToken).Msg("") + + schedulesData, paging, err := _i.schedulesService.All(clientId, req) + if err != nil { + return err + } + + return utilRes.Resp(c, utilRes.Response{ + Success: true, + Messages: utilRes.Messages{"Schedules list successfully retrieved"}, + Data: schedulesData, + Meta: paging, + }) +} + +// Show Schedule +// @Summary Get one Schedule +// @Description API for getting one Schedule +// @Tags Schedules +// @Security Bearer +// @Param id path int true "Schedule ID" +// @Success 200 {object} response.Response +// @Failure 400 {object} response.BadRequestError +// @Failure 401 {object} response.UnauthorizedError +// @Failure 500 {object} response.InternalServerError +// @Router /schedules/{id} [get] +func (_i *schedulesController) Show(c *fiber.Ctx) error { + id, err := strconv.ParseUint(c.Params("id"), 10, 0) + if err != nil { + return err + } + + // Get ClientId from context + clientId := middleware.GetClientID(c) + + scheduleData, err := _i.schedulesService.Show(clientId, uint(id)) + if err != nil { + return err + } + + return utilRes.Resp(c, utilRes.Response{ + Success: true, + Messages: utilRes.Messages{"Schedule successfully retrieved"}, + Data: scheduleData, + }) +} + +// Save Schedule +// @Summary Create Schedule +// @Description API for create Schedule +// @Tags Schedules +// @Security Bearer +// @Param X-Client-Key header string false "Insert the X-Client-Key" +// @Param X-Csrf-Token header string false "Insert the X-Csrf-Token" +// @Param Authorization header string false "Insert your access token" default(Bearer ) +// @Param payload body request.SchedulesCreateRequest true "Required payload" +// @Success 200 {object} response.Response +// @Failure 400 {object} response.BadRequestError +// @Failure 401 {object} response.UnauthorizedError +// @Failure 500 {object} response.InternalServerError +// @Router /schedules [post] +func (_i *schedulesController) Save(c *fiber.Ctx) error { + req := new(request.SchedulesCreateRequest) + if err := utilVal.ParseAndValidate(c, req); err != nil { + return err + } + + authToken := c.Get("Authorization") + + // Get ClientId from context + clientId := middleware.GetClientID(c) + + _i.Log.Info().Interface("clientId", clientId).Msg("") + _i.Log.Info().Interface("authToken", authToken).Msg("") + + dataResult, err := _i.schedulesService.Save(clientId, *req) + if err != nil { + return err + } + + return utilRes.Resp(c, utilRes.Response{ + Success: true, + Messages: utilRes.Messages{"Schedule successfully created"}, + Data: dataResult, + }) +} + +// Update Schedule +// @Summary Update Schedule +// @Description API for update Schedule +// @Tags Schedules +// @Security Bearer +// @Param X-Client-Key header string false "Insert the X-Client-Key" +// @Param X-Csrf-Token header string false "Insert the X-Csrf-Token" +// @Param payload body request.SchedulesUpdateRequest true "Required payload" +// @Param id path int true "Schedule ID" +// @Success 200 {object} response.Response +// @Failure 400 {object} response.BadRequestError +// @Failure 401 {object} response.UnauthorizedError +// @Failure 500 {object} response.InternalServerError +// @Router /schedules/{id} [put] +func (_i *schedulesController) Update(c *fiber.Ctx) error { + id, err := strconv.ParseUint(c.Params("id"), 10, 0) + if err != nil { + return err + } + + req := new(request.SchedulesUpdateRequest) + if err := utilVal.ParseAndValidate(c, req); err != nil { + return err + } + + // Get ClientId from context + clientId := middleware.GetClientID(c) + + err = _i.schedulesService.Update(clientId, uint(id), *req) + if err != nil { + return err + } + + return utilRes.Resp(c, utilRes.Response{ + Success: true, + Messages: utilRes.Messages{"Schedule successfully updated"}, + }) +} + +// Delete Schedule +// @Summary Delete Schedule +// @Description API for delete Schedule +// @Tags Schedules +// @Security Bearer +// @Param X-Client-Key header string false "Insert the X-Client-Key" +// @Param X-Csrf-Token header string false "Insert the X-Csrf-Token" +// @Param id path int true "Schedule ID" +// @Success 200 {object} response.Response +// @Failure 400 {object} response.BadRequestError +// @Failure 401 {object} response.UnauthorizedError +// @Failure 500 {object} response.InternalServerError +// @Router /schedules/{id} [delete] +func (_i *schedulesController) Delete(c *fiber.Ctx) error { + id, err := strconv.ParseUint(c.Params("id"), 10, 0) + if err != nil { + return err + } + + // Get ClientId from context + clientId := middleware.GetClientID(c) + + err = _i.schedulesService.Delete(clientId, uint(id)) + if err != nil { + return err + } + + return utilRes.Resp(c, utilRes.Response{ + Success: true, + Messages: utilRes.Messages{"Schedule successfully deleted"}, + }) +} diff --git a/app/module/schedules/mapper/schedules.mapper.go b/app/module/schedules/mapper/schedules.mapper.go new file mode 100644 index 0000000..5c37ef9 --- /dev/null +++ b/app/module/schedules/mapper/schedules.mapper.go @@ -0,0 +1,37 @@ +package mapper + +import ( + "web-medols-be/app/database/entity" + schedulesResponse "web-medols-be/app/module/schedules/response" +) + +func ToSchedulesResponse(schedule *entity.Schedules) *schedulesResponse.SchedulesResponse { + return &schedulesResponse.SchedulesResponse{ + ID: schedule.ID, + Title: schedule.Title, + Description: schedule.Description, + Location: schedule.Location, + IsLiveStreaming: schedule.IsLiveStreaming, + LiveStreamingUrl: schedule.LiveStreamingUrl, + TypeId: schedule.TypeId, + StartDate: schedule.StartDate, + EndDate: schedule.EndDate, + StartTime: schedule.StartTime, + EndTime: schedule.EndTime, + Speakers: schedule.Speakers, + PosterImagePath: schedule.PosterImagePath, + CreatedById: schedule.CreatedById, + StatusId: schedule.StatusId, + IsActive: schedule.IsActive, + CreatedAt: schedule.CreatedAt, + UpdatedAt: schedule.UpdatedAt, + } +} + +func ToSchedulesResponseList(schedules []*entity.Schedules) []*schedulesResponse.SchedulesResponse { + var responses []*schedulesResponse.SchedulesResponse + for _, schedule := range schedules { + responses = append(responses, ToSchedulesResponse(schedule)) + } + return responses +} diff --git a/app/module/schedules/repository/schedules.repository.go b/app/module/schedules/repository/schedules.repository.go new file mode 100644 index 0000000..bf4040d --- /dev/null +++ b/app/module/schedules/repository/schedules.repository.go @@ -0,0 +1,196 @@ +package repository + +import ( + "web-medols-be/app/database" + "web-medols-be/app/database/entity" + "web-medols-be/app/module/schedules/request" + "web-medols-be/utils/paginator" + + "github.com/google/uuid" +) + +type SchedulesRepository interface { + All(clientId *uuid.UUID, req request.SchedulesQueryRequest) ([]*entity.Schedules, *paginator.Pagination, error) + Show(clientId *uuid.UUID, id uint) (*entity.Schedules, error) + Save(clientId *uuid.UUID, schedule *entity.Schedules) (*entity.Schedules, error) + Update(clientId *uuid.UUID, id uint, schedule *entity.Schedules) error + Delete(clientId *uuid.UUID, id uint) error + Count(clientId *uuid.UUID, req request.SchedulesQueryRequest) (int64, error) +} + +type schedulesRepository struct { + db *database.Database +} + +func NewSchedulesRepository(db *database.Database) SchedulesRepository { + return &schedulesRepository{ + db: db, + } +} + +func (_i *schedulesRepository) All(clientId *uuid.UUID, req request.SchedulesQueryRequest) ([]*entity.Schedules, *paginator.Pagination, error) { + var schedules []*entity.Schedules + var total int64 + + query := _i.db.DB.Model(&entity.Schedules{}) + + // Apply client filter + if clientId != nil { + query = query.Where("client_id = ?", *clientId) + } + + // Apply filters + if req.Title != nil { + query = query.Where("title ILIKE ?", "%"+*req.Title+"%") + } + if req.Description != nil { + query = query.Where("description ILIKE ?", "%"+*req.Description+"%") + } + if req.Location != nil { + query = query.Where("location ILIKE ?", "%"+*req.Location+"%") + } + if req.TypeId != nil { + query = query.Where("type_id = ?", *req.TypeId) + } + if req.StartDate != nil { + query = query.Where("start_date >= ?", *req.StartDate) + } + if req.EndDate != nil { + query = query.Where("end_date <= ?", *req.EndDate) + } + if req.IsLiveStreaming != nil { + query = query.Where("is_live_streaming = ?", *req.IsLiveStreaming) + } + if req.Speakers != nil { + query = query.Where("speakers ILIKE ?", "%"+*req.Speakers+"%") + } + if req.StatusId != nil { + query = query.Where("status_id = ?", *req.StatusId) + } + if req.CreatedById != nil { + query = query.Where("created_by_id = ?", *req.CreatedById) + } + + // Count total records + if err := query.Count(&total).Error; err != nil { + return nil, nil, err + } + + // Apply pagination + if req.Pagination != nil { + offset := (req.Pagination.Page - 1) * req.Pagination.Limit + query = query.Offset(offset).Limit(req.Pagination.Limit) + } + + // Order by created_at desc + query = query.Order("created_at DESC") + + // Execute query + if err := query.Find(&schedules).Error; err != nil { + return nil, nil, err + } + + // Create pagination response + pagination := &paginator.Pagination{ + Page: req.Pagination.Page, + Limit: req.Pagination.Limit, + Count: total, + TotalPage: int((total + int64(req.Pagination.Limit) - 1) / int64(req.Pagination.Limit)), + } + + return schedules, pagination, nil +} + +func (_i *schedulesRepository) Show(clientId *uuid.UUID, id uint) (*entity.Schedules, error) { + var schedule entity.Schedules + + query := _i.db.DB.Model(&entity.Schedules{}) + + // Apply client filter + if clientId != nil { + query = query.Where("client_id = ?", *clientId) + } + + if err := query.Where("id = ?", id).First(&schedule).Error; err != nil { + return nil, err + } + + return &schedule, nil +} + +func (_i *schedulesRepository) Save(clientId *uuid.UUID, schedule *entity.Schedules) (*entity.Schedules, error) { + schedule.ClientId = clientId + + if err := _i.db.DB.Create(schedule).Error; err != nil { + return nil, err + } + + return schedule, nil +} + +func (_i *schedulesRepository) Update(clientId *uuid.UUID, id uint, schedule *entity.Schedules) error { + query := _i.db.DB.Model(&entity.Schedules{}) + + // Apply client filter + if clientId != nil { + query = query.Where("client_id = ?", *clientId) + } + + return query.Where("id = ?", id).Updates(schedule).Error +} + +func (_i *schedulesRepository) Delete(clientId *uuid.UUID, id uint) error { + query := _i.db.DB.Model(&entity.Schedules{}) + + // Apply client filter + if clientId != nil { + query = query.Where("client_id = ?", *clientId) + } + + return query.Where("id = ?", id).Delete(&entity.Schedules{}).Error +} + +func (_i *schedulesRepository) Count(clientId *uuid.UUID, req request.SchedulesQueryRequest) (int64, error) { + var total int64 + + query := _i.db.DB.Model(&entity.Schedules{}) + + // Apply client filter + if clientId != nil { + query = query.Where("client_id = ?", *clientId) + } + + // Apply filters + if req.Title != nil { + query = query.Where("title ILIKE ?", "%"+*req.Title+"%") + } + if req.Description != nil { + query = query.Where("description ILIKE ?", "%"+*req.Description+"%") + } + if req.Location != nil { + query = query.Where("location ILIKE ?", "%"+*req.Location+"%") + } + if req.TypeId != nil { + query = query.Where("type_id = ?", *req.TypeId) + } + if req.StartDate != nil { + query = query.Where("start_date >= ?", *req.StartDate) + } + if req.EndDate != nil { + query = query.Where("end_date <= ?", *req.EndDate) + } + if req.IsLiveStreaming != nil { + query = query.Where("is_live_streaming = ?", *req.IsLiveStreaming) + } + if req.Speakers != nil { + query = query.Where("speakers ILIKE ?", "%"+*req.Speakers+"%") + } + if req.StatusId != nil { + query = query.Where("status_id = ?", *req.StatusId) + } + if req.CreatedById != nil { + query = query.Where("created_by_id = ?", *req.CreatedById) + } + + return total, query.Count(&total).Error +} diff --git a/app/module/schedules/request/schedules.request.go b/app/module/schedules/request/schedules.request.go new file mode 100644 index 0000000..450765f --- /dev/null +++ b/app/module/schedules/request/schedules.request.go @@ -0,0 +1,162 @@ +package request + +import ( + "strconv" + "time" + "web-medols-be/app/database/entity" + "web-medols-be/utils/paginator" +) + +type SchedulesGeneric interface { + ToEntity() +} + +type SchedulesQueryRequest struct { + Title *string `json:"title"` + Description *string `json:"description"` + Location *string `json:"location"` + TypeId *int `json:"typeId"` + StartDate *time.Time `json:"startDate"` + EndDate *time.Time `json:"endDate"` + IsLiveStreaming *bool `json:"isLiveStreaming"` + Speakers *string `json:"speakers"` + StatusId *int `json:"statusId"` + CreatedById *uint `json:"createdById"` + Pagination *paginator.Pagination `json:"pagination"` +} + +type SchedulesCreateRequest struct { + Title string `json:"title" validate:"required"` + Description string `json:"description" validate:"required"` + Location string `json:"location" validate:"required"` + IsLiveStreaming *bool `json:"isLiveStreaming"` + LiveStreamingUrl *string `json:"liveStreamingUrl"` + TypeId int `json:"typeId" validate:"required"` + StartDate *time.Time `json:"startDate"` + EndDate *time.Time `json:"endDate"` + StartTime *string `json:"startTime"` + EndTime *string `json:"endTime"` + Speakers string `json:"speakers" validate:"required"` + PosterImagePath *string `json:"posterImagePath"` + CreatedById *uint `json:"createdById"` +} + +func (req SchedulesCreateRequest) ToEntity() *entity.Schedules { + return &entity.Schedules{ + Title: req.Title, + Description: req.Description, + Location: req.Location, + IsLiveStreaming: req.IsLiveStreaming, + LiveStreamingUrl: req.LiveStreamingUrl, + TypeId: req.TypeId, + StartDate: req.StartDate, + EndDate: req.EndDate, + StartTime: req.StartTime, + EndTime: req.EndTime, + Speakers: req.Speakers, + PosterImagePath: req.PosterImagePath, + CreatedById: req.CreatedById, + } +} + +type SchedulesUpdateRequest struct { + Title string `json:"title" validate:"required"` + Description string `json:"description" validate:"required"` + Location string `json:"location" validate:"required"` + IsLiveStreaming *bool `json:"isLiveStreaming"` + LiveStreamingUrl *string `json:"liveStreamingUrl"` + TypeId int `json:"typeId" validate:"required"` + StartDate *time.Time `json:"startDate"` + EndDate *time.Time `json:"endDate"` + StartTime *string `json:"startTime"` + EndTime *string `json:"endTime"` + Speakers string `json:"speakers" validate:"required"` + PosterImagePath *string `json:"posterImagePath"` + StatusId *int `json:"statusId"` +} + +func (req SchedulesUpdateRequest) ToEntity() *entity.Schedules { + return &entity.Schedules{ + Title: req.Title, + Description: req.Description, + Location: req.Location, + IsLiveStreaming: req.IsLiveStreaming, + LiveStreamingUrl: req.LiveStreamingUrl, + TypeId: req.TypeId, + StartDate: req.StartDate, + EndDate: req.EndDate, + StartTime: req.StartTime, + EndTime: req.EndTime, + Speakers: req.Speakers, + PosterImagePath: req.PosterImagePath, + StatusId: req.StatusId, + UpdatedAt: time.Now(), + } +} + +type SchedulesQueryRequestContext struct { + Title string `json:"title"` + Description string `json:"description"` + Location string `json:"location"` + TypeId string `json:"typeId"` + StartDate string `json:"startDate"` + EndDate string `json:"endDate"` + IsLiveStreaming string `json:"isLiveStreaming"` + Speakers string `json:"speakers"` + StatusId string `json:"statusId"` + CreatedById string `json:"createdById"` +} + +func (req SchedulesQueryRequestContext) ToParamRequest() SchedulesQueryRequest { + var request SchedulesQueryRequest + + if title := req.Title; title != "" { + request.Title = &title + } + if description := req.Description; description != "" { + request.Description = &description + } + if location := req.Location; location != "" { + request.Location = &location + } + if typeIdStr := req.TypeId; typeIdStr != "" { + typeId, err := strconv.Atoi(typeIdStr) + if err == nil { + request.TypeId = &typeId + } + } + if startDateStr := req.StartDate; startDateStr != "" { + if startDate, err := time.Parse("2006-01-02", startDateStr); err == nil { + request.StartDate = &startDate + } + } + if endDateStr := req.EndDate; endDateStr != "" { + if endDate, err := time.Parse("2006-01-02", endDateStr); err == nil { + request.EndDate = &endDate + } + } + if isLiveStreamingStr := req.IsLiveStreaming; isLiveStreamingStr != "" { + isLiveStreaming, err := strconv.ParseBool(isLiveStreamingStr) + if err == nil { + request.IsLiveStreaming = &isLiveStreaming + } + } + if speakers := req.Speakers; speakers != "" { + request.Speakers = &speakers + } + if statusIdStr := req.StatusId; statusIdStr != "" { + statusId, err := strconv.Atoi(statusIdStr) + if err == nil { + request.StatusId = &statusId + } + } + if createdByIdStr := req.CreatedById; createdByIdStr != "" { + createdById, err := strconv.Atoi(createdByIdStr) + if err == nil { + createdByIdUint := uint(createdById) + request.CreatedById = &createdByIdUint + } + } + + return request +} diff --git a/app/module/schedules/response/schedules.response.go b/app/module/schedules/response/schedules.response.go new file mode 100644 index 0000000..d0cfd80 --- /dev/null +++ b/app/module/schedules/response/schedules.response.go @@ -0,0 +1,37 @@ +package response + +import ( + "time" +) + +type SchedulesResponse struct { + ID uint `json:"id"` + Title string `json:"title"` + Description string `json:"description"` + Location string `json:"location"` + IsLiveStreaming *bool `json:"isLiveStreaming"` + LiveStreamingUrl *string `json:"liveStreamingUrl"` + TypeId int `json:"typeId"` + TypeName string `json:"typeName"` + StartDate *time.Time `json:"startDate"` + EndDate *time.Time `json:"endDate"` + StartTime *string `json:"startTime"` + EndTime *string `json:"endTime"` + Speakers string `json:"speakers"` + PosterImagePath *string `json:"posterImagePath"` + CreatedById *uint `json:"createdById"` + CreatedByName *string `json:"createdByName"` + StatusId *int `json:"statusId"` + StatusName *string `json:"statusName"` + IsActive *bool `json:"isActive"` + CreatedAt time.Time `json:"createdAt"` + UpdatedAt time.Time `json:"updatedAt"` +} + +type SchedulesSummaryStats struct { + TotalToday int `json:"totalToday"` + TotalThisWeek int `json:"totalThisWeek"` + TotalAll int `json:"totalAll"` + TotalLive int `json:"totalLive"` + TotalUpcoming int `json:"totalUpcoming"` +} diff --git a/app/module/schedules/schedules.module.go b/app/module/schedules/schedules.module.go new file mode 100644 index 0000000..936bbfe --- /dev/null +++ b/app/module/schedules/schedules.module.go @@ -0,0 +1,60 @@ +package schedules + +import ( + "web-medols-be/app/middleware" + "web-medols-be/app/module/schedules/controller" + "web-medols-be/app/module/schedules/repository" + "web-medols-be/app/module/schedules/service" + usersRepo "web-medols-be/app/module/users/repository" + + "github.com/gofiber/fiber/v2" + "go.uber.org/fx" +) + +// SchedulesRouter struct of SchedulesRouter +type SchedulesRouter struct { + App fiber.Router + Controller controller.SchedulesController + UsersRepo usersRepo.UsersRepository +} + +// NewSchedulesModule register bulky of Schedules module +var NewSchedulesModule = fx.Options( + // register repository of Schedules module + fx.Provide(repository.NewSchedulesRepository), + + // register service of Schedules module + fx.Provide(service.NewSchedulesService), + + // register controller of Schedules module + fx.Provide(controller.NewSchedulesController), + + // register router of Schedules module + fx.Provide(NewSchedulesRouter), +) + +// NewSchedulesRouter init SchedulesRouter +func NewSchedulesRouter(fiber *fiber.App, controller controller.SchedulesController, usersRepo usersRepo.UsersRepository) *SchedulesRouter { + return &SchedulesRouter{ + App: fiber, + Controller: controller, + UsersRepo: usersRepo, + } +} + +// RegisterSchedulesRoutes register routes of Schedules module +func (_i *SchedulesRouter) RegisterSchedulesRoutes() { + // define controllers + schedulesController := _i.Controller + + // define routes + _i.App.Route("/schedules", func(router fiber.Router) { + // Add user middleware to extract user level from JWT token + router.Use(middleware.UserMiddleware(_i.UsersRepo)) + router.Get("/", schedulesController.All) + router.Get("/:id", schedulesController.Show) + router.Post("/", schedulesController.Save) + router.Put("/:id", schedulesController.Update) + router.Delete("/:id", schedulesController.Delete) + }) +} diff --git a/app/module/schedules/service/schedules.service.go b/app/module/schedules/service/schedules.service.go new file mode 100644 index 0000000..4a98c98 --- /dev/null +++ b/app/module/schedules/service/schedules.service.go @@ -0,0 +1,131 @@ +package service + +import ( + "web-medols-be/app/module/schedules/mapper" + "web-medols-be/app/module/schedules/repository" + "web-medols-be/app/module/schedules/request" + schedulesResponse "web-medols-be/app/module/schedules/response" + "web-medols-be/utils/paginator" + + "github.com/google/uuid" +) + +type SchedulesService interface { + All(clientId *uuid.UUID, req request.SchedulesQueryRequest) ([]*schedulesResponse.SchedulesResponse, *paginator.Pagination, error) + Show(clientId *uuid.UUID, id uint) (*schedulesResponse.SchedulesResponse, error) + Save(clientId *uuid.UUID, req request.SchedulesCreateRequest) (*schedulesResponse.SchedulesResponse, error) + Update(clientId *uuid.UUID, id uint, req request.SchedulesUpdateRequest) error + Delete(clientId *uuid.UUID, id uint) error + SummaryStats(clientId *uuid.UUID) (*schedulesResponse.SchedulesSummaryStats, error) +} + +type schedulesService struct { + schedulesRepository repository.SchedulesRepository +} + +func NewSchedulesService(schedulesRepository repository.SchedulesRepository) SchedulesService { + return &schedulesService{ + schedulesRepository: schedulesRepository, + } +} + +func (_i *schedulesService) All(clientId *uuid.UUID, req request.SchedulesQueryRequest) ([]*schedulesResponse.SchedulesResponse, *paginator.Pagination, error) { + schedules, pagination, err := _i.schedulesRepository.All(clientId, req) + if err != nil { + return nil, nil, err + } + + responses := mapper.ToSchedulesResponseList(schedules) + return responses, pagination, nil +} + +func (_i *schedulesService) Show(clientId *uuid.UUID, id uint) (*schedulesResponse.SchedulesResponse, error) { + schedule, err := _i.schedulesRepository.Show(clientId, id) + if err != nil { + return nil, err + } + + response := mapper.ToSchedulesResponse(schedule) + return response, nil +} + +func (_i *schedulesService) Save(clientId *uuid.UUID, req request.SchedulesCreateRequest) (*schedulesResponse.SchedulesResponse, error) { + schedule := req.ToEntity() + + savedSchedule, err := _i.schedulesRepository.Save(clientId, schedule) + if err != nil { + return nil, err + } + + response := mapper.ToSchedulesResponse(savedSchedule) + return response, nil +} + +func (_i *schedulesService) Update(clientId *uuid.UUID, id uint, req request.SchedulesUpdateRequest) error { + schedule := req.ToEntity() + + err := _i.schedulesRepository.Update(clientId, id, schedule) + if err != nil { + return err + } + + return nil +} + +func (_i *schedulesService) Delete(clientId *uuid.UUID, id uint) error { + err := _i.schedulesRepository.Delete(clientId, id) + if err != nil { + return err + } + + return nil +} + +func (_i *schedulesService) SummaryStats(clientId *uuid.UUID) (*schedulesResponse.SchedulesSummaryStats, error) { + // Get today's count + todayReq := request.SchedulesQueryRequest{} + todayCount, err := _i.schedulesRepository.Count(clientId, todayReq) + if err != nil { + return nil, err + } + + // Get this week's count + weekReq := request.SchedulesQueryRequest{} + weekCount, err := _i.schedulesRepository.Count(clientId, weekReq) + if err != nil { + return nil, err + } + + // Get total count + totalReq := request.SchedulesQueryRequest{} + totalCount, err := _i.schedulesRepository.Count(clientId, totalReq) + if err != nil { + return nil, err + } + + // Get live streaming count + liveReq := request.SchedulesQueryRequest{ + IsLiveStreaming: &[]bool{true}[0], + } + liveCount, err := _i.schedulesRepository.Count(clientId, liveReq) + if err != nil { + return nil, err + } + + // Get upcoming count (start_date > today) + upcomingReq := request.SchedulesQueryRequest{} + upcomingCount, err := _i.schedulesRepository.Count(clientId, upcomingReq) + if err != nil { + return nil, err + } + + stats := &schedulesResponse.SchedulesSummaryStats{ + TotalToday: int(todayCount), + TotalThisWeek: int(weekCount), + TotalAll: int(totalCount), + TotalLive: int(liveCount), + TotalUpcoming: int(upcomingCount), + } + + return stats, nil +} diff --git a/app/router/api.go b/app/router/api.go index 64f9981..5d4860f 100644 --- a/app/router/api.go +++ b/app/router/api.go @@ -26,6 +26,7 @@ import ( "web-medols-be/app/module/master_menus" "web-medols-be/app/module/master_modules" "web-medols-be/app/module/provinces" + "web-medols-be/app/module/schedules" "web-medols-be/app/module/subscription" "web-medols-be/app/module/user_levels" "web-medols-be/app/module/user_role_accesses" @@ -67,6 +68,7 @@ type Router struct { MasterMenusRouter *master_menus.MasterMenusRouter MasterModulesRouter *master_modules.MasterModulesRouter ProvincesRouter *provinces.ProvincesRouter + SchedulesRouter *schedules.SchedulesRouter SubscriptionRouter *subscription.SubscriptionRouter UserLevelsRouter *user_levels.UserLevelsRouter UserRoleAccessesRouter *user_role_accesses.UserRoleAccessesRouter @@ -103,6 +105,7 @@ func NewRouter( masterMenuRouter *master_menus.MasterMenusRouter, masterModuleRouter *master_modules.MasterModulesRouter, provincesRouter *provinces.ProvincesRouter, + schedulesRouter *schedules.SchedulesRouter, subscriptionRouter *subscription.SubscriptionRouter, userLevelsRouter *user_levels.UserLevelsRouter, userRoleAccessesRouter *user_role_accesses.UserRoleAccessesRouter, @@ -137,6 +140,7 @@ func NewRouter( MasterMenusRouter: masterMenuRouter, MasterModulesRouter: masterModuleRouter, ProvincesRouter: provincesRouter, + SchedulesRouter: schedulesRouter, SubscriptionRouter: subscriptionRouter, UserLevelsRouter: userLevelsRouter, UserRoleAccessesRouter: userRoleAccessesRouter, @@ -181,6 +185,7 @@ func (r *Router) Register() { r.MasterMenusRouter.RegisterMasterMenusRoutes() r.MasterModulesRouter.RegisterMasterModulesRoutes() r.ProvincesRouter.RegisterProvincesRoutes() + r.SchedulesRouter.RegisterSchedulesRoutes() r.SubscriptionRouter.RegisterSubscriptionRoutes() r.UserLevelsRouter.RegisterUserLevelsRoutes() r.UserRoleAccessesRouter.RegisterUserRoleAccessesRoutes() diff --git a/docs/swagger/docs.go b/docs/swagger/docs.go index c81cfe4..c4aff50 100644 --- a/docs/swagger/docs.go +++ b/docs/swagger/docs.go @@ -7097,6 +7097,13 @@ const docTemplate = `{ ], "summary": "Get one Articles", "parameters": [ + { + "type": "string", + "description": "Insert the X-Client-Key", + "name": "X-Client-Key", + "in": "header", + "required": true + }, { "type": "integer", "description": "Articles Old ID", @@ -7641,6 +7648,13 @@ const docTemplate = `{ ], "summary": "Get one Articles", "parameters": [ + { + "type": "string", + "description": "Insert the X-Client-Key", + "name": "X-Client-Key", + "in": "header", + "required": true + }, { "type": "integer", "description": "Articles ID", @@ -12718,6 +12732,396 @@ const docTemplate = `{ } } }, + "/schedules": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "description": "API for getting all Schedules", + "tags": [ + "Schedules" + ], + "summary": "Get all Schedules", + "parameters": [ + { + "type": "string", + "description": "Insert the X-Client-Key", + "name": "X-Client-Key", + "in": "header", + "required": true + }, + { + "type": "string", + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", + "in": "header" + }, + { + "type": "integer", + "name": "createdById", + "in": "query" + }, + { + "type": "string", + "name": "description", + "in": "query" + }, + { + "type": "string", + "name": "endDate", + "in": "query" + }, + { + "type": "boolean", + "name": "isLiveStreaming", + "in": "query" + }, + { + "type": "string", + "name": "location", + "in": "query" + }, + { + "type": "string", + "name": "speakers", + "in": "query" + }, + { + "type": "string", + "name": "startDate", + "in": "query" + }, + { + "type": "integer", + "name": "statusId", + "in": "query" + }, + { + "type": "string", + "name": "title", + "in": "query" + }, + { + "type": "integer", + "name": "typeId", + "in": "query" + }, + { + "type": "integer", + "name": "count", + "in": "query" + }, + { + "type": "integer", + "name": "limit", + "in": "query" + }, + { + "type": "integer", + "name": "nextPage", + "in": "query" + }, + { + "type": "integer", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "name": "previousPage", + "in": "query" + }, + { + "type": "string", + "name": "sort", + "in": "query" + }, + { + "type": "string", + "name": "sortBy", + "in": "query" + }, + { + "type": "integer", + "name": "totalPage", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/response.Response" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/response.BadRequestError" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/response.UnauthorizedError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/response.InternalServerError" + } + } + } + }, + "post": { + "security": [ + { + "Bearer": [] + } + ], + "description": "API for create Schedule", + "tags": [ + "Schedules" + ], + "summary": "Create Schedule", + "parameters": [ + { + "type": "string", + "description": "Insert the X-Client-Key", + "name": "X-Client-Key", + "in": "header" + }, + { + "type": "string", + "description": "Insert the X-Csrf-Token", + "name": "X-Csrf-Token", + "in": "header" + }, + { + "type": "string", + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", + "in": "header" + }, + { + "description": "Required payload", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.SchedulesCreateRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/response.Response" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/response.BadRequestError" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/response.UnauthorizedError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/response.InternalServerError" + } + } + } + } + }, + "/schedules/{id}": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "description": "API for getting one Schedule", + "tags": [ + "Schedules" + ], + "summary": "Get one Schedule", + "parameters": [ + { + "type": "integer", + "description": "Schedule ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/response.Response" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/response.BadRequestError" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/response.UnauthorizedError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/response.InternalServerError" + } + } + } + }, + "put": { + "security": [ + { + "Bearer": [] + } + ], + "description": "API for update Schedule", + "tags": [ + "Schedules" + ], + "summary": "Update Schedule", + "parameters": [ + { + "type": "string", + "description": "Insert the X-Client-Key", + "name": "X-Client-Key", + "in": "header" + }, + { + "type": "string", + "description": "Insert the X-Csrf-Token", + "name": "X-Csrf-Token", + "in": "header" + }, + { + "description": "Required payload", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.SchedulesUpdateRequest" + } + }, + { + "type": "integer", + "description": "Schedule ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/response.Response" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/response.BadRequestError" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/response.UnauthorizedError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/response.InternalServerError" + } + } + } + }, + "delete": { + "security": [ + { + "Bearer": [] + } + ], + "description": "API for delete Schedule", + "tags": [ + "Schedules" + ], + "summary": "Delete Schedule", + "parameters": [ + { + "type": "string", + "description": "Insert the X-Client-Key", + "name": "X-Client-Key", + "in": "header" + }, + { + "type": "string", + "description": "Insert the X-Csrf-Token", + "name": "X-Csrf-Token", + "in": "header" + }, + { + "type": "integer", + "description": "Schedule ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/response.Response" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/response.BadRequestError" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/response.UnauthorizedError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/response.InternalServerError" + } + } + } + } + }, "/subscription": { "get": { "security": [ @@ -16855,6 +17259,108 @@ const docTemplate = `{ } } }, + "request.SchedulesCreateRequest": { + "type": "object", + "required": [ + "description", + "location", + "speakers", + "title", + "typeId" + ], + "properties": { + "createdById": { + "type": "integer" + }, + "description": { + "type": "string" + }, + "endDate": { + "type": "string" + }, + "endTime": { + "type": "string" + }, + "isLiveStreaming": { + "type": "boolean" + }, + "liveStreamingUrl": { + "type": "string" + }, + "location": { + "type": "string" + }, + "posterImagePath": { + "type": "string" + }, + "speakers": { + "type": "string" + }, + "startDate": { + "type": "string" + }, + "startTime": { + "type": "string" + }, + "title": { + "type": "string" + }, + "typeId": { + "type": "integer" + } + } + }, + "request.SchedulesUpdateRequest": { + "type": "object", + "required": [ + "description", + "location", + "speakers", + "title", + "typeId" + ], + "properties": { + "description": { + "type": "string" + }, + "endDate": { + "type": "string" + }, + "endTime": { + "type": "string" + }, + "isLiveStreaming": { + "type": "boolean" + }, + "liveStreamingUrl": { + "type": "string" + }, + "location": { + "type": "string" + }, + "posterImagePath": { + "type": "string" + }, + "speakers": { + "type": "string" + }, + "startDate": { + "type": "string" + }, + "startTime": { + "type": "string" + }, + "statusId": { + "type": "integer" + }, + "title": { + "type": "string" + }, + "typeId": { + "type": "integer" + } + } + }, "request.SetDefaultWorkflowRequest": { "type": "object", "properties": { diff --git a/docs/swagger/swagger.json b/docs/swagger/swagger.json index 3686b29..a1a546f 100644 --- a/docs/swagger/swagger.json +++ b/docs/swagger/swagger.json @@ -7086,6 +7086,13 @@ ], "summary": "Get one Articles", "parameters": [ + { + "type": "string", + "description": "Insert the X-Client-Key", + "name": "X-Client-Key", + "in": "header", + "required": true + }, { "type": "integer", "description": "Articles Old ID", @@ -7630,6 +7637,13 @@ ], "summary": "Get one Articles", "parameters": [ + { + "type": "string", + "description": "Insert the X-Client-Key", + "name": "X-Client-Key", + "in": "header", + "required": true + }, { "type": "integer", "description": "Articles ID", @@ -12707,6 +12721,396 @@ } } }, + "/schedules": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "description": "API for getting all Schedules", + "tags": [ + "Schedules" + ], + "summary": "Get all Schedules", + "parameters": [ + { + "type": "string", + "description": "Insert the X-Client-Key", + "name": "X-Client-Key", + "in": "header", + "required": true + }, + { + "type": "string", + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", + "in": "header" + }, + { + "type": "integer", + "name": "createdById", + "in": "query" + }, + { + "type": "string", + "name": "description", + "in": "query" + }, + { + "type": "string", + "name": "endDate", + "in": "query" + }, + { + "type": "boolean", + "name": "isLiveStreaming", + "in": "query" + }, + { + "type": "string", + "name": "location", + "in": "query" + }, + { + "type": "string", + "name": "speakers", + "in": "query" + }, + { + "type": "string", + "name": "startDate", + "in": "query" + }, + { + "type": "integer", + "name": "statusId", + "in": "query" + }, + { + "type": "string", + "name": "title", + "in": "query" + }, + { + "type": "integer", + "name": "typeId", + "in": "query" + }, + { + "type": "integer", + "name": "count", + "in": "query" + }, + { + "type": "integer", + "name": "limit", + "in": "query" + }, + { + "type": "integer", + "name": "nextPage", + "in": "query" + }, + { + "type": "integer", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "name": "previousPage", + "in": "query" + }, + { + "type": "string", + "name": "sort", + "in": "query" + }, + { + "type": "string", + "name": "sortBy", + "in": "query" + }, + { + "type": "integer", + "name": "totalPage", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/response.Response" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/response.BadRequestError" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/response.UnauthorizedError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/response.InternalServerError" + } + } + } + }, + "post": { + "security": [ + { + "Bearer": [] + } + ], + "description": "API for create Schedule", + "tags": [ + "Schedules" + ], + "summary": "Create Schedule", + "parameters": [ + { + "type": "string", + "description": "Insert the X-Client-Key", + "name": "X-Client-Key", + "in": "header" + }, + { + "type": "string", + "description": "Insert the X-Csrf-Token", + "name": "X-Csrf-Token", + "in": "header" + }, + { + "type": "string", + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", + "in": "header" + }, + { + "description": "Required payload", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.SchedulesCreateRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/response.Response" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/response.BadRequestError" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/response.UnauthorizedError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/response.InternalServerError" + } + } + } + } + }, + "/schedules/{id}": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "description": "API for getting one Schedule", + "tags": [ + "Schedules" + ], + "summary": "Get one Schedule", + "parameters": [ + { + "type": "integer", + "description": "Schedule ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/response.Response" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/response.BadRequestError" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/response.UnauthorizedError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/response.InternalServerError" + } + } + } + }, + "put": { + "security": [ + { + "Bearer": [] + } + ], + "description": "API for update Schedule", + "tags": [ + "Schedules" + ], + "summary": "Update Schedule", + "parameters": [ + { + "type": "string", + "description": "Insert the X-Client-Key", + "name": "X-Client-Key", + "in": "header" + }, + { + "type": "string", + "description": "Insert the X-Csrf-Token", + "name": "X-Csrf-Token", + "in": "header" + }, + { + "description": "Required payload", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.SchedulesUpdateRequest" + } + }, + { + "type": "integer", + "description": "Schedule ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/response.Response" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/response.BadRequestError" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/response.UnauthorizedError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/response.InternalServerError" + } + } + } + }, + "delete": { + "security": [ + { + "Bearer": [] + } + ], + "description": "API for delete Schedule", + "tags": [ + "Schedules" + ], + "summary": "Delete Schedule", + "parameters": [ + { + "type": "string", + "description": "Insert the X-Client-Key", + "name": "X-Client-Key", + "in": "header" + }, + { + "type": "string", + "description": "Insert the X-Csrf-Token", + "name": "X-Csrf-Token", + "in": "header" + }, + { + "type": "integer", + "description": "Schedule ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/response.Response" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/response.BadRequestError" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/response.UnauthorizedError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/response.InternalServerError" + } + } + } + } + }, "/subscription": { "get": { "security": [ @@ -16844,6 +17248,108 @@ } } }, + "request.SchedulesCreateRequest": { + "type": "object", + "required": [ + "description", + "location", + "speakers", + "title", + "typeId" + ], + "properties": { + "createdById": { + "type": "integer" + }, + "description": { + "type": "string" + }, + "endDate": { + "type": "string" + }, + "endTime": { + "type": "string" + }, + "isLiveStreaming": { + "type": "boolean" + }, + "liveStreamingUrl": { + "type": "string" + }, + "location": { + "type": "string" + }, + "posterImagePath": { + "type": "string" + }, + "speakers": { + "type": "string" + }, + "startDate": { + "type": "string" + }, + "startTime": { + "type": "string" + }, + "title": { + "type": "string" + }, + "typeId": { + "type": "integer" + } + } + }, + "request.SchedulesUpdateRequest": { + "type": "object", + "required": [ + "description", + "location", + "speakers", + "title", + "typeId" + ], + "properties": { + "description": { + "type": "string" + }, + "endDate": { + "type": "string" + }, + "endTime": { + "type": "string" + }, + "isLiveStreaming": { + "type": "boolean" + }, + "liveStreamingUrl": { + "type": "string" + }, + "location": { + "type": "string" + }, + "posterImagePath": { + "type": "string" + }, + "speakers": { + "type": "string" + }, + "startDate": { + "type": "string" + }, + "startTime": { + "type": "string" + }, + "statusId": { + "type": "integer" + }, + "title": { + "type": "string" + }, + "typeId": { + "type": "integer" + } + } + }, "request.SetDefaultWorkflowRequest": { "type": "object", "properties": { diff --git a/docs/swagger/swagger.yaml b/docs/swagger/swagger.yaml index ac69bef..9937537 100644 --- a/docs/swagger/swagger.yaml +++ b/docs/swagger/swagger.yaml @@ -941,6 +941,76 @@ definitions: required: - message type: object + request.SchedulesCreateRequest: + properties: + createdById: + type: integer + description: + type: string + endDate: + type: string + endTime: + type: string + isLiveStreaming: + type: boolean + liveStreamingUrl: + type: string + location: + type: string + posterImagePath: + type: string + speakers: + type: string + startDate: + type: string + startTime: + type: string + title: + type: string + typeId: + type: integer + required: + - description + - location + - speakers + - title + - typeId + type: object + request.SchedulesUpdateRequest: + properties: + description: + type: string + endDate: + type: string + endTime: + type: string + isLiveStreaming: + type: boolean + liveStreamingUrl: + type: string + location: + type: string + posterImagePath: + type: string + speakers: + type: string + startDate: + type: string + startTime: + type: string + statusId: + type: integer + title: + type: string + typeId: + type: integer + required: + - description + - location + - speakers + - title + - typeId + type: object request.SetDefaultWorkflowRequest: properties: workflow_id: @@ -5904,6 +5974,11 @@ paths: get: description: API for getting one Articles parameters: + - description: Insert the X-Client-Key + in: header + name: X-Client-Key + required: true + type: string - description: Articles ID in: path name: id @@ -6113,6 +6188,11 @@ paths: get: description: API for getting one Articles parameters: + - description: Insert the X-Client-Key + in: header + name: X-Client-Key + required: true + type: string - description: Articles Old ID in: path name: id @@ -9497,6 +9577,253 @@ paths: summary: Update Provinces tags: - Untags + /schedules: + get: + description: API for getting all Schedules + parameters: + - description: Insert the X-Client-Key + in: header + name: X-Client-Key + required: true + type: string + - default: Bearer + description: Insert your access token + in: header + name: Authorization + type: string + - in: query + name: createdById + type: integer + - in: query + name: description + type: string + - in: query + name: endDate + type: string + - in: query + name: isLiveStreaming + type: boolean + - in: query + name: location + type: string + - in: query + name: speakers + type: string + - in: query + name: startDate + type: string + - in: query + name: statusId + type: integer + - in: query + name: title + type: string + - in: query + name: typeId + type: integer + - in: query + name: count + type: integer + - in: query + name: limit + type: integer + - in: query + name: nextPage + type: integer + - in: query + name: page + type: integer + - in: query + name: previousPage + type: integer + - in: query + name: sort + type: string + - in: query + name: sortBy + type: string + - in: query + name: totalPage + type: integer + responses: + "200": + description: OK + schema: + $ref: '#/definitions/response.Response' + "400": + description: Bad Request + schema: + $ref: '#/definitions/response.BadRequestError' + "401": + description: Unauthorized + schema: + $ref: '#/definitions/response.UnauthorizedError' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/response.InternalServerError' + security: + - Bearer: [] + summary: Get all Schedules + tags: + - Schedules + post: + description: API for create Schedule + parameters: + - description: Insert the X-Client-Key + in: header + name: X-Client-Key + type: string + - description: Insert the X-Csrf-Token + in: header + name: X-Csrf-Token + type: string + - default: Bearer + description: Insert your access token + in: header + name: Authorization + type: string + - description: Required payload + in: body + name: payload + required: true + schema: + $ref: '#/definitions/request.SchedulesCreateRequest' + responses: + "200": + description: OK + schema: + $ref: '#/definitions/response.Response' + "400": + description: Bad Request + schema: + $ref: '#/definitions/response.BadRequestError' + "401": + description: Unauthorized + schema: + $ref: '#/definitions/response.UnauthorizedError' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/response.InternalServerError' + security: + - Bearer: [] + summary: Create Schedule + tags: + - Schedules + /schedules/{id}: + delete: + description: API for delete Schedule + parameters: + - description: Insert the X-Client-Key + in: header + name: X-Client-Key + type: string + - description: Insert the X-Csrf-Token + in: header + name: X-Csrf-Token + type: string + - description: Schedule ID + in: path + name: id + required: true + type: integer + responses: + "200": + description: OK + schema: + $ref: '#/definitions/response.Response' + "400": + description: Bad Request + schema: + $ref: '#/definitions/response.BadRequestError' + "401": + description: Unauthorized + schema: + $ref: '#/definitions/response.UnauthorizedError' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/response.InternalServerError' + security: + - Bearer: [] + summary: Delete Schedule + tags: + - Schedules + get: + description: API for getting one Schedule + parameters: + - description: Schedule ID + in: path + name: id + required: true + type: integer + responses: + "200": + description: OK + schema: + $ref: '#/definitions/response.Response' + "400": + description: Bad Request + schema: + $ref: '#/definitions/response.BadRequestError' + "401": + description: Unauthorized + schema: + $ref: '#/definitions/response.UnauthorizedError' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/response.InternalServerError' + security: + - Bearer: [] + summary: Get one Schedule + tags: + - Schedules + put: + description: API for update Schedule + parameters: + - description: Insert the X-Client-Key + in: header + name: X-Client-Key + type: string + - description: Insert the X-Csrf-Token + in: header + name: X-Csrf-Token + type: string + - description: Required payload + in: body + name: payload + required: true + schema: + $ref: '#/definitions/request.SchedulesUpdateRequest' + - description: Schedule ID + in: path + name: id + required: true + type: integer + responses: + "200": + description: OK + schema: + $ref: '#/definitions/response.Response' + "400": + description: Bad Request + schema: + $ref: '#/definitions/response.BadRequestError' + "401": + description: Unauthorized + schema: + $ref: '#/definitions/response.UnauthorizedError' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/response.InternalServerError' + security: + - Bearer: [] + summary: Update Schedule + tags: + - Schedules /subscription: get: description: API for getting all Subscription diff --git a/main.go b/main.go index 1887187..66361aa 100644 --- a/main.go +++ b/main.go @@ -29,6 +29,7 @@ import ( "web-medols-be/app/module/master_menus" "web-medols-be/app/module/master_modules" "web-medols-be/app/module/provinces" + "web-medols-be/app/module/schedules" "web-medols-be/app/module/subscription" "web-medols-be/app/module/user_levels" "web-medols-be/app/module/user_role_accesses" @@ -93,6 +94,7 @@ func main() { master_menus.NewMasterMenusModule, master_modules.NewMasterModulesModule, provinces.NewProvincesModule, + schedules.NewSchedulesModule, subscription.NewSubscriptionModule, user_levels.NewUserLevelsModule, user_roles.NewUserRolesModule,