-
Notifications
You must be signed in to change notification settings - Fork 0
Feat/link backend mobile guests #181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
9f7ec48
rooms migration file
eric-kitagawa 3967f59
Merge branch 'main' into eric/rooms-migration
eric-kitagawa 33cf39f
feat: guest booking migration
eric-kitagawa f0e18cc
rls fix
manueltorres0 6fd9bf6
indexes on both tables
manueltorres0 6a67568
type fix
manueltorres0 da22ba4
incomplete guest bookings table + endpoint
manueltorres0 fae3721
server integrated + openapi
manueltorres0 4fbeb9b
moved getRooms to rooms repo
manueltorres0 074032b
get guests endpoint
manueltorres0 9b5449d
changes
manueltorres0 e6442b9
fixed openapi
manueltorres0 38df682
remove stale webhook dir
eric-kitagawa 394febf
route for specific guest info
manueltorres0 9a508e3
cleanup GetBookingsByFloor handler
eric-kitagawa 138b68f
changes to endpoints and fe
manueltorres0 0bfab1e
changed some models
manueltorres0 47d04b7
Merge branch 'feat/guest-and-booking-endpoint' into feat/link-backend…
manueltorres0 40d21eb
bum ass
manueltorres0 959351a
small refactor of model
manueltorres0 872212b
swag fix
manueltorres0 e05f10d
build issues
manueltorres0 0242c4f
merged guest bookings
manueltorres0 c3017e5
small fix
manueltorres0 d10e876
Merge branch 'main' into feat/guest-and-booking-endpoint
manueltorres0 e4310ad
filtered by hotel id
manueltorres0 2a5d7d5
Merge branch 'feat/guest-and-booking-endpoint' into feat/link-backend…
manueltorres0 d9b1aa0
fixes and more fixes
manueltorres0 b44bf13
pagination
manueltorres0 be57799
pretty much done
manueltorres0 05be5dc
final things and removed logs
manueltorres0 64f5105
uncomment middleware
manueltorres0 65dfa4c
Merge branch 'main' into feat/link-backend-mobile-guests
manueltorres0 29728a6
fixes
manueltorres0 3273d8d
pipeline fix
manueltorres0 e4aeab0
merged
manueltorres0 c1e8117
merged main
manueltorres0 5a02cd7
merged
manueltorres0 d83d009
swagger fix
manueltorres0 85e516a
comments
manueltorres0 defceac
comp refactor
manueltorres0 522e018
merged main
manueltorres0 392d3e1
lint
manueltorres0 3dbe0da
please linter
manueltorres0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| package handler | ||
|
|
||
| import ( | ||
| "context" | ||
| "strconv" | ||
| "strings" | ||
|
|
||
| "github.com/generate/selfserve/internal/errs" | ||
| "github.com/generate/selfserve/internal/models" | ||
| "github.com/gofiber/fiber/v2" | ||
| ) | ||
|
|
||
| type GuestBookingsRepository interface { | ||
| FindBookingByFloor(ctx context.Context, floors []int) ([]*models.GuestBooking, error) | ||
| } | ||
|
|
||
| type GuestBookingHandler struct { | ||
| repo GuestBookingsRepository | ||
| } | ||
|
|
||
| func NewGuestBookingsHandler(repo GuestBookingsRepository) *GuestBookingHandler { | ||
| return &GuestBookingHandler{repo: repo} | ||
| } | ||
|
|
||
| // GetBookingsByFloor godoc | ||
| // @Summary Get guest Bookings By Floor | ||
| // @Description Retrieves multiple guest bookings whose booked rooms are in the provided floors array | ||
| // @Tags guest-bookings | ||
| // @Produce json | ||
| // @Param floors query string true "Comma-separated floor numbers" | ||
| // @Success 200 {object} []models.GuestBooking | ||
| // @Failure 400 {object} map[string]string | ||
| // @Failure 500 {object} map[string]string | ||
| // @Router /guest_bookings/floor [get] | ||
| func (h *GuestBookingHandler) GetBookingsByFloor(c *fiber.Ctx) error { | ||
| floors, err := getQueryFloors(c.Query("floors")) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| bookings, err := h.repo.FindBookingByFloor(c.Context(), floors) | ||
|
|
||
| if err != nil { | ||
| return errs.InternalServerError() | ||
| } | ||
|
|
||
| return c.JSON(bookings) | ||
| } | ||
|
|
||
| func getQueryFloors(rawFloors string) ([]int, error) { | ||
| if rawFloors == "" { | ||
| return nil, errs.BadRequest("Floors must be provided") | ||
| } | ||
|
|
||
| parts := strings.Split(rawFloors, ",") | ||
| floors := make([]int, 0, len(parts)) | ||
| for _, p := range parts { | ||
| floor, err := strconv.Atoi(strings.TrimSpace(p)) | ||
| if err != nil { | ||
| return nil, errs.BadRequest("Floors must be an array of integers") | ||
| } | ||
| floors = append(floors, floor) | ||
| } | ||
| return floors, nil | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left this cmt on a your other pr but might be relevant here
I'm missing some context on what you're using this for so I'll just be adding additional info and let you use your best judgement.
If your page only requires to filter by floor, this is ok for now. But typically, filtering should be done using a post endpoint, since it's not really ideal to filter a lot of data using a query parameter. The query body is a much better use case for passing more complicated objects to the backend, and so filtering typically use query bodies to pass their objects/lists instead.
Also note that if you only want to retrieve bookings for rooms 1-50, your query would be very long.
Overall, if it's just fetching this to display a fixed amount that you know is small, than this is fine. Otherwise, I'd advise swapping over to use a POST to pass more complicated objects and data in the body.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
forgot to delete this on this pr too, but this is not needed and dont think it will be in general, so I will delete, if it is needed later on we have to refactor anyway