feat: add medias controller, service and dto

This commit is contained in:
Rogee
2025-01-14 20:16:13 +08:00
parent 307509e787
commit 591771ce77
4 changed files with 99 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
package medias
import (
"github.com/gofiber/fiber"
log "github.com/sirupsen/logrus"
)
// @provider
type Controller struct {
svc *Service
log *log.Entry `inject:"false"`
}
func (ctl *Controller) Prepare() error {
ctl.log = log.WithField("module", "medias.Controller")
return nil
}
// Upload
// @Router /api/v1/medias/upload [post]
// @Bind req body
func (ctl *Controller) Upload(ctx fiber.Ctx, req *UploadReq) (*UploadResp, error) {
return ctl.svc.Upload(ctx.Context(), req)
}

View File

@@ -0,0 +1,18 @@
package medias
type UploadReq struct {
Files []string `json:"files"`
}
type UploadResp struct {
Files []UploadFile `json:"files"`
}
type UploadFile struct {
HashID string `json:"hash_id"`
Name string `json:"name"`
Size int64 `json:"size"`
MimeType string `json:"type"`
Path string `json:"path"`
Preview string `json:"preview"`
}

View File

@@ -0,0 +1,20 @@
package medias
import (
"database/sql"
. "github.com/go-jet/jet/v2/postgres"
log "github.com/sirupsen/logrus"
)
// @provider:except
type Service struct {
db *sql.DB
log *log.Entry `inject:"false"`
}
func (svc *Service) Prepare() error {
svc.log = log.WithField("module", "medias.service")
_ = Int(1)
return nil
}

View File

@@ -0,0 +1,37 @@
package medias
import (
"testing"
"backend/app/service/testx"
. "github.com/smartystreets/goconvey/convey"
"github.com/stretchr/testify/suite"
"go.uber.org/dig"
)
type ServiceInjectParams struct {
dig.In
Svc *Service
}
type ServiceTestSuite struct {
suite.Suite
ServiceInjectParams
}
func Test_DiscoverMedias(t *testing.T) {
providers := testx.Default().With(
Provide,
)
testx.Serve(providers, t, func(params ServiceInjectParams) {
suite.Run(t, &ServiceTestSuite{ServiceInjectParams: params})
})
}
func (s *ServiceTestSuite) Test_Service() {
Convey("Test Service", s.T(), func() {
So(s.Svc, ShouldNotBeNil)
})
}