From 315110893d8b0cc0eeb4179e85dcb7c71f7a81d1 Mon Sep 17 00:00:00 2001 From: bmf-san Date: Wed, 17 Apr 2024 10:02:48 +0900 Subject: [PATCH] [update] renamed publish to public --- app/interfaces/repository/post.go | 72 +++++++++++++++---------------- app/usecase/interactor/post.go | 18 ++++---- app/usecase/repository/post.go | 18 ++++---- doc/API.md | 54 +++++++++++------------ doc/Specification.md | 2 +- 5 files changed, 82 insertions(+), 82 deletions(-) diff --git a/app/interfaces/repository/post.go b/app/interfaces/repository/post.go index eee2076c..90d0f3e9 100644 --- a/app/interfaces/repository/post.go +++ b/app/interfaces/repository/post.go @@ -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 { @@ -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(*) @@ -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 { @@ -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(*) @@ -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 { @@ -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(*) @@ -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 { @@ -120,8 +120,8 @@ 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 @@ -129,7 +129,7 @@ func (pr *Post) FindAllPublish(page int, limit int) (domain.Posts, error) { FROM view_posts WHERE - status = "publish" + status = "public" ORDER BY id DESC LIMIT ?, ? @@ -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 @@ -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 @@ -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 ?, ? @@ -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 @@ -592,8 +592,8 @@ 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 @@ -601,7 +601,7 @@ func (pr *Post) FindAllPublishByCategory(page int, limit int, name string) (doma FROM view_posts WHERE - status = "publish" + status = "public" AND category_name = ? ORDER BY id DESC @@ -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 @@ -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 @@ -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 ?, ? @@ -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 @@ -1325,7 +1325,7 @@ func (pr *Post) FindPublishByTitle(title string) (domain.Post, error) { WHERE title = ? AND - status = "publish" + status = "public" `, title) defer func() { @@ -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) @@ -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) diff --git a/app/usecase/interactor/post.go b/app/usecase/interactor/post.go index 14868442..bbd18a63 100644 --- a/app/usecase/interactor/post.go +++ b/app/usecase/interactor/post.go @@ -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()) } @@ -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()) } @@ -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()) } @@ -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()) } @@ -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()) } diff --git a/app/usecase/repository/post.go b/app/usecase/repository/post.go index 04df803e..44f60f6d 100644 --- a/app/usecase/repository/post.go +++ b/app/usecase/repository/post.go @@ -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 diff --git a/doc/API.md b/doc/API.md index b0049812..27c6c883 100644 --- a/doc/API.md +++ b/doc/API.md @@ -22,7 +22,7 @@ - [Request bodies](#request-bodies) - [Response bodies](#response-bodies) - [Post](#post-2) - - [Get all publish posts](#get-all-publish-posts) + - [Get all public posts](#get-all-public-posts) - [Endpoint](#endpoint-1) - [Query Parameters](#query-parameters) - [Requests](#requests) @@ -31,7 +31,7 @@ - [Response](#response) - [Header](#header-1) - [Body](#body-1) - - [Get publish posts by search keywords](#get-publish-posts-by-search-keywords) + - [Get public posts by search keywords](#get-public-posts-by-search-keywords) - [Endpoint](#endpoint-2) - [Query Parameters](#query-parameters-1) - [Requests](#requests-1) @@ -40,7 +40,7 @@ - [Response](#response-1) - [Header](#header-3) - [Body](#body-3) - - [Get all publish posts by category](#get-all-publish-posts-by-category) + - [Get all public posts by category](#get-all-public-posts-by-category) - [Endpoint](#endpoint-3) - [Path Parameters](#path-parameters) - [Request](#request) @@ -49,7 +49,7 @@ - [Response](#response-2) - [Header](#header-5) - [Body](#body-5) - - [Get all publish posts by tag](#get-all-publish-posts-by-tag) + - [Get all public posts by tag](#get-all-public-posts-by-tag) - [Endpoint](#endpoint-4) - [Path Parameters](#path-parameters-1) - [Request](#request-1) @@ -498,10 +498,10 @@ Public API is open api that does not required authentication. | Method | Endpoint | Description | | :----- | :---------------------- | :------------------------------------------------------ | | POST | /signin | Get an access token and a refresh token by credentials. | -| GET | /posts/search | Get publish posts by search keywords. | -| GET | /posts | Get all publish posts. | -| GET | /posts/categories/:name | Get all publish posts by cagtegory. | -| GET | /posts/tags/:name | Get all publish posts by tag. | +| GET | /posts/search | Get public posts by search keywords. | +| GET | /posts | Get all public posts. | +| GET | /posts/categories/:name | Get all public posts by cagtegory. | +| GET | /posts/tags/:name | Get all public posts by tag. | | GET | /posts/:title | Get the specified post by title. | | POST | /posts/:title/comments | Store a newly comment. | | GET | /categories | Get all categories. | @@ -531,7 +531,7 @@ Public API is open api that does not required authentication. ``` ## Post -### Get all publish posts +### Get all public posts #### Endpoint `GET /posts` @@ -588,7 +588,7 @@ N/A "title":"1title", "md_body":"#md-body", "html_body":"html_body", - "status":"publish", + "status":"public", "comments":null, "created_at":"2020-09-28T15:10:18Z", "updated_at":"2020-09-28T15:10:18Z" @@ -616,7 +616,7 @@ N/A "title": "2title", "md_body":"#md-body", "html_body":"html_body", - "status":"publish", + "status":"public", "comments":null, "created_at":"2020-09-28T15:10:21Z", "updated_at":"2020-09-28T15:10:21Z" @@ -644,7 +644,7 @@ N/A "title":"3title", "md_body":"#md-body", "html_body":"html_body", - "status":"publish", + "status":"public", "comments":null, "created_at":"2020-09-28T15:10:24Z", "updated_at":"2020-09-28T15:10:24Z" @@ -652,7 +652,7 @@ N/A ] ``` -### Get publish posts by search keywords +### Get public posts by search keywords #### Endpoint `GET /posts/search` @@ -710,7 +710,7 @@ N/A "title":"1title", "md_body":"#md-body", "html_body":"html_body", - "status":"publish", + "status":"public", "comments":null, "created_at":"2020-09-28T15:10:18Z", "updated_at":"2020-09-28T15:10:18Z" @@ -738,7 +738,7 @@ N/A "title": "2title", "md_body":"#md-body", "html_body":"html_body", - "status":"publish", + "status":"public", "comments":null, "created_at":"2020-09-28T15:10:21Z", "updated_at":"2020-09-28T15:10:21Z" @@ -766,7 +766,7 @@ N/A "title":"3title", "md_body":"#md-body", "html_body":"html_body", - "status":"publish", + "status":"public", "comments":null, "created_at":"2020-09-28T15:10:24Z", "updated_at":"2020-09-28T15:10:24Z" @@ -774,7 +774,7 @@ N/A ] ``` -### Get all publish posts by category +### Get all public posts by category #### Endpoint `GET /posts/categories/:name` @@ -812,7 +812,7 @@ N/A ] ``` -### Get all publish posts by tag +### Get all public posts by tag #### Endpoint `GET /posts/tags/:name` @@ -858,7 +858,7 @@ N/A "title":"1title", "md_body":"#md-body", "html_body":"\u003chtml\u003e\u003cbody\u003ehtml_body\u003c/body\u003e\u003c/html\u003e", - "status":"publish", + "status":"public", "comments":null, "created_at":"2020-09-28T15:10:18Z", "updated_at":"2020-09-28T15:10:18Z" @@ -886,7 +886,7 @@ N/A "title":"2title", "md_body":"#md-body", "html_body":"\u003chtml\u003e\u003cbody\u003ehtml_body\u003c/body\u003e\u003c/html\u003e", - "status":"publish", + "status":"public", "comments":null, "created_at":"2020-09-28T15:10:24Z", "updated_at":"2020-09-28T15:10:24Z" @@ -914,7 +914,7 @@ N/A "title":"3title", "md_body":"#md-body", "html_body":"\u003ch1 id=\"ge\"\u003ege\u003c/h1\u003e\n", - "status":"publish", + "status":"public", "comments":null, "created_at":"2020-09-28T15:10:27Z", "updated_at":"2020-09-28T15:10:27Z" @@ -942,7 +942,7 @@ N/A "title":"4title", "md_body":"#md-body", "html_body":"\u003chtml\u003e\u003cbody\u003ehtml_body\u003c/body\u003e\u003c/html\u003e", - "status":"publish", + "status":"public", "comments":null, "created_at":"2020-09-28T15:10:30Z", "updated_at":"2020-09-28T15:10:30Z" @@ -995,7 +995,7 @@ N/A "title":"1title", "md_body":"#md-body", "html_body":"\u003chtml\u003e\u003cbody\u003ehtml_body\u003c/body\u003e\u003c/html\u003e", - "status":"publish", + "status":"public", "comments":null, "created_at":"2020-09-28T15:18:16Z", "updated_at":"2020-09-28T15:18:16Z" @@ -1393,7 +1393,7 @@ N/A "title":"2title", "md_body":"2md_body", "html_body":"2html_body", - "status":"publish", + "status":"public", "comments":null, "created_at":"2020-10-04T16:30:46Z", "updated_at":"2020-10-04T16:30:46Z" @@ -1480,7 +1480,7 @@ N/A "title":"1title", "md_body":"#md-body", "html_body":"\u003chtml\u003e\u003cbody\u003ehtml_body\u003c/body\u003e\u003c/html\u003e", - "status":"publish", + "status":"public", "comments":null, "created_at":"2020-09-28T15:18:16Z", "updated_at":"2020-09-28T15:18:16Z" @@ -1514,7 +1514,7 @@ N/A "body": "foo-bar-body", "md_body": "#md-body", "html_body": "html_body", - "status": "draft|publish" + "status": "draft|public" } ``` @@ -1592,7 +1592,7 @@ N/A "body": "foo-bar-body", "md_body": "#md-body", "html_body": "html_body", - "status": "draft|publish" + "status": "draft|public" } ``` diff --git a/doc/Specification.md b/doc/Specification.md index 3dddf23d..00c4d8fc 100644 --- a/doc/Specification.md +++ b/doc/Specification.md @@ -1,7 +1,7 @@ # Specification ## Post - Can draft articles -- Can publish articles +- Can public articles - Can archive articles ## Comment