From 945264cd446e699602e6274722389bd71543bf4a Mon Sep 17 00:00:00 2001 From: HiSeungmin Date: Wed, 8 Jan 2025 16:42:09 +0900 Subject: [PATCH] =?UTF-8?q?Chore:=20Member=20Controller=20=EB=B0=98?= =?UTF-8?q?=ED=99=98=20=ED=83=80=EC=9E=85=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/controller/MemberController.java | 52 +++++++++++++------ .../devlens/global/response/ErrorCode.java | 2 + 2 files changed, 37 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/seveneleven/devlens/domain/member/controller/MemberController.java b/src/main/java/com/seveneleven/devlens/domain/member/controller/MemberController.java index 60abae70..cc55b784 100644 --- a/src/main/java/com/seveneleven/devlens/domain/member/controller/MemberController.java +++ b/src/main/java/com/seveneleven/devlens/domain/member/controller/MemberController.java @@ -1,5 +1,6 @@ package com.seveneleven.devlens.domain.member.controller; +import com.seveneleven.devlens.domain.admin.dto.CompanyDto; import com.seveneleven.devlens.domain.member.dto.MemberJoinDto; import com.seveneleven.devlens.domain.member.dto.TokenDto; import com.seveneleven.devlens.domain.member.entity.Member; @@ -8,6 +9,11 @@ import com.seveneleven.devlens.global.config.Annotation.UserAuthorize; import com.seveneleven.devlens.global.config.JwtFilter; import com.seveneleven.devlens.global.config.TokenProvider; +import com.seveneleven.devlens.global.exception.BusinessException; +import com.seveneleven.devlens.global.response.APIResponse; +import com.seveneleven.devlens.global.response.ErrorCode; +import com.seveneleven.devlens.global.response.SuccessCode; +import jakarta.servlet.http.HttpServletResponse; import lombok.AllArgsConstructor; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; @@ -31,12 +37,13 @@ public class MemberController { private final AuthenticationManagerBuilder authenticationManagerBuilder; private final MemberService memberService; + @PostMapping("/login") - public ResponseEntity login(MemberJoinDto dto) { + public ResponseEntity> login(MemberJoinDto dto) { Member member = memberService.getUserWithAuthorities(dto.getUserid()).get(); - if (ObjectUtils.isEmpty(member)) { + if (!ObjectUtils.isEmpty(member)) { UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(dto.getUserid(), dto.getPw()); @@ -51,31 +58,42 @@ public ResponseEntity login(MemberJoinDto dto) { // response header에 jwt token에 넣어줌 httpHeaders.add(JwtFilter.AUTHORIZATION_HEADER, "Bearer " + jwt); + // tokenDto를 이용해 response body에도 넣어서 리턴 - return new ResponseEntity<>(new TokenDto(jwt), httpHeaders, HttpStatus.OK); + // return new ResponseEntity<>(new TokenDto(jwt), httpHeaders, HttpStatus.OK); + + + return ResponseEntity.status(SuccessCode.OK.getStatus()) + .headers(httpHeaders) // 헤더 추가 + .build(); // APIResponse 반환 + } - return new ResponseEntity<>(HttpStatus.BAD_REQUEST); + throw new BusinessException(ErrorCode.USER_NOT_FOUND); } @PostMapping("/join") - public ResponseEntity join(@RequestBody MemberJoinDto dto) { + public ResponseEntity> join(@RequestBody MemberJoinDto dto) { try { // memberService.join(dto.getUserid(), dto.getPw()); - return ResponseEntity.ok("join success"); + return ResponseEntity.status(SuccessCode.OK.getStatus()) + .body(APIResponse.success(SuccessCode.OK)); } catch (Exception e) { - return ResponseEntity.badRequest().body(e.getMessage()); + throw new BusinessException(ErrorCode.DUPLICATE_USER_ID); } } - @GetMapping("/setting/admin") - @AdminAuthorize - public String adminSettingPage() { - return "admin_setting"; - } - @GetMapping("/setting/user") - @UserAuthorize - public String userSettingPage() { - return "user_setting"; - } + // 테스트용 입니다. (삭제 예정) + +// @GetMapping("/setting/admin") +// @AdminAuthorize +// public String adminSettingPage() { +// return "admin_setting"; +// } +// +// @GetMapping("/setting/user") +// @UserAuthorize +// public String userSettingPage() { +// return "user_setting"; +// } } \ No newline at end of file diff --git a/src/main/java/com/seveneleven/devlens/global/response/ErrorCode.java b/src/main/java/com/seveneleven/devlens/global/response/ErrorCode.java index 3f3c509d..579be95c 100644 --- a/src/main/java/com/seveneleven/devlens/global/response/ErrorCode.java +++ b/src/main/java/com/seveneleven/devlens/global/response/ErrorCode.java @@ -14,6 +14,8 @@ public enum ErrorCode { NOT_FOUND_TOKEN(1002, HttpStatus.INTERNAL_SERVER_ERROR, "유효하지 않은 JWT 토큰입니다."), EXPIRED_TOKEN(1003, HttpStatus.INTERNAL_SERVER_ERROR, "만료된 JWT 토큰입니다."), JWT_FILTER_ERROR(1004, HttpStatus.INTERNAL_SERVER_ERROR, "필터 처리 중 예외가 발생했습니다."), + DUPLICATE_USER_ID(1005, HttpStatus.BAD_REQUEST,"이미 존재하는 ID 입니다."), + USER_NOT_FOUND(1006, HttpStatus.BAD_REQUEST,"존재하지 않는 사용자입니다."), COMPANY_DUPLICATED_NUMBER(1051, HttpStatus.BAD_REQUEST,"이미 등록된 회사입니다."), COMPANY_IS_DEACTIVATED(1052, HttpStatus.BAD_REQUEST,"비활성화된 회사 정보입니다."),