From 3825186cdcef41ff9adbb7fa72422146b9a6eb1f Mon Sep 17 00:00:00 2001 From: bblueberries Date: Sat, 23 Dec 2023 21:30:05 +0700 Subject: [PATCH] feat: init Post usecase, checkinPOST endpoint , controller --- src/controller/user/user_controller.go | 23 +++++++++++++++++++++++ src/server/routes.go | 2 ++ src/usecase/user_usecase.go | 10 ++++++++++ 3 files changed, 35 insertions(+) diff --git a/src/controller/user/user_controller.go b/src/controller/user/user_controller.go index 78a34b5..a711917 100644 --- a/src/controller/user/user_controller.go +++ b/src/controller/user/user_controller.go @@ -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 { @@ -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 + } + + + + + + + + + +} \ No newline at end of file diff --git a/src/server/routes.go b/src/server/routes.go index d0aa965..e6b4dbe 100644 --- a/src/server/routes.go +++ b/src/server/routes.go @@ -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 } diff --git a/src/usecase/user_usecase.go b/src/usecase/user_usecase.go index 2c40fc4..1a08256 100644 --- a/src/usecase/user_usecase.go +++ b/src/usecase/user_usecase.go @@ -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 +} +