-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
커넥션풀 관련 설정 추가 + 회원탈퇴시 fk 관련 삭제 로직 추가 #784
Changes from 5 commits
983762e
d3a29da
ba0b65c
8bb0a9c
2abc0a6
21de272
f1aa59e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
package com.votogether.domain.member.service; | ||
|
||
import com.votogether.domain.alarm.entity.Alarm; | ||
import com.votogether.domain.alarm.entity.ReportActionAlarm; | ||
import com.votogether.domain.alarm.repository.AlarmRepository; | ||
import com.votogether.domain.alarm.repository.ReportActionAlarmRepository; | ||
import com.votogether.domain.member.dto.request.MemberDetailRequest; | ||
import com.votogether.domain.member.dto.response.MemberInfoResponse; | ||
import com.votogether.domain.member.entity.Member; | ||
|
@@ -12,6 +14,8 @@ | |
import com.votogether.domain.member.repository.MemberCategoryRepository; | ||
import com.votogether.domain.member.repository.MemberMetricRepository; | ||
import com.votogether.domain.member.repository.MemberRepository; | ||
import com.votogether.domain.notice.entity.Notice; | ||
import com.votogether.domain.notice.repository.NoticeRepository; | ||
import com.votogether.domain.post.entity.Post; | ||
import com.votogether.domain.post.entity.comment.Comment; | ||
import com.votogether.domain.post.repository.CommentRepository; | ||
|
@@ -43,6 +47,8 @@ public class MemberService { | |
private final ReportRepository reportRepository; | ||
private final CommentRepository commentRepository; | ||
private final AlarmRepository alarmRepository; | ||
private final ReportActionAlarmRepository reportActionAlarmRepository; | ||
private final NoticeRepository noticeRepository; | ||
|
||
@Transactional | ||
public Member register(final Member member) { | ||
|
@@ -120,6 +126,8 @@ public void deleteMember(final Member member) { | |
deleteMemberCategories(member); | ||
deleteReports(member, posts, comments); | ||
deleteAlarms(member); | ||
deleteReportActionAlarms(member); | ||
deleteNotices(member); | ||
|
||
memberMetricRepository.deleteByMember(member); | ||
memberRepository.delete(member); | ||
|
@@ -216,4 +224,20 @@ private void deleteAlarms(final Member member) { | |
alarmRepository.deleteAllById(alarmIds); | ||
} | ||
|
||
private void deleteReportActionAlarms(final Member member) { | ||
final List<Long> reportActionAlarmIds = reportActionAlarmRepository.findAllByMember(member) | ||
.stream() | ||
.map(ReportActionAlarm::getId) | ||
.toList(); | ||
reportActionAlarmRepository.deleteAllById(reportActionAlarmIds); | ||
} | ||
|
||
private void deleteNotices(final Member member) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 공지사항까지 챙겨주셔서 감사합니다 👍🏻 |
||
final List<Long> noticeIds = noticeRepository.findAllByMember(member) | ||
.stream() | ||
.map(Notice::getId) | ||
.toList(); | ||
noticeRepository.deleteAllById(noticeIds); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,10 @@ spring: | |
url: ${DATASOURCE_URL} | ||
username: ${DATASOURCE_USERNAME} | ||
password: ${DATASOURCE_PASSWORD} | ||
hikari: | ||
maximumPoolSize: ${MAXIMUM_POOL_SIZE} | ||
connectionTimeout: ${CONNECTION_TIMEOUT} | ||
maxLifetime: ${MAX_LIFETIME} | ||
Comment on lines
+7
to
+10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이외의 설정도 많았던 것 같은데 3개의 설정만 해주시는 이유가 있나요?! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 그 이외의 설정값들은 default값이여서 따로 설정은 하지 않았습니다! |
||
|
||
jpa: | ||
database-platform: org.hibernate.dialect.MySQLDialect | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,6 @@ | |
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import org.springframework.core.ParameterizedTypeReference; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.HttpStatus; | ||
|
||
|
@@ -90,12 +89,14 @@ void getReportAlarmActions() { | |
|
||
// when | ||
List<ReportActionAlarmResponse> results = RestAssuredMockMvc | ||
.given().log().all() | ||
.queryParam("page", 0) | ||
.when().get("/alarms/report?page=0") | ||
.then().log().all() | ||
.status(HttpStatus.OK) | ||
.extract() | ||
.as(new ParameterizedTypeReference<List<ReportActionAlarmResponse>>() { | ||
}.getType()); | ||
.as(new TypeRef<>() { | ||
}); | ||
Comment on lines
-97
to
+99
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 👍 |
||
|
||
// then | ||
assertThat(results.get(0)).isEqualTo(response); | ||
|
@@ -117,6 +118,7 @@ void getReportAlarmAction() { | |
|
||
// when | ||
ReportActionResponse result = RestAssuredMockMvc | ||
.given().log().all() | ||
.when().get("/alarms/report/{id}", 1) | ||
.then().log().all() | ||
.status(HttpStatus.OK) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,8 @@ | |
import static org.assertj.core.api.SoftAssertions.assertSoftly; | ||
import static org.junit.jupiter.api.Assertions.assertAll; | ||
|
||
import com.votogether.domain.alarm.entity.ReportActionAlarm; | ||
import com.votogether.domain.alarm.repository.ReportActionAlarmRepository; | ||
import com.votogether.domain.category.entity.Category; | ||
import com.votogether.domain.category.repository.CategoryRepository; | ||
import com.votogether.domain.member.dto.request.MemberDetailRequest; | ||
|
@@ -16,6 +18,8 @@ | |
import com.votogether.domain.member.repository.MemberCategoryRepository; | ||
import com.votogether.domain.member.repository.MemberMetricRepository; | ||
import com.votogether.domain.member.repository.MemberRepository; | ||
import com.votogether.domain.notice.entity.Notice; | ||
import com.votogether.domain.notice.repository.NoticeRepository; | ||
import com.votogether.domain.post.entity.Post; | ||
import com.votogether.domain.post.entity.comment.Comment; | ||
import com.votogether.domain.post.repository.CommentRepository; | ||
|
@@ -67,6 +71,12 @@ class MemberServiceTest extends ServiceTest { | |
@Autowired | ||
PostTestPersister postTestPersister; | ||
|
||
@Autowired | ||
ReportActionAlarmRepository reportActionAlarmRepository; | ||
|
||
@Autowired | ||
NoticeRepository noticeRepository; | ||
|
||
@Autowired | ||
EntityManager em; | ||
|
||
|
@@ -481,6 +491,55 @@ void deleteWithReportedNickname() { | |
); | ||
} | ||
|
||
@Test | ||
@DisplayName("회원과 신고조치알림 모두 삭제된다.") | ||
void deleteWithReportActionAlarms() { | ||
// given | ||
Member member = memberRepository.save(MemberFixtures.MALE_20.get()); | ||
|
||
ReportActionAlarm reportActionAlarm = ReportActionAlarm.builder() | ||
.reportType(ReportType.POST) | ||
.member(member) | ||
.isChecked(false) | ||
.target("1") | ||
.reasons("광고성, 부적합성") | ||
.build(); | ||
reportActionAlarmRepository.save(reportActionAlarm); | ||
|
||
// when | ||
memberService.deleteMember(member); | ||
|
||
// then | ||
assertAll( | ||
() -> assertThat(memberRepository.findAll()).isEmpty(), | ||
() -> assertThat(reportActionAlarmRepository.findAll()).isEmpty() | ||
); | ||
Comment on lines
+513
to
+516
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. assertAll 대신 assertSoftly 써보는 것은 어떨까요. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 네 수정하도록 할께요~ |
||
} | ||
|
||
@Test | ||
@DisplayName("회원과 작성한 공지사항 모두 삭제된다.") | ||
void deleteWithNotices() { | ||
// given | ||
Member member = memberRepository.save(MemberFixtures.MALE_20.get()); | ||
|
||
Notice notice = Notice.builder() | ||
.member(member) | ||
.title("title") | ||
.content("content") | ||
.deadline(LocalDateTime.now().plusDays(1)) | ||
.build(); | ||
noticeRepository.save(notice); | ||
|
||
// when | ||
memberService.deleteMember(member); | ||
|
||
// then | ||
assertAll( | ||
() -> assertThat(memberRepository.findAll()).isEmpty(), | ||
() -> assertThat(noticeRepository.findAll()).isEmpty() | ||
); | ||
} | ||
|
||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
인덱스를 탈 수 있는 ID를 정렬에 사용하는게 좋을 것 같아요 :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
무슨말씀인지 잘 이해가 안되요 ㅠ
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
auto increment 전략을 사용하고 있기에 id순이 생성순과 동일하고, id에는 PK 인덱스가 걸려있지만, createdAt에는 인덱스가 걸려있지 않아 인덱스가 걸려있는 id를 사용하는게 좋을 것 같다는 의견이었습니다 !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
아하 어차피 id로 최신순으로 이미 정렬이 가능하니 id로 가져온다는 말씀이군요! 수정해보겠습니다!