Skip to content

Commit

Permalink
feat: APP BE 와의 통신을 위한 모임 목록 조회 API 개발 (#486)
Browse files Browse the repository at this point in the history
* move(external): 알림 관련 기능 internal -> external 로 변경

* chore(Meeting): getMeetingStatusValue 과 getMeetingStatus 메서드 분리

* style(PageOptionsDto): 코드 배치 수정

* chore(SecurityConfig): internal 기능 화이트리스트에 추가

* add(Dto): Dto 추가

* feat(InternalMeetingController): 모임 목록 조회 컨트롤러 구현

* feat(InternalMeetingService): 모임 목록 조회 서비스 로직 구현

* rename(AdvertisementCustomPageable): 기존에 있던 CustomPageable -> AdvertisementCustomPageable 로 이름 변경

* feat(CustomPageable): CustomPageable 구현 및 적용

* fix(CustomPageable): take -> size 수정

* fix: 3항 연산자 -> if 문으로 수정

* docs(InternalMeetingGetAllMeetingQueryDto): 스웨거 설명 추가

* fix(InternalMeetingController): requestBody -> requestParam 변경

* docs(InternalMeetingApi): 스웨거 추가

* docs(AdvertisementCustomPageable): javadoc 추가

* chore: getBlockedUsers 기존 메서드 수정
  • Loading branch information
mikekks authored Nov 17, 2024
1 parent adaa6d8 commit 6542937
Show file tree
Hide file tree
Showing 28 changed files with 393 additions and 96 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.sopt.makers.crew.main.comment.v2.service;

import static org.sopt.makers.crew.main.internal.notification.PushNotificationEnums.NEW_COMMENT_MENTION_PUSH_NOTIFICATION_TITLE;
import static org.sopt.makers.crew.main.internal.notification.PushNotificationEnums.NEW_COMMENT_PUSH_NOTIFICATION_TITLE;
import static org.sopt.makers.crew.main.internal.notification.PushNotificationEnums.PUSH_NOTIFICATION_CATEGORY;
import static org.sopt.makers.crew.main.external.notification.PushNotificationEnums.NEW_COMMENT_MENTION_PUSH_NOTIFICATION_TITLE;
import static org.sopt.makers.crew.main.external.notification.PushNotificationEnums.NEW_COMMENT_PUSH_NOTIFICATION_TITLE;
import static org.sopt.makers.crew.main.external.notification.PushNotificationEnums.PUSH_NOTIFICATION_CATEGORY;

import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -42,8 +42,8 @@
import org.sopt.makers.crew.main.entity.user.User;
import org.sopt.makers.crew.main.entity.user.UserRepository;
import org.sopt.makers.crew.main.external.playground.service.MemberBlockService;
import org.sopt.makers.crew.main.internal.notification.PushNotificationService;
import org.sopt.makers.crew.main.internal.notification.dto.PushNotificationRequestDto;
import org.sopt.makers.crew.main.external.notification.PushNotificationService;
import org.sopt.makers.crew.main.external.notification.dto.PushNotificationRequestDto;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand Down Expand Up @@ -174,7 +174,11 @@ public CommentV2GetCommentsResponseDto getComments(Integer postId, Integer page,
User user = userRepository.findByIdOrThrow(userId);
Long orgId = user.getOrgId().longValue();

Map<Long, Boolean> blockedUsers = memberBlockService.getBlockedUsers(orgId);
List<Long> userOrgIds = comments.stream()
.map(comment -> comment.getUser().getOrgId().longValue())
.toList();

Map<Long, Boolean> blockedUsers = memberBlockService.getBlockedUsers(orgId, userOrgIds);

MyLikes myLikes = new MyLikes(likeRepository.findAllByUserIdAndCommentIdNotNull(userId));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import jakarta.persistence.Column;
import jakarta.persistence.Convert;
import jakarta.persistence.Entity;
import jakarta.persistence.EntityListeners;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
Expand Down Expand Up @@ -36,7 +35,6 @@
import org.sopt.makers.crew.main.entity.meeting.enums.MeetingJoinablePart;
import org.sopt.makers.crew.main.entity.meeting.vo.ImageUrlVO;
import org.sopt.makers.crew.main.entity.user.User;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

@Entity
@Getter
Expand Down Expand Up @@ -201,14 +199,17 @@ public Meeting(User user, Integer userId, String title, MeetingCategory category
*
* @return 모임 모집상태
*/
public Integer getMeetingStatus(LocalDateTime now) {
public Integer getMeetingStatusValue(LocalDateTime now) {
return getMeetingStatus(now).getValue();
}

public EnMeetingStatus getMeetingStatus(LocalDateTime now) {
if (now.isBefore(startDate)) {
return EnMeetingStatus.BEFORE_START.getValue();
return EnMeetingStatus.BEFORE_START;
} else if (now.isBefore(endDate)) {
return EnMeetingStatus.APPLY_ABLE.getValue();
return EnMeetingStatus.APPLY_ABLE;
} else {
return EnMeetingStatus.RECRUITMENT_COMPLETE.getValue();
return EnMeetingStatus.RECRUITMENT_COMPLETE;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
package org.sopt.makers.crew.main.entity.meeting.enums;

import java.util.Arrays;

import org.sopt.makers.crew.main.global.exception.BadRequestException;

/** 모임 상태 */
public enum EnMeetingStatus {
/** 시작 전 */
BEFORE_START(0),
/** 시작 전 */
BEFORE_START(0),

/** 지원 가능 */
APPLY_ABLE(1),
/** 지원 가능 */
APPLY_ABLE(1),

/** 모집 완료 */
RECRUITMENT_COMPLETE(2);
/** 모집 완료 */
RECRUITMENT_COMPLETE(2);

private final int value;
private final int value;

EnMeetingStatus(int value) {
this.value = value;
}
EnMeetingStatus(int value) {
this.value = value;
}

public static EnMeetingStatus ofValue(int dbData) {
return Arrays.stream(EnMeetingStatus.values()).filter(v -> v.getValue() == (dbData)).findFirst()
.orElseThrow(() -> new BadRequestException(
String.format("EnMeetingStatus 클래스에 value = [%s] 값을 가진 enum 객체가 없습니다.", dbData)));
}
public static EnMeetingStatus ofValue(int dbData) {
return Arrays.stream(EnMeetingStatus.values()).filter(v -> v.getValue() == (dbData)).findFirst()
.orElseThrow(() -> new BadRequestException(
String.format("EnMeetingStatus 클래스에 value = [%s] 값을 가진 enum 객체가 없습니다.", dbData)));
}

public int getValue() {
return value;
}
public int getValue() {
return value;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.sopt.makers.crew.main.internal.notification;
package org.sopt.makers.crew.main.external.notification;

import lombok.AccessLevel;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.sopt.makers.crew.main.internal.notification;
package org.sopt.makers.crew.main.external.notification;

import org.sopt.makers.crew.main.internal.notification.dto.PushNotificationRequestDto;
import org.sopt.makers.crew.main.internal.notification.dto.PushNotificationResponseDto;
import org.sopt.makers.crew.main.external.notification.dto.PushNotificationRequestDto;
import org.sopt.makers.crew.main.external.notification.dto.PushNotificationResponseDto;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package org.sopt.makers.crew.main.internal.notification;
package org.sopt.makers.crew.main.external.notification;

import static org.sopt.makers.crew.main.global.exception.ErrorStatus.*;
import static org.sopt.makers.crew.main.internal.notification.PushNotificationEnums.PUSH_NOTIFICATION_ACTION;

import java.util.UUID;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import org.sopt.makers.crew.main.internal.notification.dto.PushNotificationRequestDto;
import org.sopt.makers.crew.main.external.notification.dto.PushNotificationRequestDto;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

Expand All @@ -28,7 +27,7 @@ public class PushNotificationService {
public void sendPushNotification(PushNotificationRequestDto request) {
try {
pushServerClient.sendPushNotification(pushNotificationApiKey,
PUSH_NOTIFICATION_ACTION.getValue(), UUID.randomUUID().toString(), service, request);
PushNotificationEnums.PUSH_NOTIFICATION_ACTION.getValue(), UUID.randomUUID().toString(), service, request);
}catch (Exception e){
log.error(NOTIFICATION_SERVER_ERROR.getErrorCode(), e);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.sopt.makers.crew.main.internal.notification.dto;
package org.sopt.makers.crew.main.external.notification.dto;

import lombok.AllArgsConstructor;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.sopt.makers.crew.main.internal.notification.dto;
package org.sopt.makers.crew.main.external.notification.dto;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,4 @@

public interface MemberBlockService {
Map<Long, Boolean> getBlockedUsers(Long blockerOrgId, List<Long> userOrgIds);

Map<Long, Boolean> getBlockedUsers(Long blockerOrgId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,4 @@ public Map<Long, Boolean> getBlockedUsers(Long blockerOrgId, List<Long> userOrgI
.filter(memberBlock -> userOrgIds.contains(memberBlock.getBlockedMember()))
.collect(Collectors.toMap(MemberBlock::getBlockedMember, memberBlock -> true));
}

@Override
public Map<Long, Boolean> getBlockedUsers(Long blockerOrgId) {
List<MemberBlock> memberBlocks = memberBlockRepository.findAllByBlockerAndIsBlockedTrue(blockerOrgId);

return memberBlocks.stream()
.collect(Collectors.toMap(MemberBlock::getBlockedMember, memberBlock -> true));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private String[] getAuthWhitelist() {
"/auth/v2",
"/auth/v2/**",
actuatorEndPoint + "/health",
"/sentry" // prod에서 테스트 후 삭제
"/internal/**"
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public static MeetingResponseDto of(Meeting meeting, User meetingCreator, int ap

return new MeetingResponseDto(meeting.getId(), meeting.getTitle(),
meeting.getTargetActiveGeneration(), meeting.getJoinableParts(), meeting.getCategory().getValue(),
canJoinOnlyActiveGeneration, meeting.getMeetingStatus(now), meeting.getImageURL(),
canJoinOnlyActiveGeneration, meeting.getMeetingStatusValue(now), meeting.getImageURL(),
meeting.getIsMentorNeeded(), meeting.getMStartDate(), meeting.getMEndDate(), meeting.getCapacity(),
creatorDto, approvedCount, approvedCount);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
@Getter
public class PageOptionsDto {

@Schema(description = "각 페이지", defaultValue = "1", example = "1")
@Min(1)
private Integer page;
@Schema(description = "각 페이지", defaultValue = "1", example = "1")
@Min(1)
private Integer page;

@Schema(description = "가져올 데이터 개수", defaultValue = "12", example = "12")
@Min(1)
@Max(50)
private Integer take;
@Schema(description = "가져올 데이터 개수", defaultValue = "12", example = "12")
@Min(1)
@Max(50)
private Integer take;

public PageOptionsDto(Integer page, Integer take) {
this.page = page == null ? 1 : page;
this.take = take == null ? 12 : take;
}
public PageOptionsDto(Integer page, Integer take) {
this.page = page == null ? 1 : page;
this.take = take == null ? 12 : take;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package org.sopt.makers.crew.main.global.util;

import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;

/**
* AdvertisementCustomPageable : 광고 관련된 컨텐츠에 대해 페이지네이션이 필요할 때 사용하는 클래스
*
* @implSpec : 광고 때문에 첫페이지는 11개를, 나머지는 12개를 반환해야 한다.
* @implNote : 일반적인 페이지네이션 방식과 다르기에 해당 클래스를 따로 만들어 커스텀화하였다.
* */
public class AdvertisementCustomPageable implements Pageable {

private final int page;
private final int size;
private final Sort sort;

public AdvertisementCustomPageable(int page, Sort sort) {
this.page = page;
this.sort = sort;
this.size = calculateSize(page);
}

private int calculateSize(int page) {
// 첫 번째 페이지는 11개, 그 이후부터는 12개
if (page == 0) {
return 11;
}
return 12;
}

@Override
public int getPageNumber() {
return this.page;
}

@Override
public int getPageSize() {
return this.size;
}

@Override
public long getOffset() {
// 오프셋 계산
// 첫 번째 페이지는 11개, 그 이후부터는 12개 고려
if (page == 0) {
return 0;
}
return 11 + (page - 1) * 12L;
}

@Override
public Sort getSort() {
return this.sort;
}

@Override
public Pageable next() {
return new AdvertisementCustomPageable(this.page + 1, this.sort);
}

@Override
public Pageable previousOrFirst() {
if (page == 0) {
return this;
}
return new AdvertisementCustomPageable(this.page - 1, this.sort);
}

@Override
public Pageable first() {
return new AdvertisementCustomPageable(0, this.sort);
}

@Override
public boolean hasPrevious() {
return this.page > 0;
}

@Override
public Pageable withPage(int pageNumber) {
// 새로운 페이지 번호로 CustomPageable 생성
return new AdvertisementCustomPageable(pageNumber, this.sort);
}
}
Loading

0 comments on commit 6542937

Please sign in to comment.