-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement fetching wedding basic details and user logout
- Loading branch information
1 parent
5329b37
commit c2ee2b9
Showing
56 changed files
with
1,056 additions
and
411 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,5 @@ | |
*.g.* | ||
*.freezed.* | ||
*.mocks.* | ||
|
||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,49 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:core/models/auth/dta_user.dart'; | ||
import 'package:dart_frog/dart_frog.dart'; | ||
|
||
import '../../src/utils/custom_errors.dart'; | ||
import '../../src/utils/extensions.dart'; | ||
import '../../src/utils/utils.dart'; | ||
|
||
Future<Response> onRequest(RequestContext context) async { | ||
if (!context.isGetRequest) { | ||
return Response( | ||
statusCode: HttpStatus.badRequest, | ||
body: 'This endpoint only supports GET requests!', | ||
); | ||
} | ||
|
||
try { | ||
final user = await context.userFromJWT; | ||
if (user == null) throw JWTException('Invalid token!'); | ||
|
||
return Response.json( | ||
body: user.copyWith( | ||
hashedPassword: null, | ||
passwordSalt: null, | ||
), | ||
); | ||
} catch (e) { | ||
if (e is JWTException) { | ||
Future<Response> onRequest(RequestContext context) { | ||
return protected( | ||
context, | ||
body: (userFromJWT) async { | ||
return await context.onRequestMethod( | ||
get: () async { | ||
return Response.json( | ||
body: userFromJWT?.copyWith( | ||
hashedPassword: null, | ||
passwordSalt: null, | ||
), | ||
); | ||
}, | ||
patch: () async { | ||
final userRepo = await context.injectUserRepository(); | ||
final rawUser = await context.request.bodyAsMap; | ||
final user = DTAUser.fromJson(rawUser); | ||
final success = await userRepo.upsertUser(user); | ||
return Response( | ||
statusCode: success ? HttpStatus.ok : HttpStatus.expectationFailed, | ||
body: success | ||
? null | ||
: 'Could not update user! Please check your input(s) or try ' | ||
'again later.', | ||
); | ||
}, | ||
orElse: () => Response( | ||
statusCode: HttpStatus.badRequest, | ||
body: 'This endpoint only supports GET and PATCH requests!', | ||
), | ||
); | ||
}, | ||
onError: (e, st) { | ||
return Response( | ||
statusCode: HttpStatus.unauthorized, | ||
body: 'Your access token is either invalid or expired! Please make ' | ||
'sure to use a valid token.', | ||
statusCode: HttpStatus.internalServerError, | ||
body: 'The server is facing some issues in addressing your request at ' | ||
'the moment. Please try again later.', | ||
); | ||
} | ||
return Response( | ||
statusCode: HttpStatus.internalServerError, | ||
body: 'The server is facing some issues in addressing your request at ' | ||
'the moment. Please try again later.', | ||
); | ||
} | ||
}, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.