mirror of
https://github.com/Floriansylvain/RenewCMS.git
synced 2026-08-19 11:43:22 +02:00
feat: migrated prisma -> gorm
This commit is contained in:
@@ -3,6 +3,7 @@ package useCases
|
||||
import (
|
||||
. "GohCMS2/adapters/secondary/gateways"
|
||||
. "GohCMS2/domain/article"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type CreateArticleUseCase struct {
|
||||
@@ -14,12 +15,12 @@ type CreateArticleCommand struct {
|
||||
Body string
|
||||
}
|
||||
|
||||
func NewCreateArticleUseCase() *CreateArticleUseCase {
|
||||
func NewCreateArticleUseCase(db *gorm.DB) *CreateArticleUseCase {
|
||||
return &CreateArticleUseCase{
|
||||
articleRepository: *NewArticleRepository(),
|
||||
articleRepository: *NewArticleRepository(db),
|
||||
}
|
||||
}
|
||||
|
||||
func (g *CreateArticleUseCase) CreateAarticle(article CreateArticleCommand) Article {
|
||||
func (g *CreateArticleUseCase) CreateArticle(article CreateArticleCommand) (Article, error) {
|
||||
return g.articleRepository.Create(FromApi(article.Title, article.Body))
|
||||
}
|
||||
|
||||
@@ -3,18 +3,19 @@ package useCases
|
||||
import (
|
||||
. "GohCMS2/adapters/secondary/gateways"
|
||||
. "GohCMS2/domain/article"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type GetArticleUseCase struct {
|
||||
articleRepository ArticleRepository
|
||||
}
|
||||
|
||||
func NewGetArticleUseCase() *GetArticleUseCase {
|
||||
func NewGetArticleUseCase(db *gorm.DB) *GetArticleUseCase {
|
||||
return &GetArticleUseCase{
|
||||
articleRepository: *NewArticleRepository(),
|
||||
articleRepository: *NewArticleRepository(db),
|
||||
}
|
||||
}
|
||||
|
||||
func (g *GetArticleUseCase) GetArticle(id int) Article {
|
||||
func (g *GetArticleUseCase) GetArticle(id uint32) (Article, error) {
|
||||
return g.articleRepository.Get(id)
|
||||
}
|
||||
|
||||
@@ -3,15 +3,16 @@ package useCases
|
||||
import (
|
||||
. "GohCMS2/adapters/secondary/gateways"
|
||||
. "GohCMS2/domain/article"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type ListArticlesUseCase struct {
|
||||
articleRepository ArticleRepository
|
||||
}
|
||||
|
||||
func NewListArticlesUseCase() *ListArticlesUseCase {
|
||||
func NewListArticlesUseCase(db *gorm.DB) *ListArticlesUseCase {
|
||||
return &ListArticlesUseCase{
|
||||
articleRepository: *NewArticleRepository(),
|
||||
articleRepository: *NewArticleRepository(db),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user