1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
|
use crate::graphql::types::{
alert,
jwt::{self},
position,
user::{self},
};
use async_graphql::{Context, FieldResult, Object};
use super::types::notification;
/// Mutation struct
pub struct Mutation;
#[Object]
impl Mutation {
/// Make GraphQL login
///
/// Example:
/// ```text
/// curl -X POST http://localhost:8000/graphql \
/// -H "Content-Type: application/json" \
/// -d '{
/// "query": "mutation Login($input: LoginCredentials!) { login(input: $input) { accessToken tokenType userId } }",
/// "variables": {
/// "input": {
/// "email": "***",
/// "password": "***"
/// }
/// }
/// }'
/// ```
async fn login<'ctx>(
&self,
ctx: &Context<'ctx>,
input: jwt::LoginCredentials,
) -> FieldResult<jwt::AuthBody> {
jwt::mutations::login(ctx, input).await
}
/// Make GraphQL call to register a notification device token for the user.
///
/// Example:
/// ```text
/// curl -X POST http://localhost:8000/graphql \
/// -H "Content-Type: application/json" \
/// -H "Authorization: Bearer ***" \
/// -d '{
/// "query": "mutation RegisterDevice($input: RegisterNotificationToken!) { registerDevice(input: $input) { id name email } }",
/// "variables": {
/// "input": {
/// "token": "***",
/// }
/// }
/// }'
/// ```
async fn register_device<'ctx>(
&self,
ctx: &Context<'ctx>,
input: user::RegisterNotificationToken,
) -> FieldResult<user::User> {
user::mutations::register_device(ctx, input).await
}
/// Make GraphQL call to edit their passowrd.
///
/// Example:
/// ```text
/// curl -X POST http://localhost:8000/graphql \
/// -H "Content-Type: application/json" \
/// -H "Authorization: Bearer ***" \
/// -d '{
/// "query": "mutation UserPasswordEdit($input: UserPasswordEdit!) { userPasswordEdit(input: $input) { id email name address is_admin } }",
/// "variables": {
/// "input": {
/// "password1": "***",
/// "password2": "***"
/// }
/// }
/// }'
/// ```
async fn user_password_edit<'ctx>(
&self,
ctx: &Context<'ctx>,
input: user::UserPasswordEdit,
) -> FieldResult<user::User> {
user::mutations::user_password_edit(ctx, input).await
}
/// Make GraphQL call to edit an user. Not admins can edit only the user linked to the access
/// token used.
///
/// Example:
/// ```text
/// curl -X POST http://localhost:8000/graphql \
/// -H "Content-Type: application/json" \
/// -H "Authorization: Bearer ***" \
/// -d '{
/// "query": "mutation UserEdit($input: UserEdit!, $id: Int!) { userEdit(input: $input, id: $id) { id email name address is_admin } }",
/// "variables": {
/// "input": {
/// "email": "mario.rossi@example.com",
/// "name": "Mario Rossi",
/// "address": ""
/// },
/// "id": 42
/// }
/// }'
/// ```
async fn user_edit<'ctx>(
&self,
ctx: &Context<'ctx>,
input: user::UserEdit,
id: i32,
) -> FieldResult<user::User> {
user::mutations::user_edit(ctx, input, id).await
}
/// Make GraphQL request to create new position to track
///
/// Example:
/// ```text
/// curl -X POST http://localhost:8000/graphql \
/// -H "Content-Type: application/json" \
/// -H "Authorization: Bearer ***" \
/// -d '{
/// "query": "mutation NewPosition($input: PositionInput!) { newPosition(input: $input) { id userId createdAt latitude longitude movingActivity } }",
/// "variables": {
/// "input": {
/// "latitude": 44.50800643571219,
/// "longitude": 11.299600981136905,
/// "movingActivity": "STILL"
/// }
/// }
/// }'
/// ```
async fn new_position<'ctx>(
&self,
ctx: &Context<'ctx>,
input: position::PositionInput,
) -> FieldResult<position::Position> {
position::mutations::new_position(ctx, input).await
}
/// Make GraphQL request to create new alert. Only for admins.
///
/// Example:
/// ```text
/// curl -X POST http://localhost:8000/graphql \
/// -H "Content-Type: application/json" \
/// -H "Authorization: Bearer ****" \
/// -d '{
/// "query": "mutation NewAlert($input: AlertInput!) { newAlert(input: $input) { id createdAt } }",
/// "variables": {
/// "input": {
/// "points": [
/// { "latitude": 44.490025, "longitude": 11.311499},
/// { "latitude": 44.490361, "longitude": 11.327903},
/// { "latitude": 44.497280, "longitude": 11.327776},
/// { "latitude": 44.498321, "longitude": 11.312145},
/// { "latitude": 44.490025, "longitude": 11.311498}
/// ],
/// "text1": "Alert level 1",
/// "text2": "Alert level 2",
/// "text3": "Alert level 3"
/// }
/// }
/// }
async fn new_alert<'ctx>(
&self,
ctx: &Context<'ctx>,
input: alert::AlertInput,
) -> FieldResult<alert::Alert> {
alert::mutations::new_alert(ctx, input).await
}
/// Make GraphQL request to update notification seen status.
///
/// Example:
/// ```text
/// curl -X POST http://localhost:8000/graphql \
/// -H "Content-Type: application/json" \
/// -H "Authorization: Bearer ****" \
/// -d '{
/// "query": "mutation NotificationUpdate($input: NotificationUpdateInput!) { notificationUpdate(input: $input) { id seen } }",
/// "variables": {
/// "input": {
/// "id": 42,
/// "seen": true
/// }
/// }
/// }
async fn notification_update<'ctx>(
&self,
ctx: &Context<'ctx>,
input: notification::NotificationUpdateInput,
) -> FieldResult<notification::Notification> {
notification::mutations::notification_update(ctx, input).await
}
}
|