Skip to content

Commit 6a30110

Browse files
committed
Switch ids to strings for uuids
1 parent 3cc981e commit 6a30110

File tree

5 files changed

+10
-6
lines changed

5 files changed

+10
-6
lines changed

dao/user_dao.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import (
1111
var users []models.User
1212

1313
func InitDb() {
14-
users = append(users, models.User{Id: 1, AuthToken: "userA", Email: "[email protected]", DOB: "01/23/1984", FavoriteCity: "Dallas"})
15-
users = append(users, models.User{Id: 2, AuthToken: "userB", Email: "[email protected]", DOB: "02/27/1991", FavoriteCity: "Portland", Admin: true})
14+
users = append(users, models.User{Id: "abc", AuthToken: "userA", Email: "[email protected]", DOB: "01/23/1984", FavoriteCity: "Dallas"})
15+
users = append(users, models.User{Id: "xyz", AuthToken: "userB", Email: "[email protected]", DOB: "02/27/1991", FavoriteCity: "Portland", Admin: true})
1616
}
1717

1818
func GetAllUsers(currentUser models.User) []models.User {
@@ -31,7 +31,7 @@ func GetAllUsers(currentUser models.User) []models.User {
3131
return results
3232
}
3333

34-
func GetUserById(id int64, currentUser models.User) (models.User, error) {
34+
func GetUserById(id string, currentUser models.User) (models.User, error) {
3535
// if not admin, make only itself findable
3636
if !currentUser.Admin {
3737
for _, u := range users {

models/user.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package models
22

33
type User struct {
4-
Id int64 `json:"id"`
4+
Id string `json:"id"`
55
Email string `json:"email"`
66
DOB string `json:"dob"`
77
FavoriteCity string `json:"favorite_city"`

resources/helper.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ func getIntParam(c *gin.Context, name string) (int64, error) {
1818
return id, nil
1919
}
2020

21+
func getStringParam(c *gin.Context, name string) (string, error) {
22+
return c.Params.ByName(name), nil
23+
}
24+
2125
func getCurrentUser(c *gin.Context) models.User {
2226
return c.MustGet("currentUser").(models.User)
2327
}

resources/user_resource.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func GetAllUsers(c *gin.Context) {
1515
func GetUserById(c *gin.Context) {
1616
currentUser := getCurrentUser(c)
1717

18-
id, err := getIntParam(c, "id")
18+
id, err := getStringParam(c, "id")
1919
if err != nil {
2020
c.JSON(400, "could not parse id")
2121
return

serializers/user_serializers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type UserSubsetJSON struct {
1919
}
2020

2121
type UserSubset struct {
22-
Id int64 `json:"id"`
22+
Id string `json:"id"`
2323
Email string `json:"email"`
2424
DOB string `json:"dob"`
2525
}

0 commit comments

Comments
 (0)