Files
YouAndMe/src/main/java/com/yam/app/account/presentation/AccountQueryApi.java
JiwonDev d3ff00e167 ADD session maintaining
- @LoginAccount 파라메타를 command 객체로 바꾸는 ArgumentResolver 추가
- .editorconfig 에서 로그파일 (app.log)를 무시하도록 설정 추가
2021-09-14 09:16:46 +09:00

53 lines
1.9 KiB
Java

package com.yam.app.account.presentation;
import com.yam.app.account.application.AccountFacade;
import javax.validation.Valid;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping(
produces = MediaType.APPLICATION_JSON_VALUE,
consumes = MediaType.APPLICATION_JSON_VALUE
)
public final class AccountQueryApi {
private final AccountFacade accountFacade;
public AccountQueryApi(AccountFacade accountFacade) {
this.accountFacade = accountFacade;
}
@PostMapping("/api/accounts/login")
public ResponseEntity<Void> login(
@Valid @RequestBody LoginAccountRequestCommand request) {
try {
accountFacade.login(request);
} catch (IllegalStateException e) {
return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
}
LoginSessionUtils.setLoginAccountEmail(request.getEmail());
return ResponseEntity.ok().build();
}
@GetMapping("/api/accounts/me")
public ResponseEntity<AccountResponse> getAccount(
@LoginAccount GetSessionAccountCommand request) {
return ResponseEntity.ok(accountFacade.getSessionAccount(request));
}
// LoginAccountMethodArgumentResolver 테스트를 위해 임시로 만든 @ExceptionHandler
@ExceptionHandler
public ResponseEntity<Void> defaultException(IllegalStateException e) {
return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
}
}