Skip to content

Commit

Permalink
feat: PlanController 구현 및 PlanForm, PlanName DTO 생성(#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
heej-ng committed Apr 16, 2022
1 parent 67845ff commit 57eb7d4
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package planshare.server.planshare.plan.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;
import planshare.server.planshare.domain.Plan;
import planshare.server.planshare.plan.dto.PlanForm;
import planshare.server.planshare.plan.dto.PlanName;
import planshare.server.planshare.plan.service.PlanService;
import planshare.server.planshare.user.dto.CustomUserDetailsVO;

import java.util.List;
import java.util.Optional;

@RequiredArgsConstructor
@RestController
public class PlanController {

private final PlanService planService;

@ApiOperation(value = "plan 생성 API", notes = "생성한 plan 객체 반환")
@PostMapping("/goals/{goalId}/plans")
public Plan create(@AuthenticationPrincipal CustomUserDetailsVO userDetailsVO,
@PathVariable(name = "goalId") Long goalId,
@RequestBody PlanForm planForm){
System.out.println("planController : goalId : "+goalId+" , body "+planForm);
return planService.addPlan(userDetailsVO, goalId, planForm);
}

@ApiOperation(value = "plan 하나 조회(by goalId + planId) API", notes = "찾은 plan 객체 반환")
@GetMapping("/goals/{goalId}/plans/{planId}")
public Optional<Plan> readPlanByPlanId(@AuthenticationPrincipal CustomUserDetailsVO userDetailsVO,
@PathVariable(name = "goalId") Long goalId,
@PathVariable(name = "planId") Long planId){
return planService.findPlanOfId(goalId, planId);
}

@ApiOperation(value = "해당 goal에 속한 plan 목록 조회 API", notes = "plan 리스트 반환")
@GetMapping("/goals/{goalId}/plans")
public List<Plan> readPlansByGoal(@AuthenticationPrincipal CustomUserDetailsVO userDetailsVO,
@PathVariable(name = "goalId") Long goalId){
return planService.findPlansOfGoal(goalId);
}

@ApiOperation(value = "특정 plan 이름 수정 API", notes = "수정한 plan 객체 반환")
@PutMapping("/goals/{goalId}/plans/{planId}")
public Plan modifyNameOfPlan(@AuthenticationPrincipal CustomUserDetailsVO userDetailsVO,
@PathVariable(name = "goalId") Long goalId,
@PathVariable(name = "planId") Long planId,
@RequestBody PlanName planName){
return planService.updatePlanName(userDetailsVO, goalId, planId, planName.getName());
}

@ApiOperation(value = "특정 plan 완료여부 수정 API", notes = "수정한 plan 객체 반환")
@PutMapping("/goals/{goalId}/plans/{planId}/check")
public Plan modifyCheckOfPlan(@AuthenticationPrincipal CustomUserDetailsVO userDetailsVO,
@PathVariable(name = "goalId") Long goalId,
@PathVariable(name = "planId") Long planId){
return planService.updatePlanStatus(userDetailsVO, goalId, planId);
}

@ApiOperation(value = "특정 plan 삭제 API", notes = "삭제 성공시 정수 1 반환 / 실패시 0 반환")
@DeleteMapping("/goals/{goalId}/plans/{planId}")
public int deletePlan(@AuthenticationPrincipal CustomUserDetailsVO userDetailsVO,
@PathVariable(name = "goalId") Long goalId,
@PathVariable(name = "planId") Long planId){
return planService.deletePlan(userDetailsVO, goalId, planId);
}

}
19 changes: 19 additions & 0 deletions src/main/java/planshare/server/planshare/plan/dto/PlanForm.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package planshare.server.planshare.plan.dto;

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

import java.time.LocalDate;

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

private String name;

private LocalDate date;

}
15 changes: 15 additions & 0 deletions src/main/java/planshare/server/planshare/plan/dto/PlanName.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package planshare.server.planshare.plan.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 PlanName {

private String name;

}

0 comments on commit 57eb7d4

Please sign in to comment.