refac: remove frontend & clearer DDD

This commit is contained in:
Floriansylvain
2025-12-21 21:31:30 +01:00
parent 6796ce63cb
commit 61a84201d8
212 changed files with 2097 additions and 13007 deletions
@@ -0,0 +1,25 @@
package useCases
import (
"RenewCMS/internal/domain/article"
)
type CreateArticleUseCase struct {
articleRepository article.Repository
}
type CreateArticleCommand struct {
Title string
Body string
}
func NewCreateArticleUseCase(articleRepository article.Repository) *CreateArticleUseCase {
return &CreateArticleUseCase{articleRepository}
}
func (g *CreateArticleUseCase) CreateArticle(createArticle CreateArticleCommand) (article.Article, error) {
return g.articleRepository.Create(article.FromApi(
createArticle.Title,
createArticle.Body,
))
}
@@ -0,0 +1,18 @@
package useCases
import (
"RenewCMS/internal/domain/image"
"mime/multipart"
)
type CreateImageUseCase struct {
imageRepository image.Repository
}
func NewCreateImageUseCase(imageRepository image.Repository) *CreateImageUseCase {
return &CreateImageUseCase{imageRepository}
}
func (g *CreateImageUseCase) CreateImage(file multipart.File, fileHeader multipart.FileHeader) (image.Image, error) {
return g.imageRepository.Create(file, fileHeader)
}
@@ -0,0 +1,39 @@
package useCases
import (
"RenewCMS/internal/domain/user"
"github.com/google/uuid"
)
type CreateUserUseCase struct {
userRepository user.Repository
}
type CreateUserCommand struct {
Username string
Password string
Email string
}
func NewCreateUserUseCase(userRepository user.Repository) *CreateUserUseCase {
return &CreateUserUseCase{userRepository}
}
func (g *CreateUserUseCase) CreateUser(createUser CreateUserCommand) (user.User, error) {
rawUuid := uuid.NewString()
createdUser, err := g.userRepository.Create(user.FromApi(
createUser.Username,
createUser.Password,
"",
createUser.Email,
rawUuid,
))
if err != nil {
return user.User{}, err
}
createdUser.VerificationCode = rawUuid
return createdUser, nil
}
@@ -0,0 +1,15 @@
package useCases
import "RenewCMS/internal/domain/article"
type DeleteArticleUseCase struct {
articleRepository article.Repository
}
func NewDeleteArticleUseCase(articleRepository article.Repository) *DeleteArticleUseCase {
return &DeleteArticleUseCase{articleRepository}
}
func (g *DeleteArticleUseCase) DeleteArticle(userId uint32) error {
return g.articleRepository.Delete(userId)
}
@@ -0,0 +1,15 @@
package useCases
import "RenewCMS/internal/domain/image"
type DeleteImageUseCase struct {
imageRepository image.Repository
}
func NewDeleteImageUseCase(imageRepository image.Repository) *DeleteImageUseCase {
return &DeleteImageUseCase{imageRepository}
}
func (g *DeleteImageUseCase) DeleteImage(imageId uint32) error {
return g.imageRepository.Delete(imageId)
}
@@ -0,0 +1,15 @@
package useCases
import "RenewCMS/internal/domain/user"
type DeleteUserUseCase struct {
userRepository user.Repository
}
func NewDeleteUserUseCase(userRepository user.Repository) *DeleteUserUseCase {
return &DeleteUserUseCase{userRepository}
}
func (g *DeleteUserUseCase) DeleteUser(userId uint32) error {
return g.userRepository.Delete(userId)
}
@@ -0,0 +1,19 @@
package useCases
import "RenewCMS/internal/domain/article"
type GetArticleUseCase struct {
articleRepository article.Repository
}
func NewGetArticleUseCase(articleRepository article.Repository) *GetArticleUseCase {
return &GetArticleUseCase{articleRepository}
}
func (g *GetArticleUseCase) GetArticle(id uint32) (article.Article, error) {
return g.articleRepository.Get(id)
}
func (g *GetArticleUseCase) GetArticleByName(name string) (article.Article, error) {
return g.articleRepository.GetByName(name)
}
@@ -0,0 +1,23 @@
package useCases
import "RenewCMS/internal/domain/user"
type GetUserUseCase struct {
userRepository user.Repository
}
func NewGetUserUseCase(userRepository user.Repository) *GetUserUseCase {
return &GetUserUseCase{userRepository}
}
func (g *GetUserUseCase) GetUser(id uint32) (user.User, error) {
return g.userRepository.Get(id)
}
func (g *GetUserUseCase) GetUserByUsername(username string) (user.User, error) {
return g.userRepository.GetByUsername(username)
}
func (g *GetUserUseCase) GetUserByEmail(email string) (user.User, error) {
return g.userRepository.GetByEmail(email)
}
@@ -0,0 +1,15 @@
package useCases
import "RenewCMS/internal/domain/article"
type ListArticlesUseCase struct {
articleRepository article.Repository
}
func NewListArticlesUseCase(articleRepository article.Repository) *ListArticlesUseCase {
return &ListArticlesUseCase{articleRepository}
}
func (g *ListArticlesUseCase) ListArticles() []article.Article {
return g.articleRepository.GetAll()
}
@@ -0,0 +1,15 @@
package useCases
import "RenewCMS/internal/domain/user"
type ListUsersUseCase struct {
userRepository user.Repository
}
func NewListUsersUseCase(userRepository user.Repository) *ListUsersUseCase {
return &ListUsersUseCase{userRepository}
}
func (g *ListUsersUseCase) ListUsers() []user.User {
return g.userRepository.GetAll()
}
@@ -0,0 +1,15 @@
package useCases
import "RenewCMS/internal/domain/mail"
type SendMailUseCase struct {
mailRepository mail.Repository
}
func NewSendMailUseCase(mailRepository mail.Repository) *SendMailUseCase {
return &SendMailUseCase{mailRepository}
}
func (g *SendMailUseCase) SendMail(receiverAddress string, templateName string, data any) error {
return g.mailRepository.Send(receiverAddress, templateName, data)
}
@@ -0,0 +1,23 @@
package useCases
import "RenewCMS/internal/domain/article"
type UpdateArticleUseCase struct {
articleRepository article.Repository
}
func NewUpdateArticleUseCase(articleRepository article.Repository) *UpdateArticleUseCase {
return &UpdateArticleUseCase{articleRepository}
}
func (g *UpdateArticleUseCase) UpdateBody(id uint32, body string) (article.Article, error) {
return g.articleRepository.UpdateBody(id, body)
}
func (g *UpdateArticleUseCase) AddImage(articleId uint32, imageId uint32) error {
return g.articleRepository.AddImage(articleId, imageId)
}
func (g *UpdateArticleUseCase) UpdateIsOnline(id uint32, isOnline bool) (article.Article, error) {
return g.articleRepository.UpdateIsOnline(id, isOnline)
}
@@ -0,0 +1,23 @@
package useCases
import "RenewCMS/internal/domain/user"
type UpdateUserUseCase struct {
userRepository user.Repository
}
func NewUpdateUserUseCase(userRepository user.Repository) *UpdateUserUseCase {
return &UpdateUserUseCase{userRepository}
}
func (g *UpdateUserUseCase) UpdateVerificationStatus(userId uint32, isVerified bool) (user.User, error) {
return g.userRepository.UpdateVerificationStatus(userId, isVerified)
}
func (g *UpdateUserUseCase) UpdatePasswordResetCode(userId uint32, code string) (user.User, error) {
return g.userRepository.UpdatePasswordResetCode(userId, code)
}
func (g *UpdateUserUseCase) UpdatePassword(userId uint32, password string) (user.User, error) {
return g.userRepository.UpdatePassword(userId, password)
}