Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions api/accomodation/gate.controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,47 @@ func UpdateAccommodationById(c *gin.Context) {
pkg.Log.SuccessCtx(c)
}

func DeleteAccommodationById(c *gin.Context) {
accIdStr := c.Param("accId")
accId, ok := pkg.GrabUuid(c, accIdStr, "DELETE-ACCOMMODATION", "Accommodation")
if !ok {
return
}

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

conn, err := cmd.DBPool.Acquire(ctx)
if pkg.HandleDbAcquireErr(c, err, "DELETE-ACCOMMODATION") {
return
}
defer conn.Release()

q := db.New()

row, err := q.DeleteAccommodationByIdQuery(ctx, conn, accId)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{
"message": "Oops! Something happened. Please try again later.",
})
pkg.Log.ErrorCtx(c, "[DELETE-ACCOMMODATION-ERROR]: Failed to delete accommodation request", err)
return
}
if row == 0 {
c.JSON(http.StatusNotFound, gin.H{
"message": "Accommodation request not found",
})
pkg.Log.WarnCtx(c, "[DELETE-ACCOMMODATION-WARN]: Accommodation ID does not exist")
return
}

c.JSON(http.StatusOK, gin.H{
"message": "Accommodation request deleted successfully",
})
pkg.Log.SuccessCtx(c)

}

func GateCheckIn(c *gin.Context) {
personellIdStr, ok := pkg.GrabUserId(c, "GATE")
if !ok {
Expand Down
1 change: 1 addition & 0 deletions api/accomodation/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func GateRoutes(r *gin.RouterGroup) {
r.POST("/app/map", mw.Auth, mw.CheckHospitality, mw.CheckGate, MapQrStudentId)
r.GET("/app/:accId", mw.Auth, mw.CheckHospitality, mw.CheckGate, GetAccommodationById)
r.PUT("/app/:accId", mw.Auth, mw.CheckHospitality, mw.CheckGate, UpdateAccommodationById)
r.DELETE("/app/:accId", mw.Auth, mw.CheckHospitality, mw.CheckGate, DeleteAccommodationById)

r.GET("/app/gate/status/check-in/:hospId", mw.Auth, mw.CheckHospitality, mw.CheckGate, GateCheckInStatus)
r.POST("/app/gate/check-in/:hospId", mw.Auth, mw.CheckHospitality, mw.CheckGate, GateCheckIn)
Expand Down
20 changes: 20 additions & 0 deletions bruno/hospitality (all)/DeleteAccommodation.bru
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
meta {
name: DeleteAccommodation
type: http
seq: 22
}

delete {
url: {{baseUrl}}/accommodation/app/:accId
body: none
auth: inherit
}

params:path {
accId: 008c88d4-332f-4246-845c-f8d4c234c557
}

settings {
encodeUrl: true
timeout: 0
}
13 changes: 13 additions & 0 deletions db/gen/accomodation-for-hospitality-panel.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions db/queries/accomodation-for-hospitality-panel.sql
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ SET
updated_at = NOW()
WHERE id = $1;

-- name: DeleteAccommodationByIdQuery :execrows
DELETE FROM accomodation_details
WHERE id = $1;

-- name: MapQrStudentIdQuery :one
UPDATE student
SET hospitality_id = $2
Expand Down