Skip to content

Commit 2188e31

Browse files
committed
Fix the article query naming
1 parent fbaaac8 commit 2188e31

3 files changed

Lines changed: 31 additions & 31 deletions

File tree

backend/query/article.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ type Article struct {
2222
Tags []string `db:"tags"`
2323
}
2424

25-
func (qry *Query) ListArticles(limit, offset int) ([]Article, error) {
25+
func (qry *Query) ListRecentArticles(limit, offset int) ([]Article, error) {
2626
stmt := `
2727
WITH latest AS (
2828
SELECT
@@ -64,7 +64,7 @@ func (qry *Query) ListArticles(limit, offset int) ([]Article, error) {
6464
return articles, nil
6565
}
6666

67-
func (f *Query) ListArticlesByAccount(account *model.Account, limit, offset int) ([]Article, error) {
67+
func (qry *Query) ListRecentArticlesByAccount(account *model.Account, limit, offset int) ([]Article, error) {
6868
stmt := `
6969
WITH latest AS (
7070
SELECT
@@ -98,7 +98,7 @@ func (f *Query) ListArticlesByAccount(account *model.Account, limit, offset int)
9898
ctx, cancel := context.WithTimeout(context.Background(), postgres.Timeout)
9999
defer cancel()
100100

101-
rows, err := f.conn.Query(ctx, stmt, account.ID(), limit, offset)
101+
rows, err := qry.conn.Query(ctx, stmt, account.ID(), limit, offset)
102102
if err != nil {
103103
return nil, err
104104
}
@@ -111,7 +111,7 @@ func (f *Query) ListArticlesByAccount(account *model.Account, limit, offset int)
111111
return articles, nil
112112
}
113113

114-
func (f *Query) SearchArticles(search string, limit, offset int) ([]Article, error) {
114+
func (qry *Query) ListRelevantArticles(search string, limit, offset int) ([]Article, error) {
115115
stmt := `
116116
WITH relevant AS (
117117
SELECT
@@ -141,7 +141,7 @@ func (f *Query) SearchArticles(search string, limit, offset int) ([]Article, err
141141
ctx, cancel := context.WithTimeout(context.Background(), postgres.Timeout)
142142
defer cancel()
143143

144-
rows, err := f.conn.Query(ctx, stmt, search, limit, offset)
144+
rows, err := qry.conn.Query(ctx, stmt, search, limit, offset)
145145
if err != nil {
146146
return nil, err
147147
}
@@ -154,7 +154,7 @@ func (f *Query) SearchArticles(search string, limit, offset int) ([]Article, err
154154
return articles, nil
155155
}
156156

157-
func (f *Query) SearchArticlesByAccount(account *model.Account, search string, limit, offset int) ([]Article, error) {
157+
func (qry *Query) ListRelevantArticlesByAccount(account *model.Account, search string, limit, offset int) ([]Article, error) {
158158
stmt := `
159159
WITH relevant AS (
160160
SELECT
@@ -189,7 +189,7 @@ func (f *Query) SearchArticlesByAccount(account *model.Account, search string, l
189189
ctx, cancel := context.WithTimeout(context.Background(), postgres.Timeout)
190190
defer cancel()
191191

192-
rows, err := f.conn.Query(ctx, stmt, account.ID(), search, limit, offset)
192+
rows, err := qry.conn.Query(ctx, stmt, account.ID(), search, limit, offset)
193193
if err != nil {
194194
return nil, err
195195
}
@@ -202,15 +202,15 @@ func (f *Query) SearchArticlesByAccount(account *model.Account, search string, l
202202
return articles, nil
203203
}
204204

205-
func (f *Query) CountArticles() (int, error) {
205+
func (qry *Query) CountRecentArticles() (int, error) {
206206
stmt := `
207207
SELECT count(*)
208208
FROM post`
209209

210210
ctx, cancel := context.WithTimeout(context.Background(), postgres.Timeout)
211211
defer cancel()
212212

213-
rows, err := f.conn.Query(ctx, stmt)
213+
rows, err := qry.conn.Query(ctx, stmt)
214214
if err != nil {
215215
return 0, err
216216
}
@@ -223,7 +223,7 @@ func (f *Query) CountArticles() (int, error) {
223223
return count, nil
224224
}
225225

226-
func (f *Query) CountArticlesByAccount(account *model.Account) (int, error) {
226+
func (qry *Query) CountRecentArticlesByAccount(account *model.Account) (int, error) {
227227
stmt := `
228228
SELECT count(*)
229229
FROM post
@@ -236,7 +236,7 @@ func (f *Query) CountArticlesByAccount(account *model.Account) (int, error) {
236236
ctx, cancel := context.WithTimeout(context.Background(), postgres.Timeout)
237237
defer cancel()
238238

239-
rows, err := f.conn.Query(ctx, stmt, account.ID())
239+
rows, err := qry.conn.Query(ctx, stmt, account.ID())
240240
if err != nil {
241241
return 0, err
242242
}
@@ -249,7 +249,7 @@ func (f *Query) CountArticlesByAccount(account *model.Account) (int, error) {
249249
return count, nil
250250
}
251251

252-
func (f *Query) CountSearchArticles(search string) (int, error) {
252+
func (qry *Query) CountRelevantArticles(search string) (int, error) {
253253
stmt := `
254254
SELECT count(*)
255255
FROM post
@@ -258,7 +258,7 @@ func (f *Query) CountSearchArticles(search string) (int, error) {
258258
ctx, cancel := context.WithTimeout(context.Background(), postgres.Timeout)
259259
defer cancel()
260260

261-
rows, err := f.conn.Query(ctx, stmt, search)
261+
rows, err := qry.conn.Query(ctx, stmt, search)
262262
if err != nil {
263263
return 0, err
264264
}
@@ -271,7 +271,7 @@ func (f *Query) CountSearchArticles(search string) (int, error) {
271271
return count, nil
272272
}
273273

274-
func (f *Query) CountSearchArticlesByAccount(account *model.Account, search string) (int, error) {
274+
func (qry *Query) CountRelevantArticlesByAccount(account *model.Account, search string) (int, error) {
275275
stmt := `
276276
SELECT count(*)
277277
FROM post
@@ -285,7 +285,7 @@ func (f *Query) CountSearchArticlesByAccount(account *model.Account, search stri
285285
ctx, cancel := context.WithTimeout(context.Background(), postgres.Timeout)
286286
defer cancel()
287287

288-
rows, err := f.conn.Query(ctx, stmt, account.ID(), search)
288+
rows, err := qry.conn.Query(ctx, stmt, account.ID(), search)
289289
if err != nil {
290290
return 0, err
291291
}

backend/query/article_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func TestListArticles(t *testing.T) {
2020
blog := test.CreateBlog(t, repo)
2121
test.CreatePost(t, repo, blog)
2222

23-
articles, err := find.ListArticles(1, 0)
23+
articles, err := find.ListRecentArticles(1, 0)
2424
test.AssertNilError(t, err)
2525

2626
test.AssertEqual(t, len(articles), 1)
@@ -49,7 +49,7 @@ func TestListArticlesByAccount(t *testing.T) {
4949
test.CreateAccountBlog(t, repo, account, followedBlog)
5050

5151
// List posts from blogs followed by this account.
52-
articles, err := find.ListArticlesByAccount(account, 5, 0)
52+
articles, err := find.ListRecentArticlesByAccount(account, 5, 0)
5353
test.AssertNilError(t, err)
5454

5555
// We should only get the three posts associated with the followed blog.
@@ -96,7 +96,7 @@ func TestSearchArticles(t *testing.T) {
9696
test.AssertNilError(t, err)
9797

9898
// list articles that relate to python
99-
articles, err := find.SearchArticles("python", 1, 0)
99+
articles, err := find.ListRelevantArticles("python", 1, 0)
100100
test.AssertNilError(t, err)
101101

102102
// should find at least one
@@ -148,7 +148,7 @@ func TestSearchArticlesByAccount(t *testing.T) {
148148
test.CreateAccountBlog(t, repo, account, followedBlog)
149149

150150
// List posts (from followed blogs) that relate to python.
151-
articles, err := find.SearchArticlesByAccount(account, "python", 5, 0)
151+
articles, err := find.ListRelevantArticlesByAccount(account, "python", 5, 0)
152152
test.AssertNilError(t, err)
153153

154154
// Should only return the three posts from followed blogs.
@@ -169,7 +169,7 @@ func TestCountArticles(t *testing.T) {
169169
test.CreatePost(t, repo, blog)
170170
test.CreatePost(t, repo, blog)
171171

172-
count, err := find.CountArticles()
172+
count, err := find.CountRecentArticles()
173173
test.AssertNilError(t, err)
174174

175175
test.AssertAtLeast(t, count, 3)
@@ -198,7 +198,7 @@ func TestCountArticlesByAccount(t *testing.T) {
198198
test.CreateAccountBlog(t, repo, account, followedBlog)
199199

200200
// We should only count the three posts associated with the followed blog.
201-
count, err := find.CountArticlesByAccount(account)
201+
count, err := find.CountRecentArticlesByAccount(account)
202202
test.AssertNilError(t, err)
203203
test.AssertEqual(t, count, 3)
204204
}
@@ -241,7 +241,7 @@ func TestCountSearchArticles(t *testing.T) {
241241
test.AssertNilError(t, err)
242242

243243
// count posts that relate to python
244-
count, err := find.CountSearchArticles("python")
244+
count, err := find.CountRelevantArticles("python")
245245
test.AssertNilError(t, err)
246246

247247
// should find at least one
@@ -293,7 +293,7 @@ func TestCountSearchArticlesByAccount(t *testing.T) {
293293
test.CreateAccountBlog(t, repo, account, followedBlog)
294294

295295
// Count posts (from followed blogs) that relate to python.
296-
count, err := find.CountSearchArticlesByAccount(account, "python")
296+
count, err := find.CountRelevantArticlesByAccount(account, "python")
297297
test.AssertNilError(t, err)
298298

299299
// Should only return the three posts from followed blogs.

backend/web/index.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,47 +46,47 @@ func HandleIndexPage(qry *query.Query) http.Handler {
4646
if search != "" {
4747
g.Go(func() error {
4848
var err error
49-
count, err = qry.CountSearchArticlesByAccount(account, search)
49+
count, err = qry.CountRelevantArticlesByAccount(account, search)
5050
return err
5151
})
5252
g.Go(func() error {
5353
var err error
54-
articles, err = qry.SearchArticlesByAccount(account, search, limit, offset)
54+
articles, err = qry.ListRelevantArticlesByAccount(account, search, limit, offset)
5555
return err
5656
})
5757
} else {
5858
g.Go(func() error {
5959
var err error
60-
count, err = qry.CountArticlesByAccount(account)
60+
count, err = qry.CountRecentArticlesByAccount(account)
6161
return err
6262
})
6363
g.Go(func() error {
6464
var err error
65-
articles, err = qry.ListArticlesByAccount(account, limit, offset)
65+
articles, err = qry.ListRecentArticlesByAccount(account, limit, offset)
6666
return err
6767
})
6868
}
6969
} else {
7070
if search != "" {
7171
g.Go(func() error {
7272
var err error
73-
count, err = qry.CountSearchArticles(search)
73+
count, err = qry.CountRelevantArticles(search)
7474
return err
7575
})
7676
g.Go(func() error {
7777
var err error
78-
articles, err = qry.SearchArticles(search, limit, offset)
78+
articles, err = qry.ListRelevantArticles(search, limit, offset)
7979
return err
8080
})
8181
} else {
8282
g.Go(func() error {
8383
var err error
84-
count, err = qry.CountArticles()
84+
count, err = qry.CountRecentArticles()
8585
return err
8686
})
8787
g.Go(func() error {
8888
var err error
89-
articles, err = qry.ListArticles(limit, offset)
89+
articles, err = qry.ListRecentArticles(limit, offset)
9090
return err
9191
})
9292
}

0 commit comments

Comments
 (0)