-
Notifications
You must be signed in to change notification settings - Fork 1
[NO-ISSUE] 어드민 관련 파일 수정 #217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,8 @@ | ||
| package com.souzip.application.admin; | ||
|
|
||
| import com.souzip.application.admin.provided.AdminLocationModifier; | ||
| import com.souzip.application.admin.required.CityCommandPort; | ||
| import com.souzip.domain.city.application.command.*; | ||
| import com.souzip.domain.city.application.port.CityManagementPort; | ||
| import com.souzip.domain.city.entity.CityCreateRequest; | ||
| import com.souzip.domain.city.entity.CityUpdateRequest; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
@@ -13,25 +14,37 @@ | |
| @Service | ||
| public class AdminLocationModifyService implements AdminLocationModifier { | ||
|
|
||
| private final CityCommandPort cityCommandPort; | ||
| private final CityManagementPort cityManagementPort; | ||
|
|
||
| @Override | ||
| public void createCity(CityCreateRequest request) { | ||
| cityCommandPort.createCity(request); | ||
| cityManagementPort.createCity(new CreateCityCommand( | ||
| request.nameEn(), | ||
| request.nameKr(), | ||
| request.coordinate().getLatitude().doubleValue(), | ||
| request.coordinate().getLongitude().doubleValue(), | ||
| request.countryId() | ||
| )); | ||
|
Comment on lines
+21
to
+27
|
||
| } | ||
|
|
||
| @Override | ||
| public void updateCity(Long cityId, CityUpdateRequest request) { | ||
| cityCommandPort.updateCity(cityId, request); | ||
| cityManagementPort.updateCity(new UpdateCityCommand( | ||
| cityId, | ||
| request.nameEn(), | ||
| request.nameKr(), | ||
| request.coordinate().getLatitude().doubleValue(), | ||
| request.coordinate().getLongitude().doubleValue() | ||
| )); | ||
|
Comment on lines
+32
to
+38
|
||
| } | ||
|
|
||
| @Override | ||
| public void deleteCity(Long cityId) { | ||
| cityCommandPort.deleteCity(cityId); | ||
| cityManagementPort.deleteCity(new DeleteCityCommand(cityId)); | ||
| } | ||
|
|
||
| @Override | ||
| public void updateCityPriority(Long cityId, Integer priority) { | ||
| cityCommandPort.updateCityPriority(cityId, priority); | ||
| cityManagementPort.updateCityPriority(new UpdateCityPriorityCommand(cityId, priority)); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,10 @@ | ||
| package com.souzip.application.admin; | ||
|
|
||
| import com.souzip.application.admin.provided.AdminLocationFinder; | ||
| import com.souzip.application.admin.required.CityQueryPort; | ||
| import com.souzip.application.admin.required.CountryQueryPort; | ||
| import com.souzip.domain.city.entity.City; | ||
| import com.souzip.domain.city.repository.CityRepository; | ||
| import com.souzip.domain.country.entity.Country; | ||
| import com.souzip.domain.country.repository.CountryRepository; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.data.domain.Page; | ||
| import org.springframework.data.domain.Pageable; | ||
|
|
@@ -18,16 +18,22 @@ | |
| @Service | ||
| public class AdminLocationQueryService implements AdminLocationFinder { | ||
|
|
||
| private final CityQueryPort cityQueryPort; | ||
| private final CountryQueryPort countryQueryPort; | ||
| private final CityRepository cityRepository; | ||
| private final CountryRepository countryRepository; | ||
|
|
||
| @Override | ||
| public Page<City> getCities(Long countryId, String keyword, Pageable pageable) { | ||
| return cityQueryPort.getCities(countryId, keyword, pageable); | ||
| if (keyword == null || keyword.isBlank()) { | ||
| return cityRepository.findByCountryIdWithPaging(countryId, pageable); | ||
| } | ||
| return cityRepository.searchByKeyword(countryId, keyword, pageable); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| } | ||
|
Comment on lines
25
to
30
|
||
|
|
||
| @Override | ||
| public List<Country> getCountries(String keyword) { | ||
| return countryQueryPort.getCountries(keyword); | ||
| if (keyword == null || keyword.isBlank()) { | ||
| return countryRepository.findAllByOrderByNameKrAsc(); | ||
| } | ||
| return countryRepository.findByKeywordOrderByNameKrAsc(keyword); | ||
| } | ||
| } | ||
| } | ||
This file was deleted.
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,95 +1,100 @@ | ||
| package com.souzip.domain.city.application.command; | ||
| package com.souzip.domain.city.application.command; | ||
|
|
||
| import com.souzip.domain.city.application.port.CityManagementPort; | ||
| import com.souzip.domain.city.entity.City; | ||
| import com.souzip.domain.city.event.CityCreatedEvent; | ||
| import com.souzip.domain.city.event.CityDeletedEvent; | ||
| import com.souzip.domain.city.event.CityPriorityUpdatedEvent; | ||
| import com.souzip.domain.city.repository.CityRepository; | ||
| import com.souzip.domain.city.service.CityPriorityDomainService; | ||
| import com.souzip.domain.country.entity.Country; | ||
| import com.souzip.domain.country.repository.CountryRepository; | ||
| import com.souzip.global.exception.BusinessException; | ||
| import com.souzip.global.exception.ErrorCode; | ||
| import java.math.BigDecimal; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.context.ApplicationEventPublisher; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
| import com.souzip.domain.city.application.port.CityManagementPort; | ||
| import com.souzip.domain.city.entity.City; | ||
| import com.souzip.domain.city.event.CityCreatedEvent; | ||
|
Comment on lines
+1
to
+5
|
||
| import com.souzip.domain.city.event.CityDeletedEvent; | ||
| import com.souzip.domain.city.event.CityPriorityUpdatedEvent; | ||
| import com.souzip.domain.city.repository.CityRepository; | ||
| import com.souzip.domain.city.service.CityPriorityDomainService; | ||
| import com.souzip.domain.country.entity.Country; | ||
| import com.souzip.domain.country.repository.CountryRepository; | ||
| import com.souzip.global.exception.BusinessException; | ||
| import com.souzip.global.exception.ErrorCode; | ||
| import java.math.BigDecimal; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.context.ApplicationEventPublisher; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| @RequiredArgsConstructor | ||
| @Service | ||
| public class CityCommandService implements CityManagementPort { | ||
| @RequiredArgsConstructor | ||
| @Service | ||
| public class CityCommandService implements CityManagementPort { | ||
|
|
||
| private final CityRepository cityRepository; | ||
| private final CountryRepository countryRepository; | ||
| private final ApplicationEventPublisher eventPublisher; | ||
| private final CityPriorityDomainService cityPriorityDomainService; | ||
| private final CityRepository cityRepository; | ||
| private final CountryRepository countryRepository; | ||
| private final ApplicationEventPublisher eventPublisher; | ||
| private final CityPriorityDomainService cityPriorityDomainService; | ||
|
|
||
| @Transactional | ||
| @Override | ||
| public void createCity(CreateCityCommand command) { | ||
| Country country = findCountryById(command.countryId()); | ||
| City city = City.create( | ||
| command.nameEn(), | ||
| command.nameKr(), | ||
| BigDecimal.valueOf(command.latitude()), | ||
| BigDecimal.valueOf(command.longitude()), | ||
| country | ||
| ); | ||
| cityRepository.save(city); | ||
| @Transactional | ||
| @Override | ||
| public void createCity(CreateCityCommand command) { | ||
| Country country = findCountryById(command.countryId()); | ||
| City city = City.create( | ||
| command.nameEn(), | ||
| command.nameKr(), | ||
| BigDecimal.valueOf(command.latitude()), | ||
| BigDecimal.valueOf(command.longitude()), | ||
| country | ||
| ); | ||
| cityRepository.save(city); | ||
|
|
||
| eventPublisher.publishEvent(CityCreatedEvent.of( | ||
| city.getId(), | ||
| country.getId() | ||
| )); | ||
| } | ||
| eventPublisher.publishEvent(CityCreatedEvent.of( | ||
| city.getId(), | ||
| country.getId() | ||
| )); | ||
| } | ||
|
|
||
| @Transactional | ||
| @Override | ||
| public void updateCity(UpdateCityCommand command) { | ||
| City city = findCityById(command.cityId()); | ||
| city.updateName(command.nameEn(), command.nameKr()); | ||
| } | ||
| @Transactional | ||
| @Override | ||
| public void updateCity(UpdateCityCommand command) { | ||
| City city = findCityById(command.cityId()); | ||
| city.update( | ||
| command.nameEn(), | ||
| command.nameKr(), | ||
| BigDecimal.valueOf(command.latitude()), | ||
| BigDecimal.valueOf(command.longitude()) | ||
| ); | ||
|
Comment on lines
+50
to
+57
|
||
| } | ||
|
|
||
| @Transactional | ||
| @Override | ||
| public void deleteCity(DeleteCityCommand command) { | ||
| City city = findCityById(command.cityId()); | ||
| cityRepository.delete(city); | ||
| @Transactional | ||
| @Override | ||
| public void deleteCity(DeleteCityCommand command) { | ||
| City city = findCityById(command.cityId()); | ||
| cityRepository.delete(city); | ||
|
|
||
| eventPublisher.publishEvent(CityDeletedEvent.of(city.getId())); | ||
| } | ||
| eventPublisher.publishEvent(CityDeletedEvent.of(city.getId())); | ||
| } | ||
|
|
||
| @Transactional | ||
| @Override | ||
| public void updateCityPriority(UpdateCityPriorityCommand command) { | ||
| City city = findCityByIdWithLock(command.cityId()); | ||
| Integer oldPriority = city.getPriority(); | ||
| Long countryId = city.getCountry().getId(); | ||
| @Transactional | ||
| @Override | ||
| public void updateCityPriority(UpdateCityPriorityCommand command) { | ||
| City city = findCityByIdWithLock(command.cityId()); | ||
| Integer oldPriority = city.getPriority(); | ||
| Long countryId = city.getCountry().getId(); | ||
|
|
||
| cityPriorityDomainService.adjustPriorities(city.getId(), oldPriority, command.newPriority(), countryId); | ||
| city.updatePriority(command.newPriority()); | ||
| cityPriorityDomainService.adjustPriorities(city.getId(), oldPriority, command.newPriority(), countryId); | ||
| city.updatePriority(command.newPriority()); | ||
|
|
||
| eventPublisher.publishEvent(CityPriorityUpdatedEvent.of( | ||
| city.getId(), | ||
| oldPriority, | ||
| command.newPriority() | ||
| )); | ||
| } | ||
| eventPublisher.publishEvent(CityPriorityUpdatedEvent.of( | ||
| city.getId(), | ||
| oldPriority, | ||
| command.newPriority() | ||
| )); | ||
| } | ||
|
|
||
| private City findCityByIdWithLock(Long cityId) { | ||
| return cityRepository.findByIdWithLock(cityId) | ||
| .orElseThrow(() -> new BusinessException(ErrorCode.NOT_FOUND, "도시를 찾을 수 없습니다.")); | ||
| } | ||
| private City findCityByIdWithLock(Long cityId) { | ||
| return cityRepository.findByIdWithLock(cityId) | ||
| .orElseThrow(() -> new BusinessException(ErrorCode.NOT_FOUND, "도시를 찾을 수 없습니다.")); | ||
| } | ||
|
|
||
| private City findCityById(Long cityId) { | ||
| return cityRepository.findById(cityId) | ||
| .orElseThrow(() -> new BusinessException(ErrorCode.NOT_FOUND, "도시를 찾을 수 없습니다.")); | ||
| } | ||
| private City findCityById(Long cityId) { | ||
| return cityRepository.findById(cityId) | ||
| .orElseThrow(() -> new BusinessException(ErrorCode.NOT_FOUND, "도시를 찾을 수 없습니다.")); | ||
| } | ||
|
|
||
| private Country findCountryById(Long countryId) { | ||
| return countryRepository.findById(countryId) | ||
| .orElseThrow(() -> new BusinessException(ErrorCode.NOT_FOUND, "나라를 찾을 수 없습니다.")); | ||
| private Country findCountryById(Long countryId) { | ||
| return countryRepository.findById(countryId) | ||
| .orElseThrow(() -> new BusinessException(ErrorCode.NOT_FOUND, "나라를 찾을 수 없습니다.")); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,8 @@ | |
| public record UpdateCityCommand( | ||
| Long cityId, | ||
| String nameEn, | ||
| String nameKr | ||
| String nameKr, | ||
| Double latitude, | ||
| Double longitude | ||
|
Comment on lines
3
to
+8
|
||
| ) { | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,9 +62,11 @@ public void updatePriority(Integer priority) { | |
| this.priority = priority; | ||
| } | ||
|
|
||
| public void updateName(String nameEn, String nameKr) { | ||
| public void update(String nameEn, String nameKr, BigDecimal latitude, BigDecimal longitude) { | ||
| this.nameEn = nameEn; | ||
| this.nameKr = nameKr; | ||
| this.latitude = latitude; | ||
| this.longitude = longitude; | ||
| } | ||
|
Comment on lines
+65
to
70
|
||
|
|
||
| private void validatePriority(Integer priority) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
request.coordinate().getLatitude().doubleValue()를 바로 호출하면coordinate내부 필드가 비어 있는 요청(예:{"coordinate":{...}}에서 latitude/longitude 누락)에서NullPointerException이 발생해 500으로 떨어집니다.CityCreateRequest/CityUpdateRequest는coordinate객체 존재만 검증하고 내부 숫자 null은 막지 못하므로, 여기서 null 체크를 추가하거나Coordinate필드에@NotNull제약을 걸어 4xx로 일관되게 처리해야 합니다.Useful? React with 👍 / 👎.