Skip to content

Commit

Permalink
feat: fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
hiwatee committed Jan 6, 2021
1 parent a7e28fd commit 29adbb3
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 18 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
/swagger
app
beego-members-api
mem-230.memprof
*.memprof
*.pprof
*.tmp
6 changes: 6 additions & 0 deletions controllers/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package controllers

type DefaultSuccessResponse struct {
// TODO: enumをサポートしたらenumに変更する
Message string `json:"message" required:"true" example:"success" description:"result status"`
}
11 changes: 3 additions & 8 deletions controllers/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,8 @@ func (c *LoginController) URLMapping() {
}

type LoginRequest struct {
Email string `json:"email" required:"true" example:"[email protected]"`
Pasword string `json:"password" required:"true" example:"password"`
}

type LoginResponse struct {
// TODO: enumをサポートしたらenumに変更する
Message string `json:"message" required:"true" example:"success" description:"result status"`
Email string `orm:"size(128)" json:"email" example:"[email protected]"`
Password string `orm:"size(128)" json:"password" example:"password"`
}

// NOTE: exampleの出し分けが出来ないので別にしています。
Expand Down Expand Up @@ -54,7 +49,7 @@ func (c *LoginController) Login() {
// パスワード照合 | 間違ったら403

// set_cookie
mes := LoginResponse{Message: "success"}
mes := DefaultSuccessResponse{Message: "success"}
c.Data["json"] = mes
c.ServeJSON()
}
6 changes: 3 additions & 3 deletions controllers/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ type ProfileRequest struct {
Age int64 `json:"age" required:"true" example:"0"`
}
type UserCreateRequest struct {
Email string `json:"email" required:"true" example:"[email protected]"`
Password string `json:"password" required:"true" example:"password"`
Profile ProfileRequest `json:"profile" required:"true"`
LoginRequest
models.UserInfoBody
Profile models.ProfileBody `json:"profile" required:"true"`
}

// URLMapping ...
Expand Down
25 changes: 19 additions & 6 deletions models/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,32 @@ import (
)

type User struct {
Id int64 `orm:"auto" json:"id,omitempty"`
Email string `orm:"size(128)" json:"email"`
Password string `orm:"size(128)" json:"-"`
TimeStamp
Id int64 `orm:"auto" json:"id,omitempty"`
UserLoginBody
UserInfoBody
Profile *Profile `orm:"rel(one)" json:"profile"` // OneToOne relation
TimeStamp
}

type Profile struct {
Id int64 `orm:"auto" json:"id,omitempty"`
Age int64 `orm:"size(128)" json:"age"`
Id int64 `orm:"auto" json:"id,omitempty"`
ProfileBody
TimeStamp
}

type ProfileBody struct {
Age int64 `orm:"size(128)" json:"age"`
}

type UserLoginBody struct {
Email string `orm:"size(128)" json:"email"`
Password string `orm:"size(128)" json:"-"`
}

type UserInfoBody struct {
Name string `orm:"size(128)" json:"name" example:"山田太郎"`
}

// AddUser insert a new User into database and returns
// last inserted Id on success.
func AddUser(m *User) (id int64, err error) {
Expand Down

0 comments on commit 29adbb3

Please sign in to comment.