Skip to content
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

다른 사람의 알림까지 보이는 문제 해결 #773

Merged
merged 8 commits into from
Oct 18, 2023

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,32 +1,9 @@
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<List<ReportActionAlarmResponse>> getReportActionAlarms(
@Parameter(description = "현재 페이지 위치", example = "0")
@PositiveOrZero(message = "페이지는 0이상 정수만 가능합니다.") final int page,
final Member member
);

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

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
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.alarm.service.AlarmQueryService;
import com.votogether.domain.member.entity.Member;
Expand All @@ -10,6 +12,7 @@
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;
import org.springframework.web.bind.annotation.RestController;
Expand All @@ -27,8 +30,26 @@ public ResponseEntity<List<PostAlarmResponse>> getPostAlarm(
@RequestParam @PositiveOrZero(message = "페이지는 0이상 정수만 가능합니다.") final int page,
@Auth final Member loginMember
) {
final List<PostAlarmResponse> postAlarmResponses = alarmQueryService.getPostAlarm(page, 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 loginMember
) {
final List<ReportActionAlarmResponse> response = alarmQueryService.getReportActionAlarms(loginMember, page);
return ResponseEntity.ok(response);
}

@GetMapping("/report/{id}")
public ResponseEntity<ReportActionResponse> getReportActionAlarm(
@PathVariable("id") final Long reportActionAlarmId,
@Auth final Member loginMember
) {
final ReportActionResponse response = alarmQueryService.getReportActionAlarm(reportActionAlarmId, loginMember);
return ResponseEntity.ok(response);
}

}
Original file line number Diff line number Diff line change
@@ -1,10 +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 Down Expand Up @@ -34,4 +37,19 @@ ResponseEntity<List<PostAlarmResponse>> getPostAlarm(
@Auth final Member loginMember
);

@Operation(summary = "신고 조치 알림 조회", description = "신고 조치 알림 목록을 조회한다.")
@ApiResponse(responseCode = "201", description = "조회 성공")
ResponseEntity<List<ReportActionAlarmResponse>> getReportActionAlarms(
@Parameter(description = "현재 페이지 위치", example = "0")
@PositiveOrZero(message = "페이지는 0이상 정수만 가능합니다.") final int page,
final Member member
);

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

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

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

@Transactional(readOnly = true)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3
QueryService@Transactional을 다 제거해도 괜찮을 것 같아요 :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

삭제하겠습니다!

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();
}

@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);
}

}

This file was deleted.

This file was deleted.

Loading