REFACTOR: Seperated Catagories And Video DB Repositories
Build, Push and Deploy CMS / build-push-deploy (push) Successful in 2m45s

This commit is contained in:
FahdShalhoub
2026-08-26 08:51:40 +03:00
parent b77afbfed6
commit 4132c6071e
8 changed files with 182 additions and 155 deletions
+8 -6
View File
@@ -13,6 +13,8 @@ import (
"strconv"
"strings"
"thamanyah/cms/v2/internal/api"
"thamanyah/cms/v2/internal/db/repositories"
"thamanyah/cms/v2/internal/models"
"thamanyah/cms/v2/internal/services"
"time"
)
@@ -33,7 +35,7 @@ const (
// @Failure 500 {object} api.ProblemDetails "Categories could not be read from the database"
// @Router /api/categories [get]
func ListCategories(w http.ResponseWriter, r *http.Request) {
categories, err := services.DB.ListCategories(r.Context())
categories, err := repositories.CatagoriesRepo.ListCategories(r.Context())
if err != nil {
log.Printf("Something Went Wrong Loading Categories: %s", err)
writeProblem(w, http.StatusInternalServerError, "Something Went Wrong Loading Categories",
@@ -143,7 +145,7 @@ func CompleteVideoUpload(w http.ResponseWriter, r *http.Request) {
return
}
err := resolveCategoryIDs(r.Context(), req.CategoryIDs)
err := validateCatagoryIDS(r.Context(), req.CategoryIDs)
if err != nil {
log.Printf("Something Went Wrong Loading Categories: %s", err)
writeProblem(w, http.StatusInternalServerError, "Something Went Wrong Loading Categories",
@@ -159,7 +161,7 @@ func CompleteVideoUpload(w http.ResponseWriter, r *http.Request) {
return
}
video, err := services.DB.CreateVideo(r.Context(), services.Video{
video, err := repositories.VideoRepo.CreateVideo(r.Context(), models.Video{
Title: title,
Description: strings.TrimSpace(req.Description),
CategoryIDs: req.CategoryIDs,
@@ -167,7 +169,7 @@ func CompleteVideoUpload(w http.ResponseWriter, r *http.Request) {
FileName: strings.TrimSpace(req.FileName),
StorageKey: key,
MediaConvertJobID: jobID,
Status: services.VideoStatusProcessing,
Status: models.VideoStatusProcessing,
SizeBytes: 60,
})
if err != nil {
@@ -193,8 +195,8 @@ func CompleteVideoUpload(w http.ResponseWriter, r *http.Request) {
})
}
func resolveCategoryIDs(ctx context.Context, submitted []int16) (err error) {
categoryIDS, err := services.DB.ListCategoriesIDs(ctx)
func validateCatagoryIDS(ctx context.Context, submitted []int16) (err error) {
categoryIDS, err := repositories.CatagoriesRepo.ListCategoriesIDs(ctx)
if err != nil {
return err
}