main / internal/domain/ports.go
2.5 KB · Go Raw
1package domain
2
3import "context"
4
5type UserRepository interface {
6 Create(ctx context.Context, u *User) error
7 ByUsername(ctx context.Context, name string) (*User, error)
8 ByID(ctx context.Context, id string) (*User, error)
9}
10
11type PasswordHasher interface {
12 Hash(plain string) (string, error)
13 Compare(hash, plain string) error
14}
15
16type RepositoryRepository interface {
17 Create(ctx context.Context, r *Repository) error
18 Delete(ctx context.Context, id int64) error
19 ByOwnerAndName(ctx context.Context, owner, name string) (*Repository, error)
20 ListByOwner(ctx context.Context, ownerID int64) ([]*Repository, error)
21 ListPublic(ctx context.Context) ([]*Repository, error)
22}
23
24type GitService interface {
25 InitBare(ctx context.Context, owner, name, defaultBranch string) error
26 RemovePath(ctx context.Context, owner, name string) error
27 Merge(ctx context.Context, owner, name, base, head, message, authorName, authorEmail string) error
28}
29
30type IssueRepository interface {
31 Create(ctx context.Context, i *Issue) error
32 ByNumber(ctx context.Context, repoID int64, number int) (*Issue, error)
33 List(ctx context.Context, repoID int64, state IssueState) ([]*Issue, error)
34 SetState(ctx context.Context, id int64, state IssueState) error
35
36 AddComment(ctx context.Context, c *IssueComment) error
37 Comments(ctx context.Context, issueID int64) ([]*IssueComment, error)
38 CountByState(ctx context.Context, repoID int64) (open, closed int, err error)
39}
40
41type GitReader interface {
42 IsEmpty(ctx context.Context, owner, name string) (bool, error)
43 Branches(ctx context.Context, owner, name string) ([]string, error)
44 Tip(ctx context.Context, owner, name, ref string) (*Commit, error)
45 Tree(ctx context.Context, owner, name, ref, path string) ([]TreeEntry, error)
46 Blob(ctx context.Context, owner, name, ref, path string) (*FileBlob, error)
47 Log(ctx context.Context, owner, name, ref string, limit, offset int) ([]Commit, error)
48 CommitDiff(ctx context.Context, owner, name, hash string) (*Commit, []FileDiff, error)
49 Compare(ctx context.Context, owner, name, base, head string) (*Comparison, error)
50}
51
52type PullRequestRepository interface {
53 Create(ctx context.Context, pr *PullRequest) error
54 ByNumber(ctx context.Context, repoID int64, number int) (*PullRequest, error)
55 List(ctx context.Context, repoID int64, state PRState) ([]*PullRequest, error)
56 SetState(ctx context.Context, id int64, state PRState) error
57
58 AddComment(ctx context.Context, c *PRComment) error
59 Comments(ctx context.Context, prID int64) ([]*PRComment, error)
60 CountByState(ctx context.Context, repoID int64) (open, merged, closed int, err error)
61}