@@ -109,7 +109,7 @@ pub fn doc(operation: TransformOperation) -> TransformOperation {
109
109
. id ( "createUser" )
110
110
. summary ( "Create a new user" )
111
111
. tag ( "user" )
112
- . response_with :: < 200 , Json < SingleResponse < User > > , _ > ( |t| {
112
+ . response_with :: < 201 , Json < SingleResponse < User > > , _ > ( |t| {
113
113
let [ sample, ..] = User :: samples ( ) ;
114
114
let response = SingleResponse :: new_canonical ( sample) ;
115
115
t. description ( "User was created" ) . example ( response)
@@ -137,7 +137,7 @@ pub async fn handler(
137
137
NoApi ( mut rng) : NoApi < BoxRng > ,
138
138
State ( homeserver) : State < BoxHomeserverConnection > ,
139
139
Json ( params) : Json < Request > ,
140
- ) -> Result < Json < SingleResponse < User > > , RouteError > {
140
+ ) -> Result < ( StatusCode , Json < SingleResponse < User > > ) , RouteError > {
141
141
if repo. user ( ) . exists ( & params. username ) . await ? {
142
142
return Err ( RouteError :: UserAlreadyExists ) ;
143
143
}
@@ -170,7 +170,10 @@ pub async fn handler(
170
170
171
171
repo. save ( ) . await ?;
172
172
173
- Ok ( Json ( SingleResponse :: new_canonical ( User :: from ( user) ) ) )
173
+ Ok ( (
174
+ StatusCode :: CREATED ,
175
+ Json ( SingleResponse :: new_canonical ( User :: from ( user) ) ) ,
176
+ ) )
174
177
}
175
178
176
179
#[ cfg( test) ]
@@ -194,7 +197,7 @@ mod tests {
194
197
} ) ) ;
195
198
196
199
let response = state. request ( request) . await ;
197
- response. assert_status ( StatusCode :: OK ) ;
200
+ response. assert_status ( StatusCode :: CREATED ) ;
198
201
199
202
let body: serde_json:: Value = response. json ( ) ;
200
203
assert_eq ! ( body[ "data" ] [ "type" ] , "user" ) ;
@@ -245,7 +248,7 @@ mod tests {
245
248
} ) ) ;
246
249
247
250
let response = state. request ( request) . await ;
248
- response. assert_status ( StatusCode :: OK ) ;
251
+ response. assert_status ( StatusCode :: CREATED ) ;
249
252
250
253
let body: serde_json:: Value = response. json ( ) ;
251
254
assert_eq ! ( body[ "data" ] [ "type" ] , "user" ) ;
@@ -296,7 +299,7 @@ mod tests {
296
299
} ) ) ;
297
300
298
301
let response = state. request ( request) . await ;
299
- response. assert_status ( StatusCode :: OK ) ;
302
+ response. assert_status ( StatusCode :: CREATED ) ;
300
303
301
304
let body: serde_json:: Value = response. json ( ) ;
302
305
let id = body[ "data" ] [ "id" ] . as_str ( ) . unwrap ( ) ;
0 commit comments