-
Notifications
You must be signed in to change notification settings - Fork 5
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
feat: 지역 검색 기능을 추가한다 #836
Merged
feat: 지역 검색 기능을 추가한다 #836
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
025c75f
refactor: 컨벤션에 맞게 final 키워드 제거
sosow0212 f83e1e0
feat: 도시 정보 도메인 생성
sosow0212 bdd286f
feat: 도시 정보 repository 추가
sosow0212 3b52b35
feat: 서버 시작시 도시 정보를 저장하는 기능 추가. 단, 이미 저장 됐다면 저장하지 않음
sosow0212 c68ea30
refactor: 지역도 검색되도록 변경
sosow0212 3ce4272
refactor: 인덱스 제거
sosow0212 a73bc4f
refactor: 메서드명 변경
sosow0212 d206487
refactor: orderBy 추가
sosow0212 4d5c177
refactor: 테스트 변경
sosow0212 f41a96a
feat: City 관리자 페이지 CRUD & Test 생성
sosow0212 f008ab8
feat: 요청 보내는 기능 분리
sosow0212 0038c77
refactor: 요청 보내는 기능 분리
sosow0212 c675ec0
refactor: 패키지 이동 및 api 실행 제어
sosow0212 43cd123
refactor: request_url 변경
sosow0212 64bc863
refactor: 패키지 구조 변경
sosow0212 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
66 changes: 66 additions & 0 deletions
66
backend/src/main/java/com/carffeine/carffeine/admin/controller/AdminCityController.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,66 @@ | ||
package com.carffeine.carffeine.admin.controller; | ||
|
||
import com.carffeine.carffeine.admin.common.CustomPage; | ||
import com.carffeine.carffeine.admin.controller.dto.CityResponse; | ||
import com.carffeine.carffeine.admin.service.AdminCityService; | ||
import com.carffeine.carffeine.admin.service.dto.CityCreateRequest; | ||
import com.carffeine.carffeine.admin.service.dto.CityUpdateRequest; | ||
import com.carffeine.carffeine.auth.controller.support.AuthMember; | ||
import com.carffeine.carffeine.city.domain.City; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PatchMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.List; | ||
|
||
@RequiredArgsConstructor | ||
@RequestMapping("/admin/cities") | ||
@RestController | ||
public class AdminCityController { | ||
|
||
private final AdminCityService adminCityService; | ||
|
||
@GetMapping | ||
public ResponseEntity<CustomPage<CityResponse>> findAllCities(@AuthMember Long memberId, Pageable pageable) { | ||
Page<City> pagedCities = adminCityService.findAll(pageable, memberId); | ||
|
||
int totalPage = pagedCities.getTotalPages(); | ||
List<CityResponse> cities = pagedCities.getContent() | ||
.stream() | ||
.map(CityResponse::from) | ||
.toList(); | ||
|
||
return ResponseEntity.ok(new CustomPage<>(totalPage, cities)); | ||
} | ||
|
||
@PostMapping | ||
public ResponseEntity<CityResponse> saveNewCity(@AuthMember Long memberId, @RequestBody CityCreateRequest cityCreateRequest) { | ||
City city = adminCityService.save(memberId, cityCreateRequest); | ||
return ResponseEntity.status(HttpStatus.CREATED) | ||
.body(CityResponse.from(city)); | ||
} | ||
|
||
@PatchMapping("/{cityId}") | ||
public ResponseEntity<CityResponse> updateCity(@AuthMember Long memberId, | ||
@PathVariable Long cityId, | ||
@RequestBody CityUpdateRequest cityUpdateRequest) { | ||
City updatedCity = adminCityService.update(memberId, cityId, cityUpdateRequest); | ||
return ResponseEntity.ok(CityResponse.from(updatedCity)); | ||
} | ||
|
||
@DeleteMapping("/{cityId}") | ||
public ResponseEntity<Void> deleteCity(@AuthMember Long memberId, @PathVariable Long cityId) { | ||
adminCityService.deleteByCityId(memberId, cityId); | ||
return ResponseEntity.noContent().build(); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
backend/src/main/java/com/carffeine/carffeine/admin/controller/dto/CitiesResponse.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,15 @@ | ||
package com.carffeine.carffeine.admin.controller.dto; | ||
|
||
import com.carffeine.carffeine.city.domain.City; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public record CitiesResponse(List<CityResponse> cities) { | ||
|
||
public static CitiesResponse from(List<City> cities) { | ||
return cities.stream() | ||
.map(CityResponse::from) | ||
.collect(Collectors.collectingAndThen(Collectors.toList(), CitiesResponse::new)); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
backend/src/main/java/com/carffeine/carffeine/admin/controller/dto/CityResponse.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,20 @@ | ||
package com.carffeine.carffeine.admin.controller.dto; | ||
|
||
import com.carffeine.carffeine.city.domain.City; | ||
|
||
import java.math.BigDecimal; | ||
|
||
public record CityResponse(Long id, | ||
String name, | ||
BigDecimal latitude, | ||
BigDecimal longitude) { | ||
|
||
public static CityResponse from(City city) { | ||
return new CityResponse( | ||
city.getId(), | ||
city.getName(), | ||
city.getLatitude().getValue(), | ||
city.getLongitude().getValue() | ||
); | ||
} | ||
} |
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
70 changes: 70 additions & 0 deletions
70
backend/src/main/java/com/carffeine/carffeine/admin/service/AdminCityService.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,70 @@ | ||
package com.carffeine.carffeine.admin.service; | ||
|
||
import com.carffeine.carffeine.admin.exception.AdminException; | ||
import com.carffeine.carffeine.admin.exception.AdminExceptionType; | ||
import com.carffeine.carffeine.admin.service.dto.CityCreateRequest; | ||
import com.carffeine.carffeine.admin.service.dto.CityUpdateRequest; | ||
import com.carffeine.carffeine.member.domain.Member; | ||
import com.carffeine.carffeine.member.domain.MemberRepository; | ||
import com.carffeine.carffeine.city.domain.City; | ||
import com.carffeine.carffeine.city.domain.CityRepository; | ||
import com.carffeine.carffeine.station.domain.station.Latitude; | ||
import com.carffeine.carffeine.station.domain.station.Longitude; | ||
import com.carffeine.carffeine.city.exception.CityException; | ||
import com.carffeine.carffeine.city.exception.CityExceptionType; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@RequiredArgsConstructor | ||
@Service | ||
public class AdminCityService { | ||
|
||
private final MemberRepository memberRepository; | ||
private final CityRepository cityRepository; | ||
|
||
@Transactional(readOnly = true) | ||
public Page<City> findAll(Pageable pageable, Long memberId) { | ||
validateRole(memberId); | ||
return cityRepository.findAll(pageable); | ||
} | ||
|
||
@Transactional | ||
public City save(Long memberId, CityCreateRequest request) { | ||
validateRole(memberId); | ||
|
||
return cityRepository.save(new City( | ||
request.name(), | ||
Latitude.from(request.latitude()), | ||
Longitude.from(request.longitude())) | ||
); | ||
} | ||
|
||
@Transactional | ||
public City update(Long memberId, | ||
Long cityId, | ||
CityUpdateRequest cityUpdateRequest) { | ||
validateRole(memberId); | ||
City city = findCity(cityId); | ||
return city.update(cityUpdateRequest.name(), cityUpdateRequest.latitude(), cityUpdateRequest.longitude()); | ||
} | ||
|
||
private void validateRole(Long memberId) { | ||
memberRepository.findById(memberId) | ||
.filter(Member::isAdmin) | ||
.orElseThrow(() -> new AdminException(AdminExceptionType.NOT_ADMIN)); | ||
} | ||
|
||
private City findCity(Long cityId) { | ||
return cityRepository.findById(cityId) | ||
.orElseThrow(() -> new CityException(CityExceptionType.NOT_FOUND)); | ||
} | ||
|
||
@Transactional | ||
public void deleteByCityId(Long memberId, Long cityId) { | ||
validateRole(memberId); | ||
cityRepository.deleteById(cityId); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
backend/src/main/java/com/carffeine/carffeine/admin/service/dto/CityCreateRequest.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,8 @@ | ||
package com.carffeine.carffeine.admin.service.dto; | ||
|
||
import java.math.BigDecimal; | ||
|
||
public record CityCreateRequest(String name, | ||
BigDecimal longitude, | ||
BigDecimal latitude) { | ||
} |
8 changes: 8 additions & 0 deletions
8
backend/src/main/java/com/carffeine/carffeine/admin/service/dto/CityUpdateRequest.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,8 @@ | ||
package com.carffeine.carffeine.admin.service.dto; | ||
|
||
import java.math.BigDecimal; | ||
|
||
public record CityUpdateRequest(String name, | ||
BigDecimal latitude, | ||
BigDecimal longitude) { | ||
} |
55 changes: 55 additions & 0 deletions
55
backend/src/main/java/com/carffeine/carffeine/city/domain/City.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,55 @@ | ||
package com.carffeine.carffeine.city.domain; | ||
|
||
import com.carffeine.carffeine.station.domain.station.Latitude; | ||
import com.carffeine.carffeine.station.domain.station.Longitude; | ||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import javax.persistence.Column; | ||
import javax.persistence.Embedded; | ||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
import javax.persistence.Table; | ||
import java.math.BigDecimal; | ||
|
||
@Getter | ||
@Builder | ||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@EqualsAndHashCode(of = "id", callSuper = false) | ||
@Entity | ||
@Table(name = "city") | ||
public class City { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@Column(nullable = false) | ||
private String name; | ||
|
||
@Embedded | ||
private Latitude latitude; | ||
|
||
@Embedded | ||
private Longitude longitude; | ||
|
||
public City(String name, Latitude latitude, Longitude longitude) { | ||
this.name = name; | ||
this.latitude = latitude; | ||
this.longitude = longitude; | ||
} | ||
|
||
public City update(String name, BigDecimal latitude, BigDecimal longitude) { | ||
this.name = name; | ||
this.latitude = Latitude.from(latitude); | ||
this.longitude = Longitude.from(longitude); | ||
return this; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
backend/src/main/java/com/carffeine/carffeine/city/domain/CityRepository.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,18 @@ | ||
package com.carffeine.carffeine.city.domain; | ||
|
||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.repository.Repository; | ||
|
||
import java.util.Optional; | ||
|
||
public interface CityRepository extends Repository<City, Long> { | ||
|
||
Page<City> findAll(Pageable pageable); | ||
|
||
Optional<City> findById(Long id); | ||
|
||
City save(City city); | ||
|
||
void deleteById(Long id); | ||
} |
11 changes: 11 additions & 0 deletions
11
backend/src/main/java/com/carffeine/carffeine/city/exception/CityException.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,11 @@ | ||
package com.carffeine.carffeine.city.exception; | ||
|
||
import com.carffeine.carffeine.common.exception.BaseException; | ||
import com.carffeine.carffeine.common.exception.ExceptionType; | ||
|
||
public class CityException extends BaseException { | ||
|
||
public CityException(final ExceptionType exceptionType) { | ||
super(exceptionType); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
backend/src/main/java/com/carffeine/carffeine/city/exception/CityExceptionType.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 com.carffeine.carffeine.city.exception; | ||
|
||
import com.carffeine.carffeine.common.exception.ExceptionType; | ||
import com.carffeine.carffeine.common.exception.Status; | ||
|
||
public enum CityExceptionType implements ExceptionType { | ||
|
||
NOT_FOUND(Status.NOT_FOUND, 10001, "요청하신 도시를 찾을 수 없습니다."); | ||
|
||
private final Status status; | ||
private final int exceptionCode; | ||
private final String message; | ||
|
||
CityExceptionType(Status status, int exceptionCode, String message) { | ||
this.status = status; | ||
this.exceptionCode = exceptionCode; | ||
this.message = message; | ||
} | ||
|
||
@Override | ||
public Status status() { | ||
return status; | ||
} | ||
|
||
@Override | ||
public int exceptionCode() { | ||
return exceptionCode; | ||
} | ||
|
||
@Override | ||
public String message() { | ||
return message; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
custom page 좋아요