87 lines
2.2 KiB
Go
87 lines
2.2 KiB
Go
|
|
package request
|
||
|
|
|
||
|
|
import (
|
||
|
|
"fmt"
|
||
|
|
"time"
|
||
|
|
|
||
|
|
"github.com/go-playground/validator/v10"
|
||
|
|
|
||
|
|
"furtuna-be/internal/entity"
|
||
|
|
)
|
||
|
|
|
||
|
|
type EventParam struct {
|
||
|
|
Name string `form:"name" json:"name" example:"Ketua Umum"`
|
||
|
|
Limit int `form:"limit" json:"limit" example:"10"`
|
||
|
|
Offset int `form:"offset" json:"offset" example:"0"`
|
||
|
|
}
|
||
|
|
|
||
|
|
func (p *EventParam) ToEntity() entity.EventSearch {
|
||
|
|
return entity.EventSearch{
|
||
|
|
Name: p.Name,
|
||
|
|
Limit: p.Limit,
|
||
|
|
Offset: p.Offset,
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
type Event struct {
|
||
|
|
Name string `json:"name" validate:"required"`
|
||
|
|
Description string `json:"description"`
|
||
|
|
StartDate string `json:"start_date" validate:"required"`
|
||
|
|
StartTime string `json:"start_time"`
|
||
|
|
EndDate string `json:"end_date" validate:"required"`
|
||
|
|
EndTime string `json:"end_time"`
|
||
|
|
Location string `json:"location" validate:"required"`
|
||
|
|
Level string `json:"level" validate:"required"`
|
||
|
|
Included []string `json:"included"`
|
||
|
|
Price float64 `json:"price"`
|
||
|
|
Paid bool `json:"paid"`
|
||
|
|
Status entity.Status `json:"status"`
|
||
|
|
LocationID int64 `json:"location_id"`
|
||
|
|
startDateTime time.Time
|
||
|
|
endDateTime time.Time
|
||
|
|
}
|
||
|
|
|
||
|
|
func (e *Event) ToEntity() *entity.Event {
|
||
|
|
return &entity.Event{
|
||
|
|
Name: e.Name,
|
||
|
|
Description: e.Description,
|
||
|
|
StartDate: e.startDateTime,
|
||
|
|
EndDate: e.endDateTime,
|
||
|
|
Location: e.Location,
|
||
|
|
Level: e.Level,
|
||
|
|
Included: e.Included,
|
||
|
|
Price: e.Price,
|
||
|
|
Paid: e.Paid,
|
||
|
|
LocationID: &e.LocationID,
|
||
|
|
Status: e.Status,
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func (e *Event) Validate() error {
|
||
|
|
validate := validator.New()
|
||
|
|
if err := validate.Struct(e); err != nil {
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
|
||
|
|
startDateTimeStr := e.StartDate + "T" + e.StartTime + "Z"
|
||
|
|
endDateTimeStr := e.EndDate + "T" + e.EndTime + "Z"
|
||
|
|
|
||
|
|
startDateTime, err := time.Parse(time.RFC3339, startDateTimeStr)
|
||
|
|
if err != nil {
|
||
|
|
fmt.Println("Error parsing start date-time:", err)
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
|
||
|
|
e.startDateTime = startDateTime
|
||
|
|
|
||
|
|
endDateTime, err := time.Parse(time.RFC3339, endDateTimeStr)
|
||
|
|
if err != nil {
|
||
|
|
fmt.Println("Error parsing end date-time:", err)
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
|
||
|
|
e.endDateTime = endDateTime
|
||
|
|
|
||
|
|
return nil
|
||
|
|
}
|