feat: add endpoints to handle user favorites operations (EM-GO-CHALLENGE)#44
feat: add endpoints to handle user favorites operations (EM-GO-CHALLENGE)#44tmavroeid wants to merge 6 commits into
Conversation
pamanta
left a comment
There was a problem hiding this comment.
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 :)
| if err := h.favoriteSvc.RemoveFromFavorites(userID, assetID); err != nil { | ||
| c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) | ||
| return | ||
| } |
There was a problem hiding this comment.
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?
| v1.GET("/users/:user_id/favorites", h.getFavorites) | ||
| v1.POST("/users/:user_id/favorites", h.addFavorite) |
There was a problem hiding this comment.
Can you identify any drawbacks in having the user_id on the path? If yes how would you handle it in a production environment?
| log.Printf("listening on %s", addr) | ||
| if err := http.ListenAndServe(addr, r); err != nil { | ||
| log.Fatal(err) | ||
| } |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
could you explain a bit the rationale behind using an id with type text?
Summary
Two new endpoints are introduced to support the following operations:
Changes
userstable and upgradedfavoritesto store per-user overrides (overrideJSONB), so your tweaks don’t change the asset for everyone else.pg.go,asset.postgres.go,favorites.postgres.go.after_t+after_id) to keep response time consistent and handle unlimited favorites without burdening the response time.