File tree Expand file tree Collapse file tree 3 files changed +18
-9
lines changed
src/main/java/com/somemore/location Expand file tree Collapse file tree 3 files changed +18
-9
lines changed Original file line number Diff line number Diff line change 77import com .somemore .location .dto .request .LocationUpdateRequestDto ;
88import com .somemore .location .repository .LocationRepository ;
99import com .somemore .location .usecase .command .UpdateLocationUseCase ;
10- import com .somemore .location .usecase .query .LocationQueryUseCase ;
1110import lombok .RequiredArgsConstructor ;
1211import org .springframework .stereotype .Service ;
1312import org .springframework .transaction .annotation .Transactional ;
1716@ Service
1817public class UpdateLocationService implements UpdateLocationUseCase {
1918
20- private final LocationQueryUseCase locationQueryUseCase ;
2119 private final LocationRepository locationRepository ;
2220
2321 @ Override
2422 public void updateLocation (LocationUpdateRequestDto requestDto , Long locationId ) {
25- Location location = locationQueryUseCase .findById (locationId )
26- .orElseThrow (() -> new BadRequestException (NOT_EXISTS_LOCATION .getMessage ()));
23+ Location location = getLocation (locationId );
2724 location .updateWith (requestDto );
2825 locationRepository .save (location );
2926 }
27+
28+ private Location getLocation (Long locationId ) {
29+ return locationRepository .findById (locationId )
30+ .orElseThrow (() -> new BadRequestException (NOT_EXISTS_LOCATION .getMessage ()));
31+ }
3032}
Original file line number Diff line number Diff line change 11package com .somemore .location .service .query ;
22
3+ import static com .somemore .global .exception .ExceptionMessage .NOT_EXISTS_LOCATION ;
4+
5+ import com .somemore .global .exception .BadRequestException ;
36import com .somemore .location .domain .Location ;
47import com .somemore .location .repository .LocationRepository ;
58import com .somemore .location .usecase .query .LocationQueryUseCase ;
6- import java .util .Optional ;
79import lombok .RequiredArgsConstructor ;
810import org .springframework .stereotype .Service ;
911import org .springframework .transaction .annotation .Transactional ;
@@ -16,8 +18,14 @@ public class LocationQueryService implements LocationQueryUseCase {
1618 private final LocationRepository locationRepository ;
1719
1820 @ Override
19- public Optional <Location > findById (Long id ) {
20- return locationRepository .findById (id );
21+ public Location getById (Long id ) {
22+ return getLocation (id );
23+ }
24+
25+ private Location getLocation (Long id ) {
26+ return locationRepository .findById (id ).orElseThrow (
27+ () -> new BadRequestException (NOT_EXISTS_LOCATION .getMessage ())
28+ );
2129 }
2230
2331}
Original file line number Diff line number Diff line change 11package com .somemore .location .usecase .query ;
22
33import com .somemore .location .domain .Location ;
4- import java .util .Optional ;
54
65public interface LocationQueryUseCase {
76
8- Optional < Location > findById (Long id );
7+ Location getById (Long id );
98
109}
You can’t perform that action at this time.
0 commit comments