diff --git a/src/main/java/planshare/server/planshare/domain/Goal.java b/src/main/java/planshare/server/planshare/domain/Goal.java index a7817f0..5fe6ff3 100644 --- a/src/main/java/planshare/server/planshare/domain/Goal.java +++ b/src/main/java/planshare/server/planshare/domain/Goal.java @@ -10,7 +10,6 @@ @Data @NoArgsConstructor @AllArgsConstructor -@JsonNaming(value = PropertyNamingStrategy.SnakeCaseStrategy.class) public class Goal { @Id @@ -23,7 +22,7 @@ public class Goal { // HEX COLOR CODE; private String color; - private int iconNumber; + private String icon; // 공개 여부 private boolean visibility; @@ -32,11 +31,11 @@ public class Goal { @JoinColumn(name = "m_id") private Member member; - public static Goal createGoal(String name, String color, int iconNumber, boolean visibility, Member member){ + public static Goal createGoal(String name, String color, String icon, boolean visibility, Member member){ Goal goal = new Goal(); goal.name = name; goal.color = color; - goal.iconNumber = iconNumber; + goal.icon = icon; goal.visibility = visibility; goal.member = member; @@ -47,10 +46,10 @@ public void modifyName(String name){ this.name = name; } - public void modifyGoal(String name, String color, int iconNumber, boolean visibility){ + public void modifyGoal(String name, String color, String icon, boolean visibility){ this.name = name; this.color = color; - this.iconNumber =iconNumber; + this.icon = icon; this.visibility = visibility; } } diff --git a/src/main/java/planshare/server/planshare/domain/Plan.java b/src/main/java/planshare/server/planshare/domain/Plan.java index 7386846..7136582 100644 --- a/src/main/java/planshare/server/planshare/domain/Plan.java +++ b/src/main/java/planshare/server/planshare/domain/Plan.java @@ -22,6 +22,9 @@ public class Plan { private LocalDateTime end; + // 체크 여부 + private boolean checkStatus; + @ManyToOne @JoinColumn(name = "g_id") private Goal goal; diff --git a/src/main/java/planshare/server/planshare/goal/controller/GoalController.java b/src/main/java/planshare/server/planshare/goal/controller/GoalController.java index 2c124bf..89df787 100644 --- a/src/main/java/planshare/server/planshare/goal/controller/GoalController.java +++ b/src/main/java/planshare/server/planshare/goal/controller/GoalController.java @@ -1,5 +1,6 @@ package planshare.server.planshare.goal.controller; +import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.*; @@ -18,6 +19,7 @@ public class GoalController { private final GoalService goalService; + @ApiOperation(value = "goal 생성 API", notes = "생성한 goal 객체 반환") @PostMapping("/create") public Goal create(@AuthenticationPrincipal CustomUserDetailsVO userDetailsVO, @RequestBody GoalForm goalForm){ @@ -27,13 +29,15 @@ public Goal create(@AuthenticationPrincipal CustomUserDetailsVO userDetailsVO, } // goal by id + @ApiOperation(value = "goal 하나 조회(by goalId) API", notes = "찾은 goal 객체 반환") @GetMapping("/read/{goalId}") - public Optional<Goal> readGoal(@AuthenticationPrincipal CustomUserDetailsVO userDetailsVO, + public Optional<Goal> readGoalById(@AuthenticationPrincipal CustomUserDetailsVO userDetailsVO, @PathVariable(name = "goalId") Long id){ return goalService.findGoalOfId(userDetailsVO, id); } // goal of member and name + @ApiOperation(value = "나의 goal 목록 조회 API", notes = "name 파라미터 추가시(필수x) 해당 이름의 goal 리스트 반환") @GetMapping("/read/myself") public List<Goal> listOfMyselfAndName(@AuthenticationPrincipal CustomUserDetailsVO userDetailsVO, @RequestParam(required = false) String name){ @@ -43,8 +47,9 @@ public List<Goal> listOfMyselfAndName(@AuthenticationPrincipal CustomUserDetails return goalService.findMyGoalsOfName(userDetailsVO, name); } + @ApiOperation(value = "특정 멤버의 goal 목록 조회 API", notes = "name 파라미터 추가시(필수x) 해당 이름의 goal 리스트 반환") @GetMapping("/read/member/{memberId}") - public List<Goal> listOfMember(@AuthenticationPrincipal CustomUserDetailsVO userDetailsVO, + public List<Goal> listOfMemberAndName(@AuthenticationPrincipal CustomUserDetailsVO userDetailsVO, @RequestParam(required = false) String name, @PathVariable(name = "memberId") Long memberId){ if(name == null){ @@ -54,6 +59,7 @@ public List<Goal> listOfMember(@AuthenticationPrincipal CustomUserDetailsVO user } // goal of name + @ApiOperation(value = "모든 멤버의 goal 목록 조회 API", notes = "name 파라미터 추가시(필수x) 해당 이름의 goal 리스트 반환") @GetMapping("/read/alluser") public List<Goal> listOfName(@AuthenticationPrincipal CustomUserDetailsVO userDetailsVO, @RequestParam(required = false) String name){ @@ -64,6 +70,7 @@ public List<Goal> listOfName(@AuthenticationPrincipal CustomUserDetailsVO userDe } // goal update + @ApiOperation(value = "특정 goal 내용 수정 API", notes = "수정한 goal 객체 반환") @PutMapping("/update/{goalId}") public Goal modifyGoal(@AuthenticationPrincipal CustomUserDetailsVO userDetailsVO, @RequestBody GoalForm goalForm, @@ -72,13 +79,11 @@ public Goal modifyGoal(@AuthenticationPrincipal CustomUserDetailsVO userDetailsV } // goal delete + @ApiOperation(value = "특정 goal 삭제 API", notes = "삭제 성공시 정수 1 반환 / 실패시 0 반환") @DeleteMapping("/delete/{goalId}") public int deleteGoal(@AuthenticationPrincipal CustomUserDetailsVO userDetailsVO, @PathVariable(name = "goalId") Long id){ return goalService.deleteGoal(userDetailsVO, id); } - - - } diff --git a/src/main/java/planshare/server/planshare/goal/dto/GoalForm.java b/src/main/java/planshare/server/planshare/goal/dto/GoalForm.java index ba99040..f20dbb1 100644 --- a/src/main/java/planshare/server/planshare/goal/dto/GoalForm.java +++ b/src/main/java/planshare/server/planshare/goal/dto/GoalForm.java @@ -14,7 +14,7 @@ public class GoalForm { private String color; - private int iconNumber; + private String icon; private boolean visibility; diff --git a/src/main/java/planshare/server/planshare/goal/service/GoalService.java b/src/main/java/planshare/server/planshare/goal/service/GoalService.java index bf41426..c209171 100644 --- a/src/main/java/planshare/server/planshare/goal/service/GoalService.java +++ b/src/main/java/planshare/server/planshare/goal/service/GoalService.java @@ -26,7 +26,7 @@ public Goal addGoal(CustomUserDetailsVO cud, GoalForm form){ Optional<Member> member = memberRepository.findByEmail(cud.getUsername()); - Goal goal = Goal.createGoal(form.getName(), form.getColor(), form.getIconNumber(), form.isVisibility(), member.get()); + Goal goal = Goal.createGoal(form.getName(), form.getColor(), form.getIcon(), form.isVisibility(), member.get()); System.out.println("service : "+member); System.out.println("service : "+goal); @@ -58,7 +58,11 @@ public List<Goal> findMyGoalsOfName(CustomUserDetailsVO cud, String name){ public List<Goal> findGoalsOfMember(Long memberId){ Optional<Member> member = memberRepository.findById(memberId); - return goalRepository.findByMember(member.get()); + if(member.isPresent()) { + return goalRepository.findByMember(member.get()); + } else { + return null; + } } /** @@ -67,7 +71,11 @@ public List<Goal> findGoalsOfMember(Long memberId){ public List<Goal> findGoalsOfMemberAndName(Long memberId, String name){ Optional<Member> member = memberRepository.findById(memberId); - return goalRepository.findByMemberAndName(member.get(), name); + if(member.isPresent()) { + return goalRepository.findByMemberAndName(member.get(), name); + } else { + return null; + } } /** @@ -99,13 +107,17 @@ public Optional<Goal> findGoalOfId(CustomUserDetailsVO cud, Long goalId){ public Goal updateGoalName(CustomUserDetailsVO cud, Long goalId, GoalForm goalForm){ Optional<Member> member = memberRepository.findByEmail(cud.getUsername()); - Goal goal = goalRepository.findById(goalId).get(); + Optional<Goal> goal = goalRepository.findById(goalId); - if(member.get().getId() == goal.getMember().getId()){ - goal.modifyGoal(goalForm.getName(), goalForm.getColor(), goalForm.getIconNumber(), goalForm.isVisibility()); + if(goal.isPresent() && member.get().getId() == goal.get().getMember().getId()){ + goal.get().modifyGoal(goalForm.getName(), goalForm.getColor(), goalForm.getIcon(), goalForm.isVisibility()); + + return goalRepository.save(goal.get()); + } else { + return null; } - return goalRepository.save(goal); + } /** @@ -115,13 +127,12 @@ public int deleteGoal(CustomUserDetailsVO cud, Long goalId){ int rows = 0; Optional<Member> member = memberRepository.findByEmail(cud.getUsername()); - Goal goal = goalRepository.findById(goalId).get(); + Optional<Goal> goal = goalRepository.findById(goalId); - if(member.get().getId() == goal.getMember().getId()){ + if(goal.isPresent() && member.get().getId() == goal.get().getMember().getId()){ rows = goalRepository.deleteById(goalId); } return rows; } - }