From f2e750de837126ebf3e42fb7362c097c106e5488 Mon Sep 17 00:00:00 2001 From: sangeun Date: Thu, 23 May 2024 15:27:07 +0900 Subject: [PATCH 1/4] =?UTF-8?q?fix=20:=20=EC=9C=A0=EC=A0=80=EA=B0=80=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=ED=95=9C=20=ED=99=9C=EB=8F=99=EB=A7=8C=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20=EA=B0=80=EB=8A=A5=ED=95=98=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../activity/application/ActivityUpdateService.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/hobak/happinessql/domain/activity/application/ActivityUpdateService.java b/src/main/java/com/hobak/happinessql/domain/activity/application/ActivityUpdateService.java index a7e2592..06102fc 100644 --- a/src/main/java/com/hobak/happinessql/domain/activity/application/ActivityUpdateService.java +++ b/src/main/java/com/hobak/happinessql/domain/activity/application/ActivityUpdateService.java @@ -6,6 +6,7 @@ import com.hobak.happinessql.domain.activity.dto.ActivityUpdateResponseDto; import com.hobak.happinessql.domain.activity.exception.ActivityNotFoundException; import com.hobak.happinessql.domain.activity.repository.ActivityRepository; +import com.hobak.happinessql.domain.user.domain.User; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -16,11 +17,14 @@ public class ActivityUpdateService { private final ActivityRepository activityRepository; - public ActivityUpdateResponseDto updateActivity(Long activityId, ActivityUpdateRequestDto requestDto){ + public ActivityUpdateResponseDto updateActivity(Long activityId, ActivityUpdateRequestDto requestDto, User user){ Activity activity = activityRepository.findById(activityId) .orElseThrow(()-> new ActivityNotFoundException("Activity with id " + activityId)); - activity.updateName(requestDto.getName()); - return ActivityConverter.toActivityUpdateResponseDto(activity); + if(activity.getCategory().getUserId().equals(user.getUserId())) { + activity.updateName(requestDto.getName()); + return ActivityConverter.toActivityUpdateResponseDto(activity); + } + return null; } } From 9c87881f75413ede8436471fcebee6fdd7bc4130 Mon Sep 17 00:00:00 2001 From: sangeun Date: Thu, 23 May 2024 15:27:18 +0900 Subject: [PATCH 2/4] =?UTF-8?q?fix=20:=20=EC=9C=A0=EC=A0=80=EA=B0=80=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=ED=95=9C=20=ED=99=9C=EB=8F=99=EB=A7=8C=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=20=EA=B0=80=EB=8A=A5=ED=95=98=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../activity/application/ActivityDeleteService.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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 ab3d3d8..289c708 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 @@ -4,6 +4,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 com.hobak.happinessql.domain.user.domain.User; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -13,9 +14,13 @@ @RequiredArgsConstructor public class ActivityDeleteService { private final ActivityRepository activityRepository; - public void deleteActivity(Long activityId){ + public Long deleteActivity(Long activityId, User user){ Activity activity = activityRepository.findById(activityId) .orElseThrow(()->new ActivityNotFoundException("Activity with id " + activityId)); - activityRepository.delete(activity); + if(activity.getCategory().getUserId().equals(user.getUserId())) { + activityRepository.delete(activity); + return activity.getActivityId(); + } + return null; } } From ace88346727ea6d6d8d96ff9432247f501cc4fcc Mon Sep 17 00:00:00 2001 From: sangeun Date: Thu, 23 May 2024 15:27:49 +0900 Subject: [PATCH 3/4] =?UTF-8?q?fix=20:=20=EC=9C=A0=EC=A0=80=EA=B0=80=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=ED=95=9C=20=ED=99=9C=EB=8F=99=EC=97=90=20?= =?UTF-8?q?=EB=8C=80=ED=95=B4=EC=84=9C=EB=A7=8C=20=EC=88=98=EC=A0=95=20?= =?UTF-8?q?=EB=B0=8F=20=EC=82=AD=EC=A0=9C=20=EA=B0=80=EB=8A=A5=ED=95=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../activity/api/ActivityController.java | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 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 474d8f8..70821e9 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 @@ -46,17 +46,30 @@ public DataResponseDto createActivity(@RequestBody Activity @Operation(summary = "활동 삭제", description = "기타 카테고리에 있는 활동을 삭제합니다.") @DeleteMapping("/{activityId}") - public DataResponseDto deleteActivity(@PathVariable Long activityId){ - activityDeleteService.deleteActivity(activityId); - ActivityResponseDto responseDto = ActivityConverter.toActivityResponseDto(activityId); - return DataResponseDto.of(responseDto, "활동을 성공적으로 삭제했습니다."); + public DataResponseDto deleteActivity(@PathVariable Long activityId, @AuthenticationPrincipal UserDetails userDetails){ + User user = userFindService.findByUserDetails(userDetails); + Long deleteActivityId = activityDeleteService.deleteActivity(activityId, user); + if(deleteActivityId != null) { + ActivityResponseDto responseDto = ActivityConverter.toActivityResponseDto(deleteActivityId); + return DataResponseDto.of(responseDto, "활동을 성공적으로 삭제했습니다."); + } + else { + return DataResponseDto.of(null, "본인이 추가하지 않은 활동은 삭제가 불가합니다."); + } + } @Operation(summary = "활동 수정", description = "기타 카테고리에 있는 활동을 수정합니다.") @PutMapping("/{activityId}") - public DataResponseDto updateActicity(@PathVariable Long activityId, @RequestBody ActivityUpdateRequestDto requestDto){ - ActivityUpdateResponseDto responseDto = activityUpdateService.updateActivity(activityId,requestDto); - return DataResponseDto.of(responseDto,"활동을 성공적으로 수정했습니다."); + public DataResponseDto updateActivity(@PathVariable Long activityId, @RequestBody ActivityUpdateRequestDto requestDto, @AuthenticationPrincipal UserDetails userDetails){ + User user = userFindService.findByUserDetails(userDetails); + ActivityUpdateResponseDto responseDto = activityUpdateService.updateActivity(activityId,requestDto, user); + if(responseDto != null){ + return DataResponseDto.of(responseDto,"활동을 성공적으로 수정했습니다."); + } + else { + return DataResponseDto.of(null, "본인이 추가하지 않은 활동은 수정이 불가합니다."); + } } @Operation(summary = "활동 검색", description = "유저가 갖고 있는 활동을 검색합니다. (활동의 description에 있는 내용은 아직 검색되지 않습니다.)") From 12c6261781ba090306e42c40565e23f9510b7a32 Mon Sep 17 00:00:00 2001 From: sangeun Date: Thu, 23 May 2024 15:51:35 +0900 Subject: [PATCH 4/4] =?UTF-8?q?fix=20:=20=EC=97=90=EB=9F=AC=20=EC=9D=91?= =?UTF-8?q?=EB=8B=B5=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 | 6 ++++-- 1 file changed, 4 insertions(+), 2 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 70821e9..749e6d5 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 @@ -5,6 +5,8 @@ import com.hobak.happinessql.domain.activity.dto.*; import com.hobak.happinessql.domain.user.application.UserFindService; import com.hobak.happinessql.domain.user.domain.User; +import com.hobak.happinessql.global.exception.GeneralException; +import com.hobak.happinessql.global.response.Code; import com.hobak.happinessql.global.response.DataResponseDto; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; @@ -54,7 +56,7 @@ public DataResponseDto deleteActivity(@PathVariable Long ac return DataResponseDto.of(responseDto, "활동을 성공적으로 삭제했습니다."); } else { - return DataResponseDto.of(null, "본인이 추가하지 않은 활동은 삭제가 불가합니다."); + throw new GeneralException(Code.INTERNAL_ERROR,"본인이 추가하지 않은 활동은 삭제가 불가합니다."); } } @@ -68,7 +70,7 @@ public DataResponseDto updateActivity(@PathVariable L return DataResponseDto.of(responseDto,"활동을 성공적으로 수정했습니다."); } else { - return DataResponseDto.of(null, "본인이 추가하지 않은 활동은 수정이 불가합니다."); + throw new GeneralException(Code.INTERNAL_ERROR,"본인이 추가하지 않은 활동은 수정이 불가합니다."); } }