Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#26 feat : 일정 삭제 api 구현 #29

Merged
merged 1 commit into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -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<Day,Long> {

void deleteAllByMemberAndPlan (Member member, Plan plan);
}
Original file line number Diff line number Diff line change
@@ -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, Long> {

Plan findPlanByMemberAndPlanIdAndDeletedAtIsNull(Member member,Long planId);
void deletePlanByPlanId(Long id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}
}
4 changes: 2 additions & 2 deletions src/main/java/Journey/Together/global/exception/Success.java
Original file line number Diff line number Diff line change
Expand Up @@ -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, "카테고리 수정 완료"),
Expand Down