diff --git a/src/main/java/planshare/server/planshare/plan/controller/PlanController.java b/src/main/java/planshare/server/planshare/plan/controller/PlanController.java new file mode 100644 index 0000000..ddabe0b --- /dev/null +++ b/src/main/java/planshare/server/planshare/plan/controller/PlanController.java @@ -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 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 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); + } + +} diff --git a/src/main/java/planshare/server/planshare/plan/dto/PlanForm.java b/src/main/java/planshare/server/planshare/plan/dto/PlanForm.java new file mode 100644 index 0000000..5314d0f --- /dev/null +++ b/src/main/java/planshare/server/planshare/plan/dto/PlanForm.java @@ -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; + +} diff --git a/src/main/java/planshare/server/planshare/plan/dto/PlanName.java b/src/main/java/planshare/server/planshare/plan/dto/PlanName.java new file mode 100644 index 0000000..3e92f6b --- /dev/null +++ b/src/main/java/planshare/server/planshare/plan/dto/PlanName.java @@ -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; + +}