fixes on structuring

This commit is contained in:
Fran Jurmanović
2021-05-15 22:23:30 +02:00
parent e7a80796f7
commit cc98d0cf49
10 changed files with 125 additions and 60 deletions

View File

@@ -8,3 +8,7 @@ type LoginModel struct {
Email string
Password string
}
type AuthModel struct {
Id string
}

View File

@@ -1,9 +1,20 @@
package models
import "time"
import (
"time"
"github.com/google/uuid"
)
type CommonModel struct {
Id string `json:"id" pg:"id"`
Id string `json:"id" pg:"id,pk"`
DateCreated time.Time `json:"dateCreated" pg:"datecreated"`
DateUpdated time.Time `json:"dateUpdated" pg:"dateupdated"`
}
func (cm *CommonModel) Init() {
date := time.Now()
cm.Id = uuid.NewString()
cm.DateCreated = date
cm.DateUpdated = date
}

View File

@@ -3,9 +3,9 @@ package models
type UserModel struct {
tableName struct{} `pg:"users,alias:users"`
CommonModel
Username string `json:"username"`
Password string `json:"password"`
Email string `json:"email"`
Username string `json:"username" pg:"username"`
Password string `json:"password" pg:"password"`
Email string `json:"email" pg:"email"`
}
type UserReturnInfoModel struct {
@@ -15,11 +15,11 @@ type UserReturnInfoModel struct {
Email string `json:"email"`
}
func (um *UserModel) Payload() UserReturnInfoModel {
payload := UserReturnInfoModel{
CommonModel: um.CommonModel,
Username: um.Username,
Email: um.Email,
}
func (um *UserModel) Payload() *UserReturnInfoModel {
payload := new(UserReturnInfoModel)
payload.CommonModel = um.CommonModel
payload.Username = um.Username
payload.Email = um.Email
return payload
}