From 3b1ae28e39fee0413cf36fb7aaf77b9c319a10e2 Mon Sep 17 00:00:00 2001 From: Jihwan Jung Date: Sun, 12 May 2024 15:02:00 +0900 Subject: [PATCH] =?UTF-8?q?#69=20feat:=20=EB=AA=A8=EC=9E=84=EC=9D=98=20?= =?UTF-8?q?=EA=B3=BC=EC=A0=9C=20=EB=B6=88=EB=9F=AC=EC=98=A4=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/AssignmentController.java | 8 +++++ .../controller/dto/AssignmentResponse.java | 30 +++++++++++++++++++ .../domain/AssignmentRepository.java | 4 +++ .../assignment/service/AssignmentService.java | 16 +++++++++- 4 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 backend/src/main/java/com/project/capstone/assignment/controller/dto/AssignmentResponse.java diff --git a/backend/src/main/java/com/project/capstone/assignment/controller/AssignmentController.java b/backend/src/main/java/com/project/capstone/assignment/controller/AssignmentController.java index a5d07ffc01..d76f92120e 100644 --- a/backend/src/main/java/com/project/capstone/assignment/controller/AssignmentController.java +++ b/backend/src/main/java/com/project/capstone/assignment/controller/AssignmentController.java @@ -1,5 +1,6 @@ package com.project.capstone.assignment.controller; +import com.project.capstone.assignment.controller.dto.AssignmentResponse; import com.project.capstone.assignment.controller.dto.CreateAssignmentRequest; import com.project.capstone.assignment.service.AssignmentService; import com.project.capstone.auth.domain.PrincipalDetails; @@ -8,6 +9,8 @@ import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.*; +import java.util.List; + @RestController @RequestMapping("/assign") @RequiredArgsConstructor @@ -24,4 +27,9 @@ public ResponseEntity createAssignment(@AuthenticationPrincipal PrincipalDeta } // 모임의 과제 조회 + @GetMapping("/get") + public ResponseEntity> getAssignment(@RequestParam Long clubId) { + List assignmentResponseList = assignmentService.getAssignment(clubId); + return ResponseEntity.ok().body(assignmentResponseList); + } } diff --git a/backend/src/main/java/com/project/capstone/assignment/controller/dto/AssignmentResponse.java b/backend/src/main/java/com/project/capstone/assignment/controller/dto/AssignmentResponse.java new file mode 100644 index 0000000000..919d146b87 --- /dev/null +++ b/backend/src/main/java/com/project/capstone/assignment/controller/dto/AssignmentResponse.java @@ -0,0 +1,30 @@ +package com.project.capstone.assignment.controller.dto; + +import com.project.capstone.assignment.domain.Assignment; +import com.project.capstone.content.controller.dto.ContentResponse; +import com.project.capstone.content.domain.Content; +import com.project.capstone.post.controller.dto.PostResponse; +import com.project.capstone.post.domain.Post; + +import java.util.ArrayList; +import java.util.List; + +public record AssignmentResponse( + Long id, + String name, + String startDate, + String endDate, + List contentList +) { + public AssignmentResponse(Assignment assignment) { + this(assignment.getId(), assignment.getName(), assignment.getStartDate(), assignment.getEndDate(), createContentList(assignment.getContentList())); + } + + private static List createContentList(List contents) { + List contentResponseList = new ArrayList<>(); + for (Content content : contents) { + contentResponseList.add(new ContentResponse(content)); + } + return contentResponseList; + } +} diff --git a/backend/src/main/java/com/project/capstone/assignment/domain/AssignmentRepository.java b/backend/src/main/java/com/project/capstone/assignment/domain/AssignmentRepository.java index 0e25843121..293da11ed8 100644 --- a/backend/src/main/java/com/project/capstone/assignment/domain/AssignmentRepository.java +++ b/backend/src/main/java/com/project/capstone/assignment/domain/AssignmentRepository.java @@ -1,6 +1,10 @@ package com.project.capstone.assignment.domain; +import com.project.capstone.club.domain.Club; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; + public interface AssignmentRepository extends JpaRepository { + List findAssignmentsByClub(Club club); } diff --git a/backend/src/main/java/com/project/capstone/assignment/service/AssignmentService.java b/backend/src/main/java/com/project/capstone/assignment/service/AssignmentService.java index 17e1880539..6a777b29aa 100644 --- a/backend/src/main/java/com/project/capstone/assignment/service/AssignmentService.java +++ b/backend/src/main/java/com/project/capstone/assignment/service/AssignmentService.java @@ -1,16 +1,19 @@ package com.project.capstone.assignment.service; +import com.project.capstone.assignment.controller.dto.AssignmentResponse; import com.project.capstone.assignment.controller.dto.CreateAssignmentRequest; import com.project.capstone.assignment.domain.Assignment; import com.project.capstone.assignment.domain.AssignmentRepository; import com.project.capstone.club.domain.Club; import com.project.capstone.club.domain.ClubRepository; import com.project.capstone.club.exception.ClubException; -import com.project.capstone.club.exception.ClubExceptionType; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; +import java.util.ArrayList; +import java.util.List; + import static com.project.capstone.club.exception.ClubExceptionType.CLUB_NOT_FOUND; import static com.project.capstone.club.exception.ClubExceptionType.UNAUTHORIZED_ACTION; @@ -32,4 +35,15 @@ public void createAssignment(String userId, CreateAssignmentRequest request, Lon } + public List getAssignment(Long clubId) { + Club club = clubRepository.findClubById(clubId).orElseThrow( + () -> new ClubException(CLUB_NOT_FOUND) + ); + List assignmentsByClub = assignmentRepository.findAssignmentsByClub(club); + List assignmentResponseList = new ArrayList<>(); + for (Assignment assignment : assignmentsByClub) { + assignmentResponseList.add(new AssignmentResponse(assignment)); + } + return assignmentResponseList; + } }