Skip to content

Commit

Permalink
Merge pull request #87 from KAU-2024-Sanhak/pr-merge
Browse files Browse the repository at this point in the history
Pr merge
  • Loading branch information
jyc0011 authored Nov 9, 2024
2 parents aa9c72e + 679622c commit 303408e
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<List<roadmapListDTO>> getMyRoadmapList(HttpSession session) {
// 세션에서 uid 가져오기
int uid = (int) session.getAttribute("uid");
List<roadmapListDTO> 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<List<roadmapDTO>> getMyRoadmap(HttpSession session) {
@GetMapping("/roadmap/{ur_id}")
public ResponseEntity<List<roadmapDTO>> getMyRoadmap(HttpSession session,
@PathVariable int ur_id) {
// 세션에서 uid 가져오기
int uid = (int) session.getAttribute("uid");
List<roadmapDTO> roadmapList = mypageService.getRoadmapsByUid(uid);
List<roadmapDTO> roadmapList = mypageService.getRoadmapsByUid(uid,ur_id);
return ResponseEntity.ok(roadmapList);
}

@Operation(summary = "새 로드맵 추가",
@Operation(summary = "새 로드맵 추가",
responses = @ApiResponse(responseCode = "200", description = "새 로드맵 추가 성공"))
@GetMapping("/roadmap/add")
public ResponseEntity<String> addNewRoadmap(HttpSession session) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Integer> mapping;
}
22 changes: 13 additions & 9 deletions src/main/java/com/project/sanhak/mypage/dto/roadmapDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<parents>\":[],\"List<child>\":[2,3,4],\"position\":[0,0],\"tag\": \"none\" }," +
" {\"id\": 2, \"name\": \"Spring\",\"List<parents>\":[1],\"List<child>\":[5],\"position\":[1,0],\"tag\": \"none\" }]")
private List<categoryDTO> skilList;
}

@Schema(description = "부모 목록", example = "[]")
private List<Integer> parent;
@Schema(description = "자식 목록", example = "[56,57]")
private List<Integer> child;
@Schema(description = "위치", example = "[0,0]")
private int[] position;
@Schema(description = "태그 상태", example = "none")
private String tag;
}
21 changes: 21 additions & 0 deletions src/main/java/com/project/sanhak/mypage/dto/roadmapListDTO.java
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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<UserRoadmap, Integer> {
List<UserRoadmap> findByURuid_UId(int uid);
UserRoadmap findByURIdAndURuid(int urId, User user);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<UserRoadmapSkilPreque, Integer> {
void deleteByURSPparentscsidAndURSPchildcsid(UserRoadmapSkil parent, UserRoadmapSkil child);
List<UserRoadmapSkilPreque> findByURSPchildcsid(UserRoadmapSkil childSkill);
List<UserRoadmapSkilPreque> findByURSPparentscsid(UserRoadmapSkil parentSkill);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<UserRoadmapSkil, Integer> {
List<UserRoadmapSkil> findByURSurid(UserRoadmap userRoadmap);
}
60 changes: 46 additions & 14 deletions src/main/java/com/project/sanhak/mypage/service/MypageService.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.springframework.web.reactive.function.client.WebClient;

import java.util.*;
import java.util.stream.Collectors;

@Service
public class MypageService {
Expand Down Expand Up @@ -61,7 +62,6 @@ public void masterSkill(int uid, int msId) {
}

public quizDTO getQuiz(int msId) {
//public List<quizDTO> getQuiz(int msId) {
String url = apiBaseUrl +"/quiz";
MasterySkil mastery = masteryRepository.findByMSId(msId);
List<String> masteryInfoList = List.of(
Expand Down Expand Up @@ -92,16 +92,6 @@ public quizDTO getQuiz(int msId) {


}
//List<quizDTO> quizList = new ArrayList<>();
//if (responseList != null) {
//for (Map<String, Object> response : responseList) {
//if (response.containsKey("question") && response.containsKey("options") && response.containsKey("answer")) {
//String question = (String) response.get("question");
//List<String> options = (List<String>) response.get("options");
//int answer = (int) response.get("answer");

//quizList.add(new quizDTO(question, options, answer));
//}
else {
throw new IllegalStateException("Python 서버 응답에 필요한 'question', 'options', 'answer' 필드가 없습니다.");
}
Expand Down Expand Up @@ -192,7 +182,49 @@ public void addNewRoadmap(int uid) {
roadmapRepository.save(roadmap);
}

public List<roadmapDTO> getRoadmapsByUid(int uid) {
return null;
public List<roadmapDTO> getRoadmapsByUid(int uid, int ur_id) {
User user = userService.getUserFromUid(uid);
UserRoadmap userRoadmap = roadmapRepository.findByURIdAndURuid(ur_id, user);

List<UserRoadmapSkil> userRoadmapSkils = roadmapSkilRepository.findByURSurid(userRoadmap);

Set<Integer> 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<Integer> parents = roadmapSkilPrequeRepository.findByURSPchildcsid(userRoadmapSkil).stream()
.map(preque -> preque.getURSPparentscsid().getURSId())
.filter(userRoadmapSkilIds::contains)
.collect(Collectors.toList());
dto.setParent(parents);

List<Integer> 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<roadmapListDTO> getRoadmapListByUid(int uid) {

List<UserRoadmap> 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());
}
}
}

0 comments on commit 303408e

Please sign in to comment.