mirror of
https://github.com/Floriansylvain/RenewCMS.git
synced 2026-08-19 11:43:22 +02:00
refac: remove frontend & clearer DDD
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
package article
|
||||
|
||||
import (
|
||||
domain "RenewCMS/internal/domain/image"
|
||||
entity "RenewCMS/internal/infrastructure/persistence/models"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Article struct {
|
||||
ID uint32 `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Body string `json:"body"`
|
||||
Images []*domain.Image `json:"images"`
|
||||
IsOnline bool `json:"is_online"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
func FromApi(
|
||||
title string,
|
||||
body string,
|
||||
) Article {
|
||||
return Article{
|
||||
Title: title,
|
||||
Body: body,
|
||||
}
|
||||
}
|
||||
|
||||
func FromDb(
|
||||
id uint32,
|
||||
title string,
|
||||
body string,
|
||||
images []*entity.Image,
|
||||
isOnline bool,
|
||||
createdAt time.Time,
|
||||
updatedAt time.Time,
|
||||
) Article {
|
||||
domainImages := make([]*domain.Image, len(images))
|
||||
for i, img := range images {
|
||||
domainImage := domain.FromDB(
|
||||
img.ID,
|
||||
img.Path,
|
||||
img.ArticleID,
|
||||
img.CreatedAt,
|
||||
img.UpdatedAt,
|
||||
)
|
||||
domainImages[i] = &domainImage
|
||||
}
|
||||
return Article{
|
||||
ID: id,
|
||||
Title: title,
|
||||
Body: body,
|
||||
Images: domainImages,
|
||||
IsOnline: isOnline,
|
||||
CreatedAt: createdAt,
|
||||
UpdatedAt: updatedAt,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package article
|
||||
|
||||
type Repository interface {
|
||||
Get(id uint32) (Article, error)
|
||||
GetByName(name string) (Article, error)
|
||||
GetAll() []Article
|
||||
Create(post Article) (Article, error)
|
||||
UpdateBody(id uint32, body string) (Article, error)
|
||||
UpdateIsOnline(id uint32, isOnline bool) (Article, error)
|
||||
Delete(id uint32) error
|
||||
AddImage(postId uint32, imageId uint32) error
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type Image struct {
|
||||
ID uint32 `json:"id"`
|
||||
Path string `json:"path"`
|
||||
ArticleID uint32 `json:"article_id"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
func FromDB(id uint32, path string, articleId uint32, createdAt time.Time, updatedAt time.Time) Image {
|
||||
return Image{
|
||||
ID: id,
|
||||
Path: path,
|
||||
ArticleID: articleId,
|
||||
CreatedAt: createdAt,
|
||||
UpdatedAt: updatedAt,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"mime/multipart"
|
||||
)
|
||||
|
||||
type Repository interface {
|
||||
Create(file multipart.File, fileHeader multipart.FileHeader) (Image, error)
|
||||
Delete(id uint32) error
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package mail
|
||||
|
||||
type Repository interface {
|
||||
Send(receiverAddress string, templateName string, data any) error
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package user
|
||||
|
||||
type Repository interface {
|
||||
Get(id uint32) (User, error)
|
||||
GetByUsername(username string) (User, error)
|
||||
GetByEmail(email string) (User, error)
|
||||
GetAll() []User
|
||||
Create(user User) (User, error)
|
||||
Delete(id uint32) error
|
||||
UpdateVerificationStatus(userId uint32, isVerified bool) (User, error)
|
||||
UpdatePassword(userId uint32, password string) (User, error)
|
||||
UpdatePasswordResetCode(userId uint32, code string) (User, error)
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type User struct {
|
||||
ID uint32 `json:"id"`
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
PasswordResetCode string `json:"password_reset_code"`
|
||||
Email string `json:"email"`
|
||||
IsVerified bool `json:"is_verified"`
|
||||
VerificationCode string `json:"verification_code"`
|
||||
VerificationExpiration time.Time `json:"verification_expiration"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
func FromApi(
|
||||
username string,
|
||||
password string,
|
||||
passwordResetCode string,
|
||||
email string,
|
||||
verificationCode string,
|
||||
) User {
|
||||
expiration := time.Now().Add(2 * time.Hour)
|
||||
return User{
|
||||
Username: username,
|
||||
Password: password,
|
||||
PasswordResetCode: passwordResetCode,
|
||||
Email: email,
|
||||
IsVerified: false,
|
||||
VerificationCode: verificationCode,
|
||||
VerificationExpiration: expiration,
|
||||
}
|
||||
}
|
||||
|
||||
func FromDb(
|
||||
id uint32,
|
||||
username string,
|
||||
password string,
|
||||
passwordResetCode string,
|
||||
email string,
|
||||
isVerified bool,
|
||||
verificationCode string,
|
||||
verificationExpiration time.Time,
|
||||
createdAt time.Time,
|
||||
updatedAt time.Time,
|
||||
) User {
|
||||
return User{
|
||||
ID: id,
|
||||
Username: username,
|
||||
Password: password,
|
||||
PasswordResetCode: passwordResetCode,
|
||||
Email: email,
|
||||
IsVerified: isVerified,
|
||||
VerificationCode: verificationCode,
|
||||
VerificationExpiration: verificationExpiration,
|
||||
CreatedAt: createdAt,
|
||||
UpdatedAt: updatedAt,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user