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
5 changes: 3 additions & 2 deletions api/accomodation/gate.controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ func MapQrStudentId(c *gin.Context) {

// Check if accommodation exists (can be NULL if student hasn't opted)
if res.AccommodationID == uuid.Nil {
c.JSON(http.StatusNotFound, gin.H{
"message": "Student has not opted for accommodation",
c.JSON(http.StatusOK, gin.H{
"message": "Student has not opted for accommodation",
"has_opted_accommodation": res.HasOptedAccommodation,
})
pkg.Log.WarnCtx(c, "[MAP-QR-STUDENT-WARN]: Student has no accommodation opted")
return
Expand Down
26 changes: 26 additions & 0 deletions api/accomodation/panel.controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,22 @@ func AllotHostel(c *gin.Context) {

q := db.New()

accommodation, err := q.GetAccommodationByIdQuery(ctx, tx, accommodationId)
if err == pgx.ErrNoRows {
c.JSON(http.StatusNotFound, gin.H{
"message": "Accommodation request not found",
})
pkg.Log.WarnCtx(c, "[ALLOT-HOSTEL-WARN]: Accommodation ID does not exist")
return
}
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{
"message": "Oops! Something happened. Please try again later.",
})
pkg.Log.ErrorCtx(c, "[ALLOT-HOSTEL-ERROR]: Failed to fetch accommodation request", err)
return
}

hostel, err := q.GetHostelQuery(ctx, tx, hostelIdUuid)
if err == pgx.ErrNoRows {
c.JSON(http.StatusNotFound, gin.H{
Expand All @@ -226,6 +242,15 @@ func AllotHostel(c *gin.Context) {
return
}

if accommodation.IsMale != hostel.IsMale {
c.JSON(http.StatusBadRequest, gin.H{
"message": "Hostel gender does not match student gender",
})
pkg.Log.WarnCtx(c,
"[ALLOT-HOSTEL-WARN]: Hostel gender does not match student gender")
return
}

if hostel.RoomCount <= 0 {
c.JSON(http.StatusOK, gin.H{
"message": "No rooms available in the selected hostel",
Expand Down Expand Up @@ -256,6 +281,7 @@ func AllotHostel(c *gin.Context) {
row, err = q.AllotHostelQuery(ctx, tx, db.AllotHostelQueryParams{
ID: accommodationId,
HostelID: hostleIdPgUuid,
DayCount: req.DayCount,
})
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{
Expand Down
26 changes: 14 additions & 12 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.

3 changes: 2 additions & 1 deletion db/queries/accomodation-for-hospitality-panel.sql
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ WHERE id = $1;
UPDATE accomodation_details
SET
hostel_id = $2,
day_count = $3,
payment_expires = NOW() + INTERVAL '30 minutes',
payment_status = 'PENDING',
updated_at = NOW()
Expand Down Expand Up @@ -200,7 +201,7 @@ WHERE s.hospitality_id = $1;
SELECT
hm.id AS hostel_id,
hm.hostel_name AS hostel_name,
hm.room_count AS available_rooms,
hm.room_count AS room_count,
hm.is_male AS is_male,
hm.latitude AS latitude,
hm.longtitude AS longtitude,
Expand Down
6 changes: 4 additions & 2 deletions models/accommodation-admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,25 +61,27 @@ func (r UpdateHostelRequest) Validate() error {
&r.Latitude,
v.When(r.Latitude != "",
v.Match(decimalRegex),
).Else(v.Nil),
),
),
v.Field(
&r.Longtitude,
v.When(r.Longtitude != "",
v.Match(decimalRegex),
).Else(v.Nil),
),
),
v.Field(&r.MapUrl, is.URL),
)
}

type AllotHostelRequest struct {
HostelID string `json:"hostel_id"`
DayCount int32 `json:"day_count"`
}

func (r AllotHostelRequest) Validate() error {
return v.ValidateStruct(&r,
v.Field(&r.HostelID, v.Required, is.UUID),
v.Field(&r.DayCount, v.Required, v.Min(1), v.Max(4)),
)
}

Expand Down