Skip to content

Commit

Permalink
Merge pull request #19 from PLAN-SHARE/ISSUE-13
Browse files Browse the repository at this point in the history
[#13] Goal 속성 변경 및 기능 추가
  • Loading branch information
Johoseong authored Mar 22, 2022
2 parents ed6a31b + 34f5082 commit 69e46d5
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 22 deletions.
11 changes: 5 additions & 6 deletions src/main/java/planshare/server/planshare/domain/Goal.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
@Data
@NoArgsConstructor
@AllArgsConstructor
@JsonNaming(value = PropertyNamingStrategy.SnakeCaseStrategy.class)
public class Goal {

@Id
Expand All @@ -23,7 +22,7 @@ public class Goal {
// HEX COLOR CODE;
private String color;

private int iconNumber;
private String icon;

// 공개 여부
private boolean visibility;
Expand All @@ -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;

Expand All @@ -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;
}
}
3 changes: 3 additions & 0 deletions src/main/java/planshare/server/planshare/domain/Plan.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ public class Plan {

private LocalDateTime end;

// 체크 여부
private boolean checkStatus;

@ManyToOne
@JoinColumn(name = "g_id")
private Goal goal;
Expand Down
Original file line number Diff line number Diff line change
@@ -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.*;
Expand All @@ -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){
Expand All @@ -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){
Expand All @@ -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){
Expand All @@ -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){
Expand All @@ -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,
Expand All @@ -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);
}




}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class GoalForm {

private String color;

private int iconNumber;
private String icon;

private boolean visibility;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
}

/**
Expand All @@ -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;
}
}

/**
Expand Down Expand Up @@ -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);

}

/**
Expand All @@ -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;
}


}

0 comments on commit 69e46d5

Please sign in to comment.