From b17212b8730bd438c02a68b98f0e6905614aa08f Mon Sep 17 00:00:00 2001 From: sangeun Date: Mon, 6 May 2024 01:33:51 +0900 Subject: [PATCH 1/2] =?UTF-8?q?feat=20:=20=ED=99=9C=EB=8F=99=20=EC=82=AD?= =?UTF-8?q?=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 --- .../activity/api/ActivityController.java | 7 +++++++ .../application/ActivityDeleteService.java | 20 +++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 src/main/java/com/hobak/happinessql/domain/activity/application/ActivityDeleteService.java diff --git a/src/main/java/com/hobak/happinessql/domain/activity/api/ActivityController.java b/src/main/java/com/hobak/happinessql/domain/activity/api/ActivityController.java index a9169ae..3afdf70 100644 --- a/src/main/java/com/hobak/happinessql/domain/activity/api/ActivityController.java +++ b/src/main/java/com/hobak/happinessql/domain/activity/api/ActivityController.java @@ -1,6 +1,7 @@ package com.hobak.happinessql.domain.activity.api; import com.hobak.happinessql.domain.activity.application.ActivityCreateService; +import com.hobak.happinessql.domain.activity.application.ActivityDeleteService; import com.hobak.happinessql.domain.activity.dto.ActivityCreateRequestDto; import com.hobak.happinessql.domain.activity.dto.ActivityCreateResponseDto; import com.hobak.happinessql.domain.activity.dto.ActivityListResponseDto; @@ -16,6 +17,7 @@ public class ActivityController { private final ActivityListService activityListService; private final ActivityCreateService activityCreateService; + private final ActivityDeleteService activityDeleteService; @GetMapping public DataResponseDto getActivitiesByUserId(@RequestParam Long userId) { @@ -27,4 +29,9 @@ public DataResponseDto createActivity(@RequestBody Ac ActivityCreateResponseDto response = activityCreateService.createActivity(request,userId); return DataResponseDto.of(response,"활동을 성공적으로 추가했습니다."); } + @DeleteMapping + public Long deleteActivity(@RequestParam Long activityId){ + activityDeleteService.deleteActivity(activityId); + return activityId; + } } \ No newline at end of file diff --git a/src/main/java/com/hobak/happinessql/domain/activity/application/ActivityDeleteService.java b/src/main/java/com/hobak/happinessql/domain/activity/application/ActivityDeleteService.java new file mode 100644 index 0000000..e9f9e86 --- /dev/null +++ b/src/main/java/com/hobak/happinessql/domain/activity/application/ActivityDeleteService.java @@ -0,0 +1,20 @@ +package com.hobak.happinessql.domain.activity.application; + + +import com.hobak.happinessql.domain.activity.domain.Activity; +import com.hobak.happinessql.domain.activity.repository.ActivityRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@Transactional +@RequiredArgsConstructor +public class ActivityDeleteService { + private final ActivityRepository activityRepository; + public void deleteActivity(Long activityId){ + Activity activity = activityRepository.findById(activityId) + .orElseThrow(()->new IllegalArgumentException("해당 활동이 존재하지 않습니다. activityId: " + activityId)); + activityRepository.delete(activity); + } +} From 6d77d273295bacfa0bcd3cbf4c9a163660226e7a Mon Sep 17 00:00:00 2001 From: sangeun Date: Tue, 7 May 2024 12:41:52 +0900 Subject: [PATCH 2/2] =?UTF-8?q?feat=20:=20=ED=99=9C=EB=8F=99=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=20API=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../happinessql/domain/activity/api/ActivityController.java | 4 ++-- .../domain/activity/application/ActivityDeleteService.java | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/hobak/happinessql/domain/activity/api/ActivityController.java b/src/main/java/com/hobak/happinessql/domain/activity/api/ActivityController.java index 3afdf70..fba02c0 100644 --- a/src/main/java/com/hobak/happinessql/domain/activity/api/ActivityController.java +++ b/src/main/java/com/hobak/happinessql/domain/activity/api/ActivityController.java @@ -29,8 +29,8 @@ public DataResponseDto createActivity(@RequestBody Ac ActivityCreateResponseDto response = activityCreateService.createActivity(request,userId); return DataResponseDto.of(response,"활동을 성공적으로 추가했습니다."); } - @DeleteMapping - public Long deleteActivity(@RequestParam Long activityId){ + @DeleteMapping("/{activityId}") + public Long deleteActivity(@PathVariable Long activityId){ activityDeleteService.deleteActivity(activityId); return activityId; } diff --git a/src/main/java/com/hobak/happinessql/domain/activity/application/ActivityDeleteService.java b/src/main/java/com/hobak/happinessql/domain/activity/application/ActivityDeleteService.java index e9f9e86..ab3d3d8 100644 --- a/src/main/java/com/hobak/happinessql/domain/activity/application/ActivityDeleteService.java +++ b/src/main/java/com/hobak/happinessql/domain/activity/application/ActivityDeleteService.java @@ -2,6 +2,7 @@ import com.hobak.happinessql.domain.activity.domain.Activity; +import com.hobak.happinessql.domain.activity.exception.ActivityNotFoundException; import com.hobak.happinessql.domain.activity.repository.ActivityRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -14,7 +15,7 @@ public class ActivityDeleteService { private final ActivityRepository activityRepository; public void deleteActivity(Long activityId){ Activity activity = activityRepository.findById(activityId) - .orElseThrow(()->new IllegalArgumentException("해당 활동이 존재하지 않습니다. activityId: " + activityId)); + .orElseThrow(()->new ActivityNotFoundException("Activity with id " + activityId)); activityRepository.delete(activity); } }