WIP: add missing handlers, services nd repositories
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 5s
Gitea Actions Demo / build-and-test (push) Failing after 12s

This commit is contained in:
2026-11-06 21:20:24 +01:00
parent 50e2da8a66
commit 79653d2c43
27 changed files with 865 additions and 315 deletions
+1 -1
View File
@@ -24,7 +24,7 @@ func main() {
if err := config.InitConfig(); err != nil {
log.Fatalf("Failed to initialize config: %v", err)
}
e := router.New(handlers.NewAdminHandler(db, config.ServerConfig.ApiSecret), handlers.NewMediaHandler(db))
e := router.New(handlers.NewAdminHandler(db), handlers.NewMediaHandler(db))
// Cancel the context on SIGINT / SIGTERM
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
+3 -5
View File
@@ -12,19 +12,17 @@ type AdminHandler struct {
TokenHandler *TokenHandler
MailAccountHandler *MailAccountHandler
MailHandler *MailHandler
Secret []byte
}
func NewAdminHandler(db *bun.DB, secret []byte) *AdminHandler {
func NewAdminHandler(db *bun.DB) *AdminHandler {
adminHandler := &AdminHandler{
AuthHandler: &AuthHandler{Service: service.NewAuthService(repository.NewProfileRepository(db), secret)},
AuthHandler: NewAuthHandler(db),
ProfileHandler: NewProfileHandler(db),
PermissionHandler: &PermissionHandler{Service: service.NewPermissionService(repository.NewPermissionRepository(db))},
PermissionHandler: NewPermissionHandler(db),
AssignmentHandler: NewAssignmentHandler(db),
TokenHandler: NewTokenHandler(db),
MailAccountHandler: NewMailAccountHandler(db),
MailHandler: NewMailHandler(db),
Secret: secret,
}
return adminHandler
}
@@ -0,0 +1,30 @@
package handlers
import (
"kontor-api-echo/internal/models"
"kontor-api-echo/internal/repository"
"kontor-api-echo/internal/service"
"net/http"
"github.com/labstack/echo/v5"
"github.com/uptrace/bun"
)
type AssignmentHandler struct {
Service *service.AssignmentService
}
func NewAssignmentHandler(db *bun.DB) *AssignmentHandler {
handler := &AssignmentHandler{Service: service.NewAssignmentService(repository.NewAssignmentRepository(db))}
return handler
}
func (handler *AssignmentHandler) List(c *echo.Context) {
assignments, err := handler.Service.List(c.Request().Context())
if err != nil {
c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
return
}
dtos := models.ConvertAssignmentsToDtos(assignments)
c.JSON(http.StatusOK, dtos)
}
@@ -1,82 +1,81 @@
package handlers
import (
"kontor-api-gin/internal/globals"
"kontor-api-gin/internal/models"
"kontor-api-gin/internal/repository"
"kontor-api-gin/internal/service"
"kontor-api-echo/internal/globals"
"kontor-api-echo/internal/models"
"kontor-api-echo/internal/repository"
"kontor-api-echo/internal/service"
"net/http"
"github.com/gin-contrib/sessions"
"github.com/gin-gonic/gin"
"gorm.io/gorm"
"github.com/labstack/echo/v5"
"github.com/uptrace/bun"
)
type MediaActorFileHandler struct {
Service *service.MediaActorFileService
}
func NewMediaActorFileHandler(db *gorm.DB) *MediaActorFileHandler {
func NewMediaActorFileHandler(db *bun.DB) *MediaActorFileHandler {
mediaActorFileHandler := &MediaActorFileHandler{
Service: service.NewMediaActorFileService(repository.NewMediaActorFileRepository(db)),
}
return mediaActorFileHandler
}
func (handler *MediaActorFileHandler) List(c *gin.Context) {
media_actor_files, err := handler.Service.List(c.Request.Context())
func (handler *MediaActorFileHandler) List(c *echo.Context) {
media_actor_files, err := handler.Service.List(c.Request().Context())
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
return
}
dtos := models.ConvertMediaActorFilesToDtos(media_actor_files)
c.JSON(http.StatusOK, dtos)
}
func (handler *MediaActorFileHandler) Get(c *gin.Context) {
func (handler *MediaActorFileHandler) Get(c *echo.Context) {
id := c.Param("id")
actor, err := handler.Service.Get(c.Request.Context(), id)
actor, err := handler.Service.Get(c.Request().Context(), id)
if err != nil {
c.JSON(http.StatusNotFound, gin.H{"error": "sport not found"})
c.JSON(http.StatusNotFound, map[string]string{"error": "sport not found"})
return
}
c.JSON(http.StatusOK, actor)
}
func (handler *MediaActorFileHandler) Add(c *gin.Context) {
func (handler *MediaActorFileHandler) Add(c *echo.Context) {
var input models.MediaActorFileAdd
if err := c.ShouldBindJSON(&input); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
if err := c.Bind(&input); err != nil {
c.JSON(http.StatusBadRequest, map[string]string{"error": err.Error()})
return
}
actorfile, err := handler.Service.Add(c.Request.Context(), input.MediaActorID, input.MediaFileID)
actorfile, err := handler.Service.Add(c.Request().Context(), input.MediaActorID, input.MediaFileID)
if err != nil {
c.JSON(http.StatusNotFound, gin.H{"error": "lofi not added"})
c.JSON(http.StatusNotFound, map[string]string{"error": "lofi not added"})
return
}
c.JSON(http.StatusOK, actorfile)
}
func (handler *MediaActorFileHandler) Delete(c *gin.Context) {
func (handler *MediaActorFileHandler) Delete(c *echo.Context) {
id := c.Param("id")
err := handler.Service.Delete(c.Request.Context(), id)
err := handler.Service.Delete(c.Request().Context(), id)
if err != nil {
c.JSON(http.StatusNotFound, gin.H{"error": "sport not found"})
c.JSON(http.StatusNotFound, map[string]string{"error": "sport not found"})
return
}
c.JSON(http.StatusOK, gin.H{"ok": "true"})
c.JSON(http.StatusOK, map[string]string{"ok": "true"})
}
func (handler *MediaActorFileHandler) ListPage(c *gin.Context) {
session := sessions.Default(c)
user := session.Get(globals.UserKey)
media_actor_files, err := handler.Service.List(c.Request.Context())
func (handler *MediaActorFileHandler) ListPage(c *echo.Context) {
cookie, err := c.Cookie(globals.UserKey)
user := cookie.Value
media_actor_files, err := handler.Service.List(c.Request().Context())
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
return
}
c.HTML(http.StatusOK, "mediaactorfiles", gin.H{
c.Render(http.StatusOK, "mediaactorfiles", map[string]string{
"title": "Kontor MediaActorFiles",
"version": "0.4.0",
"message": "MediaActorFiles...",
+4 -4
View File
@@ -1,10 +1,10 @@
package handlers
import (
"kontor-api-gin/internal/globals"
"kontor-api-gin/internal/models"
"kontor-api-gin/internal/repository"
"kontor-api-gin/internal/service"
"kontor-api-echo/internal/globals"
"kontor-api-echo/internal/models"
"kontor-api-echo/internal/repository"
"kontor-api-echo/internal/service"
"net/http"
"github.com/labstack/echo/v5"
+7 -8
View File
@@ -1,14 +1,13 @@
package handlers
import (
"kontor-api-gin/internal/globals"
"kontor-api-gin/internal/models"
"kontor-api-gin/internal/repository"
"kontor-api-gin/internal/service"
"kontor-api-echo/internal/globals"
"kontor-api-echo/internal/models"
"kontor-api-echo/internal/repository"
"kontor-api-echo/internal/service"
"net/http"
"time"
"github.com/gin-contrib/sessions"
"github.com/google/uuid"
"github.com/labstack/echo/v5"
"github.com/uptrace/bun"
@@ -170,8 +169,8 @@ func (handler *MediaLoFiHandler) ChangeReviewPage(c *echo.Context) {
lofi.Review = !lofi.Review
handler.Service.Update(c.Request().Context(), lofi.ConvertMediaLoFiToDTO())
logger.Info("MediaLoFiHandler#ChangeReviewPage", "lofi", lofi)
session := sessions.Default(c)
user := session.Get(globals.UserKey)
cookie, err := c.Cookie(globals.UserKey)
user := cookie.Value
lofis, err := handler.Service.List(c.Request().Context())
if err != nil {
logger.Info("MediaLoFiHandler#ChangeReviewPage", "error", err.Error())
@@ -199,7 +198,7 @@ func (handler *MediaLoFiHandler) UpdatePage(c *echo.Context) {
var form models.MediaLoFiForm
if err := c.Bind(&form); err != nil {
logger.Info("MediaLoFiHandler#UpdatePage", "error", err.Error())
c.Render(http.StatusBadRequest, "lofi_detail", map[string]string{
c.Render(http.StatusBadRequest, "lofi_detail", map[string]any{
"Form": form,
"Errors": err.Error(),
"user": user,
+58 -60
View File
@@ -1,108 +1,106 @@
package handlers
import (
"kontor-api-gin/internal/globals"
"kontor-api-gin/internal/models"
"kontor-api-gin/internal/repository"
"kontor-api-gin/internal/service"
"kontor-api-echo/internal/globals"
"kontor-api-echo/internal/models"
"kontor-api-echo/internal/repository"
"kontor-api-echo/internal/service"
"net/http"
"github.com/gin-contrib/sessions"
"github.com/gin-contrib/slog"
"github.com/gin-gonic/gin"
"gorm.io/gorm"
"github.com/labstack/echo/v5"
"github.com/uptrace/bun"
)
type MediaMusicHandler struct {
Service *service.MediaMusicService
}
func NewMediaMusicHandler(db *gorm.DB) *MediaMusicHandler {
func NewMediaMusicHandler(db *bun.DB) *MediaMusicHandler {
mediaMusicHandler := &MediaMusicHandler{
Service: service.NewMediaMusicService(repository.NewMediaMusicRepository(db)),
}
return mediaMusicHandler
}
func (handler *MediaMusicHandler) List(c *gin.Context) {
musics, err := handler.Service.List(c.Request.Context())
func (handler *MediaMusicHandler) List(c *echo.Context) {
musics, err := handler.Service.List(c.Request().Context())
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
return
}
dtos := models.ConvertMediaMusicsToDtos(musics)
c.JSON(http.StatusOK, dtos)
}
func (handler *MediaMusicHandler) Get(c *gin.Context) {
func (handler *MediaMusicHandler) Get(c *echo.Context) {
id := c.Param("id")
music, err := handler.Service.Get(c.Request.Context(), id)
music, err := handler.Service.Get(c.Request().Context(), id)
if err != nil {
c.JSON(http.StatusNotFound, gin.H{"error": "MediaMusic not found"})
c.JSON(http.StatusNotFound, map[string]string{"error": "MediaMusic not found"})
return
}
c.JSON(http.StatusOK, music)
}
func (handler *MediaMusicHandler) Add(c *gin.Context) {
func (handler *MediaMusicHandler) Add(c *echo.Context) {
var input models.MediaLofiAdd
if err := c.ShouldBindJSON(&input); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
if err := c.Bind(&input); err != nil {
c.JSON(http.StatusBadRequest, map[string]string{"error": err.Error()})
return
}
music, err := handler.Service.Add(c.Request.Context(), input.Url)
music, err := handler.Service.Add(c.Request().Context(), input.Url)
if err != nil {
c.JSON(http.StatusNotFound, gin.H{"error": "MediaMusic not added"})
c.JSON(http.StatusNotFound, map[string]string{"error": "MediaMusic not added"})
return
}
c.JSON(http.StatusOK, music)
}
func (handler *MediaMusicHandler) Update(c *gin.Context) {
func (handler *MediaMusicHandler) Update(c *echo.Context) {
var input models.MediaMusicDTO
if err := c.ShouldBindJSON(&input); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
if err := c.Bind(&input); err != nil {
c.JSON(http.StatusBadRequest, map[string]string{"error": err.Error()})
return
}
music, err := handler.Service.Update(c.Request.Context(), input)
music, err := handler.Service.Update(c.Request().Context(), input)
if err != nil {
logger := slog.Get(c)
logger := c.Logger()
logger.Info("MediaMusicHandler#Update", "error", err.Error())
c.JSON(http.StatusNotFound, gin.H{"error": "MediaMusic not updated"})
c.JSON(http.StatusNotFound, map[string]string{"error": "MediaMusic not updated"})
return
}
c.JSON(http.StatusOK, music)
}
func (handler *MediaMusicHandler) Delete(c *gin.Context) {
func (handler *MediaMusicHandler) Delete(c *echo.Context) {
id := c.Param("id")
err := handler.Service.Delete(c.Request.Context(), id)
err := handler.Service.Delete(c.Request().Context(), id)
if err != nil {
c.JSON(http.StatusNotFound, gin.H{"error": "MediaMusic not found"})
c.JSON(http.StatusNotFound, map[string]string{"error": "MediaMusic not found"})
return
}
c.JSON(http.StatusOK, gin.H{"ok": "true"})
c.JSON(http.StatusOK, map[string]string{"ok": "true"})
}
func (handler *MediaMusicHandler) ListPage(c *gin.Context) {
session := sessions.Default(c)
user := session.Get(globals.UserKey)
logger := slog.Get(c)
func (handler *MediaMusicHandler) ListPage(c *echo.Context) {
cookie, err := c.Cookie(globals.UserKey)
user := cookie.Value
logger := c.Logger()
var (
review bool
download bool
)
paramReview, existsReview := c.GetQuery("review")
if existsReview {
paramReview, err := echo.QueryParam[string](c, "review")
if err == nil {
if paramReview == "on" {
review = true
} else {
review = false
}
}
paramDownload, existsDownload := c.GetQuery("should_download")
if existsDownload {
paramDownload, err := echo.QueryParam[string](c, "should_download")
if err == nil {
if paramDownload == "on" {
download = true
} else {
@@ -110,10 +108,10 @@ func (handler *MediaMusicHandler) ListPage(c *gin.Context) {
}
}
musics, err := handler.Service.List(c.Request.Context())
musics, err := handler.Service.List(c.Request().Context())
if err != nil {
logger.Info("MediaMusicHandler#ListPage", "error", err.Error())
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
return
}
logger.Info("MediaMusicHandler#ListPage", "MediaMusic count", len(musics))
@@ -122,44 +120,44 @@ func (handler *MediaMusicHandler) ListPage(c *gin.Context) {
data["MediaLinksUrl"] = globals.MediaMusicLink
data["isReview"] = review
data["isDownload"] = download
c.HTML(http.StatusOK, "media_links", data)
c.Render(http.StatusOK, "media_links", data)
}
func (handler *MediaMusicHandler) EditPage(c *gin.Context) {
session := sessions.Default(c)
user := session.Get(globals.UserKey)
func (handler *MediaMusicHandler) EditPage(c *echo.Context) {
cookie, err := c.Cookie(globals.UserKey)
user := cookie.Value
id := c.Param("id")
logger := slog.Get(c)
music, err := handler.Service.Get(c.Request.Context(), id)
logger := c.Logger()
music, err := handler.Service.Get(c.Request().Context(), id)
if err != nil {
logger.Info("MediaMusicHandler#EditPage", "error", err.Error())
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
return
}
logger.Info("MediaMusicHandler#EditPage", "music", music)
data := globals.GetDefaultValues(user, "MediaMusic...")
data["lofi"] = music
c.HTML(http.StatusOK, "lofi_detail", data)
c.Render(http.StatusOK, "lofi_detail", data)
}
func (handler *MediaMusicHandler) UpdatePage(c *gin.Context) {
session := sessions.Default(c)
user := session.Get(globals.UserKey)
func (handler *MediaMusicHandler) UpdatePage(c *echo.Context) {
cookie, err := c.Cookie(globals.UserKey)
user := cookie.Value
id := c.Param("id")
logger := slog.Get(c)
music, err := handler.Service.Get(c.Request.Context(), id)
logger := c.Logger()
music, err := handler.Service.Get(c.Request().Context(), id)
if err != nil {
logger.Info("MediaMusicHandler#UpdatePage", "error", err.Error())
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
return
}
var form models.MediaMusicForm
if err := c.ShouldBind(&form); err != nil {
if err := c.Bind(&form); err != nil {
logger.Info("MediaMusicHandler#UpdatePage", "error", err.Error())
data := globals.GetDefaultValues(user, "MediaMusic...")
data["Form"] = form
data["Errors"] = err.Error()
c.HTML(http.StatusBadRequest, "lofi_detail", data)
c.Render(http.StatusBadRequest, "lofi_detail", data)
return
}
logger.Info("MediaMusicHandler#UpdatePage", "music", music)
@@ -167,15 +165,15 @@ func (handler *MediaMusicHandler) UpdatePage(c *gin.Context) {
c.Redirect(http.StatusFound, globals.MediaMusicLink)
}
func (handler *MediaMusicHandler) DeletePage(c *gin.Context) {
func (handler *MediaMusicHandler) DeletePage(c *echo.Context) {
// session := sessions.Default(c)
// user := session.Get(globals.UserKey)
id := c.Param("id")
logger := slog.Get(c)
err := handler.Service.Delete(c.Request.Context(), id)
logger := c.Logger()
err := handler.Service.Delete(c.Request().Context(), id)
if err != nil {
logger.Info("MediaMusicHandler#DeletePage", "error", err.Error())
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
return
}
logger.Info("MediaMusicHandler#DeletePage", "music", id)
@@ -0,0 +1,113 @@
package handlers
import (
"kontor-api-echo/internal/globals"
"kontor-api-echo/internal/models"
"kontor-api-echo/internal/repository"
"kontor-api-echo/internal/service"
"net/http"
"github.com/labstack/echo/v5"
"github.com/uptrace/bun"
)
type MediaVideoHandler struct {
Service *service.MediaVideoService
}
func NewMediaVideoHandler(db *bun.DB) *MediaVideoHandler {
handler := &MediaVideoHandler{Service: service.NewMediaVideoService(repository.NewMediaVideoRepository(db))}
return handler
}
func (handler *MediaVideoHandler) List(c *echo.Context) {
logger := c.Logger()
logger.Info("MediaVideoHandler#List")
videos, err := handler.Service.List(c.Request().Context())
if err != nil {
c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
return
}
dtos := models.ConvertMediaVideosToDtos(videos)
c.JSON(http.StatusOK, dtos)
}
func (handler *MediaVideoHandler) ListPage(c *echo.Context) {
cookie, err := c.Cookie(globals.UserKey)
user := cookie.Value
logger := c.Logger()
videos, err := handler.Service.List(c.Request().Context())
if err != nil {
c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
return
}
logger.Info("MediaVideoHandler#ListPage", "videos count", len(videos))
data := globals.GetDefaultValues(user, "MediaVideos...")
data["title"] = "Kontor MediaVideos"
data["media_links"] = videos
data["MediaLinksUrl"] = globals.MediaVideoLink
c.Render(http.StatusOK, "media_links", data)
}
func (handler *MediaVideoHandler) EditPage(c *echo.Context) {
cookie, err := c.Cookie(globals.UserKey)
user := cookie.Value
id := c.Param("id")
logger := c.Logger()
video, err := handler.Service.Get(c.Request().Context(), id)
if err != nil {
logger.Info("MediaVideoHandler#EditPage", "error", err.Error())
c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
return
}
logger.Info("MediaVideoHandler#EditPage", "lofi", video)
data := globals.GetDefaultValues(user, "MediaLofis...")
data["lofi"] = video
c.Render(http.StatusOK, "lofi_detail", data)
}
func (handler *MediaVideoHandler) UpdatePage(c *echo.Context) {
cookie, err := c.Cookie(globals.UserKey)
user := cookie.Value
id := c.Param("id")
logger := c.Logger()
video, err := handler.Service.Get(c.Request().Context(), id)
if err != nil {
logger.Info("MediaVideoHandler#UpdatePage", "error", err.Error())
c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
return
}
var form models.MediaVideoForm
if err := c.Bind(&form); err != nil {
logger.Info("MediaVideoHandler#UpdatePage", "error", err.Error())
c.Render(http.StatusBadRequest, "lofi_detail", map[string]any{
"Form": form,
"Errors": err.Error(),
"user": user,
})
return
}
logger.Info("MediaVideoHandler#UpdatePage", "lofi", video)
//handler.Service.Update(c.Request.Context(), form.ConvertFormToMediaLofiDTO())
c.Redirect(http.StatusFound, globals.MediaVideoLink)
}
func (handler *MediaVideoHandler) DeletePage(c *echo.Context) {
cookie, err := c.Cookie(globals.UserKey)
user := cookie.Value
id := c.Param("id")
logger := c.Logger()
err = handler.Service.Delete(c.Request().Context(), id)
if err != nil {
logger.Info("MediaVideoHandler#DeletePage", "error", err.Error())
c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
return
}
logger.Info("MediaVideoHandler#DeletePage", "video", id)
c.Render(http.StatusOK, "lofi_delete", map[string]string{
"title": "Kontor MediaFiles",
"version": "0.4.0",
"message": "MediaFiles...",
"user": user,
})
}
-115
View File
@@ -1,115 +0,0 @@
package handlers
import (
"kontor-api-gin/internal/globals"
"kontor-api-gin/internal/models"
"kontor-api-gin/internal/repository"
"kontor-api-gin/internal/service"
"net/http"
"github.com/gin-contrib/sessions"
"github.com/gin-contrib/slog"
"github.com/gin-gonic/gin"
"gorm.io/gorm"
)
type MediaVideoHandler struct {
Service *service.MediaVideoService
}
func NewMediaVideoHandler(db *gorm.DB) *MediaVideoHandler {
handler := &MediaVideoHandler{Service: service.NewMediaVideoService(repository.NewMediaVideoRepository(db))}
return handler
}
func (handler *MediaVideoHandler) List(c *gin.Context) {
logger := slog.Get(c)
logger.Info("MediaVideoHandler#List")
videos, err := handler.Service.List(c.Request.Context())
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
dtos := models.ConvertMediaVideosToDtos(videos)
c.JSON(http.StatusOK, dtos)
}
func (handler *MediaVideoHandler) ListPage(c *gin.Context) {
session := sessions.Default(c)
user := session.Get(globals.UserKey)
logger := slog.Get(c)
videos, err := handler.Service.List(c.Request.Context())
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
logger.Info("MediaVideoHandler#ListPage", "videos count", len(videos))
data := globals.GetDefaultValues(user, "MediaVideos...")
data["title"] = "Kontor MediaVideos"
data["media_links"] = videos
data["MediaLinksUrl"] = globals.MediaVideoLink
c.HTML(http.StatusOK, "media_links", data)
}
func (handler *MediaVideoHandler) EditPage(c *gin.Context) {
session := sessions.Default(c)
user := session.Get(globals.UserKey)
id := c.Param("id")
logger := slog.Get(c)
video, err := handler.Service.Get(c.Request.Context(), id)
if err != nil {
logger.Info("MediaVideoHandler#EditPage", "error", err.Error())
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
logger.Info("MediaVideoHandler#EditPage", "lofi", video)
data := globals.GetDefaultValues(user, "MediaLofis...")
data["lofi"] = video
c.HTML(http.StatusOK, "lofi_detail", data)
}
func (handler *MediaVideoHandler) UpdatePage(c *gin.Context) {
session := sessions.Default(c)
user := session.Get(globals.UserKey)
id := c.Param("id")
logger := slog.Get(c)
video, err := handler.Service.Get(c.Request.Context(), id)
if err != nil {
logger.Info("MediaVideoHandler#UpdatePage", "error", err.Error())
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
var form models.MediaVideoForm
if err := c.ShouldBind(&form); err != nil {
logger.Info("MediaVideoHandler#UpdatePage", "error", err.Error())
c.HTML(http.StatusBadRequest, "lofi_detail", gin.H{
"Form": form,
"Errors": err.Error(),
"user": user,
})
return
}
logger.Info("MediaVideoHandler#UpdatePage", "lofi", video)
//handler.Service.Update(c.Request.Context(), form.ConvertFormToMediaLofiDTO())
c.Redirect(http.StatusFound, globals.MediaVideoLink)
}
func (handler *MediaVideoHandler) DeletePage(c *gin.Context) {
session := sessions.Default(c)
user := session.Get(globals.UserKey)
id := c.Param("id")
logger := slog.Get(c)
err := handler.Service.Delete(c.Request.Context(), id)
if err != nil {
logger.Info("MediaVideoHandler#DeletePage", "error", err.Error())
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
logger.Info("MediaVideoHandler#DeletePage", "video", id)
c.HTML(http.StatusOK, "lofi_delete", gin.H{
"title": "Kontor MediaFiles",
"version": "0.4.0",
"message": "MediaFiles...",
"user": user,
})
}
@@ -0,0 +1,28 @@
package handlers
import (
"kontor-api-echo/internal/repository"
"kontor-api-echo/internal/service"
"net/http"
"github.com/labstack/echo/v5"
"github.com/uptrace/bun"
)
type PermissionHandler struct {
Service *service.PermissionService
}
func NewPermissionHandler(db *bun.DB) *PermissionHandler {
handler := &PermissionHandler{Service: service.NewPermissionService(repository.NewPermissionRepository(db))}
return handler
}
func (handler *PermissionHandler) List(c *echo.Context) {
permissions, err := handler.Service.List(c.Request().Context())
if err != nil {
c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
return
}
c.JSON(http.StatusOK, permissions)
}
+30
View File
@@ -0,0 +1,30 @@
package handlers
import (
"kontor-api-echo/internal/models"
"kontor-api-echo/internal/repository"
"kontor-api-echo/internal/service"
"net/http"
"github.com/labstack/echo/v5"
"github.com/uptrace/bun"
)
type ProfileHandler struct {
Service *service.ProfileService
}
func NewProfileHandler(db *bun.DB) *ProfileHandler {
handler := &ProfileHandler{Service: service.NewProfileService(repository.NewProfileRepository(db))}
return handler
}
func (handler *ProfileHandler) List(c *echo.Context) {
profiles, err := handler.Service.List(c.Request().Context())
if err != nil {
c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
return
}
dtos := models.ConvertProfilesToDtos(profiles)
c.JSON(http.StatusOK, dtos)
}
+63
View File
@@ -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
+58
View File
@@ -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
+96
View File
@@ -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
+70
View File
@@ -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
@@ -0,0 +1,60 @@
package repository
import (
"context"
"kontor-api-echo/internal/models"
"log/slog"
"github.com/uptrace/bun"
)
type AssignmentRepository struct {
db *bun.DB
}
func NewAssignmentRepository(db *bun.DB) *AssignmentRepository {
repository := &AssignmentRepository{db: db}
return repository
}
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)
return assignments, nil
}
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())
}
return assignment, result.Error
}
func (repository *AssignmentRepository) Import(assignments 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 {
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())
}
} 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())
}
}
}
}
@@ -66,11 +66,10 @@ func (repository *MediaActorRepository) Add(context context.Context, url string)
}
func (repository *MediaActorRepository) Delete(context context.Context, id string) error {
var actor = models.MediaActor{ID: id}
slog.Info("MediaActorRepository#Delete", "id", id)
result := repository.db.Delete(&actor)
if result.Error != nil {
slog.Info("SportRepository#Delete", "error", result.Error.Error())
_, err := repository.db.NewDelete().Model((*models.MediaActor)(nil)).Where("id = ?", id).Exec(context)
if err != nil {
slog.Info("MediaArticleRepository#Delete", "error", err.Error())
}
return result.Error
return err
}
@@ -67,11 +67,10 @@ func (repository *MediaActorFileRepository) Add(context context.Context, media_a
}
func (repository *MediaActorFileRepository) Delete(context context.Context, id string) error {
var file = models.MediaActorFile{ID: id}
slog.Info("MediaActorFileRepository#Delete", "id", id)
result := repository.db.Delete(&file)
if result.Error != nil {
slog.Info("MediaActorFileRepository#Delete", "error", result.Error.Error())
_, err := repository.db.NewDelete().Model((*models.MediaActorFile)(nil)).Where("id = ?", id).Exec(context)
if err != nil {
slog.Info("MediaArticleRepository#Delete", "error", err.Error())
}
return result.Error
return err
}
@@ -67,11 +67,10 @@ func (repository *MediaFileRepository) Add(context context.Context, url string)
}
func (repository *MediaFileRepository) Delete(context context.Context, id string) error {
var file = models.MediaFile{ID: id}
slog.Info("MediaFileRepository#Delete", "id", id)
result := repository.db.Delete(&file)
if result.Error != nil {
slog.Info("MediaFileRepository#Delete", "error", result.Error.Error())
_, err := repository.db.NewDelete().Model((*models.MediaFile)(nil)).Where("id = ?", id).Exec(context)
if err != nil {
slog.Info("MediaFileRepository#Delete", "error", err.Error())
}
return result.Error
return err
}
+16 -11
View File
@@ -11,6 +11,7 @@ import (
"time"
"github.com/google/uuid"
"github.com/labstack/echo/v4"
"github.com/uptrace/bun"
)
@@ -49,8 +50,12 @@ func NewMediaLoFiRepository(db *bun.DB) *MediaLoFiRepository {
func (repository *MediaLoFiRepository) FindAll(context context.Context) ([]models.MediaLoFi, error) {
var lofis []models.MediaLoFi
result := repository.db.Find(&lofis)
slog.Info("MediaLoFiRepository#FindAll", "count", result.RowsAffected)
err := repository.db.NewSelect().Model(&lofis).Scan(context)
if err != nil {
slog.Info(err.Error())
return nil, echo.ErrInternalServerError
}
slog.Info("MediaLoFiRepository#FindAll", "count", len(lofis))
return lofis, nil
}
@@ -58,11 +63,12 @@ func (repository *MediaLoFiRepository) FindAll(context context.Context) ([]model
func (repository *MediaLoFiRepository) GetById(context context.Context, id string) (*models.MediaLoFi, error) {
var lofi = models.MediaLoFi{ID: id}
slog.Info("MediaLoFiRepository#GetById", "id", id)
result := repository.db.First(&lofi)
if result.Error != nil {
slog.Info("MediaLoFiRepository#GetById", "error", result.Error.Error())
err := repository.db.NewSelect().Model(&lofi).Where("id = ?", id).Scan(context)
if err != nil {
slog.Info("MediaLoFiRepository#GetById", "error", err.Error())
return nil, err
}
return &lofi, result.Error
return &lofi, err
}
func (repository *MediaLoFiRepository) Add(context context.Context, url string) (*models.MediaLoFi, error) {
@@ -117,11 +123,10 @@ func (repository *MediaLoFiRepository) Update(context context.Context, update mo
}
func (repository *MediaLoFiRepository) Delete(context context.Context, id string) error {
var actor = models.MediaLoFi{ID: id}
slog.Info("MediaLoFiRepository#Delete", "id", id)
result := repository.db.Delete(&actor)
if result.Error != nil {
slog.Info("MediaLoFiRepository#Delete", "error", result.Error.Error())
_, err := repository.db.NewDelete().Model((*models.MediaLoFi)(nil)).Where("id = ?", id).Exec(context)
if err != nil {
slog.Info("MediaLoFiRepository#Delete", "error", err.Error())
}
return result.Error
return err
}
@@ -117,11 +117,10 @@ func (repository *MediaMusicRepository) Update(context context.Context, update m
}
func (repository *MediaMusicRepository) Delete(context context.Context, id string) error {
var actor = models.MediaMusic{ID: id}
slog.Info("MediaMusicRepository#Delete", "id", id)
result := repository.db.Delete(&actor)
if result.Error != nil {
slog.Info("MediaMusicRepository#Delete", "error", result.Error.Error())
_, err := repository.db.NewDelete().Model((*models.MediaMusic)(nil)).Where("id = ?", id).Exec(context)
if err != nil {
slog.Info("MediaMusicRepository#Delete", "error", err.Error())
}
return result.Error
return err
}
@@ -0,0 +1,51 @@
package repository
import (
"context"
"kontor-api-echo/internal/models"
"log/slog"
"github.com/uptrace/bun"
)
type PermissionRepository struct {
db *bun.DB
}
func NewPermissionRepository(db *bun.DB) *PermissionRepository {
repository := &PermissionRepository{db: db}
return repository
}
func (repository *PermissionRepository) FindAll(context context.Context) ([]models.Permission, error) {
var permissions []models.Permission
result := repository.db.Find(&permissions)
slog.Info("ComicRepository#List", "count", result.RowsAffected)
return permissions, nil
}
func (repository *PermissionRepository) Import(permissions models.PermissionDTOList) {
slog.Info("PermissionRepository#Import")
for index, permission := range permissions {
slog.Info("importing", "index", index, "profile", permission)
model := permission.ConvertDTOToModel()
existing_item := models.Permission{ID: permission.ID}
result_existing := repository.db.First(&existing_item)
if result_existing.Error != 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())
}
} 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())
}
}
}
}
@@ -0,0 +1,61 @@
package repository
import (
"context"
"kontor-api-gin/internal/models"
"log/slog"
"gorm.io/gorm"
)
type ProfileRepository struct {
db *gorm.DB
}
func NewProfileRepository(db *gorm.DB) *ProfileRepository {
repository := &ProfileRepository{db: db}
return repository
}
func (repository *ProfileRepository) FindAll(context context.Context) ([]models.Profile, error) {
var profiles []models.Profile
result := repository.db.Find(&profiles)
slog.Info("ProfileRepository#FindAll", "count", result.RowsAffected)
return profiles, nil
}
func (repository *ProfileRepository) FindProfileByEmail(email string) (*models.Profile, error) {
var profile models.Profile
err := repository.db.Model(models.Profile{}).Where("email = ?", email).Take(&profile).Error
if err != nil {
return nil, err
}
return &profile, nil
}
func (repository *ProfileRepository) Import(profiles models.ProfileDTOList) {
slog.Info("ProfileRepository#Import")
for index, profile := range profiles {
slog.Info("importing", "index", index, "profile", profile)
model := profile.ConvertDTOToModel()
existing_profile := models.Profile{ID: profile.ID}
result_existing := repository.db.First(&existing_profile)
if result_existing.Error != 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())
}
} 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())
}
}
}
}
@@ -0,0 +1,27 @@
package service
import (
"context"
"kontor-api-gin/internal/models"
"kontor-api-gin/internal/repository"
"log/slog"
)
type AssignmentService struct {
repository *repository.AssignmentRepository
}
func NewAssignmentService(repo *repository.AssignmentRepository) *AssignmentService {
service := &AssignmentService{repository: repo}
return service
}
func (service *AssignmentService) List(context context.Context) ([]models.Assignment, error) {
slog.Info("AssignmentService#List")
return service.repository.FindAll(context)
}
func (service *AssignmentService) Get(context context.Context, id string) (models.Assignment, error) {
slog.Info("AssignmentService#Get")
return service.repository.GetById(context, id)
}
@@ -0,0 +1,23 @@
package service
import (
"context"
"kontor-api-gin/internal/models"
"kontor-api-gin/internal/repository"
"log/slog"
)
type PermissionService struct {
repository *repository.PermissionRepository
}
func NewPermissionService(repository *repository.PermissionRepository) *PermissionService {
service := &PermissionService{repository: repository}
return service
}
func (service PermissionService) List(context context.Context) ([]models.Permission, error) {
slog.Info("ComicService#List")
return service.repository.FindAll(context)
}
+22
View File
@@ -0,0 +1,22 @@
package service
import (
"context"
"kontor-api-gin/internal/models"
"kontor-api-gin/internal/repository"
"log/slog"
)
type ProfileService struct {
repository *repository.ProfileRepository
}
func NewProfileService(repo *repository.ProfileRepository) *ProfileService {
service := &ProfileService{repository: repo}
return service
}
func (service *ProfileService) List(context context.Context) ([]models.Profile, error) {
slog.Info("ProfileService#List")
return service.repository.FindAll(context)
}
-62
View File
@@ -1,62 +0,0 @@
package schema
import (
"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"`
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"`
}
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"`
Version int `bun:"version,default:0"`
Name string `bun:"name,unique:name"`
Assignments []Assignment `bun:"rel:has-many,join:id=permission_id"`
}
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"`
Version int `bun:"version,default:0"`
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 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"`
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"`
}