refactor: make vfs methods accept bun.IDB

This commit is contained in:
2025-11-30 17:31:24 +00:00
parent 89b62f6d8a
commit 0b8aee5d60
6 changed files with 82 additions and 56 deletions

View File

@@ -5,6 +5,7 @@ import (
"github.com/get-drexa/drexa/internal/account"
"github.com/gofiber/fiber/v2"
"github.com/uptrace/bun"
)
type createUploadRequest struct {
@@ -18,10 +19,11 @@ type updateUploadRequest struct {
type HTTPHandler struct {
service *Service
db *bun.DB
}
func NewHTTPHandler(s *Service) *HTTPHandler {
return &HTTPHandler{service: s}
func NewHTTPHandler(s *Service, db *bun.DB) *HTTPHandler {
return &HTTPHandler{service: s, db: db}
}
func (h *HTTPHandler) RegisterRoutes(api fiber.Router) {
@@ -43,7 +45,7 @@ func (h *HTTPHandler) Create(c *fiber.Ctx) error {
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "Invalid request"})
}
upload, err := h.service.CreateUpload(c.Context(), account.ID, CreateUploadOptions{
upload, err := h.service.CreateUpload(c.Context(), h.db, account.ID, CreateUploadOptions{
ParentID: req.ParentID,
Name: req.Name,
})
@@ -62,7 +64,7 @@ func (h *HTTPHandler) ReceiveContent(c *fiber.Ctx) error {
uploadID := c.Params("uploadID")
err := h.service.ReceiveUpload(c.Context(), account.ID, uploadID, c.Request().BodyStream())
err := h.service.ReceiveUpload(c.Context(), h.db, account.ID, uploadID, c.Request().BodyStream())
defer c.Request().CloseBodyStream()
if err != nil {
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{"error": "Internal server error"})
@@ -83,7 +85,7 @@ func (h *HTTPHandler) Update(c *fiber.Ctx) error {
}
if req.Status == StatusCompleted {
upload, err := h.service.CompleteUpload(c.Context(), account.ID, c.Params("uploadID"))
upload, err := h.service.CompleteUpload(c.Context(), h.db, account.ID, c.Params("uploadID"))
if err != nil {
if errors.Is(err, ErrNotFound) {
return c.SendStatus(fiber.StatusNotFound)