feat: sprint1 api implementation#40
Conversation
111cb4b to
9043c07
Compare
wade00754
left a comment
There was a problem hiding this comment.
@minto1226 你是不是沒有 rebase 好,swagger的commit完全被你刪光了
f0a9989 to
662d66e
Compare
|
闖大禍了 搜里 |
wade00754
left a comment
There was a problem hiding this comment.
還有一些問題要釐清,另外新加的Handler麻煩都要上swagger註解及產生新檔案
| users.POST("", api.UserCreateHandler) | ||
| users.GET("/:id", api.UserGetHandler) | ||
| users.PUT("/:id", api.UserUpdateHandler) |
There was a problem hiding this comment.
這三個endpoint都沒有要留嗎?跟下面的問題一樣
UserCreateHandler是會被UserInitHandler取代掉嗎?UserGetHandler應該要保留的UserUpdateHandler明明還在為什麼把路由刪了?
There was a problem hiding this comment.
- 是,UserCreateHandler 會用 UserInitHandler 取代
- 我理解錯清單的要求了 已經把 UserGetHandler 以及 UserUpdateHandler 加回來了
| func (a *API) UserGetHandler(c *gin.Context) { | ||
| idStr := c.Param("id") | ||
| id, err := uuid.Parse(idStr) | ||
| if err != nil { | ||
| c.JSON(http.StatusBadRequest, gin.H{"error": "invalid UUID format"}) | ||
| return | ||
| } |
| user, err := a.userRepo.GetByID(c.Request.Context(), id) | ||
| // Returns the current user's profile | ||
| func (a *API) UserMeHandler(c *gin.Context) { | ||
| supabaseID := c.GetString("userID") |
There was a problem hiding this comment.
根據後端 API 實現清單:
Middleware 將 backend User.id 寫入 c.Get("userID") 供 handler 使用
所以‵userID是User的id而不是supabase_user_id`,但這裡寫的應該是Supabase Auth 的 user UUID,不是 backend 資料庫的 User.id。
jpcorrect-backend/internal/api/auth.go
Line 169 in 662d66e
要請 @torrid-fish 確認一下清單是不是有誤
| func (a *API) UserCreateHandler(c *gin.Context) { | ||
| var user domain.User | ||
| if err := c.ShouldBindJSON(&user); err != nil { | ||
| c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) |
There was a problem hiding this comment.
UserCreateHandler是會被UserInitHandler取代掉嗎?
There was a problem hiding this comment.
是,之後若確認 UserInitHandler 沒問題會將 UserCreateHandler 刪掉
There was a problem hiding this comment.
那init的邏輯放到哪一層比較好?
First-login 用,以 JWT 中的 supabase_user_id + email 建立 User row(若已存在則 idempotent return)。回傳完整 User profile
|
|
||
| # Dependency directories (remove the comment below to include it) | ||
| # vendor/ | ||
| node_modules/ |
🛡️ PR Quality Check Summary✅ PR Title: Passed (Length: 32/75, Format: OK). 🎉 All checks passed! |
目的
完成要求的三個api功能
方法/實作說明
功能1. API層的 UserInitHandler() 接到 supabaseID 以及 email 後,呼叫 usecase 層的 InitUser() 進行 Create()。
功能2. API層的 UserMeHandler() 用 userID 去搜尋並回傳
功能3. API層的 UserMeUpdateHandler() 用 userID 去搜尋,並將要更新的暱稱與頭像(inputData) 更新上去
關聯 Issue
附註