Skip to content

Commit

Permalink
Chore: Member Controller 반환 타입 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
HiSeungmin committed Jan 8, 2025
1 parent 587293f commit 945264c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -31,12 +37,13 @@ public class MemberController {
private final AuthenticationManagerBuilder authenticationManagerBuilder;
private final MemberService memberService;


@PostMapping("/login")
public ResponseEntity<?> login(MemberJoinDto dto) {
public ResponseEntity<APIResponse<SuccessCode>> 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());
Expand All @@ -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<String> join(@RequestBody MemberJoinDto dto) {
public ResponseEntity<APIResponse<SuccessCode>> 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";
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,"비활성화된 회사 정보입니다."),
Expand Down

0 comments on commit 945264c

Please sign in to comment.