Skip to content

Commit

Permalink
[merge] 공지사항 전체 조회 api 공개여부 로직 반영
Browse files Browse the repository at this point in the history
[fix] 공지사항 전체 조회 api 공개여부 로직 반영
  • Loading branch information
bo-ram-bo-ram authored Sep 16, 2024
2 parents 3265233 + f21d720 commit e9a057c
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
public interface MoimRepository extends JpaRepository<Moim, Long> {
Optional<Moim> findMoimById(Long id);

int countByHostId(Long hostId);

List<Moim> findMoimByhostIdAndMoimState(Long hostId, String moimState);

default Moim findMoimByIdOrThrow(Long id) {
return findMoimById(id)
.orElseThrow(() -> new CustomException(ErrorCode.MOIM_NOT_FOUND));
}

int countByHostId(Long hostId);

List<Moim> findMoimByhostIdAndMoimState(Long hostId, String moimState);

@Query(value = "SELECT * FROM moims WHERE EXISTS (" +
"SELECT 1 FROM jsonb_each_text(category_list) AS categories " +
"WHERE categories.value = :category)",
Expand All @@ -37,4 +37,5 @@ default Moim findMoimByIdOrThrow(Long id) {
int CompletedMoimNumber(Long hostId);

List<Moim> findMoimByHostId(Long hostId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@ public interface MoimSubmissionRepository extends JpaRepository<MoimSubmission,

Optional<MoimSubmission> findMoimSubmissionById(Long id);

default MoimSubmission findMoimSubmissionByIdOrThrow(Long id) {
return findMoimSubmissionById(id)
.orElseThrow(() -> new CustomException(ErrorCode.MOIM_SUBMISSION_NOT_FOUND));
}

boolean existsByMoimAndGuestId(Moim moim, Long guestId);

List<MoimSubmission> findAllByGuestId(Long guestId);
boolean existsByMoimIdAndGuestId(Long moimId, Long guestId);

List<MoimSubmission> findAllByGuestIdAndMoimSubmissionState(Long guestId, String moimSubmissionState);

Expand All @@ -40,11 +45,7 @@ public interface MoimSubmissionRepository extends JpaRepository<MoimSubmission,

boolean existsByMoimIdAndGuestIdAndMoimSubmissionState(Long moimId, Long guestId, String MoimSubmissionState);

default MoimSubmission findMoimSubmissionByIdOrThrow(Long id) {
return findMoimSubmissionById(id)
.orElseThrow(() -> new CustomException(ErrorCode.MOIM_SUBMISSION_NOT_FOUND));
}

@Query("SELECT ms FROM MoimSubmission ms WHERE ms.guestId = :guestId AND ms.moimSubmissionState IN ('pendingPayment','pendingApproval', 'approved', 'rejected','refunded')")
List<MoimSubmission> findAllSubmittedMoimSubmission(@Param("guestId") Long guestId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.pickple.server.api.notice.dto.response.NoticeListGetByMoimResponse;
import com.pickple.server.api.notice.service.NoticeCommandService;
import com.pickple.server.api.notice.service.NoticeQueryService;
import com.pickple.server.global.common.annotation.GuestId;
import com.pickple.server.global.common.annotation.HostId;
import com.pickple.server.global.common.annotation.UserId;
import com.pickple.server.global.response.ApiResponseDto;
Expand Down Expand Up @@ -36,9 +37,10 @@ public ApiResponseDto createNotice(@PathVariable Long moimId,
}

@GetMapping("/v2/moim/{moimId}/notice-list")
public ApiResponseDto<List<NoticeListGetByMoimResponse>> getNoticeListByMoimId(@PathVariable Long moimId) {
public ApiResponseDto<List<NoticeListGetByMoimResponse>> getNoticeListByMoimId(
@PathVariable final Long moimId, @GuestId final Long guestId) {
return ApiResponseDto.success(SuccessCode.NOTICE_LIST_GET_SUCCESS,
noticeQueryService.getNoticeListByMoimId(moimId));
noticeQueryService.getNoticeListByMoimId(moimId, guestId));
}

@DeleteMapping("/v2/notice/{noticeId}")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.pickple.server.api.notice.controller;

import com.pickple.server.api.notice.dto.request.NoticeCreateRequest;
import com.pickple.server.api.notice.dto.response.NoticeDetailGetResponse;
import com.pickple.server.global.common.annotation.GuestId;
import com.pickple.server.global.common.annotation.HostId;
import com.pickple.server.global.common.annotation.UserId;
import com.pickple.server.global.response.ApiResponseDto;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
Expand Down Expand Up @@ -32,6 +36,32 @@ ApiResponseDto createNotice(
}
)
ApiResponseDto getNoticeListByMoimId(
@PathVariable Long moimId
@PathVariable Long moimId,
@GuestId Long guestId
);

@Operation(summary = "공지사항 삭제")
@ApiResponses(
value = {
@ApiResponse(responseCode = "20026", description = "공지사항 삭제 성공"),
@ApiResponse(responseCode = "40409", description = "존재하지 않는 공지사항입니다.")
}
)
ApiResponseDto deleteNotice(
@HostId Long hostId,
@PathVariable Long noticeId
);

@Operation(summary = "공지사항 상세 조회")
@ApiResponses(
value = {
@ApiResponse(responseCode = "20031", description = "공지사항 상세 조회 성공"),
@ApiResponse(responseCode = "40409", description = "존재하지 않는 공지사항입니다.")
}
)
ApiResponseDto<NoticeDetailGetResponse> getNoticeDetail(
@UserId Long userId,
@PathVariable Long moimId,
@PathVariable Long noticeId
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.pickple.server.api.comment.repository.CommentRepository;
import com.pickple.server.api.moim.domain.Moim;
import com.pickple.server.api.moim.repository.MoimRepository;
import com.pickple.server.api.moimsubmission.domain.MoimSubmission;
import com.pickple.server.api.moimsubmission.repository.MoimSubmissionRepository;
import com.pickple.server.api.notice.domain.Notice;
import com.pickple.server.api.notice.dto.response.NoticeDetailGetResponse;
import com.pickple.server.api.notice.dto.response.NoticeListGetByMoimResponse;
Expand All @@ -22,12 +24,16 @@ public class NoticeQueryService {
private final MoimRepository moimRepository;
private final NoticeRepository noticeRepository;
private final CommentRepository commentRepository;
private final MoimSubmissionRepository moimSubmissionRepository;

public List<NoticeListGetByMoimResponse> getNoticeListByMoimId(Long moimId) {
public List<NoticeListGetByMoimResponse> getNoticeListByMoimId(Long moimId, Long guestId) {
Moim moim = moimRepository.findMoimByIdOrThrow(moimId);
List<Notice> noticeList = noticeRepository.findNoticeByMoimIdOrderByCreatedAtDesc(moimId);

boolean isAppliedUser = isUserAppliedToMoim(moimId, guestId);

return noticeList.stream()
.filter(notice -> canAccessNotice(notice, isAppliedUser))
.map(oneNotice -> NoticeListGetByMoimResponse.builder()
.noticeId(oneNotice.getId())
.hostNickName(moim.getHost().getNickname())
Expand Down Expand Up @@ -59,8 +65,26 @@ public NoticeDetailGetResponse getNoticeDetail(Long userId, Long moimId, Long no
.build();
}

public boolean checkOwner(Long userId, Long moimId) {
private boolean checkOwner(Long userId, Long moimId) {
Moim moim = moimRepository.findMoimByIdOrThrow(moimId);
return moim.getHost().getUser().getId().equals(userId);
}

private boolean isUserAppliedToMoim(Long moimId, Long guestId) {
if (moimSubmissionRepository.existsByMoimIdAndGuestId(moimId, guestId)) {
MoimSubmission moimSubmission = moimSubmissionRepository.findByMoimIdAndGuestId(moimId, guestId);

// 참가한 상태일 경우(승인된 상태 - approved , completed
if (moimSubmission.getMoimSubmissionState().equals("completed")
|| moimSubmission.getMoimSubmissionState().equals("approved")) {
return true;
}
}
return false;
}

private boolean canAccessNotice(Notice notice, boolean isUserApplied) {
// 공개 공지사항이면 누구나 접근 가능하고, 비공개 공지사항이면 모임에 신청한 사람만 접근 가능
return !notice.isPrivate() || isUserApplied;
}
}

0 comments on commit e9a057c

Please sign in to comment.