mirror of
https://github.com/Floriansylvain/RenewCMS.git
synced 2026-08-19 11:43:22 +02:00
clean: refacto User and Article repos for clarity
Simplified the code for creating and returning user and article entities in userRepository.go and articleRepository.go. Direct function calls to domain.FromDb(...) were replaced with the more descriptive mapping functions mapUserToDomain(...) and mapArticleToDomain(...). This ensures better code readability and understanding and provides a single, consistent way to map database entities to domain entities.
This commit is contained in:
@@ -26,7 +26,7 @@ func (a *ArticleRepository) Get(id uint32) (domain.Article, error) {
|
||||
return domain.Article{}, err
|
||||
}
|
||||
|
||||
return domain.FromDb(article.ID, article.Title, article.Body, article.CreatedAt, article.UpdatedAt), nil
|
||||
return mapArticleToDomain(article), nil
|
||||
}
|
||||
|
||||
func (a *ArticleRepository) Create(article domain.Article) (domain.Article, error) {
|
||||
@@ -41,13 +41,7 @@ func (a *ArticleRepository) Create(article domain.Article) (domain.Article, erro
|
||||
var createdArticle entity.Article
|
||||
creationResult.Scan(&createdArticle)
|
||||
|
||||
return domain.FromDb(
|
||||
createdArticle.ID,
|
||||
createdArticle.Title,
|
||||
createdArticle.Body,
|
||||
createdArticle.CreatedAt,
|
||||
createdArticle.UpdatedAt),
|
||||
nil
|
||||
return mapArticleToDomain(createdArticle), nil
|
||||
}
|
||||
|
||||
func (a *ArticleRepository) GetAll() []domain.Article {
|
||||
|
||||
Reference in New Issue
Block a user