From c21c1c4cfea01be999489742dced464e17d6e7a6 Mon Sep 17 00:00:00 2001 From: jyc0011 <122250128+jyc0011@users.noreply.github.com> Date: Sat, 9 Nov 2024 11:09:29 +0900 Subject: [PATCH] =?UTF-8?q?feat=20:=20roadmap=20=ED=98=B8=EC=B6=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/skil/user/UserRoadmapSkil.java | 4 +- .../mypage/controller/MypageController.java | 28 ++++++--- .../sanhak/mypage/dto/changeRoadmapDTO.java | 2 +- .../project/sanhak/mypage/dto/roadmapDTO.java | 22 ++++--- .../sanhak/mypage/dto/roadmapListDTO.java | 21 +++++++ .../mypage/repository/RoadmapRepository.java | 6 ++ .../RoadmapSkilPrequeRepository.java | 5 ++ .../repository/RoadmapSkilRepository.java | 3 + .../sanhak/mypage/service/MypageService.java | 60 ++++++++++++++----- 9 files changed, 117 insertions(+), 34 deletions(-) create mode 100644 src/main/java/com/project/sanhak/mypage/dto/roadmapListDTO.java diff --git a/src/main/java/com/project/sanhak/domain/skil/user/UserRoadmapSkil.java b/src/main/java/com/project/sanhak/domain/skil/user/UserRoadmapSkil.java index 2ba8a4cf..758eda97 100644 --- a/src/main/java/com/project/sanhak/domain/skil/user/UserRoadmapSkil.java +++ b/src/main/java/com/project/sanhak/domain/skil/user/UserRoadmapSkil.java @@ -10,12 +10,12 @@ public class UserRoadmapSkil { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private int URSId; - @ManyToOne @JoinColumn(referencedColumnName = "URId") private UserRoadmap URSurid; - private int URScsid; + private String URSTag; private String URScsName; private int URScsX; private int URScsY; + private int URScsid; } \ No newline at end of file diff --git a/src/main/java/com/project/sanhak/mypage/controller/MypageController.java b/src/main/java/com/project/sanhak/mypage/controller/MypageController.java index 7949f542..13601ebf 100644 --- a/src/main/java/com/project/sanhak/mypage/controller/MypageController.java +++ b/src/main/java/com/project/sanhak/mypage/controller/MypageController.java @@ -1,10 +1,7 @@ package com.project.sanhak.mypage.controller; import com.project.sanhak.domain.skil.code.MasterySkil; -import com.project.sanhak.mypage.dto.changeRoadmapDTO; -import com.project.sanhak.mypage.dto.masteryDTO; -import com.project.sanhak.mypage.dto.quizDTO; -import com.project.sanhak.mypage.dto.roadmapDTO; +import com.project.sanhak.mypage.dto.*; import com.project.sanhak.mypage.service.MypageService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.ArraySchema; @@ -30,17 +27,32 @@ public class MypageController { responses = @ApiResponse( responseCode = "200", description = "로드맵 목록 반환", + content = @Content(mediaType = "application/json", + array = @ArraySchema(schema = @Schema(implementation = roadmapListDTO.class))))) + @GetMapping("/roadmap/list") + public ResponseEntity> getMyRoadmapList(HttpSession session) { + // 세션에서 uid 가져오기 + int uid = (int) session.getAttribute("uid"); + List roadmapList = mypageService.getRoadmapListByUid(uid); + return ResponseEntity.ok(roadmapList); + } + + @Operation(summary = "내 로드맵 호출", + responses = @ApiResponse( + responseCode = "200", + description = "로드맵 반환", content = @Content(mediaType = "application/json", array = @ArraySchema(schema = @Schema(implementation = roadmapDTO.class))))) - @GetMapping("/roadmap") - public ResponseEntity> getMyRoadmap(HttpSession session) { + @GetMapping("/roadmap/{ur_id}") + public ResponseEntity> getMyRoadmap(HttpSession session, + @PathVariable int ur_id) { // 세션에서 uid 가져오기 int uid = (int) session.getAttribute("uid"); - List roadmapList = mypageService.getRoadmapsByUid(uid); + List roadmapList = mypageService.getRoadmapsByUid(uid,ur_id); return ResponseEntity.ok(roadmapList); } - @Operation(summary = "새 로드맵 추가", + @Operation(summary = "새 로드맵 추가", responses = @ApiResponse(responseCode = "200", description = "새 로드맵 추가 성공")) @GetMapping("/roadmap/add") public ResponseEntity addNewRoadmap(HttpSession session) { diff --git a/src/main/java/com/project/sanhak/mypage/dto/changeRoadmapDTO.java b/src/main/java/com/project/sanhak/mypage/dto/changeRoadmapDTO.java index e8ef5413..0226ab40 100644 --- a/src/main/java/com/project/sanhak/mypage/dto/changeRoadmapDTO.java +++ b/src/main/java/com/project/sanhak/mypage/dto/changeRoadmapDTO.java @@ -18,6 +18,6 @@ public class changeRoadmapDTO { @Schema(description = "상태 -> add는 1, delete는 0", example = "1") private int state; - @Schema(description = "매핑 -> 노드면 이게 x,y 좌표, 라인이면 부모,자식", example = "[1, 2]") + @Schema(description = "매핑 -> 노드면 이게 x,y 좌표, 라인이면 부모,자식", example = "[55, 56]") private List mapping; } diff --git a/src/main/java/com/project/sanhak/mypage/dto/roadmapDTO.java b/src/main/java/com/project/sanhak/mypage/dto/roadmapDTO.java index a27d7ef8..d89df31d 100644 --- a/src/main/java/com/project/sanhak/mypage/dto/roadmapDTO.java +++ b/src/main/java/com/project/sanhak/mypage/dto/roadmapDTO.java @@ -12,14 +12,18 @@ @NoArgsConstructor @Schema(description = "로드맵 정보 객체") public class roadmapDTO { - @Schema(description = "로드맵 ID", example = "1") + @Schema(description = "로드맵 스킬 ID", example = "55") private int id; - - @Schema(description = "로드맵 이름", example = "웹 개발 로드맵") + @Schema(description = "코드 스킬 ID", example = "1") + private int cs_id; + @Schema(description = "스킬 이름", example = "html") private String name; - - @Schema(description = "스킬 리스트", example = "[{\"id\": 1, \"name\": \"Java\",\"List\":[],\"List\":[2,3,4],\"position\":[0,0],\"tag\": \"none\" }," + - " {\"id\": 2, \"name\": \"Spring\",\"List\":[1],\"List\":[5],\"position\":[1,0],\"tag\": \"none\" }]") - private List skilList; -} - + @Schema(description = "부모 목록", example = "[]") + private List parent; + @Schema(description = "자식 목록", example = "[56,57]") + private List child; + @Schema(description = "위치", example = "[0,0]") + private int[] position; + @Schema(description = "태그 상태", example = "none") + private String tag; +} \ No newline at end of file diff --git a/src/main/java/com/project/sanhak/mypage/dto/roadmapListDTO.java b/src/main/java/com/project/sanhak/mypage/dto/roadmapListDTO.java new file mode 100644 index 00000000..958f7206 --- /dev/null +++ b/src/main/java/com/project/sanhak/mypage/dto/roadmapListDTO.java @@ -0,0 +1,21 @@ +package com.project.sanhak.mypage.dto; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +@Schema(description = "로드맵 리스트 객체") +public class roadmapListDTO { + @Schema(description = "로드맵 ID", example = "1") + private int id; + + @Schema(description = "로드맵 이름", example = "웹 개발 로드맵") + private String name; + + @Schema(description = "로드맵 상태", example = "0") + private int state; +} diff --git a/src/main/java/com/project/sanhak/mypage/repository/RoadmapRepository.java b/src/main/java/com/project/sanhak/mypage/repository/RoadmapRepository.java index 7ec4a95e..f164d255 100644 --- a/src/main/java/com/project/sanhak/mypage/repository/RoadmapRepository.java +++ b/src/main/java/com/project/sanhak/mypage/repository/RoadmapRepository.java @@ -1,9 +1,15 @@ package com.project.sanhak.mypage.repository; import com.project.sanhak.domain.skil.user.UserRoadmap; +import com.project.sanhak.domain.user.User; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +import java.util.List; +import java.util.Optional; + @Repository public interface RoadmapRepository extends JpaRepository { + List findByURuid_UId(int uid); + UserRoadmap findByURIdAndURuid(int urId, User user); } diff --git a/src/main/java/com/project/sanhak/mypage/repository/RoadmapSkilPrequeRepository.java b/src/main/java/com/project/sanhak/mypage/repository/RoadmapSkilPrequeRepository.java index 8a0cb613..211c48cf 100644 --- a/src/main/java/com/project/sanhak/mypage/repository/RoadmapSkilPrequeRepository.java +++ b/src/main/java/com/project/sanhak/mypage/repository/RoadmapSkilPrequeRepository.java @@ -6,7 +6,12 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +import java.util.Arrays; +import java.util.List; + @Repository public interface RoadmapSkilPrequeRepository extends JpaRepository { void deleteByURSPparentscsidAndURSPchildcsid(UserRoadmapSkil parent, UserRoadmapSkil child); + List findByURSPchildcsid(UserRoadmapSkil childSkill); + List findByURSPparentscsid(UserRoadmapSkil parentSkill); } diff --git a/src/main/java/com/project/sanhak/mypage/repository/RoadmapSkilRepository.java b/src/main/java/com/project/sanhak/mypage/repository/RoadmapSkilRepository.java index 3ac3a633..aca0d459 100644 --- a/src/main/java/com/project/sanhak/mypage/repository/RoadmapSkilRepository.java +++ b/src/main/java/com/project/sanhak/mypage/repository/RoadmapSkilRepository.java @@ -5,6 +5,9 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +import java.util.List; + @Repository public interface RoadmapSkilRepository extends JpaRepository { + List findByURSurid(UserRoadmap userRoadmap); } diff --git a/src/main/java/com/project/sanhak/mypage/service/MypageService.java b/src/main/java/com/project/sanhak/mypage/service/MypageService.java index cf5d234f..3745c896 100644 --- a/src/main/java/com/project/sanhak/mypage/service/MypageService.java +++ b/src/main/java/com/project/sanhak/mypage/service/MypageService.java @@ -17,6 +17,7 @@ import org.springframework.web.reactive.function.client.WebClient; import java.util.*; +import java.util.stream.Collectors; @Service public class MypageService { @@ -61,7 +62,6 @@ public void masterSkill(int uid, int msId) { } public quizDTO getQuiz(int msId) { - //public List getQuiz(int msId) { String url = apiBaseUrl +"/quiz"; MasterySkil mastery = masteryRepository.findByMSId(msId); List masteryInfoList = List.of( @@ -92,16 +92,6 @@ public quizDTO getQuiz(int msId) { } - //List quizList = new ArrayList<>(); - //if (responseList != null) { - //for (Map response : responseList) { - //if (response.containsKey("question") && response.containsKey("options") && response.containsKey("answer")) { - //String question = (String) response.get("question"); - //List options = (List) response.get("options"); - //int answer = (int) response.get("answer"); - - //quizList.add(new quizDTO(question, options, answer)); - //} else { throw new IllegalStateException("Python 서버 응답에 필요한 'question', 'options', 'answer' 필드가 없습니다."); } @@ -192,7 +182,49 @@ public void addNewRoadmap(int uid) { roadmapRepository.save(roadmap); } - public List getRoadmapsByUid(int uid) { - return null; + public List getRoadmapsByUid(int uid, int ur_id) { + User user = userService.getUserFromUid(uid); + UserRoadmap userRoadmap = roadmapRepository.findByURIdAndURuid(ur_id, user); + + List userRoadmapSkils = roadmapSkilRepository.findByURSurid(userRoadmap); + + Set userRoadmapSkilIds = userRoadmapSkils.stream() + .map(UserRoadmapSkil::getURSId) + .collect(Collectors.toSet()); + + return userRoadmapSkils.stream().map(userRoadmapSkil -> { + roadmapDTO dto = new roadmapDTO(); + dto.setId(userRoadmapSkil.getURSId()); + dto.setName(userRoadmapSkil.getURScsName()); + dto.setPosition(new int[]{userRoadmapSkil.getURScsX(), userRoadmapSkil.getURScsY()}); + dto.setTag(userRoadmapSkil.getURSTag()); + + List parents = roadmapSkilPrequeRepository.findByURSPchildcsid(userRoadmapSkil).stream() + .map(preque -> preque.getURSPparentscsid().getURSId()) + .filter(userRoadmapSkilIds::contains) + .collect(Collectors.toList()); + dto.setParent(parents); + + List children = roadmapSkilPrequeRepository.findByURSPparentscsid(userRoadmapSkil).stream() + .map(preque -> preque.getURSPchildcsid().getURSId()) + .filter(userRoadmapSkilIds::contains) + .collect(Collectors.toList()); + dto.setChild(children); + + return dto; + }).collect(Collectors.toList()); + } + + public List getRoadmapListByUid(int uid) { + + List userRoadmaps = roadmapRepository.findByURuid_UId(uid); + + return userRoadmaps.stream().map(userRoadmap -> { + roadmapListDTO dto = new roadmapListDTO(); + dto.setId(userRoadmap.getURId()); + dto.setName(userRoadmap.getURName()); + dto.setState(userRoadmap.getState()); + return dto; + }).collect(Collectors.toList()); } -} +} \ No newline at end of file