From 4304f065a9ff937cad8716538552c3ad4a1bfcf9 Mon Sep 17 00:00:00 2001 From: sycuuui <102959791+sycuuui@users.noreply.github.com> Date: Mon, 3 Jun 2024 22:00:54 +0900 Subject: [PATCH] =?UTF-8?q?#26=20feat=20:=20=20=EC=9D=BC=EC=A0=95=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=20api=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dairy/controller/PlanController.java | 18 ++++++++++++---- .../dairy/repository/DayRepository.java | 6 ++++++ .../dairy/repository/PlanRepository.java | 4 +++- .../domain/dairy/service/PlanService.java | 21 +++++++++++++++++++ .../Together/global/exception/Success.java | 4 ++-- 5 files changed, 46 insertions(+), 7 deletions(-) diff --git a/src/main/java/Journey/Together/domain/dairy/controller/PlanController.java b/src/main/java/Journey/Together/domain/dairy/controller/PlanController.java index bd81db4..9f07f6c 100644 --- a/src/main/java/Journey/Together/domain/dairy/controller/PlanController.java +++ b/src/main/java/Journey/Together/domain/dairy/controller/PlanController.java @@ -8,10 +8,7 @@ import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; import org.springframework.security.core.annotation.AuthenticationPrincipal; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; @RestController @RequiredArgsConstructor @@ -24,4 +21,17 @@ public ApiResponse savePlan(@AuthenticationPrincipal PrincipalDetails principalD planService.savePlan(principalDetails.getMember(),planReq); return ApiResponse.success(Success.CREATE_PLAN_SUCCESS); } + + @PostMapping("/{plan_id}") + public ApiResponse savePlan(@AuthenticationPrincipal PrincipalDetails principalDetails, @PathVariable("plan_id") Long planId){ + planService.updatePlan(principalDetails.getMember(),planId); + return ApiResponse.success(Success.UPDATE_PLAN_SUCCESS); + } + + @DeleteMapping("/{plan_id}") + public ApiResponse deletePlan(@AuthenticationPrincipal PrincipalDetails principalDetails, @PathVariable("plan_id") Long planId){ + planService.deletePlan(principalDetails.getMember(),planId); + return ApiResponse.success(Success.DELETE_PLAN_SUCCESS); + } + } diff --git a/src/main/java/Journey/Together/domain/dairy/repository/DayRepository.java b/src/main/java/Journey/Together/domain/dairy/repository/DayRepository.java index 669ab03..b8c95eb 100644 --- a/src/main/java/Journey/Together/domain/dairy/repository/DayRepository.java +++ b/src/main/java/Journey/Together/domain/dairy/repository/DayRepository.java @@ -1,7 +1,13 @@ package Journey.Together.domain.dairy.repository; import Journey.Together.domain.dairy.entity.Day; +import Journey.Together.domain.dairy.entity.Plan; +import Journey.Together.domain.member.entity.Member; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; + public interface DayRepository extends JpaRepository { + + void deleteAllByMemberAndPlan (Member member, Plan plan); } diff --git a/src/main/java/Journey/Together/domain/dairy/repository/PlanRepository.java b/src/main/java/Journey/Together/domain/dairy/repository/PlanRepository.java index edee44d..7404e42 100644 --- a/src/main/java/Journey/Together/domain/dairy/repository/PlanRepository.java +++ b/src/main/java/Journey/Together/domain/dairy/repository/PlanRepository.java @@ -1,8 +1,10 @@ package Journey.Together.domain.dairy.repository; import Journey.Together.domain.dairy.entity.Plan; +import Journey.Together.domain.member.entity.Member; import org.springframework.data.jpa.repository.JpaRepository; public interface PlanRepository extends JpaRepository { - + Plan findPlanByMemberAndPlanIdAndDeletedAtIsNull(Member member,Long planId); + void deletePlanByPlanId(Long id); } diff --git a/src/main/java/Journey/Together/domain/dairy/service/PlanService.java b/src/main/java/Journey/Together/domain/dairy/service/PlanService.java index a0de8ba..2ce41b5 100644 --- a/src/main/java/Journey/Together/domain/dairy/service/PlanService.java +++ b/src/main/java/Journey/Together/domain/dairy/service/PlanService.java @@ -53,4 +53,25 @@ public void savePlan(Member member, PlanReq planReq){ dayRepository.save(day); } } + @Transactional + public void updatePlan(Member member,Long planId){ + // Validation + Plan plan = planRepository.findPlanByMemberAndPlanIdAndDeletedAtIsNull(member,planId); + if(plan == null){ + throw new ApplicationException(ErrorCode.NOT_FOUND_EXCEPTION); + } + + } + @Transactional + public void deletePlan(Member member,Long planId){ + // Validation + Plan plan = planRepository.findPlanByMemberAndPlanIdAndDeletedAtIsNull(member,planId); + if(plan == null){ + throw new ApplicationException(ErrorCode.NOT_FOUND_EXCEPTION); + } + //Buisness + dayRepository.deleteAllByMemberAndPlan(member,plan); + planRepository.deletePlanByPlanId(planId); + + } } diff --git a/src/main/java/Journey/Together/global/exception/Success.java b/src/main/java/Journey/Together/global/exception/Success.java index 9a2beb6..a09d358 100644 --- a/src/main/java/Journey/Together/global/exception/Success.java +++ b/src/main/java/Journey/Together/global/exception/Success.java @@ -37,13 +37,13 @@ public enum Success { RE_ISSUE_TOKEN_SUCCESS(HttpStatus.OK, "토큰 재발급 성공"), SIGNOUT_SUCCESS(HttpStatus.OK, "로그아웃 성공"), DELETE_USER_SUCCESS(HttpStatus.OK, "회원 탈퇴가 정상적으로 이루어졌습니다."), - DELETE_TOAST_SUCCESS(HttpStatus.OK, "토스트 삭제 성공"), + DELETE_PLAN_SUCCESS(HttpStatus.OK, "일정 삭제 성공"), DELETE_CATEGORY_SUCCESS(HttpStatus.OK, "카테고리 삭제 성공"), DELETE_TIMER_SUCCESS(HttpStatus.OK, "타이머 삭제 성공"), SEARCH_SUCCESS(HttpStatus.OK, "검색 성공"), PARSING_OG_SUCCESS(HttpStatus.OK, "og 데이터 파싱 결과입니다. 크롤링을 막은 페이지는 기본이미지가 나옵니다."), UPDATE_PUSH_ALLOWED_SUCCESS(HttpStatus.OK, "푸시알림 수정 성공"), - UPDATE_TOAST_TITLE_SUCCESS(HttpStatus.OK, "토스트 제목 수정 성공"), + UPDATE_PLAN_SUCCESS(HttpStatus.CREATED, "일정 수정이 완료 되었습니다."), UPDATE_ISREAD_SUCCESS(HttpStatus.OK, "열람여부 수정 완료"), UPDATE_CATEGORY_TITLE_SUCCESS(HttpStatus.OK, "카테고리 수정 완료"),