Feature delete user - check active reservations#34
Conversation
I also replaced 'Pending' with 'Active' in `GetPendingGuestReservations`, as it seemed to provide more consistency with `GetActiveHostReservations`. *Tests also need to be updated.
I need to use it so the integration tests pass.
magley
left a comment
There was a problem hiding this comment.
Ok, two things:
1) My comments left in this PR review.
- DTOs should not have gorm annotations since they're not DB models.
user-serviceshould not askroom-serviceto fetch host reservations (it should askreservation-service)
2) The missing commits.
I'm guessing this is because user-service's develop branch changed in the meantime and you wanted to fetch the new changes before creating this PR?
I had that situation yesterday after rebasing your PR into develop and then wanting to create my own PR. I didn't use cherry-picking, but instead:
[develop is updated]
git checkout my_branch
git rebase develop
git push --force-with-lease
I'm not sure if this would solve your problem, though. I just wanted to get the new commits from develop and then force push my local branch.
| type ReservationDTO struct { | ||
| ID uint `gorm:"primaryKey"` | ||
| RoomID uint `gorm:"not null"` | ||
| RoomAvailabilityID uint `gorm:"not null"` | ||
| RoomPriceID uint `gorm:"not null"` | ||
| GuestID uint `gorm:"not null"` | ||
| DateFrom time.Time `gorm:"not null"` | ||
| DateTo time.Time `gorm:"not null"` | ||
| GuestCount uint `gorm:"not null"` | ||
| Cancelled bool `gorm:"not null"` | ||
| Cost uint `gorm:"not null"` | ||
| } |
There was a problem hiding this comment.
Should a DTO have gorm annotations?
There was a problem hiding this comment.
Not really. I accidentally left it there after copying Reservation from model.go in the reservation-service. It’s now removed as part of another issue you pointed out (f171d2e).
| type ReservationDTO struct { | ||
| ID uint `gorm:"primaryKey"` | ||
| RoomID uint `gorm:"not null"` | ||
| RoomAvailabilityID uint `gorm:"not null"` | ||
| RoomPriceID uint `gorm:"not null"` | ||
| GuestID uint `gorm:"not null"` | ||
| DateFrom time.Time `gorm:"not null"` | ||
| DateTo time.Time `gorm:"not null"` | ||
| GuestCount uint `gorm:"not null"` | ||
| Cancelled bool `gorm:"not null"` | ||
| Cost uint `gorm:"not null"` | ||
| } |
There was a problem hiding this comment.
Why does roomclient need to define ReservationDTO? Just use reservationclient/model.go's definition.
There was a problem hiding this comment.
Ok, so I think it's because getActiveHostReservations is defined in roomclient.
So my question then becomes: why is room-service in charge of fetching hosts' reservations? Especially when the definition of room-service's GetActiveHostReservations() forwards the request to reservation-service.
Why not do the same here?
user-service -> reservation-service. Skip room-service as a middleman. If you need to fetch the rooms before you can get the reservations of a host, do that in reservation-service. So the flow would be like:
There was a problem hiding this comment.
Ok, so I think it's because getActiveHostReservations is defined in roomclient.
Correct.
So my question then becomes: why is room-service in charge of fetching hosts' reservations? Especially when the definition of room-service's GetActiveHostReservations() forwards the request to reservation-service.
Why not do the same here?
That's a good question. It happened because I made a shift during development. Initially, for the host, my idea was to avoid sending too many requests and creating tight coupling, so I wanted to handle everything in a single request. My plan was to contact the room service, check each room for active reservations, and if none had any, delete all rooms. Later, I came across a different design sketch (yours) and shifted from my initial idea, which led to the issue you noticed.
Sorry for the poor "sequence diagram". It's just a rough sketch I made early on, before any implementation.
I'm not entirely sure what the best approach is now. I'll take some time to think about it, especially since I still need to implement room deletion.
There was a problem hiding this comment.
You shouldn't worry too much about sending so many requests because:
- It's a microservice app, so it "comes with the territory"
- Since this is just a bunch of GET requests, we won't have any syncing issues (or, at least, none that we have to think about)
My issue with the current implementation is:
- it's inconsistent between Guest and Host (guest talks to reservation-service directly while host doesn't).
- reservations are not
room-service's concern - there's duplicated logic and code (this might be the worst offender since if we ever change
ReservationDTO, we have to remember to change it both inroomclientandreservationclient. If we had a 1000 clients, you'd have to check which ones defineReservationDTOevery time, as opposed to knowing thatReservationDTOis found only inreservationclient). - implementation details are leaking into other services
I think the client part of each microservice should be treated as "private" to that microservice only.
Another way to think about this is: imagine if room-service and reservation-service were both some external API. Who would you "ask" whether some user has any reservations? As far as user-service is concerned, the actual details of how reservation-service "answers" that question is not important (black box).
There was a problem hiding this comment.
Okay, I think I got what you meant, I hope I did it correctly this time (f171d2e).
I usually follow your approach, but yesterday I intentionally used |
| package roomclient | ||
|
|
||
| import ( | ||
| utils "bookem-user-service/util" | ||
| "context" | ||
| "encoding/json" | ||
| "fmt" | ||
| "io" | ||
| "net/http" | ||
| ) | ||
|
|
||
| type RoomClient interface { | ||
| // GetActiveHostReservations finds all reservations made to rooms owned by | ||
| // `host` that haven't completed yet. The user must be a host. | ||
| GetActiveHostReservations(ctx context.Context, jwt string) ([]ReservationDTO, error) | ||
| } | ||
|
|
||
| type roomClient struct { | ||
| baseURL string |
There was a problem hiding this comment.
You shouldn't have deleted the entire file roomclient/client.go. We'll need RoomClient later on, it's ok if it's empty for now.
I appreciate the effort but it's caused us more headaches than if you just copy-pasted the code that you need from the old branch. I mean I get that that's not a good idea and we should use cherry-picking but then stuff like this happens. |
This is possible since `room-service` has been discarded (no effective changes), and `reservation-service` has already been merged.
Closes #6.
First, I'd like to note that the branch name is not ideal, as there's still more work to be done to complete the user deletion feature.
This PR aims to incorporate as many components as feasible within the project's current state.
For more information, check the related issue #6, there will be a series of linked PRs.
Caveat: If you see empty commits, it’s very likely caused by using the
git cherry-pickcommand from an old branch and resolving many conflicts.Part of: