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
+11
View File
@@ -0,0 +1,11 @@
package gateways
import (
"GoCMS/domain/image"
"mime/multipart"
)
type IImageRepository interface {
Create(file multipart.File, fileHeader multipart.FileHeader) (image.Image, error)
Delete(id uint32) error
}
+2 -1
View File
@@ -9,6 +9,7 @@ type IPostRepository interface {
GetByName(name string) (post.Post, error)
GetAll() []post.Post
Create(post post.Post) (post.Post, error)
UpdateBody(id uint32, body string) error
UpdateBody(id uint32, body string) (post.Post, error)
Delete(id uint32) error
AddImage(postId uint32, imageId uint32) error
}
+23
View File
@@ -0,0 +1,23 @@
package image
import (
"time"
)
type Image struct {
ID uint32
Path string
PostID uint32
CreatedAt time.Time
UpdatedAt time.Time
}
func FromDB(id uint32, path string, postId uint32, createdAt time.Time, updatedAt time.Time) Image {
return Image{
ID: id,
Path: path,
PostID: postId,
CreatedAt: createdAt,
UpdatedAt: updatedAt,
}
}
+24 -6
View File
@@ -1,13 +1,18 @@
package post
import "time"
import (
entity "GoCMS/adapters/secondary/gateways/models"
domain "GoCMS/domain/image"
"time"
)
type Post struct {
ID uint32 `json:"id"`
Title string `json:"title"`
Body string `json:"body"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
ID uint32 `json:"id"`
Title string `json:"title"`
Body string `json:"body"`
Images []*domain.Image `json:"images"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
func FromApi(
@@ -24,13 +29,26 @@ func FromDb(
id uint32,
title string,
body string,
images []*entity.Image,
createdAt time.Time,
updatedAt time.Time,
) Post {
domainImages := make([]*domain.Image, len(images))
for i, img := range images {
domainImage := domain.FromDB(
img.ID,
img.Path,
img.PostID,
img.CreatedAt,
img.UpdatedAt,
)
domainImages[i] = &domainImage
}
return Post{
ID: id,
Title: title,
Body: body,
Images: domainImages,
CreatedAt: createdAt,
UpdatedAt: updatedAt,
}