JavaScript is disabled, refresh for a better experience. ambee/giterated

ambee/giterated

Git repository hosting, collaboration, and discovery for the Fediverse.

Fucking whatever there you go

Amber - ⁨2⁩ years ago

parent: tbd commit: ⁨57c2ca5

⁨plugins/giterated-issues/src/handlers.rs⁩ - ⁨2977⁩ bytes
Raw
1 use crate::db::IssueRow;
2 use crate::setting::Contents;
3 use crate::value::{Author, CommentCount, CreationDate, Name};
4 use crate::IssuesPluginState;
5 use crate::{
6 operations::{
7 CreateIssueRequest, IssueCreationError, IssueEditError, IssueEditRequest,
8 IssuePostCommentError, IssuePostCommentRequest, IssueQueryError, QueryIssuesRequest,
9 },
10 Issue,
11 };
12 use giterated_models::error::IntoInternalError;
13 use giterated_models::user::User;
14 use giterated_models::{error::OperationError, repository::Repository};
15 use sqlx::PgPool;
16
17 pub async fn create_issue_request(
18 state: IssuesPluginState,
19 repository: Repository,
20 request: CreateIssueRequest,
21 ) -> Result<Issue, OperationError<IssueCreationError>> {
22 // TODO: AUTHN & AUTHZ
23 let issue = sqlx::query_as!(
24 IssueRow,
25 r#"INSERT INTO issues VALUES (null, $1, $2, $3, $4, $5) RETURNING *"#,
26 repository.to_string(),
27 request.author.to_string(),
28 0,
29 request.name,
30 request.contents,
31 )
32 .fetch_one(&state.pool)
33 .await
34 .as_internal_error_with_context("creating issue in db")?;
35
36 Ok(Issue {
37 repository,
38 id: issue.id as u32,
39 })
40 }
41
42 pub async fn query_issues_request(
43 state: IssuesPluginState,
44 repository: Repository,
45 request: QueryIssuesRequest,
46 ) -> Result<Vec<Issue>, OperationError<IssueQueryError>> {
47 // TODO: AUTHN & AUTHZ
48 todo!()
49 }
50
51 pub async fn edit_issue_request(
52 state: IssuesPluginState,
53 issue: Issue,
54 request: IssueEditRequest,
55 ) -> Result<(), OperationError<IssueEditError>> {
56 // TODO: AUTHN & AUTHZ
57 todo!()
58 }
59
60 pub async fn issue_post_comment_request(
61 state: IssuesPluginState,
62 issue: Issue,
63 request: IssuePostCommentRequest,
64 ) -> Result<u32, OperationError<IssuePostCommentError>> {
65 // TODO: AUTHN & AUTHZ
66 todo!()
67 }
68
69 pub async fn issue_value_author(
70 state: IssuesPluginState,
71 issue: Issue,
72 ) -> Result<Author, OperationError<anyhow::Error>> {
73 todo!()
74 }
75
76 pub async fn issue_value_creation_date(
77 state: IssuesPluginState,
78 issue: Issue,
79 ) -> Result<CreationDate, OperationError<anyhow::Error>> {
80 todo!()
81 }
82
83 pub async fn issue_value_comment_count(
84 state: IssuesPluginState,
85 issue: Issue,
86 ) -> Result<CommentCount, OperationError<anyhow::Error>> {
87 todo!()
88 }
89
90 pub async fn issue_set_setting_name(
91 state: IssuesPluginState,
92 issue: Issue,
93 name: Name,
94 ) -> Result<(), OperationError<anyhow::Error>> {
95 todo!()
96 }
97
98 pub async fn issue_get_setting_name(
99 state: IssuesPluginState,
100 issue: Issue,
101 ) -> Result<Name, OperationError<anyhow::Error>> {
102 todo!()
103 }
104
105 pub async fn issue_set_setting_contents(
106 state: IssuesPluginState,
107 issue: Issue,
108 contents: Contents,
109 ) -> Result<(), OperationError<anyhow::Error>> {
110 todo!()
111 }
112
113 pub async fn issue_get_setting_contents(
114 state: IssuesPluginState,
115 issue: Issue,
116 ) -> Result<Contents, OperationError<anyhow::Error>> {
117 todo!()
118 }
119