Feat(ktm-booking): Initial commit
Some checks failed
ktm-booking-bot/ktm-booking-bot/pipeline/head Something is wrong with the build of this commit
Some checks failed
ktm-booking-bot/ktm-booking-bot/pipeline/head Something is wrong with the build of this commit
This commit is contained in:
92
backend/internal/ktmtrainbot/bookingmodel.go
Normal file
92
backend/internal/ktmtrainbot/bookingmodel.go
Normal file
@@ -0,0 +1,92 @@
|
||||
package ktmtrainbot
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"git.samuelpua.com/telboon/ktm-train-bot/backend/internal/user"
|
||||
"github.com/google/uuid"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type Booking struct {
|
||||
ID uuid.UUID `gorm:"primaryKey;type:uuid;default:uuid_generate_v4()"`
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
DeletedAt gorm.DeletedAt `gorm:"index"`
|
||||
User user.User
|
||||
UserID uuid.UUID
|
||||
TravelDate time.Time // Only date matters
|
||||
TimeCode string // e.g. 1400
|
||||
Name string
|
||||
Gender string // M/F
|
||||
Passport string
|
||||
PassportExpiry time.Time // Only date matters
|
||||
Contact string // +6512345678
|
||||
Status string // "success", "error", "pending", "running"
|
||||
}
|
||||
|
||||
type BookingCreateRequest struct {
|
||||
TravelDate time.Time `json:"travelDate" validate:"required"`
|
||||
TimeCode string `json:"timeCode" validate:"required len=4"`
|
||||
Name string `json:"name" validate:"required"`
|
||||
Gender string `json:"gender" validate:"required len=1 containsany=MF"`
|
||||
Passport string `json:"passport" validate:"required"`
|
||||
PassportExpiry time.Time `json:"passportExpiry" validate:"required"`
|
||||
Contact string `json:"contact" validate:"required e164"`
|
||||
}
|
||||
|
||||
type BookingResponse struct {
|
||||
ID uuid.UUID `json:"id"`
|
||||
TravelDate time.Time `json:"travelDate"`
|
||||
TimeCode string `json:"timeCode"`
|
||||
Name string `json:"name"`
|
||||
Gender string `json:"gender"`
|
||||
Passport string `json:"passport"`
|
||||
PassportExpiry time.Time `json:"passportExpiry"`
|
||||
Contact string `json:"contact"`
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
type BookingListResponse []BookingResponse
|
||||
|
||||
func (res *BookingResponse) Render(w http.ResponseWriter, r *http.Request) error {
|
||||
// Pre-processing before a response is marshalled and sent across the wire
|
||||
return nil
|
||||
}
|
||||
|
||||
func (res BookingListResponse) Render(w http.ResponseWriter, r *http.Request) error {
|
||||
// Pre-processing before a response is marshalled and sent across the wire
|
||||
// if res == nil {
|
||||
// var empty []BookingResponse
|
||||
// res = empty
|
||||
// }
|
||||
return nil
|
||||
}
|
||||
|
||||
func (env *Env) NewBookingResponse(model *Booking) *BookingResponse {
|
||||
res := &BookingResponse{
|
||||
ID: model.ID,
|
||||
TravelDate: model.TravelDate,
|
||||
TimeCode: model.TimeCode,
|
||||
Name: model.Name,
|
||||
Gender: model.Gender,
|
||||
Passport: model.Passport,
|
||||
PassportExpiry: model.PassportExpiry,
|
||||
Contact: model.Contact,
|
||||
Status: model.Status,
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
func (env *Env) NewBookingListResponse(model []Booking) BookingListResponse {
|
||||
var res []BookingResponse
|
||||
|
||||
for _, item := range model {
|
||||
curr := env.NewBookingResponse(&item)
|
||||
res = append(res, *curr)
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
Reference in New Issue
Block a user