feat: images

This commit is contained in:
Florian Sylvain
2024-06-13 13:34:10 +02:00
parent eb98a1003e
commit c25fb1b0a3
19 changed files with 387 additions and 100 deletions
+22
View File
@@ -0,0 +1,22 @@
package useCases
import (
"GoCMS/adapters/secondary/gateways"
"GoCMS/domain/image"
"gorm.io/gorm"
"mime/multipart"
)
type CreateImageUseCase struct {
imageRepository gateways.ImageRepository
}
func NewCreateImageUseCase(db *gorm.DB) *CreateImageUseCase {
return &CreateImageUseCase{
imageRepository: *gateways.NewImageRepository(db),
}
}
func (g *CreateImageUseCase) CreateImage(file multipart.File, fileHeader multipart.FileHeader) (image.Image, error) {
return g.imageRepository.Create(file, fileHeader)
}
+20
View File
@@ -0,0 +1,20 @@
package useCases
import (
"GoCMS/adapters/secondary/gateways"
"gorm.io/gorm"
)
type DeleteImageUseCase struct {
imageRepository gateways.ImageRepository
}
func NewDeleteImageUseCase(db *gorm.DB) *DeleteImageUseCase {
return &DeleteImageUseCase{
imageRepository: *gateways.NewImageRepository(db),
}
}
func (g *DeleteImageUseCase) DeleteImage(imageId uint32) error {
return g.imageRepository.Delete(imageId)
}
+6 -1
View File
@@ -2,6 +2,7 @@ package useCases
import (
"GoCMS/adapters/secondary/gateways"
"GoCMS/domain/post"
"gorm.io/gorm"
)
@@ -15,6 +16,10 @@ func NewUpdatePostUseCase(db *gorm.DB) *UpdatePostUseCase {
}
}
func (g *UpdatePostUseCase) UpdateBody(id uint32, body string) error {
func (g *UpdatePostUseCase) UpdateBody(id uint32, body string) (post.Post, error) {
return g.postRepository.UpdateBody(id, body)
}
func (g *UpdatePostUseCase) AddImage(postId uint32, imageId uint32) error {
return g.postRepository.AddImage(postId, imageId)
}