Skip to content

Commit

Permalink
v2.2.1
Browse files Browse the repository at this point in the history
v2.2.1
  • Loading branch information
mikekks authored Nov 11, 2024
2 parents 73fd2e9 + 3f29844 commit a2abdc3
Show file tree
Hide file tree
Showing 9 changed files with 299 additions and 106 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,56 +7,57 @@
@Getter
@RequiredArgsConstructor(access = AccessLevel.PROTECTED)
public enum ErrorStatus {
/**
* 204 NO_CONTENT
*/
NO_CONTENT_EXCEPTION("참여한 모임이 없습니다."),

/**
* 400 BAD_REQUEST
*/
VALIDATION_EXCEPTION("CF-001"),
VALIDATION_REQUEST_MISSING_EXCEPTION("요청값이 입력되지 않았습니다."),
INVALID_INPUT_VALUE("요청값이 올바르지 않습니다."),
INVALID_INPUT_VALUE_FILTER("요청값 또는 토큰이 올바르지 않습니다."),
NOT_FOUND_MEETING("모임이 없습니다."),
NOT_FOUND_POST("존재하지 않는 게시글입니다."),
NOT_FOUND_USER("존재하지 않는 유저입니다."),
NOT_FOUND_COMMENT("존재하지 않는 댓글입니다."),
FULL_MEETING_CAPACITY("정원이 꽉 찼습니다."),
ALREADY_APPLIED_MEETING("이미 지원한 모임입니다."),
ALREADY_REPORTED_COMMENT("이미 신고한 댓글입니다."),
ALREADY_REPORTED_POST("이미 신고한 게시글입니다."),
NOT_IN_APPLY_PERIOD("모임 지원 기간이 아닙니다."),
MISSING_GENERATION_PART("내 프로필에서 기수/파트 정보를 입력해주세요."),
NOT_ACTIVE_GENERATION("활동 기수가 아닙니다."),
NOT_TARGET_PART("지원 가능한 파트가 아닙니다."),
NOT_FOUND_APPLY("신청상태가 아닌 모임입니다."),
ALREADY_PROCESSED_APPLY("이미 해당 상태로 처리된 신청 정보입니다."),
MAX_IMAGE_UPLOAD_EXCEEDED("이미지는 최대 10개까지만 업로드 가능합니다."),
LEADER_CANNOT_APPLY("모임장은 신청할 수 없습니다."),
CO_LEADER_CANNOT_APPLY("공동 모임장은 신청할 수 없습니다."),
LEADER_CANNOT_BE_CO_LEADER_APPLY("모임장은 공동 모임장이 될 수 없습니다."),

/**
* 401 UNAUTHORIZED
*/
UNAUTHORIZED_TOKEN("유효하지 않은 토큰입니다."),
UNAUTHORIZED_USER("존재하지 않거나 유효하지 않은 유저입니다."),

/**
* 403 FORBIDDEN
*/
FORBIDDEN_EXCEPTION("권한이 없습니다."),

/**
* 500 SERVER_ERROR
*/
NOTIFICATION_SERVER_ERROR("알림 서버에 에러가 발생했습니다."),
CSV_ERROR("csv 처리 과정에 에러가 발생했습니다."),
S3_STORAGE_ERROR("s3 스토리지에 에러가 발생했습니다."),
INTERNAL_SERVER_ERROR("예상치 못한 서버 에러가 발생했습니다.");

private final String errorCode;

}
/**
* 204 NO_CONTENT
*/
NO_CONTENT_EXCEPTION("참여한 모임이 없습니다."),

/**
* 400 BAD_REQUEST
*/
VALIDATION_EXCEPTION("CF-001"),
VALIDATION_REQUEST_MISSING_EXCEPTION("요청값이 입력되지 않았습니다."),
INVALID_INPUT_VALUE("요청값이 올바르지 않습니다."),
INVALID_INPUT_VALUE_FILTER("요청값 또는 토큰이 올바르지 않습니다."),
NOT_FOUND_MEETING("모임이 없습니다."),
NOT_FOUND_POST("존재하지 않는 게시글입니다."),
NOT_FOUND_USER("존재하지 않는 유저입니다."),
NOT_FOUND_COMMENT("존재하지 않는 댓글입니다."),
FULL_MEETING_CAPACITY("정원이 꽉 찼습니다."),
ALREADY_APPLIED_MEETING("이미 지원한 모임입니다."),
ALREADY_REPORTED_COMMENT("이미 신고한 댓글입니다."),
ALREADY_REPORTED_POST("이미 신고한 게시글입니다."),
NOT_IN_APPLY_PERIOD("모임 지원 기간이 아닙니다."),
MISSING_GENERATION_PART("내 프로필에서 기수/파트 정보를 입력해주세요."),
NOT_ACTIVE_GENERATION("활동 기수가 아닙니다."),
NOT_TARGET_PART("지원 가능한 파트가 아닙니다."),
NOT_FOUND_APPLY("신청상태가 아닌 모임입니다."),
ALREADY_PROCESSED_APPLY("이미 해당 상태로 처리된 신청 정보입니다."),
MAX_IMAGE_UPLOAD_EXCEEDED("이미지는 최대 10개까지만 업로드 가능합니다."),
LEADER_CANNOT_APPLY("모임장은 신청할 수 없습니다."),
CO_LEADER_CANNOT_APPLY("공동 모임장은 신청할 수 없습니다."),
LEADER_CANNOT_BE_CO_LEADER_APPLY("모임장은 공동 모임장이 될 수 없습니다."),
NOT_ALLOW_MEETING_APPLY("허용되지 않는 모임 신청입니다."),

/**
* 401 UNAUTHORIZED
*/
UNAUTHORIZED_TOKEN("유효하지 않은 토큰입니다."),
UNAUTHORIZED_USER("존재하지 않거나 유효하지 않은 유저입니다."),

/**
* 403 FORBIDDEN
*/
FORBIDDEN_EXCEPTION("권한이 없습니다."),

/**
* 500 SERVER_ERROR
*/
NOTIFICATION_SERVER_ERROR("알림 서버에 에러가 발생했습니다."),
CSV_ERROR("csv 처리 과정에 에러가 발생했습니다."),
S3_STORAGE_ERROR("s3 스토리지에 에러가 발생했습니다."),
INTERNAL_SERVER_ERROR("예상치 못한 서버 에러가 발생했습니다.");

private final String errorCode;

}
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
package org.sopt.makers.crew.main.meeting.v2;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import jakarta.websocket.server.PathParam;

import java.security.Principal;
import java.util.List;

Expand All @@ -35,6 +24,17 @@
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import jakarta.websocket.server.PathParam;

@Tag(name = "모임")
public interface MeetingV2Api {
@Operation(summary = "플레이그라운드 마이페이지 내 모임 정보 조회")
Expand All @@ -58,12 +58,22 @@ ResponseEntity<MeetingV2CreateMeetingResponseDto> createMeeting(
@Valid @RequestBody MeetingV2CreateMeetingBodyDto requestBody,
Principal principal);

@Operation(summary = "모임 지원")
@Operation(summary = "일반 모임 지원")
@ApiResponses(value = {@ApiResponse(responseCode = "201", description = "지원 완료"),
@ApiResponse(responseCode = "400", description =
"\"모임이 없습니다\" or \"기수/파트를 설정해주세요\" or \"정원이 꽉찼습니다\" or \"활동 기수가 아닙니다\" " +
"or \"지원 가능한 파트가 아닙니다\" or \"지원 가능한 기간이 아닙니다\"", content = @Content),})
ResponseEntity<MeetingV2ApplyMeetingResponseDto> applyGeneralMeeting(
@RequestBody MeetingV2ApplyMeetingDto requestBody,
Principal principal);

@Operation(hidden = true, summary = "행사 모임 지원")
@ApiResponses(value = {@ApiResponse(responseCode = "201", description = "지원 완료"),
@ApiResponse(responseCode = "400", description =
"\"모임이 없습니다\" or \"기수/파트를 설정해주세요\" or \"정원이 꽉찼습니다\" or \"활동 기수가 아닙니다\" " +
"or \"지원 가능한 파트가 아닙니다\" or \"지원 가능한 기간이 아닙니다\"", content = @Content),})
ResponseEntity<MeetingV2ApplyMeetingResponseDto> applyMeeting(@RequestBody MeetingV2ApplyMeetingDto requestBody,
ResponseEntity<MeetingV2ApplyMeetingResponseDto> applyEventMeeting(
@RequestBody MeetingV2ApplyMeetingDto requestBody,
Principal principal);

@Operation(summary = "모임 지원 취소")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
package org.sopt.makers.crew.main.meeting.v2;

import io.swagger.v3.oas.annotations.Parameter;
import jakarta.validation.Valid;

import java.security.Principal;
import java.util.List;

import lombok.RequiredArgsConstructor;

import org.sopt.makers.crew.main.global.util.UserUtil;
import org.sopt.makers.crew.main.external.s3.service.S3Service;
import org.sopt.makers.crew.main.global.util.UserUtil;
import org.sopt.makers.crew.main.meeting.v2.dto.query.MeetingGetAppliesCsvQueryDto;
import org.sopt.makers.crew.main.meeting.v2.dto.query.MeetingGetAppliesQueryDto;
import org.sopt.makers.crew.main.meeting.v2.dto.query.MeetingV2GetAllMeetingByOrgUserQueryDto;
Expand Down Expand Up @@ -41,6 +36,10 @@
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.v3.oas.annotations.Parameter;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;

@RestController
@RequestMapping("/meeting/v2")
@RequiredArgsConstructor
Expand Down Expand Up @@ -78,11 +77,21 @@ public ResponseEntity<MeetingV2CreateMeetingResponseDto> createMeeting(

@Override
@PostMapping("/apply")
public ResponseEntity<MeetingV2ApplyMeetingResponseDto> applyMeeting(
public ResponseEntity<MeetingV2ApplyMeetingResponseDto> applyGeneralMeeting(
@Valid @RequestBody MeetingV2ApplyMeetingDto requestBody,
Principal principal) {
Integer userId = UserUtil.getUserId(principal);
return ResponseEntity.status(HttpStatus.CREATED)
.body(meetingV2Service.applyGeneralMeeting(requestBody, userId));
}

@PostMapping("${custom.paths.eventApply}")
public ResponseEntity<MeetingV2ApplyMeetingResponseDto> applyEventMeeting(
@Valid @RequestBody MeetingV2ApplyMeetingDto requestBody,
Principal principal) {
Integer userId = UserUtil.getUserId(principal);
return ResponseEntity.status(HttpStatus.CREATED).body(meetingV2Service.applyMeeting(requestBody, userId));
return ResponseEntity.status(HttpStatus.CREATED)
.body(meetingV2Service.applyEventMeeting(requestBody, userId));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ MeetingV2GetAllMeetingByOrgUserDto getAllMeetingByOrgUser(

MeetingV2CreateMeetingResponseDto createMeeting(MeetingV2CreateMeetingBodyDto requestBody, Integer userId);

MeetingV2ApplyMeetingResponseDto applyMeeting(MeetingV2ApplyMeetingDto requestBody, Integer userId);
MeetingV2ApplyMeetingResponseDto applyGeneralMeeting(MeetingV2ApplyMeetingDto requestBody, Integer userId);

MeetingV2ApplyMeetingResponseDto applyEventMeeting(MeetingV2ApplyMeetingDto requestBody, Integer userId);

void applyMeetingCancel(Integer meetingId, Integer userId);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.sopt.makers.crew.main.meeting.v2.service;

import static org.sopt.makers.crew.main.entity.apply.enums.EnApplyStatus.*;
import static org.sopt.makers.crew.main.global.constant.CrewConst.*;
import static org.sopt.makers.crew.main.global.exception.ErrorStatus.*;
import static org.sopt.makers.crew.main.entity.apply.enums.EnApplyStatus.*;

import java.io.FileOutputStream;
import java.io.IOException;
Expand All @@ -22,19 +22,6 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import lombok.RequiredArgsConstructor;

import org.sopt.makers.crew.main.entity.meeting.CoLeader;
import org.sopt.makers.crew.main.entity.meeting.CoLeaderRepository;
import org.sopt.makers.crew.main.entity.meeting.CoLeaders;
import org.sopt.makers.crew.main.global.dto.MeetingResponseDto;
import org.sopt.makers.crew.main.global.exception.BadRequestException;
import org.sopt.makers.crew.main.global.exception.ServerException;
import org.sopt.makers.crew.main.global.pagination.dto.PageMetaDto;
import org.sopt.makers.crew.main.global.pagination.dto.PageOptionsDto;
import org.sopt.makers.crew.main.global.util.CustomPageable;
import org.sopt.makers.crew.main.global.util.Time;
import org.sopt.makers.crew.main.global.util.UserPartUtil;
import org.sopt.makers.crew.main.entity.apply.Applies;
import org.sopt.makers.crew.main.entity.apply.Apply;
import org.sopt.makers.crew.main.entity.apply.ApplyRepository;
Expand All @@ -43,8 +30,12 @@
import org.sopt.makers.crew.main.entity.comment.Comment;
import org.sopt.makers.crew.main.entity.comment.CommentRepository;
import org.sopt.makers.crew.main.entity.like.LikeRepository;
import org.sopt.makers.crew.main.entity.meeting.CoLeader;
import org.sopt.makers.crew.main.entity.meeting.CoLeaderRepository;
import org.sopt.makers.crew.main.entity.meeting.CoLeaders;
import org.sopt.makers.crew.main.entity.meeting.Meeting;
import org.sopt.makers.crew.main.entity.meeting.MeetingRepository;
import org.sopt.makers.crew.main.entity.meeting.enums.MeetingCategory;
import org.sopt.makers.crew.main.entity.meeting.enums.MeetingJoinablePart;
import org.sopt.makers.crew.main.entity.post.Post;
import org.sopt.makers.crew.main.entity.post.PostRepository;
Expand All @@ -53,6 +44,14 @@
import org.sopt.makers.crew.main.entity.user.enums.UserPart;
import org.sopt.makers.crew.main.entity.user.vo.UserActivityVO;
import org.sopt.makers.crew.main.external.s3.service.S3Service;
import org.sopt.makers.crew.main.global.dto.MeetingResponseDto;
import org.sopt.makers.crew.main.global.exception.BadRequestException;
import org.sopt.makers.crew.main.global.exception.ServerException;
import org.sopt.makers.crew.main.global.pagination.dto.PageMetaDto;
import org.sopt.makers.crew.main.global.pagination.dto.PageOptionsDto;
import org.sopt.makers.crew.main.global.util.CustomPageable;
import org.sopt.makers.crew.main.global.util.Time;
import org.sopt.makers.crew.main.global.util.UserPartUtil;
import org.sopt.makers.crew.main.meeting.v2.dto.ApplyMapper;
import org.sopt.makers.crew.main.meeting.v2.dto.MeetingMapper;
import org.sopt.makers.crew.main.meeting.v2.dto.query.MeetingGetAppliesQueryDto;
Expand Down Expand Up @@ -81,6 +80,8 @@

import com.opencsv.CSVWriter;

import lombok.RequiredArgsConstructor;

@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
Expand Down Expand Up @@ -215,8 +216,36 @@ public MeetingV2CreateMeetingResponseDto createMeeting(MeetingV2CreateMeetingBod

@Override
@Transactional
public MeetingV2ApplyMeetingResponseDto applyMeeting(MeetingV2ApplyMeetingDto requestBody, Integer userId) {
public MeetingV2ApplyMeetingResponseDto applyGeneralMeeting(MeetingV2ApplyMeetingDto requestBody, Integer userId) {
Meeting meeting = meetingRepository.findByIdOrThrow(requestBody.getMeetingId());

validateMeetingCategoryNotEvent(meeting);

User user = userRepository.findByIdOrThrow(userId);
CoLeaders coLeaders = new CoLeaders(coLeaderRepository.findAllByMeetingId(meeting.getId()));

List<Apply> applies = applyRepository.findAllByMeetingId(meeting.getId());

validateMeetingCapacity(meeting, applies);
validateUserAlreadyApplied(userId, applies);
validateApplyPeriod(meeting);
validateUserActivities(user);
validateUserJoinableParts(user, meeting);
coLeaders.validateCoLeader(meeting.getId(), user.getId());
meeting.validateIsNotMeetingLeader(userId);

Apply apply = applyMapper.toApplyEntity(requestBody, EnApplyType.APPLY, meeting, user, userId);
Apply savedApply = applyRepository.save(apply);
return MeetingV2ApplyMeetingResponseDto.of(savedApply.getId());
}

@Override
@Transactional
public MeetingV2ApplyMeetingResponseDto applyEventMeeting(MeetingV2ApplyMeetingDto requestBody, Integer userId) {
Meeting meeting = meetingRepository.findByIdOrThrow(requestBody.getMeetingId());

validateMeetingCategoryEvent(meeting);

User user = userRepository.findByIdOrThrow(userId);
CoLeaders coLeaders = new CoLeaders(coLeaderRepository.findAllByMeetingId(meeting.getId()));

Expand Down Expand Up @@ -477,6 +506,18 @@ private List<UserActivityVO> filterUserActivities(User user, Meeting meeting) {
return user.getActivities();
}

private void validateMeetingCategoryNotEvent(Meeting meeting) {
if (meeting.getCategory() == MeetingCategory.EVENT) {
throw new BadRequestException(NOT_IN_APPLY_PERIOD.getErrorCode());
}
}

private void validateMeetingCategoryEvent(Meeting meeting) {
if (meeting.getCategory() != MeetingCategory.EVENT) {
throw new BadRequestException(NOT_IN_APPLY_PERIOD.getErrorCode());
}
}

private void validateMeetingCapacity(Meeting meeting, List<Apply> applies) {
List<Apply> approvedApplies = applies.stream()
.filter(apply -> EnApplyStatus.APPROVE.equals(apply.getStatus()))
Expand Down
8 changes: 6 additions & 2 deletions main/src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ push-notification:
push-server-url: ${DEV_PUSH_SERVER_URL}

notice:
secret-key : ${NOTICE_SECRET_KEY}
secret-key: ${NOTICE_SECRET_KEY}

playground:
server:
Expand Down Expand Up @@ -94,4 +94,8 @@ management:
prometheus:
metrics:
export:
enabled: true
enabled: true

custom:
paths:
eventApply: ${DEV_EVENT_APPLY_PATH}
Loading

0 comments on commit a2abdc3

Please sign in to comment.