Skip to content

Commit

Permalink
feat: init Post usecase, checkinPOST endpoint , controller
Browse files Browse the repository at this point in the history
  • Loading branch information
bblueberries committed Dec 23, 2023
1 parent 300d034 commit 3825186
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/controller/user/user_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/esc-chula/gearfest-backend/src/interfaces"
"github.com/esc-chula/gearfest-backend/src/usecase"
"github.com/gin-gonic/gin"
"gtihub.com/esc-chula/gearfest-backend/src/domain"
)

type UserController struct {
Expand Down Expand Up @@ -31,3 +32,25 @@ func (controller *UserController) GetUser(ctx *gin.Context) {
}
ctx.JSON(200, user)
}

func (controller *UserController) PostCheckin(ctx *gin.Context) {
id := ctx.Param("id")

var newCheckin domain.Checkin
err := ctx.BindJSON(&newCheckin)
if err != nil {
ctx.AbortWithStatusJSON(400,gin.H{
"Message" : "Invalid JSON format"
})
return
}









}
2 changes: 2 additions & 0 deletions src/server/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ func loadRoutes(sqlHandler interfaces.SqlHandler) *gin.Engine {
//user routes (need to refactor soon)
user_controller := controller.NewUserController(sqlHandler)
g.GET("/user/:id", user_controller.GetUser)
//post checkin route
g.POST("/user/checkin/:id",user_controller.PostCheckin)

return g
}
10 changes: 10 additions & 0 deletions src/usecase/user_usecase.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,13 @@ func (usecase *UserUsecase) Get(id string) (domain.User, error) {
err := usecase.UserRepository.GetByPrimaryKey(&user)
return user, err
}

func (usecase *UserUsecase) Post(id string) (domain.Checkin, error) {
checkin := domain.Checkin{
UserID: id,
}

err := usecase.UserRepository.Create(&checkin)
return checkin, err
}

0 comments on commit 3825186

Please sign in to comment.