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

feat: APP BE 와의 통신을 위한 모임 목록 조회 API 개발 #486

Merged
merged 16 commits into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 @@ -53,7 +53,7 @@ private String[] getAuthWhitelist() {
"/auth/v2",
"/auth/v2/**",
actuatorEndPoint + "/health",
"/sentry" // prod에서 테스트 후 삭제
"/internal/**"
mikekks marked this conversation as resolved.
Show resolved Hide resolved
};
}

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 {
mikekks marked this conversation as resolved.
Show resolved Hide resolved

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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,10 @@ public class CustomPageable implements Pageable {
private final int size;
private final Sort sort;

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

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

@Override
Expand All @@ -32,8 +27,7 @@ public int getPageSize() {

@Override
public long getOffset() {
// 오프셋 계산
return page == 0 ? 0 : 11 + (page - 1) * 12;
return (long)(page - 1) * size + size;
}

@Override
Expand All @@ -43,27 +37,29 @@ public Sort getSort() {

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

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

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

@Override
public boolean hasPrevious() {
return this.page > 0;
public Pageable withPage(int pageNumber) {
return new CustomPageable(pageNumber, this.size, this.sort);
}

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