Skip to content

Commit

Permalink
Merge pull request #113 from bmf-san/fix/rename-public-to-publish
Browse files Browse the repository at this point in the history
Rename publish to public
  • Loading branch information
bmf-san authored Apr 17, 2024
2 parents e0d3c71 + 3151108 commit 725965c
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 82 deletions.
72 changes: 36 additions & 36 deletions app/interfaces/repository/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ type Post struct {
ConnMySQL *sql.DB
}

// CountAllPublish count all publish entities.
func (pr *Post) CountAllPublish() (int, error) {
// CountAllPublic count all public entities.
func (pr *Post) CountAllPublic() (int, error) {
row := pr.ConnMySQL.QueryRow(`
SELECT
count(*)
FROM
view_posts
WHERE
status = "publish"
status = "public"
`)
var count int
if err := row.Scan(&count); err != nil {
Expand All @@ -49,8 +49,8 @@ func (pr *Post) CountAll() (int, error) {
return count, nil
}

// CountAllPublishByKeyword count all publish entities by keyword.
func (pr *Post) CountAllPublishByKeyword(keyword string) (int, error) {
// CountAllPublicByKeyword count all public entities by keyword.
func (pr *Post) CountAllPublicByKeyword(keyword string) (int, error) {
row := pr.ConnMySQL.QueryRow(`
SELECT
count(*)
Expand All @@ -59,7 +59,7 @@ func (pr *Post) CountAllPublishByKeyword(keyword string) (int, error) {
WHERE MATCH (title, md_body)
AGAINST (? IN BOOLEAN MODE)
AND
status = "publish"
status = "public"
`, keyword)
var count int
if err := row.Scan(&count); err != nil {
Expand All @@ -68,8 +68,8 @@ func (pr *Post) CountAllPublishByKeyword(keyword string) (int, error) {
return count, nil
}

// CountAllPublishByCategory count all publish entities by category.
func (pr *Post) CountAllPublishByCategory(name string) (int, error) {
// CountAllPublicByCategory count all public entities by category.
func (pr *Post) CountAllPublicByCategory(name string) (int, error) {
row := pr.ConnMySQL.QueryRow(`
SELECT
count(*)
Expand All @@ -78,7 +78,7 @@ func (pr *Post) CountAllPublishByCategory(name string) (int, error) {
WHERE
category_name = ?
AND
status = "publish"
status = "public"
`, name)
var count int
if err := row.Scan(&count); err != nil {
Expand All @@ -88,8 +88,8 @@ func (pr *Post) CountAllPublishByCategory(name string) (int, error) {
return count, nil
}

// CountAllPublishByTag count all publish entities by Tag.
func (pr *Post) CountAllPublishByTag(name string) (int, error) {
// CountAllPublicByTag count all public entities by Tag.
func (pr *Post) CountAllPublicByTag(name string) (int, error) {
row := pr.ConnMySQL.QueryRow(`
SELECT
count(*)
Expand All @@ -110,7 +110,7 @@ func (pr *Post) CountAllPublishByTag(name string) (int, error) {
tags.name = ?
)
AND
status = "publish"
status = "public"
`, name)
var count int
if err := row.Scan(&count); err != nil {
Expand All @@ -120,16 +120,16 @@ func (pr *Post) CountAllPublishByTag(name string) (int, error) {
return count, nil
}

// FindAllPublish returns all entities.
func (pr *Post) FindAllPublish(page int, limit int) (domain.Posts, error) {
// FindAllPublic returns all entities.
func (pr *Post) FindAllPublic(page int, limit int) (domain.Posts, error) {
var posts domain.Posts
rows, err := pr.ConnMySQL.Query(`
SELECT
*
FROM
view_posts
WHERE
status = "publish"
status = "public"
ORDER BY id
DESC
LIMIT ?, ?
Expand Down Expand Up @@ -302,8 +302,8 @@ func (pr *Post) FindAllPublish(page int, limit int) (domain.Posts, error) {
posts
ON posts.id = comments.post_id
WHERE
posts.status = "publish"
AND comments.status = "publish"
posts.status = "public"
AND comments.status = "public"
ORDER BY
posts.id
DESC
Expand Down Expand Up @@ -355,8 +355,8 @@ func (pr *Post) FindAllPublish(page int, limit int) (domain.Posts, error) {
return posts, nil
}

// FindAllPublishByKeyword returns all entities by keyword.
func (pr *Post) FindAllPublishByKeyword(page int, limit int, keyword string) (domain.Posts, error) {
// FindAllPublicByKeyword returns all entities by keyword.
func (pr *Post) FindAllPublicByKeyword(page int, limit int, keyword string) (domain.Posts, error) {
var posts domain.Posts
rows, err := pr.ConnMySQL.Query(`
SELECT
Expand All @@ -366,7 +366,7 @@ func (pr *Post) FindAllPublishByKeyword(page int, limit int, keyword string) (do
WHERE MATCH (title, md_body)
AGAINST (? IN BOOLEAN MODE)
AND
status = "publish"
status = "public"
ORDER BY id
DESC
LIMIT ?, ?
Expand Down Expand Up @@ -539,8 +539,8 @@ func (pr *Post) FindAllPublishByKeyword(page int, limit int, keyword string) (do
posts
ON posts.id = comments.post_id
WHERE
posts.status = "publish"
AND comments.status = "publish"
posts.status = "public"
AND comments.status = "public"
ORDER BY
posts.id
DESC
Expand Down Expand Up @@ -592,16 +592,16 @@ func (pr *Post) FindAllPublishByKeyword(page int, limit int, keyword string) (do
return posts, nil
}

// FindAllPublishByCategory returns all entities by category.
func (pr *Post) FindAllPublishByCategory(page int, limit int, name string) (domain.Posts, error) {
// FindAllPublicByCategory returns all entities by category.
func (pr *Post) FindAllPublicByCategory(page int, limit int, name string) (domain.Posts, error) {
var posts domain.Posts
rows, err := pr.ConnMySQL.Query(`
SELECT
*
FROM
view_posts
WHERE
status = "publish"
status = "public"
AND category_name = ?
ORDER BY id
DESC
Expand Down Expand Up @@ -775,8 +775,8 @@ func (pr *Post) FindAllPublishByCategory(page int, limit int, name string) (doma
view_posts
ON view_posts.id = comments.post_id
WHERE
view_posts.status = "publish"
AND comments.status = "publish"
view_posts.status = "public"
AND comments.status = "public"
AND view_posts.category_name = ?
ORDER BY
view_posts.id
Expand Down Expand Up @@ -828,8 +828,8 @@ func (pr *Post) FindAllPublishByCategory(page int, limit int, name string) (doma
return posts, nil
}

// FindAllPublishByTag returns all entities by tag.
func (pr *Post) FindAllPublishByTag(page int, limit int, name string) (domain.Posts, error) {
// FindAllPublicByTag returns all entities by tag.
func (pr *Post) FindAllPublicByTag(page int, limit int, name string) (domain.Posts, error) {
var posts domain.Posts
rows, err := pr.ConnMySQL.Query(`
SELECT
Expand Down Expand Up @@ -1032,8 +1032,8 @@ func (pr *Post) FindAllPublishByTag(page int, limit int, name string) (domain.Po
WHERE
tags.name = ?
)
AND posts.status = "publish"
AND comments.status = "publish"
AND posts.status = "public"
AND comments.status = "public"
ORDER BY
posts.id
LIMIT ?, ?
Expand Down Expand Up @@ -1314,8 +1314,8 @@ func (pr *Post) FindAll(page int, limit int) (domain.Posts, error) {
return posts, nil
}

// FindPublishByTitle returns the entity identified by the given title.
func (pr *Post) FindPublishByTitle(title string) (domain.Post, error) {
// FindPublicByTitle returns the entity identified by the given title.
func (pr *Post) FindPublicByTitle(title string) (domain.Post, error) {
var post domain.Post
row, err := pr.ConnMySQL.Query(`
SELECT
Expand All @@ -1325,7 +1325,7 @@ func (pr *Post) FindPublishByTitle(title string) (domain.Post, error) {
WHERE
title = ?
AND
status = "publish"
status = "public"
`, title)

defer func() {
Expand Down Expand Up @@ -1462,7 +1462,7 @@ func (pr *Post) FindPublishByTitle(title string) (domain.Post, error) {
FROM
comments
WHERE
status = "publish"
status = "public"
AND
post_id = ?
`, p.ID)
Expand Down Expand Up @@ -1655,7 +1655,7 @@ func (pr *Post) FindByID(id int) (domain.Post, error) {
FROM
comments
WHERE
status = "publish"
status = "public"
AND
post_id = ?
`, p.ID)
Expand Down
18 changes: 9 additions & 9 deletions app/usecase/interactor/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ type PostInteractor struct {
func (pi *PostInteractor) Index(req request.IndexPost) (domain.Posts, Pagination, *HTTPError) {
var ps domain.Posts
var pn Pagination
count, err := pi.Post.CountAllPublish()
count, err := pi.Post.CountAllPublic()
if err != nil {
return ps, pn, NewHTTPError(http.StatusInternalServerError, err.Error())
}
posts, err := pi.Post.FindAllPublish(req.Page, req.Limit)
posts, err := pi.Post.FindAllPublic(req.Page, req.Limit)
if err != nil {
return ps, pn, NewHTTPError(http.StatusInternalServerError, err.Error())
}
Expand All @@ -35,11 +35,11 @@ func (pi *PostInteractor) Index(req request.IndexPost) (domain.Posts, Pagination
func (pi *PostInteractor) IndexByKeyword(req request.IndexPostByKeyword) (domain.Posts, Pagination, *HTTPError) {
var ps domain.Posts
var pn Pagination
count, err := pi.Post.CountAllPublishByKeyword(req.Keyword)
count, err := pi.Post.CountAllPublicByKeyword(req.Keyword)
if err != nil {
return ps, pn, NewHTTPError(http.StatusInternalServerError, err.Error())
}
posts, err := pi.Post.FindAllPublishByKeyword(req.Page, req.Limit, req.Keyword)
posts, err := pi.Post.FindAllPublicByKeyword(req.Page, req.Limit, req.Keyword)
if err != nil {
return ps, pn, NewHTTPError(http.StatusInternalServerError, err.Error())
}
Expand All @@ -51,11 +51,11 @@ func (pi *PostInteractor) IndexByKeyword(req request.IndexPostByKeyword) (domain
func (pi *PostInteractor) IndexByCategory(req request.IndexPostByName) (domain.Posts, Pagination, *HTTPError) {
var ps domain.Posts
var pn Pagination
count, err := pi.Post.CountAllPublishByCategory(req.Name)
count, err := pi.Post.CountAllPublicByCategory(req.Name)
if err != nil {
return ps, pn, NewHTTPError(http.StatusInternalServerError, err.Error())
}
posts, err := pi.Post.FindAllPublishByCategory(req.Page, req.Limit, req.Name)
posts, err := pi.Post.FindAllPublicByCategory(req.Page, req.Limit, req.Name)
if err != nil {
return ps, pn, NewHTTPError(http.StatusInternalServerError, err.Error())
}
Expand All @@ -67,11 +67,11 @@ func (pi *PostInteractor) IndexByCategory(req request.IndexPostByName) (domain.P
func (pi *PostInteractor) IndexByTag(req request.IndexPostByName) (domain.Posts, Pagination, *HTTPError) {
var ps domain.Posts
var pn Pagination
count, err := pi.Post.CountAllPublishByTag(req.Name)
count, err := pi.Post.CountAllPublicByTag(req.Name)
if err != nil {
return ps, pn, NewHTTPError(http.StatusInternalServerError, err.Error())
}
posts, err := pi.Post.FindAllPublishByTag(req.Page, req.Limit, req.Name)
posts, err := pi.Post.FindAllPublicByTag(req.Page, req.Limit, req.Name)
if err != nil {
return ps, pn, NewHTTPError(http.StatusInternalServerError, err.Error())
}
Expand All @@ -98,7 +98,7 @@ func (pi *PostInteractor) IndexPrivate(req request.IndexPost) (domain.Posts, Pag
// Show display the specified resource.
func (pi *PostInteractor) Show(req request.ShowPostByTitle) (domain.Post, *HTTPError) {
var p domain.Post
post, err := pi.Post.FindPublishByTitle(req.Title)
post, err := pi.Post.FindPublicByTitle(req.Title)
if err != nil {
return p, NewHTTPError(http.StatusInternalServerError, err.Error())
}
Expand Down
18 changes: 9 additions & 9 deletions app/usecase/repository/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ import (

// A Post is a repository interface for a post.
type Post interface {
CountAllPublish() (int, error)
CountAllPublic() (int, error)
CountAll() (int, error)
CountAllPublishByKeyword(keyword string) (int, error)
CountAllPublishByCategory(name string) (int, error)
CountAllPublishByTag(name string) (int, error)
FindAllPublish(page int, limit int) (domain.Posts, error)
FindAllPublishByKeyword(page int, limit int, keyword string) (domain.Posts, error)
FindAllPublishByCategory(page int, limit int, name string) (domain.Posts, error)
FindAllPublishByTag(page int, limit int, name string) (domain.Posts, error)
CountAllPublicByKeyword(keyword string) (int, error)
CountAllPublicByCategory(name string) (int, error)
CountAllPublicByTag(name string) (int, error)
FindAllPublic(page int, limit int) (domain.Posts, error)
FindAllPublicByKeyword(page int, limit int, keyword string) (domain.Posts, error)
FindAllPublicByCategory(page int, limit int, name string) (domain.Posts, error)
FindAllPublicByTag(page int, limit int, name string) (domain.Posts, error)
FindAll(page int, limit int) (domain.Posts, error)
FindPublishByTitle(title string) (domain.Post, error)
FindPublicByTitle(title string) (domain.Post, error)
FindByID(id int) (domain.Post, error)
Save(req request.StorePost) (int, error)
SaveByID(req request.UpdatePost) error
Expand Down
Loading

0 comments on commit 725965c

Please sign in to comment.