Skip to content

Feature delete user - check active reservations#34

Merged
Vasilijez merged 17 commits into
developfrom
feature-delete-user-core
Oct 13, 2025
Merged

Feature delete user - check active reservations#34
Vasilijez merged 17 commits into
developfrom
feature-delete-user-core

Conversation

@Vasilijez

@Vasilijez Vasilijez commented Oct 11, 2025

Copy link
Copy Markdown
Member

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-pick command from an old branch and resolving many conflicts.

Part of:

@Vasilijez Vasilijez self-assigned this Oct 11, 2025
@Vasilijez Vasilijez added the feature New functional or non-functional requirement implementation. label Oct 11, 2025
@Vasilijez Vasilijez linked an issue Oct 11, 2025 that may be closed by this pull request
@Vasilijez Vasilijez requested a review from magley October 11, 2025 21:38

@magley magley left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, two things:

1) My comments left in this PR review.

  • DTOs should not have gorm annotations since they're not DB models.
  • user-service should not ask room-service to fetch host reservations (it should ask reservation-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.

Comment on lines +5 to +16
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"`
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should a DTO have gorm annotations?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Comment thread src/client/roomclient/model.go Outdated
Comment on lines +17 to +28
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"`
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does roomclient need to define ReservationDTO? Just use reservationclient/model.go's definition.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Image

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

image

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.

@magley magley Oct 12, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You shouldn't worry too much about sending so many requests because:

  1. It's a microservice app, so it "comes with the territory"
  2. 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:

  1. it's inconsistent between Guest and Host (guest talks to reservation-service directly while host doesn't).
  2. reservations are not room-service's concern
  3. 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 in roomclient and reservationclient. If we had a 1000 clients, you'd have to check which ones define ReservationDTO every time, as opposed to knowing that ReservationDTO is found only in reservationclient).
  4. 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).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I think I got what you meant, I hope I did it correctly this time (f171d2e).

@Vasilijez

Copy link
Copy Markdown
Member Author

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.

I usually follow your approach, but yesterday I intentionally used git cherry-pick. All of these changes were on an old branch named feature-delete-user-finish (which has been deleted in the meantime). Then I created a new branch, feature-delete-user-core, and performed the cherry-pick. I did it because many changes occurred across the entire codebase due to the new logging, and I wanted to avoid rebasing or modifying your commits in history, as that would have caused conflicts in almost every commit.
So for me, it was a better option to go commit by commit and resolve conflicts gradually. It was actually quite simple, but as you can see, a few commits ended up being empty. I assume that's because when resolving conflicts, I discarded all changes from the cherry-picked commit, resulting in no effective changes. I'll just need to be more careful next time not to push empty commits.

@Vasilijez Vasilijez requested a review from magley October 13, 2025 11:18
Comment on lines -1 to -19
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

@magley magley Oct 13, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@magley

magley commented Oct 13, 2025

Copy link
Copy Markdown
Member

I usually follow your approach, but yesterday I intentionally used git cherry-pick. All of these changes were on an old branch named feature-delete-user-finish (which has been deleted in the meantime). Then I created a new branch, feature-delete-user-core, and performed the cherry-pick. I did it because many changes occurred across the entire codebase due to the new logging, and I wanted to avoid rebasing or modifying your commits in history, as that would have caused conflicts in almost every commit.
So for me, it was a better option to go commit by commit and resolve conflicts gradually. It was actually quite simple, but as you can see, a few commits ended up being empty. I assume that's because when resolving conflicts, I discarded all changes from the cherry-picked commit, resulting in no effective changes. I'll just need to be more careful next time not to push empty commits.

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.
@Vasilijez Vasilijez requested a review from magley October 13, 2025 12:00

@magley magley left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work.

@Vasilijez Vasilijez merged commit 0e006dd into develop Oct 13, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New functional or non-functional requirement implementation.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

User account deletion

2 participants