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: 스터디 기본 정보 조회 API #608

Merged
merged 5 commits into from
Aug 14, 2024
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
@@ -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<CommonStudyResponse> getStudyInformation(@PathVariable Long studyId) {
CommonStudyResponse response = commonStudyService.getStudyInformation(studyId);
return ResponseEntity.ok(response);
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@
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) {
Assignment assignment = studyDetail.getAssignment();
return new AssignmentResponse(
studyDetail.getId(),
assignment.getTitle(),
assignment.getDeadline().toString(),
assignment.getDeadline(),
assignment.getDescriptionLink(),
assignment.getStatus());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -13,38 +13,22 @@ 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(),
study.getStudyType().getValue(),
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());
}
}