kontor-echo: setup project to show homepage
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 6s
Gitea Actions Demo / build-and-test (push) Failing after 11s

This commit is contained in:
Thomas Peetz
2026-11-09 17:02:59 +01:00
parent 074abd3c85
commit debdf3d0b0
63 changed files with 2411 additions and 485 deletions
+30 -21
View File
@@ -4,7 +4,9 @@ import (
"context"
"kontor-api-echo/internal/models"
"log/slog"
"time"
"github.com/labstack/echo/v5"
"github.com/uptrace/bun"
)
@@ -19,41 +21,48 @@ func NewAssignmentRepository(db *bun.DB) *AssignmentRepository {
func (repository *AssignmentRepository) FindAll(context context.Context) ([]models.Assignment, error) {
var assignments []models.Assignment
result := repository.db.Find(&assignments)
slog.Info("AssignmentRepository#FindAll", "count", result.RowsAffected)
err := repository.db.NewSelect().Model(&assignments).Scan(context)
if err != nil {
slog.Info(err.Error())
return nil, echo.ErrInternalServerError
}
slog.Info("AssignmentRepository#FindAll", "count", len(assignments))
return assignments, nil
}
func (repository *AssignmentRepository) GetById(context context.Context, id string) (models.Assignment, error) {
func (repository *AssignmentRepository) GetById(context context.Context, id string) (*models.Assignment, error) {
var assignment = models.Assignment{ID: id}
slog.Info("AssignmentRepository#GetById", "id", id)
result := repository.db.First(&assignment)
if result.Error != nil {
slog.Info("AssignmentRepository#GetById", "error", result.Error.Error())
err := repository.db.NewSelect().Model(&assignment).Where("id = ?", id).Scan(context)
if err != nil {
slog.Info("AssignmentRepository#GetById", "error", err.Error())
return nil, err
}
return assignment, result.Error
return &assignment, err
}
func (repository *AssignmentRepository) Import(assignments models.AssignmentDTOList) {
func (repository *AssignmentRepository) Import(dtos models.AssignmentDTOList) {
slog.Info("AssignmentRepository#Import")
for index, assignment := range assignments {
slog.Info("importing", "index", index, "profile", assignment)
model := assignment.ConvertDTOToModel()
existing_item := models.Assignment{ID: assignment.ID}
result_existing := repository.db.First(&existing_item)
if result_existing.Error != nil {
for index, dto := range dtos {
slog.Info("importing", "index", index, "assignment", dto)
model := dto.ConvertDTOToModel()
existing_item := models.Assignment{ID: dto.ID}
err := repository.db.NewSelect().Model(&existing_item).Where("id = ?", dto.ID).Scan(context.Background())
if err != nil {
slog.Info("check existing id: not found - inserting")
result := repository.db.Create(&model)
if result.Error != nil {
slog.Info("error during import", "error", result.Error.Error())
_, err := repository.db.NewInsert().Model(&model).Exec(context.Background())
if err != nil {
slog.Info("error during import", "error", err.Error())
}
} else {
slog.Info("check existing id: found - updating")
result := repository.db.Save(&model)
if result.Error != nil {
slog.Info("error during updating", "error", result.Error.Error())
_, err := repository.db.NewUpdate().Model(&model).
Set("updated_at = ? ", time.Now).
Where("id = ?", model.ID).
Exec(context.Background())
if err != nil {
slog.Info("error during updating", "error", err.Error())
}
}
}