Skip to content

Commit bd2923e

Browse files
johnhuh619garusitellgunwoong1630
authored andcommitted
feat: member delete (#58)
* fix: 멤버 삭제 구현 * feat: 멤버 삭제, 위/경도 수정 구현 * test: 테스트 수정 * Delete src/main/java/sevenstar/marineleisure/meeting/repository/MemberRepository.java * Delete src/main/java/sevenstar/marineleisure/meeting/repository/OutdoorSpotSpotRepository.java * Delete src/main/resources/test.http --------- Co-authored-by: LEESUNBIN <[email protected]> Co-authored-by: Gunwoong cho <[email protected]>
1 parent afd564a commit bd2923e

File tree

15 files changed

+613
-28
lines changed

15 files changed

+613
-28
lines changed

src/main/java/sevenstar/marineleisure/meeting/repository/MeetingRepository.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package sevenstar.marineleisure.meeting.repository;
22

33
import java.time.LocalDateTime;
4+
import java.util.List;
45

56
import org.springframework.data.domain.Pageable;
67
import org.springframework.data.domain.Slice;
@@ -29,6 +30,9 @@ public interface MeetingRepository extends JpaRepository<Meeting, Long> {
2930
@Query("SELECT COUNT(m) FROM Meeting m WHERE m.hostId = :memberId")
3031
Long countMyMeetingsByMemberId(@Param("memberId") Long memberId);
3132

33+
@Query("SELECT m FROM Meeting m WHERE m.hostId = :memberId")
34+
List<Meeting> findByHostId(@Param("memberId") Long memberId);
35+
3236

3337

3438

src/main/java/sevenstar/marineleisure/meeting/repository/ParticipantRepository.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,7 @@ public interface ParticipantRepository extends JpaRepository<Participant, Long>
2323

2424
boolean existsByUserId(Long userId);
2525

26-
boolean existsByMeetingIdAndMeetingId(Long meetingId, Long memberId);
26+
boolean existsByMeetingIdAndMemberId(Long meetingId, Long memberId);
27+
28+
List<Participant> findByMemberId(Long memberId);
2729
}

src/main/java/sevenstar/marineleisure/meeting/service/MeetingServiceImpl.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
package sevenstar.marineleisure.meeting.service;
22

3-
4-
5-
63
import java.util.List;
74
import java.util.Map;
85
import java.util.stream.Collectors;
@@ -16,18 +13,18 @@
1613
import lombok.RequiredArgsConstructor;
1714
import sevenstar.marineleisure.global.enums.MeetingRole;
1815
import sevenstar.marineleisure.global.enums.MeetingStatus;
16+
import sevenstar.marineleisure.meeting.repository.ParticipantRepository;
17+
import sevenstar.marineleisure.meeting.domain.Meeting;
18+
import sevenstar.marineleisure.meeting.domain.Participant;
19+
import sevenstar.marineleisure.meeting.domain.Tag;
20+
import sevenstar.marineleisure.meeting.dto.mapper.MeetingMapper;
1921
import sevenstar.marineleisure.meeting.dto.request.CreateMeetingRequest;
2022
import sevenstar.marineleisure.meeting.dto.request.UpdateMeetingRequest;
2123
import sevenstar.marineleisure.meeting.dto.response.MeetingDetailAndMemberResponse;
2224
import sevenstar.marineleisure.meeting.dto.response.MeetingDetailResponse;
2325
import sevenstar.marineleisure.meeting.dto.response.ParticipantResponse;
24-
import sevenstar.marineleisure.meeting.dto.mapper.MeetingMapper;
2526
import sevenstar.marineleisure.meeting.repository.MeetingRepository;
26-
import sevenstar.marineleisure.meeting.repository.ParticipantRepository;
2727
import sevenstar.marineleisure.meeting.repository.TagRepository;
28-
import sevenstar.marineleisure.meeting.domain.Meeting;
29-
import sevenstar.marineleisure.meeting.domain.Participant;
30-
import sevenstar.marineleisure.meeting.domain.Tag;
3128
import sevenstar.marineleisure.meeting.validate.MeetingValidate;
3229
import sevenstar.marineleisure.meeting.validate.MemberValidate;
3330
import sevenstar.marineleisure.meeting.validate.ParticipantValidate;

src/main/java/sevenstar/marineleisure/member/controller/MemberController.java

Lines changed: 84 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
import lombok.extern.slf4j.Slf4j;
55

66
import org.springframework.http.ResponseEntity;
7-
import org.springframework.web.bind.annotation.GetMapping;
8-
import org.springframework.web.bind.annotation.RequestMapping;
9-
import org.springframework.web.bind.annotation.RestController;
7+
import org.springframework.web.bind.annotation.*;
108

119
import sevenstar.marineleisure.global.domain.BaseResponse;
1210
import sevenstar.marineleisure.global.util.CurrentUserUtil;
1311
import sevenstar.marineleisure.member.dto.MemberDetailResponse;
12+
import sevenstar.marineleisure.member.dto.MemberLocationUpdateRequest;
13+
import sevenstar.marineleisure.member.dto.MemberNicknameUpdateRequest;
14+
import sevenstar.marineleisure.member.dto.MemberStatusUpdateRequest;
1415
import sevenstar.marineleisure.member.service.MemberService;
1516

1617
/**
@@ -41,4 +42,84 @@ public ResponseEntity<BaseResponse<MemberDetailResponse>> getCurrentMemberDetail
4142

4243
return BaseResponse.success(memberDetail);
4344
}
45+
46+
/**
47+
* 현재 로그인한 회원의 닉네임을 업데이트합니다.
48+
*
49+
* @param request 닉네임 업데이트 요청 DTO
50+
* @return 업데이트된 회원 상세 정보 응답
51+
*/
52+
@PutMapping("/me")
53+
public ResponseEntity<BaseResponse<MemberDetailResponse>> updateMemberNickname(
54+
@RequestBody MemberNicknameUpdateRequest request) {
55+
log.info("회원 닉네임 업데이트 요청: {}", request.getNickname());
56+
57+
// 현재 인증된 사용자의 ID 가져오기
58+
Long currentUserId = CurrentUserUtil.getCurrentUserId();
59+
60+
// 닉네임 업데이트
61+
MemberDetailResponse updatedMember = memberService.updateMemberNickname(currentUserId, request.getNickname());
62+
63+
return BaseResponse.success(updatedMember);
64+
}
65+
66+
/**
67+
* 현재 로그인한 회원의 위치 정보를 업데이트합니다.
68+
*
69+
* @param request 위치 정보 업데이트 요청 DTO
70+
* @return 업데이트된 회원 상세 정보 응답
71+
*/
72+
@PutMapping("/me/location")
73+
public ResponseEntity<BaseResponse<MemberDetailResponse>> updateMemberLocation(
74+
@RequestBody MemberLocationUpdateRequest request) {
75+
log.info("회원 위치 정보 업데이트 요청: latitude={}, longitude={}",
76+
request.getLatitude(), request.getLongitude());
77+
78+
// 현재 인증된 사용자의 ID 가져오기
79+
Long currentUserId = CurrentUserUtil.getCurrentUserId();
80+
81+
// 위치 정보 업데이트
82+
MemberDetailResponse updatedMember = memberService.updateMemberLocation(
83+
currentUserId, request.getLatitude(), request.getLongitude());
84+
85+
return BaseResponse.success(updatedMember);
86+
}
87+
88+
/**
89+
* 현재 로그인한 회원의 상태를 업데이트합니다.
90+
*
91+
* @param request 상태 업데이트 요청 DTO
92+
* @return 업데이트된 회원 상세 정보 응답
93+
*/
94+
@PatchMapping("/me/status")
95+
public ResponseEntity<BaseResponse<MemberDetailResponse>> updateMemberStatus(
96+
@RequestBody MemberStatusUpdateRequest request) {
97+
log.info("회원 상태 업데이트 요청: {}", request.getStatus());
98+
99+
// 현재 인증된 사용자의 ID 가져오기
100+
Long currentUserId = CurrentUserUtil.getCurrentUserId();
101+
102+
// 상태 업데이트
103+
MemberDetailResponse updatedMember = memberService.updateMemberStatus(
104+
currentUserId, request.getStatus());
105+
106+
return BaseResponse.success(updatedMember);
107+
}
108+
109+
/**
110+
* 현재 로그인한 회원을 소프트 삭제합니다 (상태를 EXPIRED로 변경).
111+
* 액세스 토큰을 통해 인증된 사용자만 자신의 계정을 삭제할 수 있습니다.
112+
*
113+
* @return 삭제 성공 메시지
114+
*/
115+
@PostMapping("/delete")
116+
public ResponseEntity<BaseResponse<String>> deleteMember() {
117+
// 현재 인증된 사용자의 ID 가져오기
118+
Long currentUserId = CurrentUserUtil.getCurrentUserId();
119+
log.info("회원 소프트 삭제 요청: 현재 인증된 사용자 ID={}", currentUserId);
120+
121+
memberService.deleteMember(currentUserId);
122+
123+
return BaseResponse.success("회원이 성공적으로 삭제되었습니다.");
124+
}
44125
}

src/main/java/sevenstar/marineleisure/member/domain/Member.java

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,35 @@ public Member(String nickname, String email, String provider, String providerId,
5555
this.longitude = longitude;
5656
}
5757

58-
public Member update(String nickname) {
59-
this.nickname = nickname;
60-
return this;
61-
}
6258
public void updateNickname(String newNickname) {
6359
if (!Objects.equals(this.nickname, newNickname)) {
6460
this.nickname = newNickname;
6561
}
6662
}
67-
}
63+
64+
/**
65+
* 회원의 상태를 업데이트합니다.
66+
*
67+
* @param newStatus 새 상태
68+
*/
69+
public void updateStatus(MemberStatus newStatus) {
70+
if (this.status != newStatus) {
71+
this.status = newStatus;
72+
}
73+
}
74+
75+
/**
76+
* 회원의 위치 정보를 업데이트합니다.
77+
*
78+
* @param newLatitude 새 위도
79+
* @param newLongitude 새 경도
80+
*/
81+
public void updateLocation(BigDecimal newLatitude, BigDecimal newLongitude) {
82+
if (newLatitude != null && (this.latitude == null || !this.latitude.equals(newLatitude))) {
83+
this.latitude = newLatitude;
84+
}
85+
if (newLongitude != null && (this.longitude == null || !this.longitude.equals(newLongitude))) {
86+
this.longitude = newLongitude;
87+
}
88+
}
89+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package sevenstar.marineleisure.member.dto;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Getter;
5+
import lombok.NoArgsConstructor;
6+
7+
import java.math.BigDecimal;
8+
9+
/**
10+
* 회원 위치 정보 업데이트 요청 DTO
11+
*/
12+
@Getter
13+
@NoArgsConstructor
14+
@AllArgsConstructor
15+
public class MemberLocationUpdateRequest {
16+
private BigDecimal latitude;
17+
private BigDecimal longitude;
18+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package sevenstar.marineleisure.member.dto;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Getter;
5+
import lombok.NoArgsConstructor;
6+
7+
/**
8+
* 회원 닉네임 업데이트 요청 DTO
9+
*/
10+
@Getter
11+
@NoArgsConstructor
12+
@AllArgsConstructor
13+
public class MemberNicknameUpdateRequest {
14+
private String nickname;
15+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package sevenstar.marineleisure.member.dto;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Getter;
5+
import lombok.NoArgsConstructor;
6+
7+
import sevenstar.marineleisure.global.enums.MemberStatus;
8+
9+
/**
10+
* 회원 상태 업데이트 요청 DTO
11+
*/
12+
@Getter
13+
@NoArgsConstructor
14+
@AllArgsConstructor
15+
public class MemberStatusUpdateRequest {
16+
private MemberStatus status;
17+
}
Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,27 @@
11
package sevenstar.marineleisure.member.repository;
22

33
import org.springframework.data.jpa.repository.JpaRepository;
4+
import org.springframework.data.jpa.repository.Modifying;
5+
import org.springframework.data.jpa.repository.Query;
6+
import org.springframework.data.repository.query.Param;
47
import org.springframework.stereotype.Repository;
58

9+
import sevenstar.marineleisure.global.enums.MemberStatus;
610
import sevenstar.marineleisure.member.domain.Member;
711

12+
import java.time.LocalDateTime;
813
import java.util.Optional;
914
@Repository
1015
public interface MemberRepository extends JpaRepository<Member, Long> {
1116
// Optional<Member> findByUserNickname(String username);
1217
Optional<Member> findByProviderAndProviderId(String provider, String providerId);
1318

14-
boolean existsById(Long id);
19+
@Modifying(flushAutomatically = true, clearAutomatically = true)
20+
@Query("""
21+
DELETE FROM Member m
22+
WHERE m.status = :status
23+
AND m.updatedAt < :expired
24+
""")
25+
int deleteByStatusAndUpdatedAtBefore(@Param("status") MemberStatus memberStatus,
26+
@Param("expired") LocalDateTime expired);
1527
}

0 commit comments

Comments
 (0)