Skip to content

feat: add endpoints to handle user favorites operations (EM-GO-CHALLENGE)#44

Open
tmavroeid wants to merge 6 commits into
GlobalWebIndex:mainfrom
tmavroeid:feat/em-go-challenge
Open

feat: add endpoints to handle user favorites operations (EM-GO-CHALLENGE)#44
tmavroeid wants to merge 6 commits into
GlobalWebIndex:mainfrom
tmavroeid:feat/em-go-challenge

Conversation

@tmavroeid

Copy link
Copy Markdown

Summary

Two new endpoints are introduced to support the following operations:

  • an endpoint that enables a user to ADD/EDIT(shared attributes)/DELETE favorites
  • an endpoint that gets the user id and returns back a list of favorites

Changes

  • Added a users table and upgraded favorites to store per-user overrides (override JSONB), so your tweaks don’t change the asset for everyone else.
  • Split repos for clarity: pg.go, asset.postgres.go, favorites.postgres.go.
  • Favorites still use fast keyset pagination (after_t + after_id) to keep response time consistent and handle unlimited favorites without burdening the response time.
  • Seed to dev locally. Seed creates 2 users, 9 assets (3 of each type), and favorites for both.
  • Dockerfile and Docker Compose are provided to enable deployment in staging faster (by SRE team) and have the same dev environment between the whole engineering team in order to assist bug resolution in the same environment no matter the OS or other local configuration.

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

Hello @tmavroeid,

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

I have also left some comments for you to have a look when you have time :)

Comment thread src/infra/http/http.go
Comment on lines +94 to +97
if err := h.favoriteSvc.RemoveFromFavorites(userID, assetID); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Should all errors originating from the service return a bad request? If not, how would you handle different types of errors here and in addFavorite, patchFavoriteOverride?

Comment thread src/infra/http/http.go
Comment on lines +138 to +139
v1.GET("/users/:user_id/favorites", h.getFavorites)
v1.POST("/users/:user_id/favorites", h.addFavorite)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Can you identify any drawbacks in having the user_id on the path? If yes how would you handle it in a production environment?

Comment on lines +34 to +37
log.Printf("listening on %s", addr)
if err := http.ListenAndServe(addr, r); err != nil {
log.Fatal(err)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

What happens on the in flight requests, when the server receives a signal to shutdown (ex. in kubernetes)? How would you handle this in a production environment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

What would be the first thing to test in your application?

var assetsRepo core.AssetRepository = repo.NewAssetRepo(pg)
var favoritesRepo core.FavoriteRepository = repo.NewFavoriteRepo(pg)

assetSvc := core.NewAssetService(assetsRepo)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

this seems to be missing and code is not compiling

# platform-go-challenge/src/infra/http
src/infra/http/http.go:14:19: undefined: core.AssetService
src/infra/http/http.go:19:32: undefined: core.AssetService


-- ===== users =====
CREATE TABLE IF NOT EXISTS users (
id text PRIMARY KEY,

@pamanta pamanta Oct 15, 2025

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 explain a bit the rationale behind using an id with type text?

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.

2 participants