-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
206 additions
and
36 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
90 changes: 90 additions & 0 deletions
90
.../com/ajou/hertz/domain/administrative_area/controller/AdministrativeAreaControllerV1.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,90 @@ | ||
package com.ajou.hertz.domain.administrative_area.controller; | ||
|
||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import com.ajou.hertz.domain.administrative_area.entity.AdministrativeAreaEmd; | ||
import com.ajou.hertz.domain.administrative_area.entity.AdministrativeAreaSgg; | ||
import com.ajou.hertz.domain.administrative_area.entity.AdministrativeAreaSido; | ||
import com.ajou.hertz.domain.administrative_area.repository.AdministrativeEmdRepository; | ||
import com.ajou.hertz.domain.administrative_area.repository.AdministrativeSggRepository; | ||
import com.ajou.hertz.domain.administrative_area.repository.AdministrativeSidoRepository; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
|
||
@Tag(name = "행정구역 조회 API") | ||
@RestController | ||
@RequestMapping("/v1/administrative-area") | ||
public class AdministrativeAreaControllerV1 { | ||
private final AdministrativeSidoRepository administrativeSidoRepository; | ||
private final AdministrativeSggRepository administrativeSggRepository; | ||
private final AdministrativeEmdRepository administrativeEmdRepository; | ||
|
||
@Autowired | ||
public AdministrativeAreaControllerV1(AdministrativeSidoRepository administrativeSidoRepository, AdministrativeSggRepository administrativeSggRepository, AdministrativeEmdRepository administrativeEmdRepository) { | ||
this.administrativeSidoRepository = administrativeSidoRepository; | ||
this.administrativeSggRepository = administrativeSggRepository; | ||
this.administrativeEmdRepository = administrativeEmdRepository; | ||
} | ||
|
||
@Operation( | ||
summary = "행정구역 시도 조회", | ||
description = "행정구역 시도를 조회합니다." | ||
) | ||
|
||
@GetMapping | ||
public List<String> getSidoList() { | ||
List<AdministrativeAreaSido> administrativeAreaSidoEntities = administrativeSidoRepository.findAll(); | ||
return administrativeAreaSidoEntities.stream() | ||
.map(AdministrativeAreaSido::getName) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
@Operation( | ||
summary = "행정구역 시군구 조회", | ||
description = "행정구역 시군구를 조회합니다." | ||
) | ||
|
||
@GetMapping("/sgg") | ||
public List<String> getSggList( | ||
@Parameter( | ||
description = "시도 id를 입력하면 됩니다", | ||
example = "1" | ||
)@RequestParam Long sidoId | ||
){ | ||
AdministrativeAreaSido administrativeAreaSido = administrativeSidoRepository.findById(sidoId) | ||
.orElseThrow(() -> new IllegalArgumentException("Invalid sidoId: " + sidoId)); | ||
|
||
return administrativeSggRepository.findByAdministrativeAreaSido(administrativeAreaSido).stream() | ||
.map(AdministrativeAreaSgg::getName) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
@Operation( | ||
summary = "행정구역 읍면동 조회", | ||
description = "행정구역 읍면동을 조회합니다." | ||
) | ||
@GetMapping("/sgg/emd") | ||
public List<String> getEmdList( | ||
@Parameter( | ||
description = "시군구 id를 입력하면 됩니다", | ||
example = "1" | ||
)@RequestParam Long sggId | ||
) { | ||
AdministrativeAreaSgg administrativeAreaSgg = administrativeSggRepository.findById(sggId) | ||
.orElseThrow(() -> new IllegalArgumentException("Invalid sggId: " + sggId)); | ||
|
||
return administrativeEmdRepository.findByAdministrativeAreaSgg(administrativeAreaSgg).stream() | ||
.map(AdministrativeAreaEmd::getName) | ||
.collect(Collectors.toList()); | ||
} | ||
} |
23 changes: 0 additions & 23 deletions
23
src/main/java/com/ajou/hertz/domain/administrative_area/controller/SidoControllerV1.java
This file was deleted.
Oops, something went wrong.
36 changes: 36 additions & 0 deletions
36
src/main/java/com/ajou/hertz/domain/administrative_area/entity/AdministrativeAreaEmd.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,36 @@ | ||
package com.ajou.hertz.domain.administrative_area.entity; | ||
|
||
import com.ajou.hertz.common.entity.TimeTrackedBaseEntity; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.FetchType; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.ManyToOne; | ||
import jakarta.persistence.Table; | ||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Entity | ||
@Table(name = "administrative_area_emd") | ||
public class AdministrativeAreaEmd extends TimeTrackedBaseEntity { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name="administrative_area_emd_id", nullable = false, updatable = false) | ||
private Long id; | ||
|
||
@Column(nullable = false) | ||
private String name; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "administrative_area_sgg_id") | ||
private AdministrativeAreaSgg administrativeAreaSgg; | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/com/ajou/hertz/domain/administrative_area/entity/AdministrativeAreaSgg.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,37 @@ | ||
package com.ajou.hertz.domain.administrative_area.entity; | ||
|
||
import com.ajou.hertz.common.entity.TimeTrackedBaseEntity; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.FetchType; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.ManyToOne; | ||
import jakarta.persistence.Table; | ||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Entity | ||
@Table(name = "administrative_area_sgg") | ||
public class AdministrativeAreaSgg extends TimeTrackedBaseEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name="administrative_area_sgg_id", nullable = false, updatable = false) | ||
private Long id; | ||
|
||
@Column(nullable = false) | ||
private String name; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "administrative_area_sido_id") | ||
private AdministrativeAreaSido administrativeAreaSido; | ||
} |
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
4 changes: 0 additions & 4 deletions
4
src/main/java/com/ajou/hertz/domain/administrative_area/entity/Emd.java
This file was deleted.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
...ava/com/ajou/hertz/domain/administrative_area/repository/AdministrativeEmdRepository.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,12 @@ | ||
package com.ajou.hertz.domain.administrative_area.repository; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import com.ajou.hertz.domain.administrative_area.entity.AdministrativeAreaEmd; | ||
import com.ajou.hertz.domain.administrative_area.entity.AdministrativeAreaSgg; | ||
|
||
public interface AdministrativeEmdRepository extends JpaRepository<AdministrativeAreaEmd, Long> { | ||
List<AdministrativeAreaEmd> findByAdministrativeAreaSgg(AdministrativeAreaSgg administrativeAreaSgg); | ||
} |
12 changes: 12 additions & 0 deletions
12
...ava/com/ajou/hertz/domain/administrative_area/repository/AdministrativeSggRepository.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,12 @@ | ||
package com.ajou.hertz.domain.administrative_area.repository; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import com.ajou.hertz.domain.administrative_area.entity.AdministrativeAreaSgg; | ||
import com.ajou.hertz.domain.administrative_area.entity.AdministrativeAreaSido; | ||
|
||
public interface AdministrativeSggRepository extends JpaRepository<AdministrativeAreaSgg, Long> { | ||
List<AdministrativeAreaSgg> findByAdministrativeAreaSido(AdministrativeAreaSido administrativeAreaSido); | ||
} |
8 changes: 8 additions & 0 deletions
8
...va/com/ajou/hertz/domain/administrative_area/repository/AdministrativeSidoRepository.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.ajou.hertz.domain.administrative_area.repository; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import com.ajou.hertz.domain.administrative_area.entity.AdministrativeAreaSido; | ||
|
||
public interface AdministrativeSidoRepository extends JpaRepository<AdministrativeAreaSido, Long> { | ||
} |