Skip to content

feat: sprint1 api implementation#40

Open
minto1226 wants to merge 2 commits into
mainfrom
feat/api-implementation
Open

feat: sprint1 api implementation#40
minto1226 wants to merge 2 commits into
mainfrom
feat/api-implementation

Conversation

@minto1226

Copy link
Copy Markdown

目的

完成要求的三個api功能

  1. 新使用者會被更新至資料庫中
  2. 取出使用者目前檔案
  3. 使用者能更新自己暱稱與頭像

方法/實作說明

功能1. API層的 UserInitHandler() 接到 supabaseID 以及 email 後,呼叫 usecase 層的 InitUser() 進行 Create()。
功能2. API層的 UserMeHandler() 用 userID 去搜尋並回傳
功能3. API層的 UserMeUpdateHandler() 用 userID 去搜尋,並將要更新的暱稱與頭像(inputData) 更新上去

  • 主要修改:
    • 於API層新增 UserInitHandler(), UserMeHandler(), UserMeUpdateHandler(),取代原來的三函數。
    • 新增 usecase 層處理判斷邏輯,加入user.go並在其中新增 nitUser().
    • 加入 GetBySupabaseID() 函數
  • 關鍵實作:

關聯 Issue

附註

  • TODO:
    • 進行 test

@minto1226 minto1226 closed this May 17, 2026
@minto1226 minto1226 changed the title Feat/api implementation Feat: sprint1 1.1 api implementation May 17, 2026
@minto1226 minto1226 reopened this May 17, 2026
@minto1226 minto1226 changed the title Feat: sprint1 1.1 api implementation Feat: api implementation May 17, 2026
@minto1226 minto1226 changed the title Feat: api implementation feat: api implementation May 17, 2026
@minto1226 minto1226 force-pushed the feat/api-implementation branch 3 times, most recently from 111cb4b to 9043c07 Compare May 18, 2026 04:53

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

@minto1226 你是不是沒有 rebase 好,swagger的commit完全被你刪光了

@minto1226 minto1226 changed the title feat: api implementation feat: sprint1 api implementation May 27, 2026
@minto1226 minto1226 force-pushed the feat/api-implementation branch from f0a9989 to 662d66e Compare May 27, 2026 04:10
@minto1226

Copy link
Copy Markdown
Author

闖大禍了 搜里
@wade00754 現在應該弄好了 再麻煩你檢查一次了

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

還有一些問題要釐清,另外新加的Handler麻煩都要上swagger註解及產生新檔案

Comment thread internal/api/api.go
Comment on lines -191 to -193
users.POST("", api.UserCreateHandler)
users.GET("/:id", api.UserGetHandler)
users.PUT("/:id", api.UserUpdateHandler)

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.

這三個endpoint都沒有要留嗎?跟下面的問題一樣

  • UserCreateHandler是會被UserInitHandler取代掉嗎?
  • UserGetHandler應該要保留的
  • UserUpdateHandler明明還在為什麼把路由刪了?

@minto1226 minto1226 Jun 6, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

  • 是,UserCreateHandler 會用 UserInitHandler 取代
  • 我理解錯清單的要求了 已經把 UserGetHandler 以及 UserUpdateHandler 加回來了

Comment thread internal/api/user.go
Comment on lines -23 to -29
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
}

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.

UserGetHandler 怎麼刪掉了?應該要保留的 Ref

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

我漏看了,之後把它加回來

Comment thread internal/api/user.go Outdated
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")

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.

根據後端 API 實現清單:

Middleware 將 backend User.id 寫入 c.Get("userID") 供 handler 使用

所以‵userID是User的id而不是supabase_user_id`,但這裡寫的應該是Supabase Auth 的 user UUID,不是 backend 資料庫的 User.id。

c.Set("userID", claims.Subject)

要請 @torrid-fish 確認一下清單是不是有誤

Comment thread internal/api/user.go
Comment on lines -54 to -57
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()})

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.

UserCreateHandler是會被UserInitHandler取代掉嗎?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

是,之後若確認 UserInitHandler 沒問題會將 UserCreateHandler 刪掉

Comment thread internal/usecase/user.go

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.

有需要新增usecase層嗎? @G36maid

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

以目前來說不需要。

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.

那init的邏輯放到哪一層比較好?

First-login 用,以 JWT 中的 supabase_user_id + email 建立 User row(若已存在則 idempotent return)。回傳完整 User profile

Comment thread .gitignore

# Dependency directories (remove the comment below to include it)
# vendor/
node_modules/

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.

go應該不會有node_modules/才對?

@github-actions

github-actions Bot commented Jun 6, 2026

Copy link
Copy Markdown

🛡️ PR Quality Check Summary

PR Title: Passed (Length: 32/75, Format: OK). feat: sprint1 api implementation
Branch Name: Follows naming convention (feat/api-implementation)
Commit Messages: All 2 commit(s) passed (Length, Format, Case)
Conflicts: No merge conflict markers found
YAML Files: All 4 file(s) passed validation
JSON Files: All 1 file(s) are valid
TOML Files: No TOML files found to check
Go Quality: All checks passed.


🎉 All checks passed!

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