Fix(booking-controller): Fixed fetching of bookings
All checks were successful
ktm-booking-bot/ktm-booking-bot/pipeline/head This commit looks good

This commit is contained in:
2022-09-27 20:29:46 +08:00
parent 51b539fe7a
commit 0ea75f6211
6 changed files with 61 additions and 31 deletions

View File

@@ -472,13 +472,16 @@ const docTemplate = `{
], ],
"properties": { "properties": {
"backToSg": { "backToSg": {
"type": "boolean" "type": "boolean",
"example": false
}, },
"contact": { "contact": {
"type": "string" "type": "string",
"example": "+6512345678"
}, },
"gender": { "gender": {
"type": "string" "type": "string",
"example": "M"
}, },
"id": { "id": {
"type": "string" "type": "string"
@@ -490,16 +493,19 @@ const docTemplate = `{
"type": "string" "type": "string"
}, },
"passportExpiry": { "passportExpiry": {
"type": "string" "type": "string",
"format": "date-time"
}, },
"status": { "status": {
"type": "string" "type": "string"
}, },
"timeCode": { "timeCode": {
"type": "string" "type": "string",
"example": "1300"
}, },
"travelDate": { "travelDate": {
"type": "string" "type": "string",
"format": "date-time"
} }
} }
}, },
@@ -571,12 +577,14 @@ const docTemplate = `{
], ],
"properties": { "properties": {
"password": { "password": {
"type": "string" "type": "string",
"example": "password"
}, },
"username": { "username": {
"type": "string", "type": "string",
"maxLength": 100, "maxLength": 100,
"minLength": 2 "minLength": 2,
"example": "user"
} }
} }
}, },
@@ -590,12 +598,14 @@ const docTemplate = `{
"password": { "password": {
"type": "string", "type": "string",
"maxLength": 100, "maxLength": 100,
"minLength": 6 "minLength": 6,
"example": "password"
}, },
"username": { "username": {
"type": "string", "type": "string",
"maxLength": 100, "maxLength": 100,
"minLength": 2 "minLength": 2,
"example": "user"
} }
} }
}, },

View File

@@ -464,13 +464,16 @@
], ],
"properties": { "properties": {
"backToSg": { "backToSg": {
"type": "boolean" "type": "boolean",
"example": false
}, },
"contact": { "contact": {
"type": "string" "type": "string",
"example": "+6512345678"
}, },
"gender": { "gender": {
"type": "string" "type": "string",
"example": "M"
}, },
"id": { "id": {
"type": "string" "type": "string"
@@ -482,16 +485,19 @@
"type": "string" "type": "string"
}, },
"passportExpiry": { "passportExpiry": {
"type": "string" "type": "string",
"format": "date-time"
}, },
"status": { "status": {
"type": "string" "type": "string"
}, },
"timeCode": { "timeCode": {
"type": "string" "type": "string",
"example": "1300"
}, },
"travelDate": { "travelDate": {
"type": "string" "type": "string",
"format": "date-time"
} }
} }
}, },
@@ -563,12 +569,14 @@
], ],
"properties": { "properties": {
"password": { "password": {
"type": "string" "type": "string",
"example": "password"
}, },
"username": { "username": {
"type": "string", "type": "string",
"maxLength": 100, "maxLength": 100,
"minLength": 2 "minLength": 2,
"example": "user"
} }
} }
}, },
@@ -582,12 +590,14 @@
"password": { "password": {
"type": "string", "type": "string",
"maxLength": 100, "maxLength": 100,
"minLength": 6 "minLength": 6,
"example": "password"
}, },
"username": { "username": {
"type": "string", "type": "string",
"maxLength": 100, "maxLength": 100,
"minLength": 2 "minLength": 2,
"example": "user"
} }
} }
}, },

View File

@@ -57,10 +57,13 @@ definitions:
ktmtrainbot.BookingResponse: ktmtrainbot.BookingResponse:
properties: properties:
backToSg: backToSg:
example: false
type: boolean type: boolean
contact: contact:
example: "+6512345678"
type: string type: string
gender: gender:
example: M
type: string type: string
id: id:
type: string type: string
@@ -69,12 +72,15 @@ definitions:
passport: passport:
type: string type: string
passportExpiry: passportExpiry:
format: date-time
type: string type: string
status: status:
type: string type: string
timeCode: timeCode:
example: "1300"
type: string type: string
travelDate: travelDate:
format: date-time
type: string type: string
required: required:
- backToSg - backToSg
@@ -123,8 +129,10 @@ definitions:
user.UserLoginRequest: user.UserLoginRequest:
properties: properties:
password: password:
example: password
type: string type: string
username: username:
example: user
maxLength: 100 maxLength: 100
minLength: 2 minLength: 2
type: string type: string
@@ -135,10 +143,12 @@ definitions:
user.UserRegisterRequest: user.UserRegisterRequest:
properties: properties:
password: password:
example: password
maxLength: 100 maxLength: 100
minLength: 6 minLength: 6
type: string type: string
username: username:
example: user
maxLength: 100 maxLength: 100
minLength: 2 minLength: 2
type: string type: string

View File

@@ -46,7 +46,7 @@ func (env *Env) createBooking(
func (env *Env) getAllBooking(user *user.User) ([]Booking, error) { func (env *Env) getAllBooking(user *user.User) ([]Booking, error) {
var booking []Booking var booking []Booking
err := env.DB.Where("user_id = ?", user.ID).Order("court_weekday asc").Find(&booking).Error err := env.DB.Where("user_id = ?", user.ID).Order("created_at asc").Find(&booking).Error
if err != nil { if err != nil {
log.Println(err) log.Println(err)

View File

@@ -40,15 +40,15 @@ type BookingCreateRequest struct {
type BookingResponse struct { type BookingResponse struct {
ID uuid.UUID `json:"id"` ID uuid.UUID `json:"id"`
TravelDate time.Time `json:"travelDate"` TravelDate time.Time `json:"travelDate" swaggertype:"string" format:"date-time"`
TimeCode string `json:"timeCode"` TimeCode string `json:"timeCode" swaggertype:"string" example:"1300"`
Name string `json:"name"` Name string `json:"name"`
Gender string `json:"gender"` Gender string `json:"gender" swaggertype:"string" example:"M" enum:"M,F"`
Passport string `json:"passport"` Passport string `json:"passport"`
PassportExpiry time.Time `json:"passportExpiry"` PassportExpiry time.Time `json:"passportExpiry" swaggertype:"string" format:"date-time"`
Contact string `json:"contact"` Contact string `json:"contact" swaggertype:"string" example:"+6512345678"`
Status string `json:"status"` Status string `json:"status"`
BackToSg bool `json:"backToSg" validate:"required"` BackToSg bool `json:"backToSg" validate:"required" example:"false"`
} }
type BookingListResponse []BookingResponse type BookingListResponse []BookingResponse

View File

@@ -26,13 +26,13 @@ type UserResponse struct {
} }
type UserRegisterRequest struct { type UserRegisterRequest struct {
Username string `json:"username" validate:"required,min=2,max=100"` Username string `json:"username" validate:"required,min=2,max=100" swaggertype:"string" example:"user"`
Password string `json:"password" validate:"required,min=6,max=100"` Password string `json:"password" validate:"required,min=6,max=100" swaggertype:"string" example:"password"`
} }
type UserLoginRequest struct { type UserLoginRequest struct {
Username string `json:"username" validate:"required,min=2,max=100"` Username string `json:"username" validate:"required,min=2,max=100" swaggertype:"string" example:"user"`
Password string `json:"password" validate:"required"` Password string `json:"password" validate:"required" swaggertype:"string" example:"password"`
} }
func (userResponse *UserResponse) Render(w http.ResponseWriter, r *http.Request) error { func (userResponse *UserResponse) Render(w http.ResponseWriter, r *http.Request) error {