Skip to content

Commit

Permalink
Merge branch 'main' into setup-basic-access-control
Browse files Browse the repository at this point in the history
  • Loading branch information
RichDom2185 authored Jul 25, 2023
2 parents 15277cc + ef8d6bd commit ee56004
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions migrations/20230725191302-add-names-to-users.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- +migrate Up

ALTER TABLE users
ADD COLUMN full_name TEXT NOT NULL DEFAULT '';

-- +migrate Down

ALTER TABLE users
DROP COLUMN full_name;
1 change: 1 addition & 0 deletions model/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

type User struct {
gorm.Model
FullName string // FIXME: Use nullable string
Username string
LoginProvider userenums.LoginProvider
}
Expand Down
2 changes: 2 additions & 0 deletions params/users/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
)

type Create struct {
Name string `json:"name"`
Username string `json:"username"`
LoginProvider string `json:"provider"`
}
Expand Down Expand Up @@ -37,6 +38,7 @@ func (params *Create) ToModel() *model.User {
panic(errors.New("Illegal path - invalid provider"))
}
return &model.User{
FullName: params.Name,
Username: params.Username,
LoginProvider: provider,
}
Expand Down
6 changes: 6 additions & 0 deletions view/users/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@ import "github.com/source-academy/stories-backend/model"

type View struct {
ID uint `json:"id"`
Name string `json:"name"`
Username string `json:"username"`
LoginProvider string `json:"provider"`
}

func SingleFrom(user model.User) View {
name := user.FullName
if name == "" {
name = user.Username
}
userView := View{
ID: user.ID,
Name: name,
Username: user.Username,
LoginProvider: user.LoginProvider.ToString(),
}
Expand Down

0 comments on commit ee56004

Please sign in to comment.