Files
tpeetz 79653d2c43
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 5s
Gitea Actions Demo / build-and-test (push) Failing after 12s
WIP: add missing handlers, services nd repositories
2026-11-06 21:20:24 +01:00

71 lines
2.1 KiB
Go

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