WIP: add missing handlers, services nd repositories
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"kontor-api-echo/internal/helpers"
|
||||
"time"
|
||||
|
||||
"github.com/uptrace/bun"
|
||||
)
|
||||
|
||||
type Assignment struct {
|
||||
bun.BaseModel `bun:"table:assignment"`
|
||||
|
||||
ID string `bun:"id,pk"`
|
||||
CreatedAt time.Time `bun:"created_date,nullzero,notnull,default:current_timestamp"`
|
||||
UpdatedAt time.Time `bun:"last_modified_date,nullzero,notnull,default:current_timestamp"`
|
||||
DeletedAt *time.Time `bun:"deleted_date,nullzero"`
|
||||
Version int `bun:"version,default:0"`
|
||||
ProfileID *string `bun:"profile_id"`
|
||||
Profile *Profile `bun:"rel:belongs-to,join:profile_id=id"`
|
||||
PermissionID *string `bun:"permission_id"`
|
||||
Permission *Permission `bun:"rel:belongs-to,join:permission_id=id"`
|
||||
}
|
||||
|
||||
type AssignmentDTO struct {
|
||||
ID string `json:"id" binding:"required"`
|
||||
CreatedAt helpers.KontorTime `json:"created_date"`
|
||||
UpdatedAt helpers.KontorTime `json:"last_modified_date"`
|
||||
DeletedAt *time.Time `json:"deleted_date,omitempty"`
|
||||
Version int `json:"version"`
|
||||
ProfileID *string `json:"profile_id"`
|
||||
PermissionID *string `json:"permission_id"`
|
||||
}
|
||||
|
||||
func (dto *AssignmentDTO) ConvertDTOToModel() Assignment {
|
||||
model := Assignment{
|
||||
ID: dto.ID,
|
||||
CreatedAt: dto.CreatedAt.Time,
|
||||
UpdatedAt: dto.UpdatedAt.Time,
|
||||
DeletedAt: dto.DeletedAt,
|
||||
Version: dto.Version,
|
||||
ProfileID: dto.ProfileID,
|
||||
PermissionID: dto.PermissionID,
|
||||
}
|
||||
return model
|
||||
}
|
||||
|
||||
func ConvertAssignmentsToDtos(assignments []Assignment) []AssignmentDTO {
|
||||
dtos := make([]AssignmentDTO, len(assignments))
|
||||
for i, assignment := range assignments {
|
||||
dtos[i] = AssignmentDTO{
|
||||
ID: assignment.ID,
|
||||
CreatedAt: helpers.KontorTime{Time: assignment.CreatedAt},
|
||||
UpdatedAt: helpers.KontorTime{Time: assignment.UpdatedAt},
|
||||
DeletedAt: assignment.DeletedAt,
|
||||
Version: assignment.Version,
|
||||
ProfileID: assignment.ProfileID,
|
||||
PermissionID: assignment.PermissionID,
|
||||
}
|
||||
}
|
||||
return dtos
|
||||
}
|
||||
|
||||
type AssignmentDTOList []AssignmentDTO
|
||||
@@ -0,0 +1,58 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"kontor-api-echo/internal/helpers"
|
||||
"time"
|
||||
|
||||
"github.com/uptrace/bun"
|
||||
)
|
||||
|
||||
type Permission struct {
|
||||
bun.BaseModel `bun:"table:permission"`
|
||||
|
||||
ID string `bun:"id,pk"`
|
||||
CreatedAt time.Time `bun:"created_date,nullzero,notnull,default:current_timestamp"`
|
||||
UpdatedAt time.Time `bun:"last_modified_date,nullzero,notnull,default:current_timestamp"`
|
||||
DeletedAt *time.Time `bun:"deleted_date,nullzero"`
|
||||
Version int `bun:"version,default:0"`
|
||||
Name string `bun:"name,unique:name"`
|
||||
Assignments []Assignment `bun:"rel:has-many,join:id=permission_id"`
|
||||
}
|
||||
|
||||
type PermissionDTO 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" binding:"required"`
|
||||
Version int `json:"version" binding:"required"`
|
||||
Name string `json:"name" binding:"required"`
|
||||
}
|
||||
|
||||
func (permission *PermissionDTO) ConvertDTOToModel() Permission {
|
||||
model := Permission{
|
||||
ID: permission.ID,
|
||||
CreatedAt: permission.CreatedAt.Time,
|
||||
UpdatedAt: permission.UpdatedAt.Time,
|
||||
DeletedAt: permission.DeletedAt,
|
||||
Version: permission.Version,
|
||||
Name: permission.Name,
|
||||
}
|
||||
return model
|
||||
}
|
||||
|
||||
func ConvertPermissionsToDtos(permissions []Permission) []PermissionDTO {
|
||||
dtos := make([]PermissionDTO, len(permissions))
|
||||
for i, permission := range permissions {
|
||||
dtos[i] = PermissionDTO{
|
||||
ID: permission.ID,
|
||||
CreatedAt: helpers.KontorTime{Time: permission.CreatedAt},
|
||||
UpdatedAt: helpers.KontorTime{Time: permission.UpdatedAt},
|
||||
DeletedAt: permission.DeletedAt,
|
||||
Version: permission.Version,
|
||||
Name: permission.Name,
|
||||
}
|
||||
}
|
||||
return dtos
|
||||
}
|
||||
|
||||
type PermissionDTOList []PermissionDTO
|
||||
@@ -0,0 +1,96 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"kontor-api-echo/internal/helpers"
|
||||
"time"
|
||||
|
||||
"github.com/uptrace/bun"
|
||||
)
|
||||
|
||||
type Profile struct {
|
||||
bun.BaseModel `bun:"table:profile"`
|
||||
|
||||
ID string `bun:"id,pk"`
|
||||
CreatedAt time.Time `bun:"created_date,nullzero,notnull,default:current_timestamp"`
|
||||
UpdatedAt time.Time `bun:"last_modified_date,nullzero,notnull,default:current_timestamp"`
|
||||
DeletedAt *time.Time `bun:"deleted_date,nullzero"`
|
||||
Version int `bun:"version,default:0"`
|
||||
FirstName string `bun:"first_name"`
|
||||
LastName string `bun:"last_name"`
|
||||
UserName string `bun:"user_name,unique:user_name"`
|
||||
Email string `bun:"email"`
|
||||
Password string `bun:"password"`
|
||||
Enabled bool `bun:"enabled"`
|
||||
Assignments []Assignment `bun:"rel:has-many,join:id=profile_id"`
|
||||
Tokens []Token `bun:"rel:has-many,join:id=profile_id"`
|
||||
}
|
||||
|
||||
func (profile *Profile) GetFullName() string {
|
||||
full_name := ""
|
||||
if profile.FirstName != "" {
|
||||
full_name += profile.FirstName
|
||||
}
|
||||
if profile.LastName != "" {
|
||||
full_name += " "
|
||||
full_name += profile.LastName
|
||||
}
|
||||
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"`
|
||||
FirstName string `json:"first_name" binding:"required"`
|
||||
LastName string `json:"last_name" binding:"required"`
|
||||
UserName 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 (profile *ProfileDTO) ConvertDTOToModel() Profile {
|
||||
model := Profile{
|
||||
ID: profile.ID,
|
||||
CreatedAt: profile.CreatedAt.Time,
|
||||
UpdatedAt: profile.UpdatedAt.Time,
|
||||
DeletedAt: profile.DeletedAt,
|
||||
Version: profile.Version,
|
||||
FirstName: profile.FirstName,
|
||||
LastName: profile.LastName,
|
||||
UserName: profile.UserName,
|
||||
Email: profile.Email,
|
||||
Password: profile.Password,
|
||||
Enabled: profile.Enabled,
|
||||
}
|
||||
return model
|
||||
}
|
||||
|
||||
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,
|
||||
FirstName: profile.FirstName,
|
||||
LastName: profile.LastName,
|
||||
UserName: profile.UserName,
|
||||
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"`
|
||||
}
|
||||
|
||||
type ProfileDTOList []ProfileDTO
|
||||
@@ -0,0 +1,70 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"kontor-api-echo/internal/helpers"
|
||||
"time"
|
||||
|
||||
"github.com/uptrace/bun"
|
||||
)
|
||||
|
||||
type Token struct {
|
||||
bun.BaseModel `bun:"table:token"`
|
||||
|
||||
ID string `bun:"id,pk"`
|
||||
CreatedAt time.Time `bun:"created_date,nullzero,notnull,default:current_timestamp"`
|
||||
UpdatedAt time.Time `bun:"last_modified_date,nullzero,notnull,default:current_timestamp"`
|
||||
DeletedAt *time.Time `bun:"deleted_date,nullzero"`
|
||||
Version int `bun:"version,default:0"`
|
||||
Token string `bun:"token,unique:token"`
|
||||
Name string `bun:"name,unique:name"`
|
||||
LastUsedAt time.Time `bun:"last_used_date,nullzero,notnull,default:current_timestamp"`
|
||||
Enabled bool `bun:"enabled,default:true"`
|
||||
ProfileID *string `bun:"profile_id"`
|
||||
Profile *Profile `bun:"rel:belongs-to,join:profile_id=id"`
|
||||
}
|
||||
|
||||
type TokenDTO struct {
|
||||
ID string `json:"id" binding:"required"`
|
||||
CreatedAt helpers.KontorTime `json:"created_date"`
|
||||
UpdatedAt helpers.KontorTime `json:"last_modified_date"`
|
||||
DeletedAt *time.Time `json:"deleted_date,omitempty"`
|
||||
Version int `json:"version"`
|
||||
Token string `json:"token"`
|
||||
Name string `json:"name"`
|
||||
LastUsedAt *time.Time `json:"last_used_date"`
|
||||
Enabled bool `json:"enabled"`
|
||||
ProfileID *string `json:"profile_id"`
|
||||
}
|
||||
|
||||
func (dto TokenDTO) ConvertDTOToModel() Token {
|
||||
model := Token{
|
||||
ID: dto.ID,
|
||||
CreatedAt: dto.CreatedAt.Time,
|
||||
UpdatedAt: dto.UpdatedAt.Time,
|
||||
DeletedAt: dto.DeletedAt,
|
||||
Version: dto.Version,
|
||||
Token: dto.Token,
|
||||
Name: dto.Name,
|
||||
LastUsedAt: *dto.LastUsedAt,
|
||||
Enabled: dto.Enabled,
|
||||
ProfileID: dto.ProfileID,
|
||||
}
|
||||
return model
|
||||
}
|
||||
|
||||
func ConvertTokensToDtos(tokens []Token) []TokenDTO {
|
||||
dtos := make([]TokenDTO, len(tokens))
|
||||
for i, token := range tokens {
|
||||
dtos[i] = TokenDTO{
|
||||
ID: token.ID,
|
||||
CreatedAt: helpers.KontorTime{Time: token.CreatedAt},
|
||||
UpdatedAt: helpers.KontorTime{Time: token.UpdatedAt},
|
||||
DeletedAt: token.DeletedAt,
|
||||
Version: token.Version,
|
||||
ProfileID: token.ProfileID,
|
||||
}
|
||||
}
|
||||
return dtos
|
||||
}
|
||||
|
||||
type TokenDTOList []TokenDTO
|
||||
Reference in New Issue
Block a user