1package board
2
3import (
4 "github.com/MichaelMure/git-bug/entities/bug"
5 "github.com/MichaelMure/git-bug/entities/identity"
6
7 "github.com/MichaelMure/git-bug/entity"
8 "github.com/MichaelMure/git-bug/entity/dag"
9 "github.com/MichaelMure/git-bug/repository"
10)
11
12var _ entity.Interface = &Board{}
13
14// 1: original format
15const formatVersion = 1
16
17var def = dag.Definition{
18 Typename: "board",
19 Namespace: "boards",
20 OperationUnmarshaler: operationUnmarshaller,
21 FormatVersion: formatVersion,
22}
23
24var ClockLoader = dag.ClockLoader(def)
25
26// Board holds the data of a project board.
27type Board struct {
28 *dag.Entity
29}
30
31// NewBoard create a new Board
32func NewBoard() *Board {
33 return &Board{
34 Entity: dag.New(def),
35 }
36}
37
38func simpleResolvers(repo repository.ClockedRepo) entity.Resolvers {
39 return entity.Resolvers{
40 &identity.Identity{}: identity.NewSimpleResolver(repo),
41 &bug.Bug{}: bug.NewSimpleResolver(repo),
42 }
43}
44
45// Read will read a board from a repository
46func Read(repo repository.ClockedRepo, id entity.Id) (*Board, error) {
47 return ReadWithResolver(repo, simpleResolvers(repo), id)
48}
49
50// ReadWithResolver will read a board from its Id, with a custom identity.Resolver
51func ReadWithResolver(repo repository.ClockedRepo, resolvers entity.Resolvers, id entity.Id) (*Board, error) {
52 e, err := dag.Read(def, repo, resolvers, id)
53 if err != nil {
54 return nil, err
55 }
56 return &Board{Entity: e}, nil
57}