Skip to content

Commit

Permalink
v2.2.3
Browse files Browse the repository at this point in the history
v2.2.3
  • Loading branch information
hoonyworld authored Nov 21, 2024
2 parents 071ff5c + 0363543 commit 51dc006
Show file tree
Hide file tree
Showing 33 changed files with 521 additions and 99 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
@@ -1,11 +1,12 @@
package org.sopt.makers.crew.main.entity.apply;

import static org.sopt.makers.crew.main.global.exception.ErrorStatus.NOT_FOUND_APPLY;
import static org.sopt.makers.crew.main.global.exception.ErrorStatus.*;

import java.util.List;

import org.sopt.makers.crew.main.global.exception.BadRequestException;
import org.sopt.makers.crew.main.entity.apply.enums.EnApplyStatus;
import org.sopt.makers.crew.main.entity.meeting.enums.MeetingCategory;
import org.sopt.makers.crew.main.global.exception.BadRequestException;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
Expand Down Expand Up @@ -57,4 +58,12 @@ default Apply findByIdOrThrow(Integer applyId) {
@Query("DELETE FROM Apply a WHERE a.meetingId = :meetingId")
void deleteAllByMeetingIdQuery(Integer meetingId);

}
@Query("SELECT COALESCE(COUNT(a.id), 0) " +
"FROM Apply a JOIN a.meeting m " +
"JOIN a.user u " +
"WHERE m.category = :category AND a.status = :status AND u.orgId = :orgId")
Long findApprovedStudyCountByOrgId(
@Param("category") MeetingCategory category,
@Param("status") EnApplyStatus status,
@Param("orgId") Integer orgId);
}
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 51dc006

Please sign in to comment.