-
Notifications
You must be signed in to change notification settings - Fork 3
refactor: replace uuid with int64 for user and todo IDs #155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Gautam7352
wants to merge
8
commits into
dev
Choose a base branch
from
pr/uuid-to-int-refactor
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9e0a1fe
refactor: replace uuid with int64 for user and todo IDs
Gautam7352 3715f74
added .kiro
Gautam7352 c6b4fa7
fix: update init.sql schema from UUID to BIGSERIAL int primary keys
Gautam7352 4778b85
fix: unify Todo.id as number throughout frontend
Gautam7352 7fe63c6
fix: update TodoItem prop types from string to number for id callbacks
Gautam7352 c1ae27d
chore: remove stale uuid dependency after int64 migration
Gautam7352 877d60a
Merge remote-tracking branch 'origin/dev' into pr/uuid-to-int-refactor
Gautam7352 db35940
Merge branch 'dev' into pr/uuid-to-int-refactor
Gautam7352 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -97,3 +97,4 @@ crash.*.log | |
| # personal | ||
| docs/ideas.md | ||
| backup/ | ||
| .kiro | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,25 @@ | ||
| -- Auto-generated schema snapshot. DO NOT EDIT MANUALLY. | ||
| -- Regenerated by CI after each successful goose migration run. | ||
| -- Dual purpose: | ||
| -- 1. Used by Docker Compose to bootstrap a fresh local dev database container. | ||
| -- 2. Referenced by migration integration tests (TestInitSQLMatchesMigrationEndState) | ||
| -- as the schema reference snapshot. | ||
| -- Source of truth for schema changes: backend/migration/db/migrations/*.sql | ||
|
|
||
| CREATE TABLE IF NOT EXISTS users ( | ||
| id UUID PRIMARY KEY, | ||
| email TEXT UNIQUE NOT NULL, | ||
| password_hash TEXT NOT NULL | ||
| id BIGSERIAL PRIMARY KEY, | ||
| email TEXT UNIQUE NOT NULL, | ||
| password_hash TEXT NOT NULL | ||
| ); | ||
|
|
||
| CREATE TABLE IF NOT EXISTS todos ( | ||
| id UUID PRIMARY KEY, | ||
| item TEXT NOT NULL, | ||
| completed BOOLEAN DEFAULT FALSE, | ||
| user_id UUID REFERENCES users(id) | ||
| id BIGSERIAL PRIMARY KEY, | ||
| item TEXT NOT NULL, | ||
| completed BOOLEAN NOT NULL DEFAULT FALSE, | ||
| user_id BIGINT NOT NULL REFERENCES users(id) ON DELETE CASCADE | ||
| ); | ||
|
|
||
| CREATE TABLE IF NOT EXISTS blacklisted_tokens ( | ||
| token TEXT PRIMARY KEY, | ||
| expired_at TIMESTAMP NOT NULL | ||
| token TEXT PRIMARY KEY, | ||
| expired_at TIMESTAMPTZ NOT NULL | ||
| ); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ package handlers | |
|
|
||
| import ( | ||
| "capuchin/internal/services" | ||
| "net/http" | ||
|
|
||
| "github.com/gin-gonic/gin" | ||
| ) | ||
|
|
@@ -14,51 +15,54 @@ func NewAuthHandler(svc services.AuthService) *AuthHandler { | |
| return &AuthHandler{authService: svc} | ||
| } | ||
|
|
||
| func (h *AuthHandler) Signup(c *gin.Context) { | ||
| var reqBody struct { | ||
| Email string `json:"email" binding:"required,email"` | ||
| Password string `json:"password" binding:"required,min=8"` | ||
| } | ||
| type signupRequest struct { | ||
| Email string `json:"email" binding:"required,email"` | ||
| Password string `json:"password" binding:"required,min=8"` | ||
| } | ||
|
|
||
| if err := c.ShouldBindJSON(&reqBody); err != nil { | ||
| c.JSON(400, gin.H{"error": "Invalid request: missing fields or invalid format. Password must be >= 8 characters."}) | ||
| type loginRequest struct { | ||
| Email string `json:"email"` | ||
| Password string `json:"password"` | ||
| } | ||
|
|
||
| func (h *AuthHandler) Signup(c *gin.Context) { | ||
| var req signupRequest | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can name it as reqBody |
||
| if err := c.ShouldBindJSON(&req); err != nil { | ||
| c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request: missing fields or invalid format. Password must be >= 8 characters."}) | ||
| return | ||
| } | ||
|
|
||
| _, err := h.authService.Signup(reqBody.Email, reqBody.Password) | ||
| _, err := h.authService.Signup(req.Email, req.Password) | ||
| if err != nil { | ||
| if err == services.ErrUserExists { | ||
| c.JSON(409, gin.H{"error": "User with this email already exists"}) | ||
| c.JSON(http.StatusConflict, gin.H{"error": "User with this email already exists"}) | ||
| return | ||
| } | ||
| c.JSON(500, gin.H{"error": "Failed to create user"}) | ||
| c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to create user"}) | ||
| return | ||
| } | ||
|
|
||
| c.JSON(201, gin.H{"message": "User created successfully"}) | ||
| c.JSON(http.StatusCreated, gin.H{"message": "User created successfully"}) | ||
| } | ||
|
|
||
| func (h *AuthHandler) Login(c *gin.Context) { | ||
| var reqBody struct { | ||
| Email string `json:"email"` | ||
| Password string `json:"password"` | ||
| } | ||
| if err := c.ShouldBindJSON(&reqBody); err != nil { | ||
| c.JSON(400, gin.H{"error": err.Error()}) | ||
| var req loginRequest | ||
| if err := c.ShouldBindJSON(&req); err != nil { | ||
| c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) | ||
| return | ||
| } | ||
|
|
||
| tokenString, err := h.authService.Login(reqBody.Email, reqBody.Password) | ||
| tokenString, err := h.authService.Login(req.Email, req.Password) | ||
| if err != nil { | ||
| if err == services.ErrInvalidCredentials { | ||
| c.JSON(401, gin.H{"error": "Invalid credentials"}) | ||
| c.JSON(http.StatusUnauthorized, gin.H{"error": "Invalid credentials"}) | ||
| return | ||
| } | ||
| c.JSON(500, gin.H{"error": "Login failed"}) | ||
| c.JSON(http.StatusInternalServerError, gin.H{"error": "Login failed"}) | ||
| return | ||
| } | ||
|
|
||
| c.JSON(200, gin.H{"token": tokenString}) | ||
| c.JSON(http.StatusOK, gin.H{"token": tokenString}) | ||
| } | ||
|
|
||
| func (h *AuthHandler) Logout(c *gin.Context) { | ||
|
|
@@ -67,12 +71,12 @@ func (h *AuthHandler) Logout(c *gin.Context) { | |
| err := h.authService.Logout(tokenStr) | ||
| if err != nil { | ||
| if err == services.ErrInvalidToken { | ||
| c.JSON(400, gin.H{"error": "Invalid token components"}) | ||
| c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid token components"}) | ||
| return | ||
| } | ||
| c.JSON(500, gin.H{"error": "Failed to logout"}) | ||
| c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to logout"}) | ||
| return | ||
| } | ||
|
|
||
| c.JSON(200, gin.H{"message": "Logged out successfully"}) | ||
| c.JSON(http.StatusOK, gin.H{"message": "Logged out successfully"}) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,14 @@ | ||
| package models | ||
|
|
||
| import "github.com/google/uuid" | ||
|
|
||
| type Todo struct { | ||
| ID uuid.UUID `json:"id"` | ||
| Item string `json:"item"` | ||
| Completed bool `json:"completed"` | ||
| UserID uuid.UUID `json:"-"` | ||
| ID int64 `json:"id"` | ||
| Item string `json:"item"` | ||
| Completed bool `json:"completed"` | ||
| UserID int64 `json:"-"` | ||
| } | ||
|
|
||
| type User struct { | ||
| ID uuid.UUID `json:"id"` | ||
| Email string `json:"email"` | ||
| PasswordHash string `json:"-"` | ||
| ID int64 `json:"id"` | ||
| Email string `json:"email"` | ||
| PasswordHash string `json:"-"` | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mentioned, SERIAL in the design doc but in the code it's mentioned BIGSERIAL.
Why this deviation