-
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.
Merge pull request #16 from volo-db/15-add-user-endpoint
feat: add new user endpoint
- Loading branch information
Showing
12 changed files
with
209 additions
and
213 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
16 changes: 0 additions & 16 deletions
16
src/main/java/dev/urner/volodb/rest/ContractErrorResponse.java
This file was deleted.
Oops, something went wrong.
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
16 changes: 0 additions & 16 deletions
16
src/main/java/dev/urner/volodb/rest/ProjectErrorResponse.java
This file was deleted.
Oops, something went wrong.
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
48 changes: 48 additions & 0 deletions
48
src/main/java/dev/urner/volodb/rest/UserRestController.java
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package dev.urner.volodb.rest; | ||
|
||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import dev.urner.volodb.entity.User; | ||
import dev.urner.volodb.entity.UserNotFoundException; | ||
import dev.urner.volodb.security.UserPrincipal; | ||
import dev.urner.volodb.service.UserService; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
|
||
@RestController | ||
@RequestMapping("/user") | ||
@RequiredArgsConstructor | ||
public class UserRestController { | ||
|
||
private final UserService userService; | ||
|
||
@GetMapping() | ||
public User getUser(@AuthenticationPrincipal UserPrincipal principal) { | ||
User theUser = userService.findByUsername(principal.getUsername()); | ||
|
||
if (theUser == null) { | ||
throw new UserNotFoundException("Username not found - " + principal.getUsername()); | ||
} | ||
|
||
return theUser; | ||
} | ||
|
||
@ExceptionHandler | ||
public ResponseEntity<VolodbErrorResponse> handleException(UserNotFoundException exc) { | ||
HttpStatus httpStatus = HttpStatus.NOT_FOUND; | ||
|
||
VolodbErrorResponse error = new VolodbErrorResponse( | ||
httpStatus.value(), | ||
exc.getMessage(), | ||
System.currentTimeMillis()); | ||
|
||
return new ResponseEntity<>(error, httpStatus); | ||
} | ||
|
||
} |
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
16 changes: 0 additions & 16 deletions
16
src/main/java/dev/urner/volodb/rest/VolunteerErrorResponse.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.