Browse Source

Fix(booking-controller): Fixed fetching of bookings

master
Samuel Pua 3 years ago
parent
commit
0ea75f6211
  1. 30
      backend/docs/docs.go
  2. 30
      backend/docs/swagger.json
  3. 10
      backend/docs/swagger.yaml
  4. 2
      backend/internal/ktmtrainbot/bookingcontroller.go
  5. 12
      backend/internal/ktmtrainbot/bookingmodel.go
  6. 8
      backend/internal/user/usermodel.go

30
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"
}
}
},

30
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"
}
}
},

10
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

2
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)

12
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

8
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 {

Loading…
Cancel
Save