mirror of
https://github.com/Floriansylvain/RenewCMS.git
synced 2026-08-19 11:43:22 +02:00
refac: fixed, better, smarter, correct dependency injection
This commit is contained in:
@@ -1,20 +1,17 @@
|
||||
package useCases
|
||||
|
||||
import (
|
||||
"GoCMS/adapters/secondary/gateways"
|
||||
"GoCMS/domain/gateways"
|
||||
"GoCMS/domain/image"
|
||||
"gorm.io/gorm"
|
||||
"mime/multipart"
|
||||
)
|
||||
|
||||
type CreateImageUseCase struct {
|
||||
imageRepository gateways.ImageRepository
|
||||
imageRepository gateways.IImageRepository
|
||||
}
|
||||
|
||||
func NewCreateImageUseCase(db *gorm.DB) *CreateImageUseCase {
|
||||
return &CreateImageUseCase{
|
||||
imageRepository: *gateways.NewImageRepository(db),
|
||||
}
|
||||
func NewCreateImageUseCase(imageRepository gateways.IImageRepository) *CreateImageUseCase {
|
||||
return &CreateImageUseCase{imageRepository}
|
||||
}
|
||||
|
||||
func (g *CreateImageUseCase) CreateImage(file multipart.File, fileHeader multipart.FileHeader) (image.Image, error) {
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
package useCases
|
||||
|
||||
import (
|
||||
"GoCMS/adapters/secondary/gateways"
|
||||
"GoCMS/domain/gateways"
|
||||
"GoCMS/domain/post"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type CreatePostUseCase struct {
|
||||
postRepository gateways.PostRepository
|
||||
postRepository gateways.IPostRepository
|
||||
}
|
||||
|
||||
type CreatePostCommand struct {
|
||||
@@ -15,10 +14,8 @@ type CreatePostCommand struct {
|
||||
Body string
|
||||
}
|
||||
|
||||
func NewCreatePostUseCase(db *gorm.DB) *CreatePostUseCase {
|
||||
return &CreatePostUseCase{
|
||||
postRepository: *gateways.NewPostRepository(db),
|
||||
}
|
||||
func NewCreatePostUseCase(postRepository gateways.IPostRepository) *CreatePostUseCase {
|
||||
return &CreatePostUseCase{postRepository}
|
||||
}
|
||||
|
||||
func (g *CreatePostUseCase) CreatePost(createPost CreatePostCommand) (post.Post, error) {
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
package useCases
|
||||
|
||||
import (
|
||||
"GoCMS/adapters/secondary/gateways"
|
||||
"GoCMS/domain/gateways"
|
||||
"GoCMS/domain/user"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type CreateUserUseCase struct {
|
||||
userRepository gateways.UserRepository
|
||||
userRepository gateways.IUserRepository
|
||||
}
|
||||
|
||||
type CreateUserCommand struct {
|
||||
@@ -17,10 +16,8 @@ type CreateUserCommand struct {
|
||||
VerificationCode string
|
||||
}
|
||||
|
||||
func NewCreateUserUseCase(db *gorm.DB) *CreateUserUseCase {
|
||||
return &CreateUserUseCase{
|
||||
userRepository: *gateways.NewUserRepository(db),
|
||||
}
|
||||
func NewCreateUserUseCase(userRepository gateways.IUserRepository) *CreateUserUseCase {
|
||||
return &CreateUserUseCase{userRepository}
|
||||
}
|
||||
|
||||
func (g *CreateUserUseCase) CreateUser(createUser CreateUserCommand) (user.User, error) {
|
||||
|
||||
@@ -1,18 +1,15 @@
|
||||
package useCases
|
||||
|
||||
import (
|
||||
"GoCMS/adapters/secondary/gateways"
|
||||
"gorm.io/gorm"
|
||||
"GoCMS/domain/gateways"
|
||||
)
|
||||
|
||||
type DeleteImageUseCase struct {
|
||||
imageRepository gateways.ImageRepository
|
||||
imageRepository gateways.IImageRepository
|
||||
}
|
||||
|
||||
func NewDeleteImageUseCase(db *gorm.DB) *DeleteImageUseCase {
|
||||
return &DeleteImageUseCase{
|
||||
imageRepository: *gateways.NewImageRepository(db),
|
||||
}
|
||||
func NewDeleteImageUseCase(imageRepository gateways.IImageRepository) *DeleteImageUseCase {
|
||||
return &DeleteImageUseCase{imageRepository}
|
||||
}
|
||||
|
||||
func (g *DeleteImageUseCase) DeleteImage(imageId uint32) error {
|
||||
|
||||
@@ -1,18 +1,15 @@
|
||||
package useCases
|
||||
|
||||
import (
|
||||
"GoCMS/adapters/secondary/gateways"
|
||||
"gorm.io/gorm"
|
||||
"GoCMS/domain/gateways"
|
||||
)
|
||||
|
||||
type DeletePostUseCase struct {
|
||||
postRepository gateways.PostRepository
|
||||
postRepository gateways.IPostRepository
|
||||
}
|
||||
|
||||
func NewDeletePostUseCase(db *gorm.DB) *DeletePostUseCase {
|
||||
return &DeletePostUseCase{
|
||||
postRepository: *gateways.NewPostRepository(db),
|
||||
}
|
||||
func NewDeletePostUseCase(postRepository gateways.IPostRepository) *DeletePostUseCase {
|
||||
return &DeletePostUseCase{postRepository}
|
||||
}
|
||||
|
||||
func (g *DeletePostUseCase) DeletePost(userId uint32) error {
|
||||
|
||||
@@ -1,18 +1,15 @@
|
||||
package useCases
|
||||
|
||||
import (
|
||||
"GoCMS/adapters/secondary/gateways"
|
||||
"gorm.io/gorm"
|
||||
"GoCMS/domain/gateways"
|
||||
)
|
||||
|
||||
type DeleteUserUseCase struct {
|
||||
userRepository gateways.UserRepository
|
||||
userRepository gateways.IUserRepository
|
||||
}
|
||||
|
||||
func NewDeleteUserUseCase(db *gorm.DB) *DeleteUserUseCase {
|
||||
return &DeleteUserUseCase{
|
||||
userRepository: *gateways.NewUserRepository(db),
|
||||
}
|
||||
func NewDeleteUserUseCase(userRepository gateways.IUserRepository) *DeleteUserUseCase {
|
||||
return &DeleteUserUseCase{userRepository}
|
||||
}
|
||||
|
||||
func (g *DeleteUserUseCase) DeleteUser(userId uint32) error {
|
||||
|
||||
+5
-7
@@ -1,19 +1,17 @@
|
||||
package useCases
|
||||
|
||||
import (
|
||||
"GoCMS/adapters/secondary/gateways"
|
||||
"GoCMS/domain/gateways"
|
||||
)
|
||||
|
||||
type GetPageUseCase struct {
|
||||
pageRepository gateways.PageRepository
|
||||
pageRepository gateways.IPageRepository
|
||||
}
|
||||
|
||||
func NewGetPageUseCase() *GetPageUseCase {
|
||||
return &GetPageUseCase{
|
||||
pageRepository: *gateways.NewPageRepository(),
|
||||
}
|
||||
func NewGetPageUseCase(pageRepository gateways.IPageRepository) *GetPageUseCase {
|
||||
return &GetPageUseCase{pageRepository}
|
||||
}
|
||||
|
||||
func (g *GetPageUseCase) GetPage(name string, data interface{}) ([]byte, error) {
|
||||
func (g *GetPageUseCase) GetPage(name string, data any) ([]byte, error) {
|
||||
return g.pageRepository.Get(name, data)
|
||||
}
|
||||
|
||||
+4
-7
@@ -1,19 +1,16 @@
|
||||
package useCases
|
||||
|
||||
import (
|
||||
"GoCMS/adapters/secondary/gateways"
|
||||
"GoCMS/domain/gateways"
|
||||
"GoCMS/domain/post"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type GetPostUseCase struct {
|
||||
postRepository gateways.PostRepository
|
||||
postRepository gateways.IPostRepository
|
||||
}
|
||||
|
||||
func NewGetPostUseCase(db *gorm.DB) *GetPostUseCase {
|
||||
return &GetPostUseCase{
|
||||
postRepository: *gateways.NewPostRepository(db),
|
||||
}
|
||||
func NewGetPostUseCase(postRepository gateways.IPostRepository) *GetPostUseCase {
|
||||
return &GetPostUseCase{postRepository}
|
||||
}
|
||||
|
||||
func (g *GetPostUseCase) GetPost(id uint32) (post.Post, error) {
|
||||
|
||||
+4
-7
@@ -1,19 +1,16 @@
|
||||
package useCases
|
||||
|
||||
import (
|
||||
"GoCMS/adapters/secondary/gateways"
|
||||
"GoCMS/domain/gateways"
|
||||
"GoCMS/domain/user"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type GetUserUseCase struct {
|
||||
userRepository gateways.UserRepository
|
||||
userRepository gateways.IUserRepository
|
||||
}
|
||||
|
||||
func NewGetUserUseCase(db *gorm.DB) *GetUserUseCase {
|
||||
return &GetUserUseCase{
|
||||
userRepository: *gateways.NewUserRepository(db),
|
||||
}
|
||||
func NewGetUserUseCase(userRepository gateways.IUserRepository) *GetUserUseCase {
|
||||
return &GetUserUseCase{userRepository}
|
||||
}
|
||||
|
||||
func (g *GetUserUseCase) GetUser(id uint32) (user.User, error) {
|
||||
|
||||
@@ -1,19 +1,16 @@
|
||||
package useCases
|
||||
|
||||
import (
|
||||
"GoCMS/adapters/secondary/gateways"
|
||||
"GoCMS/domain/gateways"
|
||||
"GoCMS/domain/post"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type ListPostsUseCase struct {
|
||||
postRepository gateways.PostRepository
|
||||
postRepository gateways.IPostRepository
|
||||
}
|
||||
|
||||
func NewListPostsUseCase(db *gorm.DB) *ListPostsUseCase {
|
||||
return &ListPostsUseCase{
|
||||
postRepository: *gateways.NewPostRepository(db),
|
||||
}
|
||||
func NewListPostsUseCase(postRepository gateways.IPostRepository) *ListPostsUseCase {
|
||||
return &ListPostsUseCase{postRepository}
|
||||
}
|
||||
|
||||
func (g *ListPostsUseCase) ListPosts() []post.Post {
|
||||
|
||||
@@ -1,19 +1,16 @@
|
||||
package useCases
|
||||
|
||||
import (
|
||||
"GoCMS/adapters/secondary/gateways"
|
||||
"GoCMS/domain/gateways"
|
||||
"GoCMS/domain/user"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type ListUsersUseCase struct {
|
||||
userRepository gateways.UserRepository
|
||||
userRepository gateways.IUserRepository
|
||||
}
|
||||
|
||||
func NewListUsersUseCase(db *gorm.DB) *ListUsersUseCase {
|
||||
return &ListUsersUseCase{
|
||||
userRepository: *gateways.NewUserRepository(db),
|
||||
}
|
||||
func NewListUsersUseCase(userRepository gateways.IUserRepository) *ListUsersUseCase {
|
||||
return &ListUsersUseCase{userRepository}
|
||||
}
|
||||
|
||||
func (g *ListUsersUseCase) ListUsers() []user.User {
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
package useCases
|
||||
|
||||
import (
|
||||
"GoCMS/adapters/secondary/gateways"
|
||||
"GoCMS/domain/gateways"
|
||||
)
|
||||
|
||||
type SendMailUseCase struct {
|
||||
mailRepository gateways.MailRepository
|
||||
mailRepository gateways.IMailRepository
|
||||
}
|
||||
|
||||
func NewSendMailUseCase() *SendMailUseCase {
|
||||
return &SendMailUseCase{}
|
||||
func NewSendMailUseCase(mailRepository gateways.IMailRepository) *SendMailUseCase {
|
||||
return &SendMailUseCase{mailRepository}
|
||||
}
|
||||
|
||||
func (g *SendMailUseCase) SendMail(receiverAddress string, templateName string, data interface{}) error {
|
||||
func (g *SendMailUseCase) SendMail(receiverAddress string, templateName string, data any) error {
|
||||
return g.mailRepository.Send(receiverAddress, templateName, data)
|
||||
}
|
||||
|
||||
@@ -1,19 +1,16 @@
|
||||
package useCases
|
||||
|
||||
import (
|
||||
"GoCMS/adapters/secondary/gateways"
|
||||
"GoCMS/domain/gateways"
|
||||
"GoCMS/domain/post"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type UpdatePostUseCase struct {
|
||||
postRepository gateways.PostRepository
|
||||
postRepository gateways.IPostRepository
|
||||
}
|
||||
|
||||
func NewUpdatePostUseCase(db *gorm.DB) *UpdatePostUseCase {
|
||||
return &UpdatePostUseCase{
|
||||
postRepository: *gateways.NewPostRepository(db),
|
||||
}
|
||||
func NewUpdatePostUseCase(postRepository gateways.IPostRepository) *UpdatePostUseCase {
|
||||
return &UpdatePostUseCase{postRepository}
|
||||
}
|
||||
|
||||
func (g *UpdatePostUseCase) UpdateBody(id uint32, body string) (post.Post, error) {
|
||||
|
||||
@@ -1,19 +1,16 @@
|
||||
package useCases
|
||||
|
||||
import (
|
||||
"GoCMS/adapters/secondary/gateways"
|
||||
"GoCMS/domain/gateways"
|
||||
"GoCMS/domain/user"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type UpdateUserUseCase struct {
|
||||
userRepository gateways.UserRepository
|
||||
userRepository gateways.IUserRepository
|
||||
}
|
||||
|
||||
func NewUpdateUserUseCase(db *gorm.DB) *UpdateUserUseCase {
|
||||
return &UpdateUserUseCase{
|
||||
userRepository: *gateways.NewUserRepository(db),
|
||||
}
|
||||
func NewUpdateUserUseCase(userRepository gateways.IUserRepository) *UpdateUserUseCase {
|
||||
return &UpdateUserUseCase{userRepository}
|
||||
}
|
||||
|
||||
func (g *UpdateUserUseCase) UpdateVerificationStatus(userId uint32, isVerified bool) (user.User, error) {
|
||||
|
||||
Reference in New Issue
Block a user