From 0ea75f621150cc9b6fa8a7350b94d597751517c8 Mon Sep 17 00:00:00 2001 From: Samuel Pua Date: Tue, 27 Sep 2022 20:29:46 +0800 Subject: [PATCH] Fix(booking-controller): Fixed fetching of bookings --- backend/docs/docs.go | 30 ++++++++++++------- backend/docs/swagger.json | 30 ++++++++++++------- backend/docs/swagger.yaml | 10 +++++++ .../internal/ktmtrainbot/bookingcontroller.go | 2 +- backend/internal/ktmtrainbot/bookingmodel.go | 12 ++++---- backend/internal/user/usermodel.go | 8 ++--- 6 files changed, 61 insertions(+), 31 deletions(-) diff --git a/backend/docs/docs.go b/backend/docs/docs.go index 429559a..dc185a2 100644 --- a/backend/docs/docs.go +++ b/backend/docs/docs.go @@ -472,13 +472,16 @@ const docTemplate = `{ ], "properties": { "backToSg": { - "type": "boolean" + "type": "boolean", + "example": false }, "contact": { - "type": "string" + "type": "string", + "example": "+6512345678" }, "gender": { - "type": "string" + "type": "string", + "example": "M" }, "id": { "type": "string" @@ -490,16 +493,19 @@ const docTemplate = `{ "type": "string" }, "passportExpiry": { - "type": "string" + "type": "string", + "format": "date-time" }, "status": { "type": "string" }, "timeCode": { - "type": "string" + "type": "string", + "example": "1300" }, "travelDate": { - "type": "string" + "type": "string", + "format": "date-time" } } }, @@ -571,12 +577,14 @@ const docTemplate = `{ ], "properties": { "password": { - "type": "string" + "type": "string", + "example": "password" }, "username": { "type": "string", "maxLength": 100, - "minLength": 2 + "minLength": 2, + "example": "user" } } }, @@ -590,12 +598,14 @@ const docTemplate = `{ "password": { "type": "string", "maxLength": 100, - "minLength": 6 + "minLength": 6, + "example": "password" }, "username": { "type": "string", "maxLength": 100, - "minLength": 2 + "minLength": 2, + "example": "user" } } }, diff --git a/backend/docs/swagger.json b/backend/docs/swagger.json index 25af692..554d824 100644 --- a/backend/docs/swagger.json +++ b/backend/docs/swagger.json @@ -464,13 +464,16 @@ ], "properties": { "backToSg": { - "type": "boolean" + "type": "boolean", + "example": false }, "contact": { - "type": "string" + "type": "string", + "example": "+6512345678" }, "gender": { - "type": "string" + "type": "string", + "example": "M" }, "id": { "type": "string" @@ -482,16 +485,19 @@ "type": "string" }, "passportExpiry": { - "type": "string" + "type": "string", + "format": "date-time" }, "status": { "type": "string" }, "timeCode": { - "type": "string" + "type": "string", + "example": "1300" }, "travelDate": { - "type": "string" + "type": "string", + "format": "date-time" } } }, @@ -563,12 +569,14 @@ ], "properties": { "password": { - "type": "string" + "type": "string", + "example": "password" }, "username": { "type": "string", "maxLength": 100, - "minLength": 2 + "minLength": 2, + "example": "user" } } }, @@ -582,12 +590,14 @@ "password": { "type": "string", "maxLength": 100, - "minLength": 6 + "minLength": 6, + "example": "password" }, "username": { "type": "string", "maxLength": 100, - "minLength": 2 + "minLength": 2, + "example": "user" } } }, diff --git a/backend/docs/swagger.yaml b/backend/docs/swagger.yaml index 7efa69a..4722353 100644 --- a/backend/docs/swagger.yaml +++ b/backend/docs/swagger.yaml @@ -57,10 +57,13 @@ definitions: ktmtrainbot.BookingResponse: properties: backToSg: + example: false type: boolean contact: + example: "+6512345678" type: string gender: + example: M type: string id: type: string @@ -69,12 +72,15 @@ definitions: passport: type: string passportExpiry: + format: date-time type: string status: type: string timeCode: + example: "1300" type: string travelDate: + format: date-time type: string required: - backToSg @@ -123,8 +129,10 @@ definitions: user.UserLoginRequest: properties: password: + example: password type: string username: + example: user maxLength: 100 minLength: 2 type: string @@ -135,10 +143,12 @@ definitions: user.UserRegisterRequest: properties: password: + example: password maxLength: 100 minLength: 6 type: string username: + example: user maxLength: 100 minLength: 2 type: string diff --git a/backend/internal/ktmtrainbot/bookingcontroller.go b/backend/internal/ktmtrainbot/bookingcontroller.go index 11890fd..dd848b9 100644 --- a/backend/internal/ktmtrainbot/bookingcontroller.go +++ b/backend/internal/ktmtrainbot/bookingcontroller.go @@ -46,7 +46,7 @@ func (env *Env) createBooking( func (env *Env) getAllBooking(user *user.User) ([]Booking, error) { 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 { log.Println(err) diff --git a/backend/internal/ktmtrainbot/bookingmodel.go b/backend/internal/ktmtrainbot/bookingmodel.go index 5a77142..38a8328 100644 --- a/backend/internal/ktmtrainbot/bookingmodel.go +++ b/backend/internal/ktmtrainbot/bookingmodel.go @@ -40,15 +40,15 @@ type BookingCreateRequest struct { type BookingResponse struct { ID uuid.UUID `json:"id"` - TravelDate time.Time `json:"travelDate"` - TimeCode string `json:"timeCode"` + TravelDate time.Time `json:"travelDate" swaggertype:"string" format:"date-time"` + TimeCode string `json:"timeCode" swaggertype:"string" example:"1300"` Name string `json:"name"` - Gender string `json:"gender"` + Gender string `json:"gender" swaggertype:"string" example:"M" enum:"M,F"` Passport string `json:"passport"` - PassportExpiry time.Time `json:"passportExpiry"` - Contact string `json:"contact"` + PassportExpiry time.Time `json:"passportExpiry" swaggertype:"string" format:"date-time"` + Contact string `json:"contact" swaggertype:"string" example:"+6512345678"` Status string `json:"status"` - BackToSg bool `json:"backToSg" validate:"required"` + BackToSg bool `json:"backToSg" validate:"required" example:"false"` } type BookingListResponse []BookingResponse diff --git a/backend/internal/user/usermodel.go b/backend/internal/user/usermodel.go index 1305527..d47d445 100644 --- a/backend/internal/user/usermodel.go +++ b/backend/internal/user/usermodel.go @@ -26,13 +26,13 @@ type UserResponse struct { } type UserRegisterRequest struct { - Username string `json:"username" validate:"required,min=2,max=100"` - Password string `json:"password" validate:"required,min=6,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" swaggertype:"string" example:"password"` } type UserLoginRequest struct { - Username string `json:"username" validate:"required,min=2,max=100"` - Password string `json:"password" validate:"required"` + Username string `json:"username" validate:"required,min=2,max=100" swaggertype:"string" example:"user"` + Password string `json:"password" validate:"required" swaggertype:"string" example:"password"` } func (userResponse *UserResponse) Render(w http.ResponseWriter, r *http.Request) error {