mirror of
https://github.com/Floriansylvain/RenewCMS.git
synced 2026-08-19 11:43:22 +02:00
fix: all remaining "article" replaced by "post"
All instances of the term "article" were replaced with "post" in variable names, type names, function names, etc. This was primarily to ensure consistent naming and reduce confusion going forward. The term "post" was chosen as it's a more commonly used term for the involved operations in the context of content management and blogging platforms. All tests were also updated to reflect these changes.
This commit is contained in:
@@ -20,43 +20,43 @@ func mapPostToDomain(post entity.Post) domain.Post {
|
||||
}
|
||||
|
||||
func (a *PostRepository) Get(id uint32) (domain.Post, error) {
|
||||
var article entity.Post
|
||||
err := a.db.Model(&entity.Post{}).First(&article, id).Error
|
||||
var post entity.Post
|
||||
err := a.db.Model(&entity.Post{}).First(&post, id).Error
|
||||
if err != nil {
|
||||
return domain.Post{}, err
|
||||
}
|
||||
|
||||
return mapPostToDomain(article), nil
|
||||
return mapPostToDomain(post), nil
|
||||
}
|
||||
|
||||
func (a *PostRepository) Create(article domain.Post) (domain.Post, error) {
|
||||
func (a *PostRepository) Create(post domain.Post) (domain.Post, error) {
|
||||
creationResult := a.db.Create(&entity.Post{
|
||||
Title: article.Title,
|
||||
Body: article.Body,
|
||||
Title: post.Title,
|
||||
Body: post.Body,
|
||||
})
|
||||
if creationResult.Error != nil {
|
||||
return domain.Post{}, creationResult.Error
|
||||
}
|
||||
|
||||
var createdArticle entity.Post
|
||||
creationResult.Scan(&createdArticle)
|
||||
var createdPost entity.Post
|
||||
creationResult.Scan(&createdPost)
|
||||
|
||||
return mapPostToDomain(createdArticle), nil
|
||||
return mapPostToDomain(createdPost), nil
|
||||
}
|
||||
|
||||
func (a *PostRepository) GetAll() []domain.Post {
|
||||
var articles []entity.Post
|
||||
err := a.db.Model(&entity.Post{}).Find(&articles).Error
|
||||
var posts []entity.Post
|
||||
err := a.db.Model(&entity.Post{}).Find(&posts).Error
|
||||
if err != nil {
|
||||
return []domain.Post{}
|
||||
}
|
||||
|
||||
var domainArticles = make([]domain.Post, 0)
|
||||
for _, article := range articles {
|
||||
domainArticles = append(domainArticles, mapPostToDomain(article))
|
||||
var domainPosts = make([]domain.Post, 0)
|
||||
for _, post := range posts {
|
||||
domainPosts = append(domainPosts, mapPostToDomain(post))
|
||||
}
|
||||
|
||||
return domainArticles
|
||||
return domainPosts
|
||||
}
|
||||
|
||||
var _ gateways.IArticleRepository = &PostRepository{}
|
||||
var _ gateways.IPostRepository = &PostRepository{}
|
||||
|
||||
+11
-11
@@ -11,9 +11,9 @@ import (
|
||||
)
|
||||
|
||||
type LocalContainer struct {
|
||||
CreateArticleUseCase *useCases.CreatePostUseCase
|
||||
GetArticleUseCase *useCases.GetArticleUseCase
|
||||
ListArticlesUseCase *useCases.ListArticlesUseCase
|
||||
CreatePostUseCase *useCases.CreatePostUseCase
|
||||
GetPostUseCase *useCases.GetPostUseCase
|
||||
ListPostsUseCase *useCases.ListPostsUseCase
|
||||
GetUserUseCase *useCases.GetUserUseCase
|
||||
CreateUserUseCase *useCases.CreateUserUseCase
|
||||
ListUsersUseCase *useCases.ListUsersUseCase
|
||||
@@ -23,18 +23,18 @@ type LocalContainer struct {
|
||||
var Container *LocalContainer
|
||||
|
||||
func setContainer(
|
||||
createArticle *useCases.CreatePostUseCase,
|
||||
getArticle *useCases.GetArticleUseCase,
|
||||
listArticle *useCases.ListArticlesUseCase,
|
||||
createPost *useCases.CreatePostUseCase,
|
||||
getPost *useCases.GetPostUseCase,
|
||||
listPost *useCases.ListPostsUseCase,
|
||||
getUser *useCases.GetUserUseCase,
|
||||
createUser *useCases.CreateUserUseCase,
|
||||
listUsers *useCases.ListUsersUseCase,
|
||||
getPage *useCases.GetPageUseCase,
|
||||
) *LocalContainer {
|
||||
Container = &LocalContainer{
|
||||
CreateArticleUseCase: createArticle,
|
||||
GetArticleUseCase: getArticle,
|
||||
ListArticlesUseCase: listArticle,
|
||||
CreatePostUseCase: createPost,
|
||||
GetPostUseCase: getPost,
|
||||
ListPostsUseCase: listPost,
|
||||
GetUserUseCase: getUser,
|
||||
CreateUserUseCase: createUser,
|
||||
ListUsersUseCase: listUsers,
|
||||
@@ -65,8 +65,8 @@ func InitContainer() {
|
||||
_ = digContainer.Provide(func() *gorm.DB { return db })
|
||||
|
||||
_ = digContainer.Provide(func(db *gorm.DB) *useCases.CreatePostUseCase { return useCases.NewCreatePostUseCase(db) })
|
||||
_ = digContainer.Provide(func(db *gorm.DB) *useCases.GetArticleUseCase { return useCases.NewGetArticleUseCase(db) })
|
||||
_ = digContainer.Provide(func(db *gorm.DB) *useCases.ListArticlesUseCase { return useCases.NewListArticlesUseCase(db) })
|
||||
_ = digContainer.Provide(func(db *gorm.DB) *useCases.GetPostUseCase { return useCases.NewGetPostUseCase(db) })
|
||||
_ = digContainer.Provide(func(db *gorm.DB) *useCases.ListPostsUseCase { return useCases.NewListPostsUseCase(db) })
|
||||
_ = digContainer.Provide(func(db *gorm.DB) *useCases.GetUserUseCase { return useCases.NewGetUserUseCase(db) })
|
||||
_ = digContainer.Provide(func(db *gorm.DB) *useCases.CreateUserUseCase { return useCases.NewCreateUserUseCase(db) })
|
||||
_ = digContainer.Provide(func(db *gorm.DB) *useCases.ListUsersUseCase { return useCases.NewListUsersUseCase(db) })
|
||||
|
||||
+5
-5
@@ -20,7 +20,7 @@ func getPost(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
post, err := Container.GetArticleUseCase.GetArticle(uint32(id))
|
||||
post, err := Container.GetPostUseCase.GetPost(uint32(id))
|
||||
if err != nil {
|
||||
http.Error(w, "The requested resource, identified by its unique ID, could not be found on the server.", http.StatusNotFound)
|
||||
return
|
||||
@@ -44,7 +44,7 @@ func postPost(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
createdArticle, err := Container.CreateArticleUseCase.CreatePost(useCases.CreatePostCommand{
|
||||
createdPost, err := Container.CreatePostUseCase.CreatePost(useCases.CreatePostCommand{
|
||||
Title: post.Title,
|
||||
Body: post.Body,
|
||||
})
|
||||
@@ -52,19 +52,19 @@ func postPost(w http.ResponseWriter, r *http.Request) {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
postJson, _ := json.Marshal(createdArticle)
|
||||
postJson, _ := json.Marshal(createdPost)
|
||||
|
||||
_, _ = w.Write(postJson)
|
||||
}
|
||||
|
||||
func listPosts(w http.ResponseWriter, _ *http.Request) {
|
||||
posts := Container.ListArticlesUseCase.ListArticles()
|
||||
posts := Container.ListPostsUseCase.ListPosts()
|
||||
postsJson, _ := json.Marshal(posts)
|
||||
|
||||
_, _ = w.Write(postsJson)
|
||||
}
|
||||
|
||||
func NewArticleRouter() http.Handler {
|
||||
func NewPostRouter() http.Handler {
|
||||
r := chi.NewRouter()
|
||||
r.Get("/{id}", getPost)
|
||||
r.Post("/", postPost)
|
||||
|
||||
@@ -4,8 +4,8 @@ import (
|
||||
"GohCMS2/domain/post"
|
||||
)
|
||||
|
||||
type IArticleRepository interface {
|
||||
type IPostRepository interface {
|
||||
Get(id uint32) (post.Post, error)
|
||||
GetAll() []post.Post
|
||||
Create(article post.Post) (post.Post, error)
|
||||
Create(post post.Post) (post.Post, error)
|
||||
}
|
||||
|
||||
+1
-1
@@ -46,7 +46,7 @@ func InitBackendRoutes() *chi.Mux {
|
||||
r.Group(func(r chi.Router) {
|
||||
r.Use(jwtauth.Verifier(api.TokenAuth))
|
||||
r.Use(jwtauth.Authenticator)
|
||||
r.Mount("/post", api.NewArticleRouter())
|
||||
r.Mount("/post", api.NewPostRouter())
|
||||
})
|
||||
r.Mount("/auth", api.NewAuthRouter())
|
||||
|
||||
|
||||
+5
-5
@@ -67,12 +67,12 @@ var TestCreatePostTitleTooShort = func(t *testing.T) {
|
||||
|
||||
var TestGetPostSuccess = func(t *testing.T) {
|
||||
var createdPost post.Post
|
||||
var articleToCreate = post.Post{
|
||||
var postToCreate = post.Post{
|
||||
Title: "Test Title",
|
||||
Body: "Test Body",
|
||||
}
|
||||
db := GetDb()
|
||||
db.Create(&articleToCreate).Scan(&createdPost)
|
||||
db.Create(&postToCreate).Scan(&createdPost)
|
||||
|
||||
r, _ := ApiRequest("GET", "/post/"+strconv.Itoa(int(createdPost.ID)), nil)
|
||||
|
||||
@@ -95,12 +95,12 @@ var TestGetPostSuccess = func(t *testing.T) {
|
||||
|
||||
var TestGetAllPostsSuccess = func(t *testing.T) {
|
||||
var createdPost post.Post
|
||||
var articleToCreate = post.Post{
|
||||
var postToCreate = post.Post{
|
||||
Title: "Test Title",
|
||||
Body: "Test Body",
|
||||
}
|
||||
db := GetDb()
|
||||
db.Create(&articleToCreate).Scan(&createdPost)
|
||||
db.Create(&postToCreate).Scan(&createdPost)
|
||||
|
||||
r, _ := ApiRequest("GET", "/post", nil)
|
||||
|
||||
@@ -131,7 +131,7 @@ var TestPostGet = func(t *testing.T) {
|
||||
}
|
||||
|
||||
var TestPostGetAll = func(t *testing.T) {
|
||||
t.Run("Should return all articles", TestGetAllPostsSuccess)
|
||||
t.Run("Should return all posts", TestGetAllPostsSuccess)
|
||||
}
|
||||
|
||||
func TestPost(t *testing.T) {
|
||||
|
||||
@@ -6,16 +6,16 @@ import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type GetArticleUseCase struct {
|
||||
articleRepository gateways.PostRepository
|
||||
type GetPostUseCase struct {
|
||||
postRepository gateways.PostRepository
|
||||
}
|
||||
|
||||
func NewGetArticleUseCase(db *gorm.DB) *GetArticleUseCase {
|
||||
return &GetArticleUseCase{
|
||||
articleRepository: *gateways.NewPostRepository(db),
|
||||
func NewGetPostUseCase(db *gorm.DB) *GetPostUseCase {
|
||||
return &GetPostUseCase{
|
||||
postRepository: *gateways.NewPostRepository(db),
|
||||
}
|
||||
}
|
||||
|
||||
func (g *GetArticleUseCase) GetArticle(id uint32) (post.Post, error) {
|
||||
return g.articleRepository.Get(id)
|
||||
func (g *GetPostUseCase) GetPost(id uint32) (post.Post, error) {
|
||||
return g.postRepository.Get(id)
|
||||
}
|
||||
|
||||
@@ -6,16 +6,16 @@ import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type ListArticlesUseCase struct {
|
||||
articleRepository gateways.PostRepository
|
||||
type ListPostsUseCase struct {
|
||||
postRepository gateways.PostRepository
|
||||
}
|
||||
|
||||
func NewListArticlesUseCase(db *gorm.DB) *ListArticlesUseCase {
|
||||
return &ListArticlesUseCase{
|
||||
articleRepository: *gateways.NewPostRepository(db),
|
||||
func NewListPostsUseCase(db *gorm.DB) *ListPostsUseCase {
|
||||
return &ListPostsUseCase{
|
||||
postRepository: *gateways.NewPostRepository(db),
|
||||
}
|
||||
}
|
||||
|
||||
func (g *ListArticlesUseCase) ListArticles() []post.Post {
|
||||
return g.articleRepository.GetAll()
|
||||
func (g *ListPostsUseCase) ListPosts() []post.Post {
|
||||
return g.postRepository.GetAll()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user