Skip to content

Commit 8609f23

Browse files
committed
refactor(location): Location 조회 수정 기능 리팩토링
1 parent a04afbd commit 8609f23

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

src/main/java/com/somemore/location/service/command/UpdateLocationService.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import com.somemore.location.dto.request.LocationUpdateRequestDto;
88
import com.somemore.location.repository.LocationRepository;
99
import com.somemore.location.usecase.command.UpdateLocationUseCase;
10-
import com.somemore.location.usecase.query.LocationQueryUseCase;
1110
import lombok.RequiredArgsConstructor;
1211
import org.springframework.stereotype.Service;
1312
import org.springframework.transaction.annotation.Transactional;
@@ -17,14 +16,17 @@
1716
@Service
1817
public 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
}

src/main/java/com/somemore/location/service/query/LocationQueryService.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package 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;
36
import com.somemore.location.domain.Location;
47
import com.somemore.location.repository.LocationRepository;
58
import com.somemore.location.usecase.query.LocationQueryUseCase;
6-
import java.util.Optional;
79
import lombok.RequiredArgsConstructor;
810
import org.springframework.stereotype.Service;
911
import 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
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
package com.somemore.location.usecase.query;
22

33
import com.somemore.location.domain.Location;
4-
import java.util.Optional;
54

65
public interface LocationQueryUseCase {
76

8-
Optional<Location> findById(Long id);
7+
Location getById(Long id);
98

109
}

0 commit comments

Comments
 (0)