Skip to content

Commit 1735d60

Browse files
authored
Merge pull request #260 from Nandgopal-R/feat/delete-accom
Feat/delete accom
2 parents 92ac966 + 0ead868 commit 1735d60

5 files changed

Lines changed: 79 additions & 0 deletions

File tree

api/accomodation/gate.controllers.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,47 @@ func UpdateAccommodationById(c *gin.Context) {
218218
pkg.Log.SuccessCtx(c)
219219
}
220220

221+
func DeleteAccommodationById(c *gin.Context) {
222+
accIdStr := c.Param("accId")
223+
accId, ok := pkg.GrabUuid(c, accIdStr, "DELETE-ACCOMMODATION", "Accommodation")
224+
if !ok {
225+
return
226+
}
227+
228+
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
229+
defer cancel()
230+
231+
conn, err := cmd.DBPool.Acquire(ctx)
232+
if pkg.HandleDbAcquireErr(c, err, "DELETE-ACCOMMODATION") {
233+
return
234+
}
235+
defer conn.Release()
236+
237+
q := db.New()
238+
239+
row, err := q.DeleteAccommodationByIdQuery(ctx, conn, accId)
240+
if err != nil {
241+
c.JSON(http.StatusInternalServerError, gin.H{
242+
"message": "Oops! Something happened. Please try again later.",
243+
})
244+
pkg.Log.ErrorCtx(c, "[DELETE-ACCOMMODATION-ERROR]: Failed to delete accommodation request", err)
245+
return
246+
}
247+
if row == 0 {
248+
c.JSON(http.StatusNotFound, gin.H{
249+
"message": "Accommodation request not found",
250+
})
251+
pkg.Log.WarnCtx(c, "[DELETE-ACCOMMODATION-WARN]: Accommodation ID does not exist")
252+
return
253+
}
254+
255+
c.JSON(http.StatusOK, gin.H{
256+
"message": "Accommodation request deleted successfully",
257+
})
258+
pkg.Log.SuccessCtx(c)
259+
260+
}
261+
221262
func GateCheckIn(c *gin.Context) {
222263
personellIdStr, ok := pkg.GrabUserId(c, "GATE")
223264
if !ok {

api/accomodation/routes.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ func GateRoutes(r *gin.RouterGroup) {
4444
r.POST("/app/map", mw.Auth, mw.CheckHospitality, mw.CheckGate, MapQrStudentId)
4545
r.GET("/app/:accId", mw.Auth, mw.CheckHospitality, mw.CheckGate, GetAccommodationById)
4646
r.PUT("/app/:accId", mw.Auth, mw.CheckHospitality, mw.CheckGate, UpdateAccommodationById)
47+
r.DELETE("/app/:accId", mw.Auth, mw.CheckHospitality, mw.CheckGate, DeleteAccommodationById)
4748

4849
r.GET("/app/gate/status/check-in/:hospId", mw.Auth, mw.CheckHospitality, mw.CheckGate, GateCheckInStatus)
4950
r.POST("/app/gate/check-in/:hospId", mw.Auth, mw.CheckHospitality, mw.CheckGate, GateCheckIn)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
meta {
2+
name: DeleteAccommodation
3+
type: http
4+
seq: 22
5+
}
6+
7+
delete {
8+
url: {{baseUrl}}/accommodation/app/:accId
9+
body: none
10+
auth: inherit
11+
}
12+
13+
params:path {
14+
accId: 008c88d4-332f-4246-845c-f8d4c234c557
15+
}
16+
17+
settings {
18+
encodeUrl: true
19+
timeout: 0
20+
}

db/gen/accomodation-for-hospitality-panel.sql.go

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

db/queries/accomodation-for-hospitality-panel.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ SET
160160
updated_at = NOW()
161161
WHERE id = $1;
162162

163+
-- name: DeleteAccommodationByIdQuery :execrows
164+
DELETE FROM accomodation_details
165+
WHERE id = $1;
166+
163167
-- name: MapQrStudentIdQuery :one
164168
UPDATE student
165169
SET hospitality_id = $2

0 commit comments

Comments
 (0)