-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d2a34c1
commit bf6475e
Showing
5 changed files
with
146 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package serializer | ||
|
||
import ( | ||
"time" | ||
|
||
db "github.com/baato/before-after/db/sqlc" | ||
) | ||
|
||
type UserResponse struct { | ||
ID int32 `json:"id"` | ||
Username string `json:"username"` | ||
PictureURL string `json:"picture_url"` | ||
CreatedAt time.Time `json:"created_at"` | ||
Role int32 `json:"role"` | ||
EmailAddress string `json:"email_address"` | ||
IsEmailVerified bool `json:"is_email_verified"` | ||
} | ||
|
||
func NewUserResponse(user db.User) UserResponse { | ||
return UserResponse{ | ||
ID: user.ID, | ||
Username: user.Username, | ||
PictureURL: user.PictureUrl.String, | ||
CreatedAt: user.CreatedAt, | ||
Role: user.Role, | ||
EmailAddress: user.EmailAddress.String, | ||
IsEmailVerified: user.IsEmailVerified.Bool, | ||
} | ||
} | ||
|
||
type UpdateUserRequest struct { | ||
ID int32 `json:"id"` | ||
Role int32 `json:"role"` | ||
EmailAddress string `json:"email_address"` | ||
IsEmailVerified bool `json:"is_email_verified"` | ||
} |
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package services | ||
|
||
import ( | ||
"context" | ||
"database/sql" | ||
|
||
db "github.com/baato/before-after/db/sqlc" | ||
) | ||
|
||
// Create a new user in db | ||
func createUser(query *db.Queries, userinfo *UserInfo) (db.User, error) { | ||
arg := db.CreateUserParams{ | ||
ID: userinfo.ID, | ||
Username: userinfo.DisplayName, | ||
PictureUrl: sql.NullString{String: userinfo.Picture.Url, Valid: true}, | ||
} | ||
user, err := query.CreateUser(context.Background(), arg) | ||
return user, err | ||
} | ||
|
||
// Updates existing user in db | ||
func updateUser(query *db.Queries, userinfo *UserInfo) (db.User, error) { | ||
arg := db.UpdateUserParams{ | ||
ID: userinfo.ID, | ||
Username: userinfo.DisplayName, | ||
PictureUrl: sql.NullString{String: userinfo.Picture.Url, Valid: true}, | ||
} | ||
user, err := query.UpdateUser(context.Background(), arg) | ||
return user, err | ||
} |