-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from Findy-org/feat/마커-삭제
[FINDY-34] feat: 마커 삭제
- Loading branch information
Showing
14 changed files
with
240 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
src/main/java/org/findy/findy_be/marker/application/delete/DeleteMarker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package org.findy.findy_be.marker.application.delete; | ||
|
||
public interface DeleteMarker { | ||
|
||
void invoke(String userId, Long markerId); | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/org/findy/findy_be/marker/application/delete/DeleteMarkerService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.findy.findy_be.marker.application.delete; | ||
|
||
import static org.findy.findy_be.common.exception.ErrorCode.*; | ||
|
||
import org.findy.findy_be.marker.domain.Marker; | ||
import org.findy.findy_be.marker.repository.MarkerRepository; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import jakarta.persistence.EntityNotFoundException; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Service | ||
@Transactional | ||
@RequiredArgsConstructor | ||
public class DeleteMarkerService implements DeleteMarker { | ||
|
||
private final MarkerRepository markerRepository; | ||
|
||
public void invoke(String userId, Long markerId) { | ||
|
||
Marker marker = markerRepository.findById(markerId) | ||
.orElseThrow( | ||
() -> new EntityNotFoundException(String.format(NOT_FOUND_MARKER_BY_ID.getMessage(), markerId))); | ||
validateMarkerUser(userId, marker); | ||
markerRepository.delete(marker); | ||
} | ||
|
||
private static void validateMarkerUser(final String userId, final Marker marker) { | ||
if (!marker.getBookmark().getUser().getUserId().equals(userId)) { | ||
throw new IllegalArgumentException(FORBIDDEN_MARKER_ACCESS.getMessage()); | ||
} | ||
} | ||
} |
5 changes: 3 additions & 2 deletions
5
src/main/java/org/findy/findy_be/marker/application/find/FindAllPagedMarkers.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
package org.findy.findy_be.marker.application.find; | ||
|
||
import org.findy.findy_be.common.dto.pagination.response.SliceResponse; | ||
import org.findy.findy_be.place.dto.response.PlaceResponse; | ||
import org.findy.findy_be.place.dto.response.MarkerPlaceResponse; | ||
|
||
public interface FindAllPagedMarkers { | ||
SliceResponse<PlaceResponse> invoke(final String userId, final Long bookmarkId, final Long cursor, final int size); | ||
SliceResponse<MarkerPlaceResponse> invoke(final String userId, final Long bookmarkId, final Long cursor, | ||
final int size); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 3 additions & 2 deletions
5
src/main/java/org/findy/findy_be/place/repository/PlaceRepositoryCustom.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
package org.findy.findy_be.place.repository; | ||
|
||
import org.findy.findy_be.place.domain.Place; | ||
import org.findy.findy_be.place.dto.response.MarkerPlaceResponse; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.domain.Slice; | ||
|
||
public interface PlaceRepositoryCustom { | ||
|
||
Slice<Place> findPlacesByUserIdAndBookmarkId(String userId, Long bookmarkId, Pageable pageable, Long cursor); | ||
Slice<MarkerPlaceResponse> findPlacesByUserIdAndBookmarkId(String userId, Long bookmarkId, Pageable pageable, | ||
Long cursor); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
src/test/java/org/findy/findy_be/marker/application/delete/DeleteMarkerServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package org.findy.findy_be.marker.application.delete; | ||
|
||
import static org.findy.findy_be.common.exception.ErrorCode.*; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.mockito.Mockito.*; | ||
|
||
import java.util.Optional; | ||
|
||
import org.findy.findy_be.bookmark.domain.Bookmark; | ||
import org.findy.findy_be.common.MockTest; | ||
import org.findy.findy_be.marker.domain.Marker; | ||
import org.findy.findy_be.marker.repository.MarkerRepository; | ||
import org.findy.findy_be.place.domain.Place; | ||
import org.findy.findy_be.user.domain.User; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.MockitoAnnotations; | ||
|
||
class DeleteMarkerServiceTest extends MockTest { | ||
|
||
@Mock | ||
private MarkerRepository markerRepository; | ||
|
||
@InjectMocks | ||
private DeleteMarkerService deleteMarkerService; | ||
|
||
private User testUser; | ||
private Bookmark bookmark; | ||
private Place place; | ||
private Marker marker; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
MockitoAnnotations.openMocks(this); | ||
|
||
testUser = mock(User.class); | ||
when(testUser.getUserId()).thenReturn("N49sfgdahdKz_fp-223424er1N3D6kd"); | ||
|
||
bookmark = mock(Bookmark.class); | ||
when(bookmark.getUser()).thenReturn(testUser); | ||
|
||
place = mock(Place.class); | ||
|
||
marker = Marker.createForCustomBookmark(bookmark, place); | ||
} | ||
|
||
@DisplayName("[성공] 마커 삭제") | ||
@Test | ||
public void 마커_삭제() throws Exception { | ||
// given | ||
Long markerId = 1L; | ||
String userId = testUser.getUserId(); | ||
when(markerRepository.findById(markerId)).thenReturn(Optional.of(marker)); | ||
|
||
// when | ||
deleteMarkerService.invoke(userId, markerId); | ||
|
||
// then | ||
verify(markerRepository, times(1)).delete(marker); | ||
} | ||
|
||
@DisplayName("[실패] 다른 유저의 마커 삭제 시도") | ||
@Test | ||
void 마커_삭제_실패_다른유저() { | ||
// given | ||
Long markerId = 1L; | ||
String userId = "differentUserId"; | ||
when(markerRepository.findById(markerId)).thenReturn(Optional.of(marker)); | ||
|
||
// when & then | ||
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, | ||
() -> deleteMarkerService.invoke(userId, markerId)); | ||
|
||
assertEquals(FORBIDDEN_MARKER_ACCESS.getMessage(), exception.getMessage()); | ||
} | ||
} |
Oops, something went wrong.