Files
Thomas Peetz b0cc5f0cd1
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 5s
Gitea Actions Demo / build-and-test (push) Failing after 14m37s
add methods in Repository and Model for importing data
2026-10-30 09:15:19 +01:00

71 lines
2.3 KiB
Go

package models
import (
"kontor-api-gin/internal/helpers"
"time"
)
type Token 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"`
Token string `gorm:"uniqueIndex,column:token" json:"token"`
Name string `gorm:"column:name" json:"name"`
LastUsedAt time.Time `gorm:"column:last_used_date" json:"last_used_date"`
Enabled bool `gorm:"column.enabled" json:"enabled"`
ProfileID *string `gorm:"column:profile_id" json:"profile_id"`
Profile *Profile `gorm:"foreignKey:ProfileID" json:"profile"`
}
func (token *Token) TableName() string {
return "token"
}
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