79 lines
2.9 KiB
Go
79 lines
2.9 KiB
Go
package models
|
|
|
|
import (
|
|
"kontor-api-gin/internal/helpers"
|
|
"time"
|
|
)
|
|
|
|
type Profile struct {
|
|
ID string `gorm:"type:string;primary_key;" json:"id"`
|
|
CreatedAt time.Time `gorm:"column:created_date" json:"created_date"`
|
|
UpdatedAt time.Time `gorm:"column:last_modified_date" json:"last_modified_date"`
|
|
DeletedAt *time.Time `gorm:"column:deleted_date" json:"deleted_date"`
|
|
Version int `gorm:"default:0" json:"version"`
|
|
First_Name *string `gorm:"column:first_name" json:"first_name"`
|
|
Last_Name *string `gorm:"column:last_name" json:"last_name"`
|
|
User_Name string `gorm:"column:user_name" json:"user_name"`
|
|
Email string `gorm:"column:email" json:"email"`
|
|
Password string `gorm:"column:password" json:"password"`
|
|
Enabled bool `gorm:"column:enabled" json:"enabled"`
|
|
|
|
Assignments []Assignment `gorm:"foreignKey:ProfileID" json:"assignments"`
|
|
Tokens []Token `gorm:"foreignKey:ProfileID" json:"tokens"`
|
|
}
|
|
|
|
func (profile *Profile) TableName() string {
|
|
return "profile"
|
|
}
|
|
|
|
func (profile *Profile) GetFullName() string {
|
|
full_name := ""
|
|
if profile.First_Name != nil {
|
|
full_name += *profile.First_Name
|
|
}
|
|
if profile.Last_Name != nil {
|
|
full_name += " "
|
|
full_name += *profile.Last_Name
|
|
}
|
|
return full_name
|
|
}
|
|
|
|
type ProfileDTO struct {
|
|
ID string `json:"id" binding:"required"`
|
|
CreatedAt helpers.KontorTime `json:"created_date" binding:"required"`
|
|
UpdatedAt helpers.KontorTime `json:"last_modified_date" binding:"required"`
|
|
DeletedAt *time.Time `json:"deleted_date,omitempty"`
|
|
Version int `json:"version" binding:"required"`
|
|
First_Name *string `json:"first_name" binding:"required"`
|
|
Last_Name *string `json:"last_name" binding:"required"`
|
|
User_Name string `json:"user_name" binding:"required"`
|
|
Email string `json:"email" binding:"required"`
|
|
Password string `json:"password" binding:"required"`
|
|
Enabled bool `json:"enabled" binding:"required"`
|
|
}
|
|
|
|
func ConvertProfilesToDtos(profiles []Profile) []ProfileDTO {
|
|
dtos := make([]ProfileDTO, len(profiles))
|
|
for i, profile := range profiles {
|
|
dtos[i] = ProfileDTO{
|
|
ID: profile.ID,
|
|
CreatedAt: helpers.KontorTime{Time: profile.CreatedAt},
|
|
UpdatedAt: helpers.KontorTime{Time: profile.UpdatedAt},
|
|
DeletedAt: profile.DeletedAt,
|
|
Version: profile.Version,
|
|
First_Name: profile.First_Name,
|
|
Last_Name: profile.Last_Name,
|
|
User_Name: profile.User_Name,
|
|
Email: profile.Email,
|
|
Password: profile.Password,
|
|
Enabled: profile.Enabled,
|
|
}
|
|
}
|
|
return dtos
|
|
}
|
|
|
|
type LoginInput struct {
|
|
Email string `json:"email" binding:"required"`
|
|
Password string `json:"password" binding:"required"`
|
|
}
|