steid

@jamesgill /

steid/src/domain/repository/issue_repo.rs
Rust4.1 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 /// One page of a repository's issues in the given state, newest first — which for a
42 /// monotonic sequence is descending number, an order that cannot tie.
43 ///
44 /// `offset` and `limit` are the list page's `?page=`. A `limit` past the end of the
45 /// list is a short page, not an error: an issue closed between two page loads is
46 /// ordinary, and so is a stale link.
47 ///
48 /// **The label filter does not go through these two.** Which labels an issue wears
49 /// is a second table the use case already reads whole to render the pills, so a
50 /// filtered list is narrowed and paged there — see `list_issues`. That is why the
51 /// filtered path asks for every issue and this one exists for the unfiltered path.
52 fn list_by_repo(
53 &self,
54 repo_id: &RepoId,
55 state: IssueState,
56 offset: usize,
57 limit: usize,
58 ) -> impl Future<Output = RepositoryResult<Vec<Issue>>> + Send;
59
60 /// How many issues the repository has open and closed.
61 fn counts(
62 &self,
63 repo_id: &RepoId,
64 ) -> impl Future<Output = RepositoryResult<IssueCounts>> + Send;
65
66 /// How many comments each issue on the repository carries.
67 ///
68 /// Per repository rather than per issue because the list renders a count on every
69 /// row: asking per row is a query per row.
70 fn comment_counts(
71 &self,
72 repo_id: &RepoId,
73 ) -> impl Future<Output = RepositoryResult<Vec<(IssueId, u64)>>> + Send;
74
75 /// Inserts or replaces an issue.
76 ///
77 /// The owning repository must already exist; the foreign key runs that direction.
78 fn save(&self, issue: &Issue) -> impl Future<Output = RepositoryResult<()>> + Send;
79
80 /// Every comment on an issue, oldest first — a conversation reads forwards.
81 ///
82 /// Comments written in the same second keep the order they were written in, which
83 /// both implementations get from insertion order rather than from the id: ids are
84 /// random UUIDs, so a tie broken by one would occasionally read backwards.
85 fn list_comments(
86 &self,
87 issue_id: &IssueId,
88 ) -> impl Future<Output = RepositoryResult<Vec<IssueComment>>> + Send;
89
90 /// Adds a comment to an issue.
91 fn add_comment(
92 &self,
93 comment: &IssueComment,
94 ) -> impl Future<Output = RepositoryResult<()>> + Send;
95}