-
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 #31 from cearps/feature/api-features
API features
- Loading branch information
Showing
4 changed files
with
42 additions
and
5 deletions.
There are no files selected for viewing
8 changes: 4 additions & 4 deletions
8
api/src/main/java/com/backend/backend/controller/AuthenticationController.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
27 changes: 27 additions & 0 deletions
27
api/src/main/java/com/backend/backend/controller/UserController.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,27 @@ | ||
package com.backend.backend.controller; | ||
|
||
import com.backend.backend.dto.CurrentUserDto; | ||
import com.backend.backend.model.User; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.security.core.Authentication; | ||
import org.springframework.security.core.context.SecurityContextHolder; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RequestMapping("/user") | ||
@RestController | ||
public class UserController { | ||
|
||
@GetMapping("/me") | ||
public ResponseEntity<CurrentUserDto> getCurrentUser() { | ||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); | ||
User currentUser = (User) authentication.getPrincipal(); | ||
CurrentUserDto response = new CurrentUserDto(); | ||
response.setEmail(currentUser.getEmail()); | ||
response.setFullName(currentUser.getFullName()); | ||
response.setId(currentUser.getId()); | ||
return ResponseEntity.ok(response); | ||
} | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
api/src/main/java/com/backend/backend/dto/CurrentUserDto.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,10 @@ | ||
package com.backend.backend.dto; | ||
|
||
import lombok.Data; | ||
|
||
@Data | ||
public class CurrentUserDto { | ||
private Long id; | ||
private String email; | ||
private String fullName; | ||
} |
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