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: 번쩍 상세 조회 GET API 구현 완료 #540

Merged
merged 12 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
Expand Up @@ -9,6 +9,7 @@
import org.sopt.makers.crew.main.entity.lightning.converter.LightningTimingTypeConverter;
import org.sopt.makers.crew.main.entity.lightning.enums.LightningPlaceType;
import org.sopt.makers.crew.main.entity.lightning.enums.LightningTimingType;
import org.sopt.makers.crew.main.entity.meeting.enums.EnMeetingStatus;
import org.sopt.makers.crew.main.entity.meeting.vo.ImageUrlVO;

import io.hypersistence.utils.hibernate.type.json.JsonBinaryType;
Expand Down Expand Up @@ -119,4 +120,23 @@ public Lightning(Integer leaderUserId, Integer meetingId, String title, String d
this.createdGeneration = createdGeneration;
this.imageURL = imageURL;
}

public boolean checkLightningMeetingLeader(Integer userId) {
return this.leaderUserId.equals(userId);
}

public int getLightningMeetingStatusValue(LocalDateTime now) {
return getLightningMeetingStatus(now).getValue();
}

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

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package org.sopt.makers.crew.main.entity.lightning;

import java.util.Optional;

import org.springframework.data.jpa.repository.JpaRepository;

public interface LightningRepository extends JpaRepository<Lightning, Integer> {
Optional<Lightning> findByMeetingId(Integer meetingId);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
package org.sopt.makers.crew.main.entity.tag;

import java.util.Optional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface TagRepository extends JpaRepository<Tag, Integer> {
@Query("SELECT t.welcomeMessageTypes FROM Tag t WHERE t.lightningId = :lightningId")
Optional<String> findWelcomeMessageTypesByLightningId(@Param("lightningId") Integer lightningId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public enum ErrorStatus {
* 405 METHOD_NOT_ALLOWED
*/
METHOD_NOT_SUPPORTED("지원되지 않는 HTTP 메서드입니다."),
TAG_NOT_FOUND_EXCEPTION("해당 태그를 찾을 수 없습니다."),

/**
* 500 SERVER_ERROR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

import org.sopt.makers.crew.main.lightning.v2.dto.request.LightningV2CreateLightningBodyDto;
import org.sopt.makers.crew.main.lightning.v2.dto.response.LightningV2CreateLightningResponseDto;
import org.sopt.makers.crew.main.lightning.v2.dto.response.LightningV2GetLightningByMeetingIdResponseDto;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;

import io.swagger.v3.oas.annotations.Operation;
Expand All @@ -26,12 +28,12 @@ ResponseEntity<LightningV2CreateLightningResponseDto> createLightning(
@Valid @RequestBody LightningV2CreateLightningBodyDto requestBody,
Principal principal);

// @Operation(summary = "번쩍 모임 상세 조회")
// @ApiResponses(value = {
// @ApiResponse(responseCode = "200", description = "번쩍 모임 상세 조회 성공"),
// @ApiResponse(responseCode = "400", description = "번쩍 모임이 없습니다.", content = @Content),
// })
// ResponseEntity<LightningV2GetLightningByIdResponseDto> getLightningById(
// @PathVariable Integer lightningId,
// Principal principal);
@Operation(summary = "번쩍 모임 상세 조회")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "번쩍 모임 상세 조회 성공"),
@ApiResponse(responseCode = "400", description = "번쩍 모임이 없습니다.", content = @Content),
})
ResponseEntity<LightningV2GetLightningByMeetingIdResponseDto> getLightningByMeetingId(
@PathVariable Integer meetingId,
Principal principal);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
import org.sopt.makers.crew.main.global.util.UserUtil;
import org.sopt.makers.crew.main.lightning.v2.dto.request.LightningV2CreateLightningBodyDto;
import org.sopt.makers.crew.main.lightning.v2.dto.response.LightningV2CreateLightningResponseDto;
import org.sopt.makers.crew.main.lightning.v2.dto.response.LightningV2GetLightningByMeetingIdResponseDto;
import org.sopt.makers.crew.main.lightning.v2.service.LightningV2Service;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -32,14 +35,14 @@ public ResponseEntity<LightningV2CreateLightningResponseDto> createLightning(
return ResponseEntity.status(HttpStatus.CREATED).body(lightningV2Service.createLightning(requestBody, userId));
}

// @Override
// @GetMapping("{lightningId}")
// public ResponseEntity<LightningV2GetLightningByIdResponseDto> getLightningById(
// @PathVariable Integer lightningId,
// Principal principal
// ) {
// Integer userId = UserUtil.getUserId(principal);
//
// return ResponseEntity.ok(lightningV2Service.getLightningById(lightningId, userId));
// }
@Override
@GetMapping("{meetingId}")
public ResponseEntity<LightningV2GetLightningByMeetingIdResponseDto> getLightningByMeetingId(
@PathVariable Integer meetingId,
Principal principal
) {
Integer userId = UserUtil.getUserId(principal);

return ResponseEntity.ok(lightningV2Service.getLightningByMeetingId(meetingId, userId));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

@Schema(name = "LightningV2CreateLightningResponseDto", description = "번쩍 모임 생성 응답 Dto")
public record LightningV2CreateLightningResponseDto(
@Schema(description = "번쩍 모임 id", example = "1")
@Schema(description = "모임 id - 번쩍 카테고리", example = "1")
@NotNull
Integer lightningId
Integer meetingId
) {
public static LightningV2CreateLightningResponseDto from(Integer lightningId) {
return new LightningV2CreateLightningResponseDto(lightningId);
public static LightningV2CreateLightningResponseDto from(Integer meetingId) {
return new LightningV2CreateLightningResponseDto(meetingId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
package org.sopt.makers.crew.main.lightning.v2.dto.response;

import java.time.LocalDateTime;
import java.util.List;

import org.sopt.makers.crew.main.entity.lightning.Lightning;
import org.sopt.makers.crew.main.entity.meeting.enums.MeetingCategory;
import org.sopt.makers.crew.main.entity.meeting.vo.ImageUrlVO;
import org.sopt.makers.crew.main.entity.tag.enums.WelcomeMessageType;
import org.sopt.makers.crew.main.global.dto.MeetingCreatorDto;
import org.sopt.makers.crew.main.meeting.v2.dto.response.ApplyWholeInfoDto;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;

@Schema(description = "번쩍 상세 조회 dto")
public record LightningV2GetLightningByMeetingIdResponseDto(

@Schema(description = "모임 id", example = "2")
@NotNull
Integer id,

@Schema(description = "번쩍장 id", example = "184")
@NotNull
Integer leaderUserId,

@Schema(description = "번쩍 제목", example = "번쩍 제목입니다.")
@NotNull
@Size(min = 1, max = 30)
String title,

@Schema(description = "모임 카테고리(번쩍)", example = "번쩍")
@NotNull
String category,

@Schema(description = "번쩍 이미지", example = "[url 형식]")
@NotNull
List<ImageUrlVO> imageURL,

@Schema(description = "번쩍 신청 종료 시간", example = "2025-07-30T23:59:59")
@NotNull
LocalDateTime endDate,

@Schema(example = "1", description = "최소 모집 인원")
@Min(1)
@NotNull
Integer minimumCapacity,

@Schema(example = "5", description = "최대 모집 인원")
@Min(1)
@Max(999)
@NotNull
Integer maximumCapacity,

@Schema(description = "환영 메시지 타입 목록")
@NotNull
List<String> welcomeMessageTypes,

@Schema(description = "번쩍 소개", example = "번쩍 소개 입니다.")
@NotNull
String desc,

@Schema(description = "번쩍 활동 시작 시간", example = "2024-08-13T15:30:00", name = "activityStartDate")
@NotNull
LocalDateTime activityStartDate,

@Schema(description = "번쩍 활동 종료 시간", example = "2024-10-13T23:59:59", name = "activityEndDate")
@NotNull
LocalDateTime activityEndDate,

@Schema(description = "번쩍 일시 타입", example = "예정 기간(협의 후 결정)")
@NotNull
String timingType,

@Schema(description = "번쩍 장소 타입", example = "온라인")
@NotNull
String placeType,

@Schema(description = "번쩍 장소", example = "Zoom 링크")
@NotNull
String place,

@Schema(description = "개설 기수", example = "36")
@NotNull
Integer createdGeneration,

@Schema(description = "번쩍 상태, 0: 모집전, 1: 모집중, 2: 모집종료", example = "1", type = "integer", allowableValues = {"0",
"1", "2"})
@NotNull
int status,

@Schema(description = "승인된 신청 수", example = "7")
@NotNull
long approvedApplyCount,

@Schema(description = "번쩍 개설자 여부", example = "true")
@NotNull
boolean host,

@Schema(description = "번쩍 신청 여부", example = "false")
@NotNull
boolean apply,

@Schema(description = "번쩍 승인 여부", example = "false")
@NotNull
boolean approved,

@Schema(description = "번쩍장 객체", example = "")
@NotNull
MeetingCreatorDto user,

@Schema(description = "신청 목록", example = "")
@NotNull
List<ApplyWholeInfoDto> appliedInfo

) {
public static LightningV2GetLightningByMeetingIdResponseDto of(
Integer meetingId,
Lightning lightning,
List<WelcomeMessageType> welcomeMessageTypes,
long approvedCount,
boolean isHost,
boolean isApply,
boolean isApproved,
MeetingCreatorDto meetingCreatorDto,
List<ApplyWholeInfoDto> appliedInfo,
LocalDateTime now
) {

int lightningMeetingStatus = lightning.getLightningMeetingStatusValue(now);
List<String> welcomeMessageTypeValues = welcomeMessageTypes.stream()
.map(WelcomeMessageType::getValue)
.toList();

return new LightningV2GetLightningByMeetingIdResponseDto(
meetingId,
lightning.getLeaderUserId(),
lightning.getTitle(),
MeetingCategory.LIGHTNING.getValue(),
lightning.getImageURL(),
lightning.getEndDate(),
lightning.getMinimumCapacity(),
lightning.getMaximumCapacity(),
welcomeMessageTypeValues,
lightning.getDesc(),
lightning.getActivityStartDate(),
lightning.getActivityEndDate(),
lightning.getLightningTimingType().getValue(),
lightning.getLightningPlaceType().getValue(),
lightning.getLightningPlace(),
lightning.getCreatedGeneration(),
lightningMeetingStatus,
approvedCount,
isHost,
isApply,
isApproved,
meetingCreatorDto,
appliedInfo);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

import org.sopt.makers.crew.main.lightning.v2.dto.request.LightningV2CreateLightningBodyDto;
import org.sopt.makers.crew.main.lightning.v2.dto.response.LightningV2CreateLightningResponseDto;
import org.sopt.makers.crew.main.lightning.v2.dto.response.LightningV2GetLightningByMeetingIdResponseDto;

public interface LightningV2Service {
LightningV2CreateLightningResponseDto createLightning(
LightningV2CreateLightningBodyDto requestBody, Integer userId);

LightningV2GetLightningByMeetingIdResponseDto getLightningByMeetingId(Integer meetingId, Integer userId);
}
Loading
Loading