Skip to content

Commit 57fdc1e

Browse files
committed
Prep for implementing commands
1 parent b9e36a1 commit 57fdc1e

6 files changed

Lines changed: 35 additions & 9 deletions

File tree

backend/command/command.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package command
2+
3+
import (
4+
"github.com/theandrew168/bloggulus/backend/repository"
5+
)
6+
7+
type Command struct {
8+
repo *repository.Repository
9+
}
10+
11+
func New(repo *repository.Repository) *Command {
12+
cmd := Command{
13+
repo: repo,
14+
}
15+
return &cmd
16+
}

backend/command/session.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package command
2+
3+
import (
4+
"time"
5+
6+
"github.com/theandrew168/bloggulus/backend/repository"
7+
)
8+
9+
func (cmd *Command) DeleteExpiredSessions(now time.Time) error {
10+
return cmd.repo.WithTransaction(func(tx *repository.Repository) error {
11+
return nil
12+
})
13+
}

backend/postgres/errors.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@ delete (CollectOneRow) - does not exist
5151
var (
5252
ErrNotFound = errors.New("postgres: not found")
5353
ErrConflict = errors.New("postgres: conflict")
54-
55-
// sentinel error used to rollback transactions
56-
ErrRollback = errors.New("postgres: rollback")
5754
)
5855

5956
func CheckCreateError(err error) error {

backend/query/article.go

Lines changed: 2 additions & 2 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 (f *Query) ListArticles(limit, offset int) ([]Article, error) {
25+
func (qry *Query) ListArticles(limit, offset int) ([]Article, error) {
2626
stmt := `
2727
WITH latest AS (
2828
SELECT
@@ -51,7 +51,7 @@ func (f *Query) ListArticles(limit, offset int) ([]Article, error) {
5151
ctx, cancel := context.WithTimeout(context.Background(), postgres.Timeout)
5252
defer cancel()
5353

54-
rows, err := f.conn.Query(ctx, stmt, limit, offset)
54+
rows, err := qry.conn.Query(ctx, stmt, limit, offset)
5555
if err != nil {
5656
return nil, err
5757
}

backend/query/blog.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ type BlogForAccount struct {
1717
}
1818

1919
// TODO: Paginate this (will need to add a CountBlogsForAccount method).
20-
func (f *Query) ListBlogsForAccount(account *model.Account) ([]BlogForAccount, error) {
20+
func (qry *Query) ListBlogsForAccount(account *model.Account) ([]BlogForAccount, error) {
2121
stmt := `
2222
SELECT
2323
blog.id,
@@ -33,7 +33,7 @@ func (f *Query) ListBlogsForAccount(account *model.Account) ([]BlogForAccount, e
3333
ctx, cancel := context.WithTimeout(context.Background(), postgres.Timeout)
3434
defer cancel()
3535

36-
rows, err := f.conn.Query(ctx, stmt, account.ID())
36+
rows, err := qry.conn.Query(ctx, stmt, account.ID())
3737
if err != nil {
3838
return nil, err
3939
}

backend/query/query.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ type Query struct {
1010
}
1111

1212
func New(conn postgres.Conn) *Query {
13-
f := Query{
13+
qry := Query{
1414
conn: conn,
1515
}
16-
return &f
16+
return &qry
1717
}

0 commit comments

Comments
 (0)