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 추가 #543

Merged
merged 2 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
@@ -1,9 +1,12 @@
package com.gdschongik.gdsc.domain.study.api;

import com.gdschongik.gdsc.domain.study.application.StudyMentorService;
import com.gdschongik.gdsc.domain.study.domain.request.AssignmentCreateRequest;
import com.gdschongik.gdsc.domain.study.dto.response.AssignmentResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
Expand All @@ -14,10 +17,26 @@
@RequiredArgsConstructor
public class StudyMentorController {

private final StudyMentorService studyMentorService;

@Operation(summary = "스터디 과제 개설", description = "멘토만 과제를 개설할 수 있습니다.")
@PutMapping("/assignment/{assignmentId}")
public ResponseEntity<Void> createStudyAssignment(
@PathVariable Long assignmentId, @Valid @RequestBody AssignmentCreateRequest request) {
return null;
}
Comment on lines +21 to 27
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

createStudyAssignment 메서드의 반환값을 수정하세요.

현재 메서드는 null을 반환하고 있습니다. 적절한 ResponseEntity를 반환하도록 수정해야 합니다.

- return null;
+ studyMentorService.createAssignment(assignmentId, request);
+ return ResponseEntity.ok().build();
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
@Operation(summary = "스터디 과제 개설", description = "멘토만 과제를 개설할 수 있습니다.")
@PutMapping("/assignment/{assignmentId}")
public ResponseEntity<Void> createStudyAssignment(
@PathVariable Long assignmentId, @Valid @RequestBody AssignmentCreateRequest request) {
return null;
}
@Operation(summary = "스터디 과제 개설", description = "멘토만 과제를 개설할 수 있습니다.")
@PutMapping("/assignment/{assignmentId}")
public ResponseEntity<Void> createStudyAssignment(
@PathVariable Long assignmentId, @Valid @RequestBody AssignmentCreateRequest request) {
studyMentorService.createAssignment(assignmentId, request);
return ResponseEntity.ok().build();
}


@Operation(summary = "스터디 주차별 과제 목록 조회", description = "주차별 스터디 과제 목록을 조회합니다.")
@GetMapping("/assignments/{studyId}")
public ResponseEntity<List<AssignmentResponse>> getWeeklyAssignments(@PathVariable Long studyId) {
List<AssignmentResponse> response = studyMentorService.getWeeklyAssignments(studyId);
return ResponseEntity.ok(response);
}

@Operation(summary = "스터디 과제 상세 조회", description = "멘토가 자신의 스터디 과제를 조회합니다.")
@GetMapping("/assignments/{studyDetailId}")
public ResponseEntity<AssignmentResponse> getStudyAssignment(@PathVariable Long studyDetailId) {
AssignmentResponse response = studyMentorService.getAssignment(studyDetailId);
return ResponseEntity.ok(response);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.gdschongik.gdsc.domain.study.application;

import static com.gdschongik.gdsc.global.exception.ErrorCode.*;

import com.gdschongik.gdsc.domain.study.dao.StudyDetailRepository;
import com.gdschongik.gdsc.domain.study.domain.StudyDetail;
import com.gdschongik.gdsc.domain.study.dto.response.AssignmentResponse;
import com.gdschongik.gdsc.global.exception.CustomException;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Slf4j
@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

메서드 레벨로 내려주세요

public class StudyMentorService {

private final StudyDetailRepository studyDetailRepository;

public List<AssignmentResponse> getWeeklyAssignments(Long studyId) {
List<StudyDetail> studyDetails = studyDetailRepository.findAllByStudyId(studyId);
return studyDetails.stream().map(AssignmentResponse::from).toList();
}

public AssignmentResponse getAssignment(Long studyDetailId) {
StudyDetail studyDetail = studyDetailRepository
.findById(studyDetailId)
.orElseThrow(() -> new CustomException(STUDY_DETAIL_NOT_FOUND));
return AssignmentResponse.from(studyDetail);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.gdschongik.gdsc.domain.study.dao;

import com.gdschongik.gdsc.domain.study.domain.StudyDetail;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;

public interface StudyDetailRepository extends JpaRepository<StudyDetail, Long> {}
public interface StudyDetailRepository extends JpaRepository<StudyDetail, Long> {

List<StudyDetail> findAllByStudyId(Long studyId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.gdschongik.gdsc.domain.study.dto.response;

import com.gdschongik.gdsc.domain.study.domain.StudyDetail;
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;

public record AssignmentResponse(
Long studyDetailId,
@Schema(description = "과제 제목") String title,
@Schema(description = "마감 기한") String 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.getDescriptionLink(),
assignment.getStatus());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ public enum ErrorCode {
STUDY_NOT_APPLICABLE(HttpStatus.CONFLICT, "스터디 신청기간이 아닙니다."),
STUDY_NOT_CANCELABLE_APPLICATION_PERIOD(HttpStatus.CONFLICT, "스터디 신청기간이 아니라면 취소할 수 없습니다."),

// StudyDetail
STUDY_DETAIL_NOT_FOUND(HttpStatus.NOT_FOUND, "존재하지 않는 스터디 상세 정보입니다."),

// StudyHistory
STUDY_HISTORY_NOT_FOUND(HttpStatus.NOT_FOUND, "존재하지 않는 스터디 수강 기록입니다."),
STUDY_HISTORY_DUPLICATE(HttpStatus.CONFLICT, "이미 해당 스터디를 신청했습니다."),
Expand Down