steid

@jamesgill /

steid/src/domain/repository/issue_repo.rs
Rust3.6 KBCode·Blame·History·Raw
1use super::RepositoryResult;
2use crate::domain::{Issue, IssueComment, IssueId, IssueNumber, IssueState, RepoId};
3
4/// How many issues a repository has in each state.
5///
6/// Both counts in one round trip because the list toolbar always shows both — asking
7/// twice would be two queries to render one line.
8#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
9pub struct IssueCounts {
10 pub open: u64,
11 pub closed: u64,
12}
13
14/// Persistence for the [`Issue`] aggregate.
15///
16/// Comments live behind the same port rather than one of their own. A comment is not an
17/// aggregate root: it has no meaning without its issue, nothing addresses one except
18/// through the issue it hangs off, and splitting them would mean a use case holding two
19/// ports that can only ever be used together.
20pub trait IssueRepository: Send + Sync {
21 /// Allocates the next number in a repository's sequence.
22 ///
23 /// **One sequence per repository, shared with pull requests**, so `#4` means one
24 /// thing on a repository whatever kind of thing it is. Allocation has to be atomic:
25 /// two concurrent creations must not both receive the same number, and the unique
26 /// `(repo_id, number)` constraint means the loser would fail its insert rather than
27 /// quietly overwrite. Numbers are consumed even when the thing being numbered is
28 /// never saved — a gap in the sequence is cheaper than a reused number.
29 fn next_number(
30 &self,
31 repo_id: &RepoId,
32 ) -> impl Future<Output = RepositoryResult<IssueNumber>> + Send;
33
34 /// Looks an issue up by the `/{handle}/repos/{name}/issues/{number}` pair.
35 fn find_by_number(
36 &self,
37 repo_id: &RepoId,
38 number: IssueNumber,
39 ) -> impl Future<Output = RepositoryResult<Option<Issue>>> + Send;
40
41 /// Every issue on a repository in the given state, newest first, ties broken by
42 /// descending number.
43 ///
44 /// Unpaged, deliberately, and the use case says so on the page. A repository with
45 /// enough issues for paging to matter is a repository this milestone does not have.
46 fn list_by_repo(
47 &self,
48 repo_id: &RepoId,
49 state: IssueState,
50 ) -> impl Future<Output = RepositoryResult<Vec<Issue>>> + Send;
51
52 /// How many issues the repository has open and closed.
53 fn counts(
54 &self,
55 repo_id: &RepoId,
56 ) -> impl Future<Output = RepositoryResult<IssueCounts>> + Send;
57
58 /// How many comments each issue on the repository carries.
59 ///
60 /// Per repository rather than per issue because the list renders a count on every
61 /// row: asking per row is a query per row.
62 fn comment_counts(
63 &self,
64 repo_id: &RepoId,
65 ) -> impl Future<Output = RepositoryResult<Vec<(IssueId, u64)>>> + Send;
66
67 /// Inserts or replaces an issue.
68 ///
69 /// The owning repository must already exist; the foreign key runs that direction.
70 fn save(&self, issue: &Issue) -> impl Future<Output = RepositoryResult<()>> + Send;
71
72 /// Every comment on an issue, oldest first — a conversation reads forwards.
73 ///
74 /// Comments written in the same second keep the order they were written in, which
75 /// both implementations get from insertion order rather than from the id: ids are
76 /// random UUIDs, so a tie broken by one would occasionally read backwards.
77 fn list_comments(
78 &self,
79 issue_id: &IssueId,
80 ) -> impl Future<Output = RepositoryResult<Vec<IssueComment>>> + Send;
81
82 /// Adds a comment to an issue.
83 fn add_comment(
84 &self,
85 comment: &IssueComment,
86 ) -> impl Future<Output = RepositoryResult<()>> + Send;
87}