Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected void doFilterInternal(HttpServletRequest request,
if (token != null && jwtUtil.isTokenValid(token)) {
String email = jwtUtil.getEmailFromToken(token);
Member member = memberRepository.findByEmail(email)
.orElseThrow(() -> new CustomException(ErrorCode.MEMBER_NOT_FOUND));
.orElseThrow(() -> new CustomException(ErrorCode.USER_NICKNAME_NOT_FOUND));

Authentication auth = new UsernamePasswordAuthenticationToken(member, null, member.getAuthorities());
SecurityContextHolder.getContext().setAuthentication(auth);
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/example/FixLog/config/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http
.csrf(csrf -> csrf.disable())
.authorizeHttpRequests(auth -> auth
.requestMatchers(HttpMethod.POST, "/api/members/signup").permitAll()
.requestMatchers(HttpMethod.POST, "/api/auth/login").permitAll()
.requestMatchers(HttpMethod.GET, "/api/members/check-email").permitAll()
.requestMatchers(HttpMethod.GET, "/api/members/check-nickname").permitAll()
.requestMatchers(HttpMethod.POST, "/members/signup").permitAll()
.requestMatchers(HttpMethod.POST, "/auth/login").permitAll()
.requestMatchers(HttpMethod.GET, "/members/check-email").permitAll()
.requestMatchers(HttpMethod.GET, "/members/check-nickname").permitAll()
.requestMatchers(HttpMethod.GET, "/h2-console/**").permitAll()
.anyRequest().authenticated()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/auth")
@RequestMapping("/auth")
@RequiredArgsConstructor
public class AuthController {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.example.FixLog.controller;


import com.example.FixLog.domain.member.Member;
import com.example.FixLog.dto.Response;
import com.example.FixLog.dto.member.MemberInfoResponseDto;
Expand All @@ -13,7 +12,7 @@
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/members")
@RequestMapping("/members")
@RequiredArgsConstructor
public class MemberController {

Expand Down Expand Up @@ -50,4 +49,10 @@ public ResponseEntity<Response<MemberInfoResponseDto>> getMyInfo(@Authentication
);
return ResponseEntity.ok(Response.success("회원 정보 조회 성공", responseDto));
}
}

@DeleteMapping("/me")
public ResponseEntity<Response<Void>> withdraw(@AuthenticationPrincipal Member member) {
memberService.withdraw(member);
return ResponseEntity.ok(Response.success("회원 탈퇴 성공", null));
}
}
4 changes: 4 additions & 0 deletions src/main/java/com/example/FixLog/domain/member/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ public class Member implements UserDetails {
@Column(nullable = false)
private Boolean isDeleted = false;

public void setIsDeleted(boolean isDeleted) {
this.isDeleted = isDeleted;
}

@Enumerated(EnumType.STRING)
@Column(nullable = false)
private SocialType socialType = SocialType.EMAIL;
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/com/example/FixLog/exception/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
@Getter
@AllArgsConstructor
public enum ErrorCode {
USER_ID_NOT_FOUND(HttpStatus.NOT_FOUND,"존재하지 않는 사용자 아이디입니다."),
USER_NICKNAME_NOT_FOUND(HttpStatus.NOT_FOUND,"존재하지 않는 사용자 아이디입니다."),
USER_EMAIL_NOT_FOUND(HttpStatus.NOT_FOUND, "회원 이메일을 찾을 수 없습니다."),
EMAIL_DUPLICATED(HttpStatus.CONFLICT, "중복된 이메일입니다"),
NICKNAME_DUPLICATED(HttpStatus.CONFLICT, "중복된 닉네임입니다"),
Expand All @@ -22,8 +22,7 @@ public enum ErrorCode {
ACCESS_DENIED(HttpStatus.FORBIDDEN, "권한이 없습니다."),
TAG_NOT_FOUND(HttpStatus.NOT_FOUND, "없는 태그 번호입니다."),
SORT_NOT_EXIST(HttpStatus.BAD_REQUEST, "사용할 수 없는 정렬입니다."),
INVALID_PASSWORD(HttpStatus.UNAUTHORIZED, "비밀번호가 일치하지 않습니다."),
MEMBER_NOT_FOUND(HttpStatus.NOT_FOUND, "존재하지 않는 사용자입니다.");
INVALID_PASSWORD(HttpStatus.UNAUTHORIZED, "비밀번호가 일치하지 않습니다.");

private final HttpStatus status;
private final String message;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/example/FixLog/service/AuthService.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class AuthService {

public LoginResponseDto login(LoginRequestDto requestDto) {
Member member = memberRepository.findByEmail(requestDto.getEmail())
.orElseThrow(() -> new CustomException(ErrorCode.MEMBER_NOT_FOUND));
.orElseThrow(() -> new CustomException(ErrorCode.USER_NICKNAME_NOT_FOUND));

if (!passwordEncoder.matches(requestDto.getPassword(), member.getPassword())) {
throw new CustomException(ErrorCode.INVALID_PASSWORD);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/example/FixLog/service/FollowService.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public FollowResponseDto follow(String requesterEmail, Long targetMemberId){
Member follower = memberRepository.findByEmail(requesterEmail)
.orElseThrow(() -> new CustomException(ErrorCode.USER_EMAIL_NOT_FOUND));
Member following = memberRepository.findById(targetMemberId)
.orElseThrow(() -> new CustomException(ErrorCode.USER_ID_NOT_FOUND));
.orElseThrow(() -> new CustomException(ErrorCode.USER_NICKNAME_NOT_FOUND));

// 자기 자신은 팔로우 불가
if (follower.getUserId().equals(following.getUserId())) {
Expand All @@ -53,7 +53,7 @@ public void unfollow(String requesterEmail, Long targetMemberId) {
.orElseThrow(() -> new CustomException(ErrorCode.USER_EMAIL_NOT_FOUND));

Member following = memberRepository.findById(targetMemberId)
.orElseThrow(() -> new CustomException(ErrorCode.USER_ID_NOT_FOUND));
.orElseThrow(() -> new CustomException(ErrorCode.USER_NICKNAME_NOT_FOUND));

// 자기 자신은 팔로우 불가
if (follower.getUserId().equals(following.getUserId())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public MainPageService(MemberRepository memberRepository, PostRepository postRep
// 회원 정보 불러오기
public Member getMemberOrThrow(Long userId) {
return memberRepository.findById(userId)
.orElseThrow(() -> new CustomException(ErrorCode.USER_ID_NOT_FOUND));
.orElseThrow(() -> new CustomException(ErrorCode.USER_NICKNAME_NOT_FOUND));
}

// 이미지 null일 때 default 사진으로 변경 (프로필 사진,
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/example/FixLog/service/MemberService.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,11 @@ public boolean isEmailDuplicated(String email) {
public boolean isNicknameDuplicated(String nickname) {
return memberRepository.findByNickname(nickname).isPresent();
}

// 회원탈퇴
public void withdraw(Member member) {
member.setIsDeleted(true);
memberRepository.save(member);
}
}

2 changes: 1 addition & 1 deletion src/main/java/com/example/FixLog/service/PostService.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public PostService(PostRepository postRepository, MemberRepository memberReposit
// 회원 정보 불러오기
public Member getMemberOrThrow(Long userId) {
return memberRepository.findById(userId)
.orElseThrow(() -> new CustomException(ErrorCode.USER_ID_NOT_FOUND));
.orElseThrow(() -> new CustomException(ErrorCode.USER_NICKNAME_NOT_FOUND));
}

// 이미지 null일 때 default 사진으로 변경 (프로필 사진,
Expand Down