mirror of
https://github.com/Floriansylvain/RenewCMS.git
synced 2026-08-19 11:43:22 +02:00
refac: mappers, file names
This commit is contained in:
@@ -6,8 +6,8 @@ import (
|
|||||||
domainMail "RenewCMS/internal/domain/mail"
|
domainMail "RenewCMS/internal/domain/mail"
|
||||||
domainUser "RenewCMS/internal/domain/user"
|
domainUser "RenewCMS/internal/domain/user"
|
||||||
"RenewCMS/internal/infrastructure/mailer"
|
"RenewCMS/internal/infrastructure/mailer"
|
||||||
"RenewCMS/internal/infrastructure/persistence"
|
|
||||||
"RenewCMS/internal/infrastructure/persistence/models"
|
"RenewCMS/internal/infrastructure/persistence/models"
|
||||||
|
persistence "RenewCMS/internal/infrastructure/persistence/repositories"
|
||||||
"RenewCMS/internal/infrastructure/useCases"
|
"RenewCMS/internal/infrastructure/useCases"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|||||||
@@ -1,46 +0,0 @@
|
|||||||
package article
|
|
||||||
|
|
||||||
import (
|
|
||||||
domain "RenewCMS/internal/domain/image"
|
|
||||||
"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 []*domain.Image,
|
|
||||||
isOnline bool,
|
|
||||||
createdAt time.Time,
|
|
||||||
updatedAt time.Time,
|
|
||||||
) Article {
|
|
||||||
return Article{
|
|
||||||
ID: id,
|
|
||||||
Title: title,
|
|
||||||
Body: body,
|
|
||||||
Images: images,
|
|
||||||
IsOnline: isOnline,
|
|
||||||
CreatedAt: createdAt,
|
|
||||||
UpdatedAt: updatedAt,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package article
|
||||||
|
|
||||||
|
import (
|
||||||
|
domain "RenewCMS/internal/domain/image"
|
||||||
|
"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"`
|
||||||
|
}
|
||||||
@@ -11,13 +11,3 @@ type Image struct {
|
|||||||
CreatedAt time.Time `json:"created_at"`
|
CreatedAt time.Time `json:"created_at"`
|
||||||
UpdatedAt time.Time `json:"updated_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,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,63 +0,0 @@
|
|||||||
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,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
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"`
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package mappers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"RenewCMS/internal/domain/article"
|
||||||
|
"RenewCMS/internal/domain/image"
|
||||||
|
"RenewCMS/internal/infrastructure/persistence/models"
|
||||||
|
)
|
||||||
|
|
||||||
|
func ArticleToDomain(m models.Article) article.Article {
|
||||||
|
domainImages := make([]*image.Image, len(m.Images))
|
||||||
|
for i, img := range m.Images {
|
||||||
|
domainImg := ImageToDomain(*img)
|
||||||
|
domainImages[i] = &domainImg
|
||||||
|
}
|
||||||
|
|
||||||
|
return article.Article{
|
||||||
|
ID: m.ID,
|
||||||
|
Title: m.Title,
|
||||||
|
Body: m.Body,
|
||||||
|
Images: domainImages,
|
||||||
|
IsOnline: m.IsOnline,
|
||||||
|
CreatedAt: m.CreatedAt,
|
||||||
|
UpdatedAt: m.UpdatedAt,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func ArticleToModel(a article.Article) models.Article {
|
||||||
|
modelImages := make([]*models.Image, len(a.Images))
|
||||||
|
for i, img := range a.Images {
|
||||||
|
modelImage := ImageToModel(*img)
|
||||||
|
modelImages[i] = &modelImage
|
||||||
|
}
|
||||||
|
|
||||||
|
return models.Article{
|
||||||
|
Title: a.Title,
|
||||||
|
Body: a.Body,
|
||||||
|
Images: modelImages,
|
||||||
|
IsOnline: a.IsOnline,
|
||||||
|
CreatedAt: a.CreatedAt,
|
||||||
|
UpdatedAt: a.UpdatedAt,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package mappers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"RenewCMS/internal/domain/image"
|
||||||
|
"RenewCMS/internal/infrastructure/persistence/models"
|
||||||
|
)
|
||||||
|
|
||||||
|
func ImageToDomain(imageModel models.Image) image.Image {
|
||||||
|
return image.Image{
|
||||||
|
ID: imageModel.ID,
|
||||||
|
Path: imageModel.Path,
|
||||||
|
ArticleID: imageModel.ArticleID,
|
||||||
|
CreatedAt: imageModel.CreatedAt,
|
||||||
|
UpdatedAt: imageModel.UpdatedAt,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func ImageToModel(imageDomain image.Image) models.Image {
|
||||||
|
return models.Image{
|
||||||
|
Path: imageDomain.Path,
|
||||||
|
ArticleID: imageDomain.ArticleID,
|
||||||
|
CreatedAt: imageDomain.CreatedAt,
|
||||||
|
UpdatedAt: imageDomain.UpdatedAt,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package mappers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"RenewCMS/internal/domain/user"
|
||||||
|
"RenewCMS/internal/infrastructure/persistence/models"
|
||||||
|
)
|
||||||
|
|
||||||
|
func UserToDomain(m models.User) user.User {
|
||||||
|
return user.User{
|
||||||
|
ID: m.ID,
|
||||||
|
Username: m.Username,
|
||||||
|
Password: m.Password,
|
||||||
|
PasswordResetCode: m.PasswordResetCode,
|
||||||
|
Email: m.Email,
|
||||||
|
IsVerified: m.IsVerified,
|
||||||
|
VerificationCode: m.VerificationCode,
|
||||||
|
VerificationExpiration: m.VerificationExpiration,
|
||||||
|
CreatedAt: m.CreatedAt,
|
||||||
|
UpdatedAt: m.UpdatedAt,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func UserToModel(a user.User) models.User {
|
||||||
|
return models.User{
|
||||||
|
Username: a.Username,
|
||||||
|
Password: a.Password,
|
||||||
|
PasswordResetCode: a.PasswordResetCode,
|
||||||
|
Email: a.Email,
|
||||||
|
IsVerified: a.IsVerified,
|
||||||
|
VerificationCode: a.VerificationCode,
|
||||||
|
VerificationExpiration: a.VerificationExpiration,
|
||||||
|
CreatedAt: a.CreatedAt,
|
||||||
|
UpdatedAt: a.UpdatedAt,
|
||||||
|
}
|
||||||
|
}
|
||||||
+2
-1
@@ -1,8 +1,9 @@
|
|||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"gorm.io/gorm"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
+7
-25
@@ -2,7 +2,7 @@ package persistence
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
domainArticle "RenewCMS/internal/domain/article"
|
domainArticle "RenewCMS/internal/domain/article"
|
||||||
domainImage "RenewCMS/internal/domain/image"
|
"RenewCMS/internal/infrastructure/persistence/mappers"
|
||||||
entity "RenewCMS/internal/infrastructure/persistence/models"
|
entity "RenewCMS/internal/infrastructure/persistence/models"
|
||||||
|
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
@@ -16,24 +16,6 @@ func NewArticleRepository(db *gorm.DB) *ArticleRepository {
|
|||||||
return &ArticleRepository{db}
|
return &ArticleRepository{db}
|
||||||
}
|
}
|
||||||
|
|
||||||
func mapArticleToDomain(article entity.Article) domainArticle.Article {
|
|
||||||
domainImages := make([]*domainImage.Image, len(article.Images))
|
|
||||||
for i, img := range article.Images {
|
|
||||||
dImg := domainImage.FromDB(img.ID, img.Path, img.ArticleID, img.CreatedAt, img.UpdatedAt)
|
|
||||||
domainImages[i] = &dImg
|
|
||||||
}
|
|
||||||
|
|
||||||
return domainArticle.FromDb(
|
|
||||||
article.ID,
|
|
||||||
article.Title,
|
|
||||||
article.Body,
|
|
||||||
domainImages,
|
|
||||||
article.IsOnline,
|
|
||||||
article.CreatedAt,
|
|
||||||
article.UpdatedAt,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *ArticleRepository) Get(id uint32) (domainArticle.Article, error) {
|
func (a *ArticleRepository) Get(id uint32) (domainArticle.Article, error) {
|
||||||
var article entity.Article
|
var article entity.Article
|
||||||
err := a.db.Model(&entity.Article{}).Preload("Images").First(&article, id).Error
|
err := a.db.Model(&entity.Article{}).Preload("Images").First(&article, id).Error
|
||||||
@@ -41,7 +23,7 @@ func (a *ArticleRepository) Get(id uint32) (domainArticle.Article, error) {
|
|||||||
return domainArticle.Article{}, err
|
return domainArticle.Article{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return mapArticleToDomain(article), nil
|
return mappers.ArticleToDomain(article), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *ArticleRepository) GetByName(name string) (domainArticle.Article, error) {
|
func (a *ArticleRepository) GetByName(name string) (domainArticle.Article, error) {
|
||||||
@@ -51,7 +33,7 @@ func (a *ArticleRepository) GetByName(name string) (domainArticle.Article, error
|
|||||||
return domainArticle.Article{}, err
|
return domainArticle.Article{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return mapArticleToDomain(article), nil
|
return mappers.ArticleToDomain(article), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *ArticleRepository) Create(article domainArticle.Article) (domainArticle.Article, error) {
|
func (a *ArticleRepository) Create(article domainArticle.Article) (domainArticle.Article, error) {
|
||||||
@@ -66,7 +48,7 @@ func (a *ArticleRepository) Create(article domainArticle.Article) (domainArticle
|
|||||||
var createdArticle entity.Article
|
var createdArticle entity.Article
|
||||||
creationResult.Scan(&createdArticle)
|
creationResult.Scan(&createdArticle)
|
||||||
|
|
||||||
return mapArticleToDomain(createdArticle), nil
|
return mappers.ArticleToDomain(createdArticle), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *ArticleRepository) GetAll() []domainArticle.Article {
|
func (a *ArticleRepository) GetAll() []domainArticle.Article {
|
||||||
@@ -78,7 +60,7 @@ func (a *ArticleRepository) GetAll() []domainArticle.Article {
|
|||||||
|
|
||||||
var domainArticles = make([]domainArticle.Article, 0)
|
var domainArticles = make([]domainArticle.Article, 0)
|
||||||
for _, article := range articles {
|
for _, article := range articles {
|
||||||
domainArticles = append(domainArticles, mapArticleToDomain(article))
|
domainArticles = append(domainArticles, mappers.ArticleToDomain(article))
|
||||||
}
|
}
|
||||||
|
|
||||||
return domainArticles
|
return domainArticles
|
||||||
@@ -97,7 +79,7 @@ func (a *ArticleRepository) UpdateBody(id uint32, body string) (domainArticle.Ar
|
|||||||
return domainArticle.Article{}, err
|
return domainArticle.Article{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
newArticle := mapArticleToDomain(localArticle)
|
newArticle := mappers.ArticleToDomain(localArticle)
|
||||||
|
|
||||||
return newArticle, nil
|
return newArticle, nil
|
||||||
}
|
}
|
||||||
@@ -115,7 +97,7 @@ func (a *ArticleRepository) UpdateIsOnline(id uint32, isOnline bool) (domainArti
|
|||||||
return domainArticle.Article{}, err
|
return domainArticle.Article{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return mapArticleToDomain(localArticle), nil
|
return mappers.ArticleToDomain(localArticle), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *ArticleRepository) Delete(id uint32) error {
|
func (a *ArticleRepository) Delete(id uint32) error {
|
||||||
+2
-11
@@ -2,6 +2,7 @@ package persistence
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
domain "RenewCMS/internal/domain/image"
|
domain "RenewCMS/internal/domain/image"
|
||||||
|
"RenewCMS/internal/infrastructure/persistence/mappers"
|
||||||
entity "RenewCMS/internal/infrastructure/persistence/models"
|
entity "RenewCMS/internal/infrastructure/persistence/models"
|
||||||
"errors"
|
"errors"
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
@@ -27,16 +28,6 @@ var contentTypeExtensions = map[string]string{
|
|||||||
"image/svg+xml": ".svg",
|
"image/svg+xml": ".svg",
|
||||||
}
|
}
|
||||||
|
|
||||||
func mapImageToDomain(image entity.Image) domain.Image {
|
|
||||||
return domain.FromDB(
|
|
||||||
image.ID,
|
|
||||||
image.Path,
|
|
||||||
image.ArticleID,
|
|
||||||
image.CreatedAt,
|
|
||||||
image.UpdatedAt,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (i ImageRepository) Create(file multipart.File, fileHeader multipart.FileHeader) (domain.Image, error) {
|
func (i ImageRepository) Create(file multipart.File, fileHeader multipart.FileHeader) (domain.Image, error) {
|
||||||
uploadDir := os.Getenv("UPLOAD_DIR")
|
uploadDir := os.Getenv("UPLOAD_DIR")
|
||||||
|
|
||||||
@@ -68,7 +59,7 @@ func (i ImageRepository) Create(file multipart.File, fileHeader multipart.FileHe
|
|||||||
var createdImage entity.Image
|
var createdImage entity.Image
|
||||||
newImage.Scan(&createdImage)
|
newImage.Scan(&createdImage)
|
||||||
|
|
||||||
return mapImageToDomain(createdImage), nil
|
return mappers.ImageToDomain(createdImage), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i ImageRepository) Delete(id uint32) error {
|
func (i ImageRepository) Delete(id uint32) error {
|
||||||
+9
-22
@@ -2,6 +2,7 @@ package persistence
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
domainUser "RenewCMS/internal/domain/user"
|
domainUser "RenewCMS/internal/domain/user"
|
||||||
|
"RenewCMS/internal/infrastructure/persistence/mappers"
|
||||||
entity "RenewCMS/internal/infrastructure/persistence/models"
|
entity "RenewCMS/internal/infrastructure/persistence/models"
|
||||||
|
|
||||||
"golang.org/x/crypto/bcrypt"
|
"golang.org/x/crypto/bcrypt"
|
||||||
@@ -16,20 +17,6 @@ func NewUserRepository(db *gorm.DB) *UserRepository {
|
|||||||
return &UserRepository{db}
|
return &UserRepository{db}
|
||||||
}
|
}
|
||||||
|
|
||||||
func mapUserToDomain(user entity.User) domainUser.User {
|
|
||||||
return domainUser.FromDb(
|
|
||||||
user.ID,
|
|
||||||
user.Username,
|
|
||||||
user.Password,
|
|
||||||
user.PasswordResetCode,
|
|
||||||
user.Email,
|
|
||||||
user.IsVerified,
|
|
||||||
user.VerificationCode,
|
|
||||||
user.VerificationExpiration,
|
|
||||||
user.CreatedAt, user.UpdatedAt,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (u *UserRepository) Get(id uint32) (domainUser.User, error) {
|
func (u *UserRepository) Get(id uint32) (domainUser.User, error) {
|
||||||
var localUser entity.User
|
var localUser entity.User
|
||||||
err := u.db.Model(&entity.User{}).First(&localUser, id).Error
|
err := u.db.Model(&entity.User{}).First(&localUser, id).Error
|
||||||
@@ -37,7 +24,7 @@ func (u *UserRepository) Get(id uint32) (domainUser.User, error) {
|
|||||||
return domainUser.User{}, err
|
return domainUser.User{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return mapUserToDomain(localUser), nil
|
return mappers.UserToDomain(localUser), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *UserRepository) Create(user domainUser.User) (domainUser.User, error) {
|
func (u *UserRepository) Create(user domainUser.User) (domainUser.User, error) {
|
||||||
@@ -58,7 +45,7 @@ func (u *UserRepository) Create(user domainUser.User) (domainUser.User, error) {
|
|||||||
var createdUser entity.User
|
var createdUser entity.User
|
||||||
creationResult.Scan(&createdUser)
|
creationResult.Scan(&createdUser)
|
||||||
|
|
||||||
return mapUserToDomain(createdUser),
|
return mappers.UserToDomain(createdUser),
|
||||||
nil
|
nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,7 +59,7 @@ func (u *UserRepository) GetAll() []domainUser.User {
|
|||||||
|
|
||||||
var domainUsers []domainUser.User
|
var domainUsers []domainUser.User
|
||||||
for _, localUser := range users {
|
for _, localUser := range users {
|
||||||
domainUsers = append(domainUsers, mapUserToDomain(localUser))
|
domainUsers = append(domainUsers, mappers.UserToDomain(localUser))
|
||||||
}
|
}
|
||||||
|
|
||||||
return domainUsers
|
return domainUsers
|
||||||
@@ -85,7 +72,7 @@ func (u *UserRepository) GetByUsername(username string) (domainUser.User, error)
|
|||||||
return domainUser.User{}, err
|
return domainUser.User{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return mapUserToDomain(localUser), nil
|
return mappers.UserToDomain(localUser), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *UserRepository) GetByEmail(email string) (domainUser.User, error) {
|
func (u *UserRepository) GetByEmail(email string) (domainUser.User, error) {
|
||||||
@@ -95,7 +82,7 @@ func (u *UserRepository) GetByEmail(email string) (domainUser.User, error) {
|
|||||||
return domainUser.User{}, err
|
return domainUser.User{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return mapUserToDomain(localUser), nil
|
return mappers.UserToDomain(localUser), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *UserRepository) UpdateVerificationStatus(userId uint32, isVerified bool) (domainUser.User, error) {
|
func (u *UserRepository) UpdateVerificationStatus(userId uint32, isVerified bool) (domainUser.User, error) {
|
||||||
@@ -111,7 +98,7 @@ func (u *UserRepository) UpdateVerificationStatus(userId uint32, isVerified bool
|
|||||||
return domainUser.User{}, err
|
return domainUser.User{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return mapUserToDomain(localUser), nil
|
return mappers.UserToDomain(localUser), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *UserRepository) UpdatePassword(userId uint32, password string) (domainUser.User, error) {
|
func (u *UserRepository) UpdatePassword(userId uint32, password string) (domainUser.User, error) {
|
||||||
@@ -128,7 +115,7 @@ func (u *UserRepository) UpdatePassword(userId uint32, password string) (domainU
|
|||||||
return domainUser.User{}, err
|
return domainUser.User{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return mapUserToDomain(localUser), nil
|
return mappers.UserToDomain(localUser), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *UserRepository) UpdatePasswordResetCode(userId uint32, code string) (domainUser.User, error) {
|
func (u *UserRepository) UpdatePasswordResetCode(userId uint32, code string) (domainUser.User, error) {
|
||||||
@@ -145,7 +132,7 @@ func (u *UserRepository) UpdatePasswordResetCode(userId uint32, code string) (do
|
|||||||
return domainUser.User{}, err
|
return domainUser.User{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return mapUserToDomain(localUser), nil
|
return mappers.UserToDomain(localUser), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ domainUser.Repository = &UserRepository{}
|
var _ domainUser.Repository = &UserRepository{}
|
||||||
@@ -18,8 +18,8 @@ func NewCreateArticleUseCase(articleRepository article.Repository) *CreateArticl
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (g *CreateArticleUseCase) CreateArticle(createArticle CreateArticleCommand) (article.Article, error) {
|
func (g *CreateArticleUseCase) CreateArticle(createArticle CreateArticleCommand) (article.Article, error) {
|
||||||
return g.articleRepository.Create(article.FromApi(
|
return g.articleRepository.Create(article.Article{
|
||||||
createArticle.Title,
|
Title: createArticle.Title,
|
||||||
createArticle.Body,
|
Body: createArticle.Body,
|
||||||
))
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package useCases
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"RenewCMS/internal/domain/user"
|
"RenewCMS/internal/domain/user"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
)
|
)
|
||||||
@@ -23,13 +24,15 @@ func NewCreateUserUseCase(userRepository user.Repository) *CreateUserUseCase {
|
|||||||
func (g *CreateUserUseCase) CreateUser(createUser CreateUserCommand) (user.User, error) {
|
func (g *CreateUserUseCase) CreateUser(createUser CreateUserCommand) (user.User, error) {
|
||||||
rawUuid := uuid.NewString()
|
rawUuid := uuid.NewString()
|
||||||
|
|
||||||
createdUser, err := g.userRepository.Create(user.FromApi(
|
createdUser, err := g.userRepository.Create(user.User{
|
||||||
createUser.Username,
|
Username: createUser.Username,
|
||||||
createUser.Password,
|
Password: createUser.Password,
|
||||||
"",
|
PasswordResetCode: "",
|
||||||
createUser.Email,
|
Email: createUser.Email,
|
||||||
rawUuid,
|
IsVerified: false,
|
||||||
))
|
VerificationCode: rawUuid,
|
||||||
|
VerificationExpiration: time.Now().Add(2 * time.Hour),
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return user.User{}, err
|
return user.User{}, err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user