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
-17
View File
@@ -1,17 +0,0 @@
package handler
import (
"net/http"
"github.com/labstack/echo/v4"
)
type Status struct {
Status string `json:"status"`
}
func GetHealth(c echo.Context) error {
status := new(Status)
status.Status = "ok"
return c.JSON(http.StatusOK, status)
}
-67
View File
@@ -1,67 +0,0 @@
package handler
import (
"context"
"fmt"
"kontor-api-echo/pkg/schema"
"log"
"net/http"
"time"
"github.com/google/uuid"
"github.com/labstack/echo/v4"
"github.com/uptrace/bun"
)
func SetupMediaRoutes(api *echo.Group) {
media := api.Group("/media")
media.GET("/files", GetAllFiles)
media.POST("/files", AddFile)
}
func GetAllFiles(c echo.Context) error {
var files []schema.MediaFile
var err error
var db *bun.DB
ctx := context.Background()
db, err = schema.GetDatabase()
if err != nil {
log.Fatal(err)
}
err = db.NewSelect().Model(&files).Relation("MediaActorFiles").Scan(ctx)
if err != nil {
log.Fatal(err)
return echo.ErrInternalServerError
}
return c.JSON(http.StatusOK, files)
}
type Link struct {
URL string `json:"url"`
}
func AddFile(c echo.Context) error {
var err error
var db *bun.DB
ctx := context.Background()
link := new(Link)
if err = c.Bind(link); err != nil {
return err
}
log.Printf("URL %s has been sent", link)
db, err = schema.GetDatabase()
if err != nil {
log.Fatal(err)
}
id := uuid.NewString()
timestamp := time.Now()
mediafile := &schema.MediaFile{ID: id, CreatedAt: timestamp, UpdatedAt: timestamp, WebLink: fmt.Sprintf("%s", link), Version: 1, ShouldDownload: true, Review: true}
_, err = db.NewInsert().Model(mediafile).Exec(ctx)
if err != nil {
return err
}
return c.String(http.StatusCreated, "Link created")
}