diff --git a/src/main/java/com/gdschongik/gdsc/domain/study/api/CommonStudyController.java b/src/main/java/com/gdschongik/gdsc/domain/study/api/CommonStudyController.java new file mode 100644 index 000000000..af1b58517 --- /dev/null +++ b/src/main/java/com/gdschongik/gdsc/domain/study/api/CommonStudyController.java @@ -0,0 +1,28 @@ +package com.gdschongik.gdsc.domain.study.api; + +import com.gdschongik.gdsc.domain.study.application.CommonStudyService; +import com.gdschongik.gdsc.domain.study.dto.response.CommonStudyResponse; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; +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.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@Tag(name = "Common Study", description = "공통 스터디 API입니다.") +@RestController +@RequestMapping("/common/studies") +@RequiredArgsConstructor +public class CommonStudyController { + + private final CommonStudyService commonStudyService; + + @Operation(summary = "스터디 기본 정보 조회", description = "스터디 기본 정보를 조회합니다.") + @GetMapping("/{studyId}") + public ResponseEntity getStudyInformation(@PathVariable Long studyId) { + CommonStudyResponse response = commonStudyService.getStudyInformation(studyId); + return ResponseEntity.ok(response); + } +} diff --git a/src/main/java/com/gdschongik/gdsc/domain/study/application/CommonStudyService.java b/src/main/java/com/gdschongik/gdsc/domain/study/application/CommonStudyService.java new file mode 100644 index 000000000..4561160e8 --- /dev/null +++ b/src/main/java/com/gdschongik/gdsc/domain/study/application/CommonStudyService.java @@ -0,0 +1,26 @@ +package com.gdschongik.gdsc.domain.study.application; + +import static com.gdschongik.gdsc.global.exception.ErrorCode.STUDY_NOT_FOUND; + +import com.gdschongik.gdsc.domain.study.dao.StudyRepository; +import com.gdschongik.gdsc.domain.study.domain.Study; +import com.gdschongik.gdsc.domain.study.dto.response.CommonStudyResponse; +import com.gdschongik.gdsc.global.exception.CustomException; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Slf4j +@Service +@RequiredArgsConstructor +public class CommonStudyService { + + private final StudyRepository studyRepository; + + @Transactional(readOnly = true) + public CommonStudyResponse getStudyInformation(Long studyId) { + Study study = studyRepository.findById(studyId).orElseThrow(() -> new CustomException(STUDY_NOT_FOUND)); + return CommonStudyResponse.from(study); + } +} diff --git a/src/main/java/com/gdschongik/gdsc/domain/study/dto/response/AssignmentResponse.java b/src/main/java/com/gdschongik/gdsc/domain/study/dto/response/AssignmentResponse.java index 33414fed9..5967f53f7 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/study/dto/response/AssignmentResponse.java +++ b/src/main/java/com/gdschongik/gdsc/domain/study/dto/response/AssignmentResponse.java @@ -4,11 +4,12 @@ import com.gdschongik.gdsc.domain.study.domain.StudyStatus; import com.gdschongik.gdsc.domain.study.domain.vo.Assignment; import io.swagger.v3.oas.annotations.media.Schema; +import java.time.LocalDateTime; public record AssignmentResponse( Long studyDetailId, @Schema(description = "과제 제목") String title, - @Schema(description = "마감 기한") String deadline, + @Schema(description = "마감 기한") LocalDateTime deadline, @Schema(description = "과제 명세 링크") String descriptionLink, @Schema(description = "과제 상태") StudyStatus assignmentStatus) { public static AssignmentResponse from(StudyDetail studyDetail) { @@ -16,7 +17,7 @@ public static AssignmentResponse from(StudyDetail studyDetail) { return new AssignmentResponse( studyDetail.getId(), assignment.getTitle(), - assignment.getDeadline().toString(), + assignment.getDeadline(), assignment.getDescriptionLink(), assignment.getStatus()); } diff --git a/src/main/java/com/gdschongik/gdsc/domain/study/dto/response/CommonStudyResponse.java b/src/main/java/com/gdschongik/gdsc/domain/study/dto/response/CommonStudyResponse.java new file mode 100644 index 000000000..096838a9d --- /dev/null +++ b/src/main/java/com/gdschongik/gdsc/domain/study/dto/response/CommonStudyResponse.java @@ -0,0 +1,40 @@ +package com.gdschongik.gdsc.domain.study.dto.response; + +import com.gdschongik.gdsc.domain.common.model.SemesterType; +import com.gdschongik.gdsc.domain.recruitment.domain.vo.Period; +import com.gdschongik.gdsc.domain.study.domain.Study; +import io.swagger.v3.oas.annotations.media.Schema; +import java.time.DayOfWeek; +import java.time.LocalTime; + +public record CommonStudyResponse( + Long studyId, + @Schema(description = "이름") String title, + @Schema(description = "활동 년도") Integer academicYear, + @Schema(description = "활동 학기") SemesterType semester, + @Schema(description = "종류") String studyType, + @Schema(description = "상세설명 노션 링크") String notionLink, + @Schema(description = "한 줄 소개") String introduction, + @Schema(description = "멘토 이름") String mentorName, + @Schema(description = "스터디 요일") DayOfWeek dayOfWeek, + @Schema(description = "스터디 시작 시간") LocalTime startTime, + @Schema(description = "스터디 종료 시간") LocalTime endTime, + @Schema(description = "총 주차수") Long totalWeek, + @Schema(description = "총 기간") Period period) { + public static CommonStudyResponse from(Study study) { + return new CommonStudyResponse( + study.getId(), + study.getTitle(), + study.getAcademicYear(), + study.getSemesterType(), + study.getStudyType().getValue(), + study.getNotionLink(), + study.getIntroduction(), + study.getMentor().getName(), + study.getDayOfWeek(), + study.getStartTime(), + study.getEndTime(), + study.getTotalWeek(), + study.getPeriod()); + } +} diff --git a/src/main/java/com/gdschongik/gdsc/domain/study/dto/response/StudyResponse.java b/src/main/java/com/gdschongik/gdsc/domain/study/dto/response/StudyResponse.java index 56b531e81..e04ccdd8e 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/study/dto/response/StudyResponse.java +++ b/src/main/java/com/gdschongik/gdsc/domain/study/dto/response/StudyResponse.java @@ -3,8 +3,8 @@ import com.gdschongik.gdsc.domain.study.domain.Study; import io.swagger.v3.oas.annotations.media.Schema; import java.time.DayOfWeek; +import java.time.LocalDateTime; import java.time.LocalTime; -import java.time.format.DateTimeFormatter; public record StudyResponse( Long studyId, @@ -13,12 +13,12 @@ public record StudyResponse( @Schema(description = "상세설명 노션 링크") String notionLink, @Schema(description = "한 줄 소개") String introduction, @Schema(description = "멘토 이름") String mentorName, - @Schema(description = "스터디 시간") String schedule, - @Schema(description = "총 주차수") String totalWeek, - @Schema(description = "개강일") String openingDate) { + @Schema(description = "스터디 요일") DayOfWeek dayOfWeek, + @Schema(description = "스터디 시작 시간") LocalTime startTime, + @Schema(description = "총 주차수") Long totalWeek, + @Schema(description = "개강일") LocalDateTime openingDate) { public static StudyResponse from(Study study) { - // todo: 포맷터로 분리 return new StudyResponse( study.getId(), study.getTitle(), @@ -26,25 +26,9 @@ public static StudyResponse from(Study study) { study.getNotionLink(), study.getIntroduction(), study.getMentor().getName(), - getSchedule(study.getDayOfWeek(), study.getStartTime()), - study.getTotalWeek().toString() + "주 코스", - DateTimeFormatter.ofPattern("MM.dd").format(study.getPeriod().getStartDate()) + " 개강"); - } - - private static String getSchedule(DayOfWeek dayOfWeek, LocalTime startTime) { - return getKoreanDayOfWeek(dayOfWeek) + startTime.format(DateTimeFormatter.ofPattern("HH")) + "시"; - } - - private static String getKoreanDayOfWeek(DayOfWeek dayOfWeek) { - return switch (dayOfWeek) { - case MONDAY -> "월"; - case TUESDAY -> "화"; - case WEDNESDAY -> "수"; - case THURSDAY -> "목"; - case FRIDAY -> "금"; - case SATURDAY -> "토"; - case SUNDAY -> "일"; - default -> ""; - }; + study.getDayOfWeek(), + study.getStartTime(), + study.getTotalWeek(), + study.getPeriod().getStartDate()); } }