diff --git a/backend/src/main/java/com/votogether/domain/alarm/controller/AlarmCommandControllerDocs.java b/backend/src/main/java/com/votogether/domain/alarm/controller/AlarmCommandControllerDocs.java deleted file mode 100644 index 73b80eab5..000000000 --- a/backend/src/main/java/com/votogether/domain/alarm/controller/AlarmCommandControllerDocs.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.votogether.domain.alarm.controller; - -import com.votogether.domain.alarm.dto.ReportActionAlarmResponse; -import com.votogether.domain.alarm.dto.ReportActionResponse; -import com.votogether.domain.member.entity.Member; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.responses.ApiResponse; -import io.swagger.v3.oas.annotations.tags.Tag; -import jakarta.validation.constraints.PositiveOrZero; -import java.util.List; -import org.springframework.http.ResponseEntity; - -@Tag(name = "알림", description = "알림 API") -public interface AlarmCommandControllerDocs { - - @Operation(summary = "신고조치알림 조회", description = "신고조치알림목록을 조회한다.") - @ApiResponse(responseCode = "201", description = "조회 성공") - ResponseEntity> getReportActionAlarms( - @Parameter(description = "현재 페이지 위치", example = "0") - @PositiveOrZero(message = "페이지는 0이상 정수만 가능합니다.") final int page, - final Member member - ); - - @Operation(summary = "신고조치알림 상세 조회", description = "신고조치알림를 상세 조회한다.") - @ApiResponse(responseCode = "201", description = "조회 성공") - public ResponseEntity getReportActionAlarm( - @Parameter(description = "신고조치알림 ID", example = "1") final Long reportActionAlarmId, - final Member member - ); - -} diff --git a/backend/src/main/java/com/votogether/domain/alarm/controller/AlarmCommandController.java b/backend/src/main/java/com/votogether/domain/alarm/controller/AlarmQueryController.java similarity index 52% rename from backend/src/main/java/com/votogether/domain/alarm/controller/AlarmCommandController.java rename to backend/src/main/java/com/votogether/domain/alarm/controller/AlarmQueryController.java index dbe841898..d33b4aa79 100644 --- a/backend/src/main/java/com/votogether/domain/alarm/controller/AlarmCommandController.java +++ b/backend/src/main/java/com/votogether/domain/alarm/controller/AlarmQueryController.java @@ -2,7 +2,8 @@ import com.votogether.domain.alarm.dto.ReportActionAlarmResponse; import com.votogether.domain.alarm.dto.ReportActionResponse; -import com.votogether.domain.alarm.service.AlarmService; +import com.votogether.domain.alarm.dto.response.PostAlarmResponse; +import com.votogether.domain.alarm.service.AlarmQueryService; import com.votogether.domain.member.entity.Member; import com.votogether.global.jwt.Auth; import jakarta.validation.constraints.PositiveOrZero; @@ -10,6 +11,7 @@ import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; @@ -19,25 +21,34 @@ @RequiredArgsConstructor @RequestMapping("/alarms") @RestController -public class AlarmCommandController implements AlarmCommandControllerDocs { +public class AlarmQueryController implements AlarmQueryControllerDocs { - private final AlarmService alarmService; + private final AlarmQueryService alarmQueryService; - @RequestMapping("/report") + @GetMapping("/content") + public ResponseEntity> getPostAlarm( + @RequestParam @PositiveOrZero(message = "페이지는 0이상 정수만 가능합니다.") final int page, + @Auth final Member loginMember + ) { + final List postAlarmResponses = alarmQueryService.getPostAlarm(loginMember, page); + return ResponseEntity.ok(postAlarmResponses); + } + + @GetMapping("/report") public ResponseEntity> getReportActionAlarms( @RequestParam @PositiveOrZero(message = "페이지는 0이상 정수만 가능합니다.") final int page, - @Auth final Member member + @Auth final Member loginMember ) { - final List response = alarmService.getReportActionAlarms(member, page); + final List response = alarmQueryService.getReportActionAlarms(loginMember, page); return ResponseEntity.ok(response); } - @RequestMapping("/report/{id}") + @GetMapping("/report/{id}") public ResponseEntity getReportActionAlarm( @PathVariable("id") final Long reportActionAlarmId, - @Auth final Member member + @Auth final Member loginMember ) { - final ReportActionResponse response = alarmService.getReportActionAlarm(reportActionAlarmId, member); + final ReportActionResponse response = alarmQueryService.getReportActionAlarm(reportActionAlarmId, loginMember); return ResponseEntity.ok(response); } diff --git a/backend/src/main/java/com/votogether/domain/alarm/controller/AlarmQueryControllerDocs.java b/backend/src/main/java/com/votogether/domain/alarm/controller/AlarmQueryControllerDocs.java index 490e2dae2..3e1e21af0 100644 --- a/backend/src/main/java/com/votogether/domain/alarm/controller/AlarmQueryControllerDocs.java +++ b/backend/src/main/java/com/votogether/domain/alarm/controller/AlarmQueryControllerDocs.java @@ -1,8 +1,13 @@ package com.votogether.domain.alarm.controller; +import com.votogether.domain.alarm.dto.ReportActionAlarmResponse; +import com.votogether.domain.alarm.dto.ReportActionResponse; import com.votogether.domain.alarm.dto.response.PostAlarmResponse; +import com.votogether.domain.member.entity.Member; import com.votogether.global.exception.ExceptionResponse; +import com.votogether.global.jwt.Auth; import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.responses.ApiResponse; @@ -28,7 +33,23 @@ public interface AlarmQueryControllerDocs { ) }) ResponseEntity> getPostAlarm( - @PositiveOrZero(message = "페이지는 0이상 정수만 가능합니다.") final int page + @PositiveOrZero(message = "페이지는 0이상 정수만 가능합니다.") final int page, + @Auth final Member loginMember + ); + + @Operation(summary = "신고 조치 알림 조회", description = "신고 조치 알림 목록을 조회한다.") + @ApiResponse(responseCode = "200", description = "조회 성공") + ResponseEntity> getReportActionAlarms( + @Parameter(description = "현재 페이지 위치", example = "0") + @PositiveOrZero(message = "페이지는 0이상 정수만 가능합니다.") final int page, + final Member member + ); + + @Operation(summary = "신고 조치 알림 상세 조회", description = "신고 조치 알림를 상세 조회한다.") + @ApiResponse(responseCode = "200", description = "조회 성공") + ResponseEntity getReportActionAlarm( + @Parameter(description = "신고 조치 알림 ID", example = "1") final Long reportActionAlarmId, + final Member member ); } diff --git a/backend/src/main/java/com/votogether/domain/alarm/controller/AlarmQueryQueryController.java b/backend/src/main/java/com/votogether/domain/alarm/controller/AlarmQueryQueryController.java deleted file mode 100644 index 886705223..000000000 --- a/backend/src/main/java/com/votogether/domain/alarm/controller/AlarmQueryQueryController.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.votogether.domain.alarm.controller; - -import com.votogether.domain.alarm.dto.response.PostAlarmResponse; -import com.votogether.domain.alarm.service.AlarmQueryService; -import jakarta.validation.constraints.PositiveOrZero; -import java.util.List; -import lombok.RequiredArgsConstructor; -import org.springframework.http.ResponseEntity; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; - -@Validated -@RequiredArgsConstructor -@RequestMapping("/alarms") -@RestController -public class AlarmQueryQueryController implements AlarmQueryControllerDocs { - - private final AlarmQueryService alarmQueryService; - - @GetMapping("/content") - public ResponseEntity> getPostAlarm( - @RequestParam @PositiveOrZero(message = "페이지는 0이상 정수만 가능합니다.") final int page - ) { - final List postAlarmResponses = alarmQueryService.getPostAlarm(page); - return ResponseEntity.ok(postAlarmResponses); - } - -} diff --git a/backend/src/main/java/com/votogether/domain/alarm/repository/AlarmRepository.java b/backend/src/main/java/com/votogether/domain/alarm/repository/AlarmRepository.java index 2a0191cbc..3050ce13f 100644 --- a/backend/src/main/java/com/votogether/domain/alarm/repository/AlarmRepository.java +++ b/backend/src/main/java/com/votogether/domain/alarm/repository/AlarmRepository.java @@ -9,7 +9,7 @@ public interface AlarmRepository extends JpaRepository { - Slice findAllByOrderByCreatedAtDesc(final Pageable pageable); + Slice findAllByMemberOrderByCreatedAtDesc(final Member member, final Pageable pageable); List findAllByMember(final Member member); diff --git a/backend/src/main/java/com/votogether/domain/alarm/service/AlarmQueryService.java b/backend/src/main/java/com/votogether/domain/alarm/service/AlarmQueryService.java index 16c93abc9..1b96112a2 100644 --- a/backend/src/main/java/com/votogether/domain/alarm/service/AlarmQueryService.java +++ b/backend/src/main/java/com/votogether/domain/alarm/service/AlarmQueryService.java @@ -1,14 +1,21 @@ package com.votogether.domain.alarm.service; +import com.votogether.domain.alarm.dto.ReportActionAlarmResponse; +import com.votogether.domain.alarm.dto.ReportActionResponse; import com.votogether.domain.alarm.dto.response.PostAlarmResponse; import com.votogether.domain.alarm.entity.Alarm; +import com.votogether.domain.alarm.entity.ReportActionAlarm; import com.votogether.domain.alarm.entity.vo.AlarmType; +import com.votogether.domain.alarm.exception.ReportActionAlarmExceptionType; import com.votogether.domain.alarm.repository.AlarmRepository; +import com.votogether.domain.alarm.repository.ReportActionAlarmRepository; import com.votogether.domain.member.entity.Member; +import com.votogether.global.exception.NotFoundException; import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Slice; +import org.springframework.data.domain.Sort; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -21,10 +28,11 @@ public class AlarmQueryService { private static final String NICKNAME_WHEN_POST_CLOSING = ""; private final AlarmRepository alarmRepository; + private final ReportActionAlarmRepository reportActionAlarmRepository; - public List getPostAlarm(final int page) { + public List getPostAlarm(final Member member, final int page) { final PageRequest pageRequest = PageRequest.of(page, BASIC_PAGE_SIZE); - final Slice alarms = alarmRepository.findAllByOrderByCreatedAtDesc(pageRequest); + final Slice alarms = alarmRepository.findAllByMemberOrderByCreatedAtDesc(member, pageRequest); return getPostAlarmResponses(alarms); } @@ -46,4 +54,23 @@ private String makeNicknameBy(final Alarm alarm) { return member.getNickname(); } + public List getReportActionAlarms(final Member member, final int page) { + final PageRequest pageRequest = PageRequest.of(page, BASIC_PAGE_SIZE, + Sort.by(Sort.Direction.DESC, "createdAt")); + final List reportActionAlarms = reportActionAlarmRepository + .findByMember(member, pageRequest); + + return reportActionAlarms.stream() + .map(ReportActionAlarmResponse::from) + .toList(); + } + + public ReportActionResponse getReportActionAlarm(final Long reportActionAlarmId, final Member member) { + final ReportActionAlarm reportActionAlarm = reportActionAlarmRepository + .findByIdAndMember(reportActionAlarmId, member) + .orElseThrow(() -> new NotFoundException(ReportActionAlarmExceptionType.NOT_FOUND)); + + return ReportActionResponse.from(reportActionAlarm); + } + } diff --git a/backend/src/main/java/com/votogether/domain/alarm/service/AlarmService.java b/backend/src/main/java/com/votogether/domain/alarm/service/AlarmService.java deleted file mode 100644 index f178cbd33..000000000 --- a/backend/src/main/java/com/votogether/domain/alarm/service/AlarmService.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.votogether.domain.alarm.service; - -import com.votogether.domain.alarm.dto.ReportActionAlarmResponse; -import com.votogether.domain.alarm.dto.ReportActionResponse; -import com.votogether.domain.alarm.entity.ReportActionAlarm; -import com.votogether.domain.alarm.exception.ReportActionAlarmExceptionType; -import com.votogether.domain.alarm.repository.ReportActionAlarmRepository; -import com.votogether.domain.member.entity.Member; -import com.votogether.global.exception.NotFoundException; -import java.util.List; -import lombok.RequiredArgsConstructor; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Sort; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -@RequiredArgsConstructor -@Service -public class AlarmService { - - private static final int BASIC_PAGE_SIZE = 10; - private final ReportActionAlarmRepository reportActionAlarmRepository; - - @Transactional(readOnly = true) - public List getReportActionAlarms(final Member member, final int page) { - final PageRequest pageRequest = PageRequest.of(page, BASIC_PAGE_SIZE, - Sort.by(Sort.Direction.DESC, "createdAt")); - final List reportActionAlarms = reportActionAlarmRepository - .findByMember(member, pageRequest); - - return reportActionAlarms.stream() - .map(ReportActionAlarmResponse::from) - .toList(); - } - - @Transactional(readOnly = true) - public ReportActionResponse getReportActionAlarm(final Long reportActionAlarmId, final Member member) { - final ReportActionAlarm reportActionAlarm = reportActionAlarmRepository - .findByIdAndMember(reportActionAlarmId, member) - .orElseThrow(() -> new NotFoundException(ReportActionAlarmExceptionType.NOT_FOUND)); - - return ReportActionResponse.from(reportActionAlarm); - } - -} diff --git a/backend/src/main/java/com/votogether/domain/post/service/PostCommentService.java b/backend/src/main/java/com/votogether/domain/post/service/PostCommentService.java index 36eac7c16..d831a76f9 100644 --- a/backend/src/main/java/com/votogether/domain/post/service/PostCommentService.java +++ b/backend/src/main/java/com/votogether/domain/post/service/PostCommentService.java @@ -60,6 +60,9 @@ public void createComment( } private void publishAlarmEvent(final Member loginMember, final Post post) { + if (post.isWriter(loginMember)) { + return; + } final PostAlarmEvent postAlarmEvent = new PostAlarmEvent( loginMember, post.getId(), diff --git a/backend/src/test/java/com/votogether/domain/alarm/controller/AlarmCommandControllerTest.java b/backend/src/test/java/com/votogether/domain/alarm/controller/AlarmCommandControllerTest.java deleted file mode 100644 index f9d8936c1..000000000 --- a/backend/src/test/java/com/votogether/domain/alarm/controller/AlarmCommandControllerTest.java +++ /dev/null @@ -1,90 +0,0 @@ -package com.votogether.domain.alarm.controller; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyInt; -import static org.mockito.ArgumentMatchers.anyLong; -import static org.mockito.BDDMockito.given; - -import com.votogether.domain.alarm.dto.ReportActionAlarmResponse; -import com.votogether.domain.alarm.dto.ReportActionResponse; -import com.votogether.domain.alarm.entity.ReportActionAlarm; -import com.votogether.domain.alarm.service.AlarmService; -import com.votogether.domain.member.entity.Member; -import com.votogether.domain.report.entity.vo.ReportType; -import com.votogether.test.ControllerTest; -import io.restassured.module.mockmvc.RestAssuredMockMvc; -import java.util.List; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -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.HttpStatus; - -@WebMvcTest(AlarmCommandControllerTest.class) -class AlarmCommandControllerTest extends ControllerTest { - - @MockBean - AlarmService alarmService; - - @BeforeEach - void setUp() { - RestAssuredMockMvc.standaloneSetup(new AlarmCommandController(alarmService)); - } - - @Test - @DisplayName("신고조치알림목록을 가져온다.") - void getReportAlarmActions() { - // given - ReportActionAlarm reportActionAlarm = ReportActionAlarm.builder() - .reportType(ReportType.POST) - .isChecked(false) - .reasons("광고성, 부적합성") - .target("1") - .build(); - ReportActionAlarmResponse response = ReportActionAlarmResponse.from(reportActionAlarm); - given(alarmService.getReportActionAlarms(any(Member.class), anyInt())) - .willReturn(List.of(response)); - - // when - List results = RestAssuredMockMvc - .when().get("/alarms/report?page=0") - .then().log().all() - .status(HttpStatus.OK) - .extract() - .as(new ParameterizedTypeReference>() { - }.getType()); - - // then - assertThat(results.get(0)).isEqualTo(response); - } - - @Test - @DisplayName("신고조치알림을 상세조회한다.") - void getReportAlarmAction() { - // given - ReportActionAlarm reportActionAlarm = ReportActionAlarm.builder() - .reportType(ReportType.POST) - .isChecked(false) - .target("1") - .reasons("광고성, 부적합성") - .build(); - ReportActionResponse response = ReportActionResponse.from(reportActionAlarm); - given(alarmService.getReportActionAlarm(anyLong(), any(Member.class))) - .willReturn(response); - - // when - ReportActionResponse result = RestAssuredMockMvc - .when().get("/alarms/report/{id}", 1) - .then().log().all() - .status(HttpStatus.OK) - .extract() - .as(ReportActionResponse.class); - - // then - assertThat(result).isEqualTo(response); - } - -} diff --git a/backend/src/test/java/com/votogether/domain/alarm/controller/AlarmQueryControllerTest.java b/backend/src/test/java/com/votogether/domain/alarm/controller/AlarmQueryControllerTest.java index 0de5d3564..becdb7049 100644 --- a/backend/src/test/java/com/votogether/domain/alarm/controller/AlarmQueryControllerTest.java +++ b/backend/src/test/java/com/votogether/domain/alarm/controller/AlarmQueryControllerTest.java @@ -1,11 +1,20 @@ package com.votogether.domain.alarm.controller; +import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.SoftAssertions.assertSoftly; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.BDDMockito.given; +import com.votogether.domain.alarm.dto.ReportActionAlarmResponse; +import com.votogether.domain.alarm.dto.ReportActionResponse; import com.votogether.domain.alarm.dto.response.PostAlarmDetailResponse; import com.votogether.domain.alarm.dto.response.PostAlarmResponse; +import com.votogether.domain.alarm.entity.ReportActionAlarm; import com.votogether.domain.alarm.service.AlarmQueryService; +import com.votogether.domain.member.entity.Member; +import com.votogether.domain.report.entity.vo.ReportType; import com.votogether.test.ControllerTest; import io.restassured.common.mapper.TypeRef; import io.restassured.module.mockmvc.RestAssuredMockMvc; @@ -16,9 +25,11 @@ 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; -@WebMvcTest(AlarmQueryQueryController.class) +@WebMvcTest(AlarmQueryController.class) class AlarmQueryControllerTest extends ControllerTest { @MockBean @@ -26,7 +37,7 @@ class AlarmQueryControllerTest extends ControllerTest { @BeforeEach void setUp() { - RestAssuredMockMvc.standaloneSetup(new AlarmQueryQueryController(alarmQueryService)); + RestAssuredMockMvc.standaloneSetup(new AlarmQueryController(alarmQueryService)); } @Test @@ -35,18 +46,17 @@ void getPostAlarm() throws Exception { // given mockingAuthArgumentResolver(); - int page = 0; PostAlarmDetailResponse postAlarmDetailResponse = new PostAlarmDetailResponse(1L, "title", "저문"); PostAlarmResponse postAlarmResponse = new PostAlarmResponse(1L, postAlarmDetailResponse, LocalDateTime.now(), false); - given(alarmQueryService.getPostAlarm(page)).willReturn(List.of(postAlarmResponse)); + given(alarmQueryService.getPostAlarm(any(Member.class), anyInt())).willReturn(List.of(postAlarmResponse)); // when List postAlarmResponses = RestAssuredMockMvc .given().log().all() .headers(HttpHeaders.AUTHORIZATION, BEARER_TOKEN) - .queryParam("page", page) + .queryParam("page", 0) .when().get("/alarms/content") .then().log().all() .extract() @@ -64,4 +74,57 @@ void getPostAlarm() throws Exception { }); } + @Test + @DisplayName("신고조치알림목록을 가져온다.") + void getReportAlarmActions() { + // given + ReportActionAlarm reportActionAlarm = ReportActionAlarm.builder() + .reportType(ReportType.POST) + .isChecked(false) + .reasons("광고성, 부적합성") + .target("1") + .build(); + ReportActionAlarmResponse response = ReportActionAlarmResponse.from(reportActionAlarm); + given(alarmQueryService.getReportActionAlarms(any(Member.class), anyInt())) + .willReturn(List.of(response)); + + // when + List results = RestAssuredMockMvc + .when().get("/alarms/report?page=0") + .then().log().all() + .status(HttpStatus.OK) + .extract() + .as(new ParameterizedTypeReference>() { + }.getType()); + + // then + assertThat(results.get(0)).isEqualTo(response); + } + + @Test + @DisplayName("신고조치알림을 상세조회한다.") + void getReportAlarmAction() { + // given + ReportActionAlarm reportActionAlarm = ReportActionAlarm.builder() + .reportType(ReportType.POST) + .isChecked(false) + .target("1") + .reasons("광고성, 부적합성") + .build(); + ReportActionResponse response = ReportActionResponse.from(reportActionAlarm); + given(alarmQueryService.getReportActionAlarm(anyLong(), any(Member.class))) + .willReturn(response); + + // when + ReportActionResponse result = RestAssuredMockMvc + .when().get("/alarms/report/{id}", 1) + .then().log().all() + .status(HttpStatus.OK) + .extract() + .as(ReportActionResponse.class); + + // then + assertThat(result).isEqualTo(response); + } + } diff --git a/backend/src/test/java/com/votogether/domain/alarm/service/AlarmEventListenerTest.java b/backend/src/test/java/com/votogether/domain/alarm/service/AlarmEventListenerTest.java index 7d6582cf8..1f4a84ce7 100644 --- a/backend/src/test/java/com/votogether/domain/alarm/service/AlarmEventListenerTest.java +++ b/backend/src/test/java/com/votogether/domain/alarm/service/AlarmEventListenerTest.java @@ -38,7 +38,7 @@ void handlePostAlarmEvent() throws Exception { TestTransaction.flagForCommit(); TestTransaction.end(); - Thread.sleep(1000); + Thread.sleep(2000); // then List alarms = alarmRepository.findAll(); diff --git a/backend/src/test/java/com/votogether/domain/alarm/service/AlarmQueryServiceTest.java b/backend/src/test/java/com/votogether/domain/alarm/service/AlarmQueryServiceTest.java index 9b2d3fe95..e54075ae0 100644 --- a/backend/src/test/java/com/votogether/domain/alarm/service/AlarmQueryServiceTest.java +++ b/backend/src/test/java/com/votogether/domain/alarm/service/AlarmQueryServiceTest.java @@ -1,18 +1,23 @@ -package com.votogether.domain.alarm.entity.service; +package com.votogether.domain.alarm.service; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.SoftAssertions.assertSoftly; +import com.votogether.domain.alarm.dto.ReportActionAlarmResponse; +import com.votogether.domain.alarm.dto.ReportActionResponse; import com.votogether.domain.alarm.dto.response.PostAlarmDetailResponse; import com.votogether.domain.alarm.dto.response.PostAlarmResponse; -import com.votogether.domain.alarm.service.AlarmQueryService; +import com.votogether.domain.alarm.entity.ReportActionAlarm; +import com.votogether.domain.alarm.repository.ReportActionAlarmRepository; import com.votogether.domain.member.entity.Member; import com.votogether.domain.post.dto.request.comment.CommentCreateRequest; import com.votogether.domain.post.entity.Post; import com.votogether.domain.post.service.PostCommandService; import com.votogether.domain.post.service.PostCommentService; +import com.votogether.domain.report.entity.vo.ReportType; import com.votogether.test.ServiceTest; import java.util.List; +import java.util.Set; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; @@ -33,13 +38,16 @@ class AlarmQueryServiceTest extends ServiceTest { @Autowired PostCommandService postCommandService; + @Autowired + ReportActionAlarmRepository reportActionAlarmRepository; + @Nested @DisplayName("알림 조회는 ") class GetPostAlarm { @Test @DisplayName("댓글을 생성할 때 가능하다.") - void whenCreateComment() { + void whenCreateComment() throws Exception { // given Member commentWriter = memberTestPersister.builder().save(); Post post = postTestPersister.postBuilder().save(); @@ -50,8 +58,10 @@ void whenCreateComment() { TestTransaction.flagForCommit(); TestTransaction.end(); + Thread.sleep(1000); + // when - List postAlarmResponses = alarmQueryService.getPostAlarm(0); + List postAlarmResponses = alarmQueryService.getPostAlarm(commentWriter, 0); // then PostAlarmResponse postAlarmResponse = postAlarmResponses.get(0); @@ -78,7 +88,7 @@ void whenPostClosed() throws Exception { Thread.sleep(1000); // when - List postAlarmResponses = alarmQueryService.getPostAlarm(0); + List postAlarmResponses = alarmQueryService.getPostAlarm(member, 0); // then PostAlarmResponse postAlarmResponse = postAlarmResponses.get(0); @@ -93,8 +103,11 @@ void whenPostClosed() throws Exception { @Test @DisplayName("어떠한 이벤트도 발생하지 않았다면 빈 리스트가 조회된다.") void getEmptyListWhenNoEventOccurs() { - // given, when - List postAlarmResponses = alarmQueryService.getPostAlarm(0); + // given + Member member = memberTestPersister.builder().save(); + + // when + List postAlarmResponses = alarmQueryService.getPostAlarm(member, 0); // then assertThat(postAlarmResponses).hasSize(0); @@ -102,4 +115,64 @@ void getEmptyListWhenNoEventOccurs() { } + @Test + @DisplayName("신고 조치 알림 목록을 조회한다.") + void getReportActionAlarms() { + // given + Member member = memberTestPersister.builder().save(); + + ReportActionAlarm reportActionAlarmA = ReportActionAlarm.builder() + .reportType(ReportType.POST) + .member(member) + .isChecked(false) + .reasons("광고성, 부적합성") + .target("1") + .build(); + + reportActionAlarmRepository.save(reportActionAlarmA); + + // when + List reportActionAlarms = alarmQueryService.getReportActionAlarms(member, 0); + + // then + ReportActionAlarmResponse result = reportActionAlarms.get(0); + assertSoftly(softly -> { + softly.assertThat(reportActionAlarms).hasSize(1); + softly.assertThat(result.alarmId()).isNotNull(); + softly.assertThat(result.isChecked()).isFalse(); + softly.assertThat(result.detail().reportActionId()).isNotNull(); + softly.assertThat(result.detail().content()).isEqualTo("1"); + softly.assertThat(result.detail().reasons()).containsAll(Set.of("광고성", "부적합성")); + softly.assertThat(result.detail().type()).isEqualTo(ReportType.POST); + }); + } + + @Test + @DisplayName("신고 조치 알림을 상세 조회한다.") + void getReportActionAlarm() { + // given + Member member = memberTestPersister.builder().save(); + + ReportActionAlarm reportActionAlarmA = ReportActionAlarm.builder() + .reportType(ReportType.POST) + .member(member) + .isChecked(false) + .reasons("광고성, 부적합성") + .target("1") + .build(); + + ReportActionAlarm savedReportActionAlarm = reportActionAlarmRepository.save(reportActionAlarmA); + + // when + ReportActionResponse response = alarmQueryService.getReportActionAlarm(savedReportActionAlarm.getId(), member); + + // then + assertSoftly(softly -> { + softly.assertThat(response.reportActionId()).isEqualTo(savedReportActionAlarm.getId()); + softly.assertThat(response.type()).isEqualTo(ReportType.POST); + softly.assertThat(response.content()).isEqualTo("1"); + softly.assertThat(response.reasons()).containsAll(Set.of("광고성", "부적합성")); + }); + } + } diff --git a/backend/src/test/java/com/votogether/domain/alarm/service/AlarmServiceTest.java b/backend/src/test/java/com/votogether/domain/alarm/service/AlarmServiceTest.java deleted file mode 100644 index 23d4e364e..000000000 --- a/backend/src/test/java/com/votogether/domain/alarm/service/AlarmServiceTest.java +++ /dev/null @@ -1,87 +0,0 @@ -package com.votogether.domain.alarm.service; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertAll; - -import com.votogether.domain.alarm.dto.ReportActionAlarmResponse; -import com.votogether.domain.alarm.dto.ReportActionResponse; -import com.votogether.domain.alarm.entity.ReportActionAlarm; -import com.votogether.domain.alarm.repository.ReportActionAlarmRepository; -import com.votogether.domain.member.entity.Member; -import com.votogether.domain.report.entity.vo.ReportType; -import com.votogether.test.ServiceTest; -import java.util.List; -import java.util.Set; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; - -class AlarmServiceTest extends ServiceTest { - - @Autowired - AlarmService alarmService; - - @Autowired - ReportActionAlarmRepository reportActionAlarmRepository; - - @Test - @DisplayName("신고조치알림 목록을 조회한다.") - void getReportActionAlarms() { - // given - Member member = memberTestPersister.builder().save(); - - ReportActionAlarm reportActionAlarmA = ReportActionAlarm.builder() - .reportType(ReportType.POST) - .member(member) - .isChecked(false) - .reasons("광고성, 부적합성") - .target("1") - .build(); - - reportActionAlarmRepository.save(reportActionAlarmA); - - // when - List reportActionAlarms = alarmService.getReportActionAlarms(member, 0); - - // then - ReportActionAlarmResponse result = reportActionAlarms.get(0); - assertAll( - () -> assertThat(reportActionAlarms.size()).isEqualTo(1), - () -> assertThat(result.alarmId()).isNotNull(), - () -> assertThat(result.isChecked()).isFalse(), - () -> assertThat(result.detail().reportActionId()).isNotNull(), - () -> assertThat(result.detail().content()).isEqualTo("1"), - () -> assertThat(result.detail().reasons()).containsAll(Set.of("광고성", "부적합성")), - () -> assertThat(result.detail().type()).isEqualTo(ReportType.POST) - ); - } - - @Test - @DisplayName("신고조치알림을 상세 조회한다.") - void getReportActionAlarm() { - // given - Member member = memberTestPersister.builder().save(); - - ReportActionAlarm reportActionAlarmA = ReportActionAlarm.builder() - .reportType(ReportType.POST) - .member(member) - .isChecked(false) - .reasons("광고성, 부적합성") - .target("1") - .build(); - - ReportActionAlarm savedReportActionAlarm = reportActionAlarmRepository.save(reportActionAlarmA); - - // when - ReportActionResponse response = alarmService.getReportActionAlarm(savedReportActionAlarm.getId(), member); - - // then - assertAll( - () -> assertThat(response.reportActionId()).isEqualTo(savedReportActionAlarm.getId()), - () -> assertThat(response.type()).isEqualTo(ReportType.POST), - () -> assertThat(response.content()).isEqualTo("1"), - () -> assertThat(response.reasons()).containsAll(Set.of("광고성", "부적합성")) - ); - } - -} diff --git a/backend/src/test/resources/truncate.sql b/backend/src/test/resources/truncate.sql index 5e4812509..2eeeeb585 100644 --- a/backend/src/test/resources/truncate.sql +++ b/backend/src/test/resources/truncate.sql @@ -11,5 +11,6 @@ TRUNCATE TABLE post; TRUNCATE TABLE member; TRUNCATE TABLE category; TRUNCATE TABLE alarm; +TRUNCATE TABLE report_action_alarm; SET FOREIGN_KEY_CHECKS = 1;