Skip to content

Commit

Permalink
fix: location_id can't be zero #13
Browse files Browse the repository at this point in the history
  • Loading branch information
xappyyy authored Jan 8, 2024
2 parents 6db6d03 + 5da8af5 commit 8bca5e4
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 13 deletions.
4 changes: 2 additions & 2 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const docTemplate = `{
"Bearer": []
}
],
"description": "Check in user with location id.",
"description": "Check in the user with location id.",
"consumes": [
"application/json"
],
Expand Down Expand Up @@ -148,7 +148,7 @@ const docTemplate = `{
"Bearer": []
}
],
"description": "Update is_user_completed to true and update cocktail_id.",
"description": "Set is_user_completed to true and update cocktail_id with a non-zero value.",
"consumes": [
"application/json"
],
Expand Down
4 changes: 2 additions & 2 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"Bearer": []
}
],
"description": "Check in user with location id.",
"description": "Check in the user with location id.",
"consumes": [
"application/json"
],
Expand Down Expand Up @@ -140,7 +140,7 @@
"Bearer": []
}
],
"description": "Update is_user_completed to true and update cocktail_id.",
"description": "Set is_user_completed to true and update cocktail_id with a non-zero value.",
"consumes": [
"application/json"
],
Expand Down
5 changes: 3 additions & 2 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ paths:
post:
consumes:
- application/json
description: Check in user with location id.
description: Check in the user with location id.
operationId: Checkin
parameters:
- description: Location id to be checked in.
Expand Down Expand Up @@ -133,7 +133,8 @@ paths:
patch:
consumes:
- application/json
description: Update is_user_completed to true and update cocktail_id.
description: Set is_user_completed to true and update cocktail_id with a non-zero
value.
operationId: PatchUserCompleted
parameters:
- description: Cocktail id of user.
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/user_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (controller *UserController) SignIn(ctx *gin.Context) {
// Checkin godoc
//
// @summary Check in
// @description Check in user with location id.
// @description Check in the user with location id.
// @tags user
// @id Checkin
// @security Bearer
Expand Down Expand Up @@ -165,7 +165,7 @@ func (controller *UserController) PatchUserName(ctx *gin.Context) {
// PatchUserCompleted godoc
//
// @summary User completed
// @description Update is_user_completed to true and update cocktail_id.
// @description Set is_user_completed to true and update cocktail_id with a non-zero value.
// @tags user
// @id PatchUserCompleted
// @security Bearer
Expand Down
2 changes: 1 addition & 1 deletion src/domains/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type Checkin struct {
}

type CreateCheckinDTO struct {
LocationID uint `json:"location_id" binding:"required"`
LocationID *uint `json:"location_id" binding:"required"`
}

type CreateUserCompletedDTO struct {
Expand Down
2 changes: 1 addition & 1 deletion src/usecases/user_usecase.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (usecase *UserUsecases) Post(id string, CheckinDTO domains.CreateCheckinDTO

checkin := domains.Checkin{
UserID: id,
LocationID: CheckinDTO.LocationID,
LocationID: *CheckinDTO.LocationID,
}

err := usecase.UserRepository.Checkin(&checkin)
Expand Down
9 changes: 6 additions & 3 deletions tests/user/user_usecase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ func (suite *UserUsecasesTest) TestCheckinSuccess() {
usecase := usecases.UserUsecases{
UserRepository: repo,
}
var locationID uint = 2
checkinDTO := domains.CreateCheckinDTO{
LocationID: 2,
LocationID: &locationID,
}
checkinInput := &domains.Checkin{
UserID: suite.User.UserID,
Expand All @@ -99,8 +100,9 @@ func (suite *UserUsecasesTest) TestAlreadyCheckin() {
usecase := usecases.UserUsecases{
UserRepository: repo,
}
var locationID uint = 0
checkinDTO := domains.CreateCheckinDTO{
LocationID: 0,
LocationID: &locationID,
}
checkinInput := &domains.Checkin{
UserID: suite.User.UserID,
Expand All @@ -123,8 +125,9 @@ func (suite *UserUsecasesTest) TestCheckinUserNotFound() {
break
}
}
var locationID uint = 1
checkinDTO := domains.CreateCheckinDTO{
LocationID: 1,
LocationID: &locationID,
}
checkinInput := &domains.Checkin{
UserID: id,
Expand Down

0 comments on commit 8bca5e4

Please sign in to comment.