Skip to content

Commit

Permalink
Merge pull request #87 from Happy-HOBAK/fix/#86
Browse files Browse the repository at this point in the history
[#86] ν™œλ™ μ‚­μ œ 및 μˆ˜μ • κΈ°λŠ₯ μˆ˜μ •
  • Loading branch information
yel-m authored May 23, 2024
2 parents 88f013f + 12c6261 commit 9444d3e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -46,17 +48,30 @@ public DataResponseDto<ActivityResponseDto> createActivity(@RequestBody Activity

@Operation(summary = "ν™œλ™ μ‚­μ œ", description = "기타 μΉ΄ν…Œκ³ λ¦¬μ— μžˆλŠ” ν™œλ™μ„ μ‚­μ œν•©λ‹ˆλ‹€.")
@DeleteMapping("/{activityId}")
public DataResponseDto<ActivityResponseDto> deleteActivity(@PathVariable Long activityId){
activityDeleteService.deleteActivity(activityId);
ActivityResponseDto responseDto = ActivityConverter.toActivityResponseDto(activityId);
return DataResponseDto.of(responseDto, "ν™œλ™μ„ μ„±κ³΅μ μœΌλ‘œ μ‚­μ œν–ˆμŠ΅λ‹ˆλ‹€.");
public DataResponseDto<ActivityResponseDto> 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 {
throw new GeneralException(Code.INTERNAL_ERROR,"본인이 μΆ”κ°€ν•˜μ§€ μ•Šμ€ ν™œλ™μ€ μ‚­μ œκ°€ λΆˆκ°€ν•©λ‹ˆλ‹€.");
}

}

@Operation(summary = "ν™œλ™ μˆ˜μ •", description = "기타 μΉ΄ν…Œκ³ λ¦¬μ— μžˆλŠ” ν™œλ™μ„ μˆ˜μ •ν•©λ‹ˆλ‹€.")
@PutMapping("/{activityId}")
public DataResponseDto<ActivityUpdateResponseDto> updateActicity(@PathVariable Long activityId, @RequestBody ActivityUpdateRequestDto requestDto){
ActivityUpdateResponseDto responseDto = activityUpdateService.updateActivity(activityId,requestDto);
return DataResponseDto.of(responseDto,"ν™œλ™μ„ μ„±κ³΅μ μœΌλ‘œ μˆ˜μ •ν–ˆμŠ΅λ‹ˆλ‹€.");
public DataResponseDto<ActivityUpdateResponseDto> 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 {
throw new GeneralException(Code.INTERNAL_ERROR,"본인이 μΆ”κ°€ν•˜μ§€ μ•Šμ€ ν™œλ™μ€ μˆ˜μ •μ΄ λΆˆκ°€ν•©λ‹ˆλ‹€.");
}
}

@Operation(summary = "ν™œλ™ 검색", description = "μœ μ €κ°€ κ°–κ³  μžˆλŠ” ν™œλ™μ„ κ²€μƒ‰ν•©λ‹ˆλ‹€. (ν™œλ™μ˜ description에 μžˆλŠ” λ‚΄μš©μ€ 아직 κ²€μƒ‰λ˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€.)")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

}

0 comments on commit 9444d3e

Please sign in to comment.