feat: add medias controller, service and dto
This commit is contained in:
24
backend/app/http/medias/controller.go
Normal file
24
backend/app/http/medias/controller.go
Normal 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)
|
||||||
|
}
|
||||||
18
backend/app/http/medias/dto.go
Normal file
18
backend/app/http/medias/dto.go
Normal 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"`
|
||||||
|
}
|
||||||
20
backend/app/http/medias/service.go
Normal file
20
backend/app/http/medias/service.go
Normal 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
|
||||||
|
}
|
||||||
37
backend/app/http/medias/service_test.go
Normal file
37
backend/app/http/medias/service_test.go
Normal 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)
|
||||||
|
})
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user