Skip to content

Commit

Permalink
#69 feat: 모임의 과제 불러오기
Browse files Browse the repository at this point in the history
  • Loading branch information
wjdwlghks committed May 12, 2024
1 parent 98e9f07 commit 3b1ae28
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand All @@ -24,4 +27,9 @@ public ResponseEntity<?> createAssignment(@AuthenticationPrincipal PrincipalDeta
}

// 모임의 과제 조회
@GetMapping("/get")
public ResponseEntity<List<AssignmentResponse>> getAssignment(@RequestParam Long clubId) {
List<AssignmentResponse> assignmentResponseList = assignmentService.getAssignment(clubId);
return ResponseEntity.ok().body(assignmentResponseList);
}
}
Original file line number Diff line number Diff line change
@@ -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<ContentResponse> contentList
) {
public AssignmentResponse(Assignment assignment) {
this(assignment.getId(), assignment.getName(), assignment.getStartDate(), assignment.getEndDate(), createContentList(assignment.getContentList()));
}

private static List<ContentResponse> createContentList(List<Content> contents) {
List<ContentResponse> contentResponseList = new ArrayList<>();
for (Content content : contents) {
contentResponseList.add(new ContentResponse(content));
}
return contentResponseList;
}
}
Original file line number Diff line number Diff line change
@@ -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<Assignment, Long> {
List<Assignment> findAssignmentsByClub(Club club);
}
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -32,4 +35,15 @@ public void createAssignment(String userId, CreateAssignmentRequest request, Lon
}


public List<AssignmentResponse> getAssignment(Long clubId) {
Club club = clubRepository.findClubById(clubId).orElseThrow(
() -> new ClubException(CLUB_NOT_FOUND)
);
List<Assignment> assignmentsByClub = assignmentRepository.findAssignmentsByClub(club);
List<AssignmentResponse> assignmentResponseList = new ArrayList<>();
for (Assignment assignment : assignmentsByClub) {
assignmentResponseList.add(new AssignmentResponse(assignment));
}
return assignmentResponseList;
}
}

0 comments on commit 3b1ae28

Please sign in to comment.