Skip to content

Complete GWI Favorites Service - Implementation#36

Open
adrfinance wants to merge 2 commits into
GlobalWebIndex:mainfrom
adrfinance:main
Open

Complete GWI Favorites Service - Implementation#36
adrfinance wants to merge 2 commits into
GlobalWebIndex:mainfrom
adrfinance:main

Conversation

@adrfinance

Copy link
Copy Markdown

No description provided.

@pamanta pamanta left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hi @adrfinance

Thank you very much for taking the time to complete the assignment!

I've left some questions for you to address, when you have the time. No rush, take your time. :)


// Repository implements FavoritesRepository using in-memory storage
type Repository struct {
mu sync.RWMutex

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Could you identify some downsides of having a shared mutex for the repository? If yes, how would you handle those downsides?

Comment on lines +64 to +70
// Update in all user favorites
for userID := range r.favorites {
if favorite, exists := r.favorites[userID][asset.GetID()]; exists {
favorite.Asset = asset
favorite.UpdatedAt = time.Now()
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

If favorites increase in size, this process could become a real bottleneck. Can you find a way to restructure the schema of the favorites repo to avoid it?

Comment on lines +124 to +125
// UpdateFavoriteDescription updates the description of a favorite asset
func (s *FavoritesService) UpdateFavoriteDescription(ctx context.Context, userID, assetID, description string) error {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Having a shared description between user favorites can be problematic? Can you identify why and how would you improve it?

api.Use(h.CORSMiddleware)

// User favorites routes
userRoutes := api.PathPrefix("/users/{userID}/favorites").Subrouter()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Identifying the user by userId passed in the path is fine for the assignment, but would that also work for a production environment? If not, how would you handle user identification differently?

@adrfinance

adrfinance commented Sep 5, 2025 via email

Copy link
Copy Markdown
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants