Skip to content

Commit

Permalink
Merge pull request #17 from PLAN-SHARE/ISSUE-13
Browse files Browse the repository at this point in the history
[#13] Goal 속성 및 기능 추가
  • Loading branch information
Johoseong authored Mar 19, 2022
2 parents ecfde83 + 1869a33 commit 265bb8b
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 40 deletions.
22 changes: 21 additions & 1 deletion src/main/java/planshare/server/planshare/domain/Goal.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package planshare.server.planshare.domain;

import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import lombok.*;

import javax.persistence.*;
Expand All @@ -8,6 +10,7 @@
@Data
@NoArgsConstructor
@AllArgsConstructor
@JsonNaming(value = PropertyNamingStrategy.SnakeCaseStrategy.class)
public class Goal {

@Id
Expand All @@ -17,13 +20,24 @@ public class Goal {

private String name;

// HEX COLOR CODE;
private String color;

private int iconNumber;

// 공개 여부
private boolean visibility;

@ManyToOne
@JoinColumn(name = "m_id")
private Member member;

public static Goal createGoal(String name, Member member){
public static Goal createGoal(String name, String color, int iconNumber, boolean visibility, Member member){
Goal goal = new Goal();
goal.name = name;
goal.color = color;
goal.iconNumber = iconNumber;
goal.visibility = visibility;
goal.member = member;

return goal;
Expand All @@ -33,4 +47,10 @@ public void modifyName(String name){
this.name = name;
}

public void modifyGoal(String name, String color, int iconNumber, boolean visibility){
this.name = name;
this.color = color;
this.iconNumber =iconNumber;
this.visibility = visibility;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,43 +33,42 @@ public Optional<Goal> readGoal(@AuthenticationPrincipal CustomUserDetailsVO user
return goalService.findGoalOfId(userDetailsVO, id);
}


// goal of member
@GetMapping("/read/member")
public List<Goal> listOfMember(@AuthenticationPrincipal CustomUserDetailsVO userDetailsVO){

return goalService.findGoalsOfMember(userDetailsVO);
}

// goal of member and name
@GetMapping("/read/member-name")
public List<Goal> listOfMemberAndName(@AuthenticationPrincipal CustomUserDetailsVO userDetailsVO,
@RequestParam String name){

return goalService.findGoalsOfMemberAndName(userDetailsVO, name);
@GetMapping("/read/myself")
public List<Goal> listOfMyselfAndName(@AuthenticationPrincipal CustomUserDetailsVO userDetailsVO,
@RequestParam(required = false) String name){
if(name == null){
return goalService.findMyGoals(userDetailsVO);
}
return goalService.findMyGoalsOfName(userDetailsVO, name);
}

// goals
@GetMapping("/read/alluser")
public List<Goal> listOfGoals(@AuthenticationPrincipal CustomUserDetailsVO userDetailsVO){

return goalService.findGoals();
@GetMapping("/read/member/{memberId}")
public List<Goal> listOfMember(@AuthenticationPrincipal CustomUserDetailsVO userDetailsVO,
@RequestParam(required = false) String name,
@PathVariable(name = "memberId") Long memberId){
if(name == null){
return goalService.findGoalsOfMember(memberId);
}
return goalService.findGoalsOfMemberAndName(memberId, name);
}

// goal of name
@GetMapping("/read/alluser-name")
@GetMapping("/read/alluser")
public List<Goal> listOfName(@AuthenticationPrincipal CustomUserDetailsVO userDetailsVO,
@RequestParam String name){

@RequestParam(required = false) String name){
if(name == null){
return goalService.findGoals();
}
return goalService.findGoalsOfName(name);
}

// goal update
@PutMapping("/update/{goalId}")
public Goal modifyName(@AuthenticationPrincipal CustomUserDetailsVO userDetailsVO,
public Goal modifyGoal(@AuthenticationPrincipal CustomUserDetailsVO userDetailsVO,
@RequestBody GoalForm goalForm,
@PathVariable(name = "goalId") Long id){
return goalService.updateGoalName(userDetailsVO, id, goalForm.getName());
return goalService.updateGoalName(userDetailsVO, id, goalForm);
}

// goal delete
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/planshare/server/planshare/goal/dto/GoalForm.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
package planshare.server.planshare.goal.dto;

import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
@JsonNaming(value = PropertyNamingStrategy.SnakeCaseStrategy.class)
public class GoalForm {

private String name;

private String color;

private int iconNumber;

private boolean visibility;

}
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(), member.get());
Goal goal = Goal.createGoal(form.getName(), form.getColor(), form.getIconNumber(), form.isVisibility(), member.get());

System.out.println("service : "+member);
System.out.println("service : "+goal);
Expand All @@ -35,40 +35,58 @@ public Goal addGoal(CustomUserDetailsVO cud, GoalForm form){
}

/**
* 전체 goal 조회
* my total goal search
*/
public List<Goal> findGoals(){
return goalRepository.findAll();
public List<Goal> findMyGoals(CustomUserDetailsVO cud){
Optional<Member> member = memberRepository.findByEmail(cud.getUsername());

return goalRepository.findByMember(member.get());
}

/**
* 한 member의 goals 전체 조회
* my goal search by name
*/
public List<Goal> findGoalsOfMember(CustomUserDetailsVO cud){
public List<Goal> findMyGoalsOfName(CustomUserDetailsVO cud, String name){
Optional<Member> member = memberRepository.findByEmail(cud.getUsername());

return goalRepository.findByMemberAndName(member.get(), name);
}

/**
* goal search by memberId
*/
public List<Goal> findGoalsOfMember(Long memberId){
Optional<Member> member = memberRepository.findById(memberId);

return goalRepository.findByMember(member.get());
}

/**
* 한 member의 goal 이름 조회
* goal search by memberId and name
*/
public List<Goal> findGoalsOfMemberAndName(CustomUserDetailsVO cud, String name){
Optional<Member> member = memberRepository.findByEmail(cud.getUsername());
public List<Goal> findGoalsOfMemberAndName(Long memberId, String name){
Optional<Member> member = memberRepository.findById(memberId);

return goalRepository.findByMemberAndName(member.get(), name);
}

/**
* goal check by name
* total goal search
*/
public List<Goal> findGoals(){
return goalRepository.findAll();
}

/**
* goal search by name
*/
public List<Goal> findGoalsOfName(String name){

return goalRepository.findByName(name);
}

/**
* goal check by id
* goal search by id
*/
public Optional<Goal> findGoalOfId(CustomUserDetailsVO cud, Long goalId){

Expand All @@ -78,18 +96,21 @@ public Optional<Goal> findGoalOfId(CustomUserDetailsVO cud, Long goalId){
/**
* goal name update
*/
public Goal updateGoalName(CustomUserDetailsVO cud, Long goalId, String name){
public Goal updateGoalName(CustomUserDetailsVO cud, Long goalId, GoalForm goalForm){

Optional<Member> member = memberRepository.findByEmail(cud.getUsername());
Goal goal = goalRepository.findById(goalId).get();

if(member.get().getId() == goal.getMember().getId()){
goal.modifyName(name);
goal.modifyGoal(goalForm.getName(), goalForm.getColor(), goalForm.getIconNumber(), goalForm.isVisibility());
}

return goalRepository.save(goal);
}

/**
* goal delete
*/
public int deleteGoal(CustomUserDetailsVO cud, Long goalId){

int rows = 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package planshare.server.planshare.goal.service;

import lombok.RequiredArgsConstructor;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import planshare.server.planshare.domain.Member;
import planshare.server.planshare.goal.repository.GoalRepository;
import planshare.server.planshare.goal.repository.JpaGoalRepository;
import planshare.server.planshare.repository.JpaMemberRepository;
import planshare.server.planshare.repository.MemberRepository;

import javax.persistence.EntityManager;
import java.util.Optional;


@RequiredArgsConstructor
public class GoalServiceTest {

EntityManager em;
Expand All @@ -23,8 +27,18 @@ public void beforeEach(){
goalService = new GoalService(goalRepository, memberRepository);
}

void addGoal(){

@Test
void optional(){
Member m = null;
Optional<Member> member = Optional.ofNullable(m);
if(member.isPresent()){
System.out.println("present : "+member.isPresent());
System.out.println("empty : "+member.isEmpty());
}
if(member.isEmpty()){
System.out.println("present : "+member.isPresent());
System.out.println("empty : "+member.isEmpty());
}
}

}

0 comments on commit 265bb8b

Please sign in to comment.