Skip to content

Commit

Permalink
Merge pull request #773 from woowacourse-teams/feat/#771
Browse files Browse the repository at this point in the history
다른 사람의 알림까지 보이는 문제 해결
  • Loading branch information
jeomxon authored Oct 18, 2023
2 parents 8b1872e + 85ee935 commit 5364500
Show file tree
Hide file tree
Showing 14 changed files with 225 additions and 311 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

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;
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.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
Expand All @@ -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<List<PostAlarmResponse>> getPostAlarm(
@RequestParam @PositiveOrZero(message = "페이지는 0이상 정수만 가능합니다.") final int page,
@Auth final Member loginMember
) {
final List<PostAlarmResponse> postAlarmResponses = alarmQueryService.getPostAlarm(loginMember, page);
return ResponseEntity.ok(postAlarmResponses);
}

@GetMapping("/report")
public ResponseEntity<List<ReportActionAlarmResponse>> getReportActionAlarms(
@RequestParam @PositiveOrZero(message = "페이지는 0이상 정수만 가능합니다.") final int page,
@Auth final Member member
@Auth final Member loginMember
) {
final List<ReportActionAlarmResponse> response = alarmService.getReportActionAlarms(member, page);
final List<ReportActionAlarmResponse> response = alarmQueryService.getReportActionAlarms(loginMember, page);
return ResponseEntity.ok(response);
}

@RequestMapping("/report/{id}")
@GetMapping("/report/{id}")
public ResponseEntity<ReportActionResponse> 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);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -28,7 +33,23 @@ public interface AlarmQueryControllerDocs {
)
})
ResponseEntity<List<PostAlarmResponse>> 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<List<ReportActionAlarmResponse>> getReportActionAlarms(
@Parameter(description = "현재 페이지 위치", example = "0")
@PositiveOrZero(message = "페이지는 0이상 정수만 가능합니다.") final int page,
final Member member
);

@Operation(summary = "신고 조치 알림 상세 조회", description = "신고 조치 알림를 상세 조회한다.")
@ApiResponse(responseCode = "200", description = "조회 성공")
ResponseEntity<ReportActionResponse> getReportActionAlarm(
@Parameter(description = "신고 조치 알림 ID", example = "1") final Long reportActionAlarmId,
final Member member
);

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

public interface AlarmRepository extends JpaRepository<Alarm, Long> {

Slice<Alarm> findAllByOrderByCreatedAtDesc(final Pageable pageable);
Slice<Alarm> findAllByMemberOrderByCreatedAtDesc(final Member member, final Pageable pageable);

List<Alarm> findAllByMember(final Member member);

Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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<PostAlarmResponse> getPostAlarm(final int page) {
public List<PostAlarmResponse> getPostAlarm(final Member member, final int page) {
final PageRequest pageRequest = PageRequest.of(page, BASIC_PAGE_SIZE);
final Slice<Alarm> alarms = alarmRepository.findAllByOrderByCreatedAtDesc(pageRequest);
final Slice<Alarm> alarms = alarmRepository.findAllByMemberOrderByCreatedAtDesc(member, pageRequest);

return getPostAlarmResponses(alarms);
}
Expand All @@ -46,4 +54,23 @@ private String makeNicknameBy(final Alarm alarm) {
return member.getNickname();
}

public List<ReportActionAlarmResponse> getReportActionAlarms(final Member member, final int page) {
final PageRequest pageRequest = PageRequest.of(page, BASIC_PAGE_SIZE,
Sort.by(Sort.Direction.DESC, "createdAt"));
final List<ReportActionAlarm> 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);
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

This file was deleted.

Loading

0 comments on commit 5364500

Please sign in to comment.