Skip to content
This repository was archived by the owner on Feb 4, 2021. It is now read-only.

Commit 072ac20

Browse files
committed
Impl role store
1 parent 6f0a3b0 commit 072ac20

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

infra/store/role/role_store.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package rolestore
2+
3+
import (
4+
"context"
5+
"database/sql"
6+
7+
"github.com/pkg/errors"
8+
9+
"github.com/ProgrammingLab/prolab-accounts/infra/record"
10+
"github.com/ProgrammingLab/prolab-accounts/infra/store"
11+
)
12+
13+
type roleStoreImpl struct {
14+
ctx context.Context
15+
db *sql.DB
16+
}
17+
18+
// NewRoleStore returns new role store
19+
func NewRoleStore(ctx context.Context, db *sql.DB) store.RoleStore {
20+
return &roleStoreImpl{
21+
ctx: ctx,
22+
db: db,
23+
}
24+
}
25+
26+
func (s *roleStoreImpl) ListRoles() ([]*record.Role, error) {
27+
roles, err := record.Roles().All(s.ctx, s.db)
28+
if err != nil {
29+
return nil, errors.WithStack(err)
30+
}
31+
return roles, nil
32+
}
33+
34+
func (s *roleStoreImpl) GetRole(roleID int64) (*record.Role, error) {
35+
r, err := record.FindRole(s.ctx, s.db, roleID)
36+
if err != nil {
37+
return nil, errors.WithStack(err)
38+
}
39+
return r, nil
40+
}

infra/store/role_store.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package store
2+
3+
import (
4+
"github.com/ProgrammingLab/prolab-accounts/infra/record"
5+
)
6+
7+
// RoleStore accesses roles
8+
type RoleStore interface {
9+
ListRoles() ([]*record.Role, error)
10+
GetRole(roleID int64) (*record.Role, error)
11+
}

0 commit comments

Comments
 (0)