Skip to content

Commit

Permalink
#38 refactor: 오타 수정 및 파일명 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
tinon1004 committed Feb 27, 2024
1 parent 2356489 commit e1f6337
Show file tree
Hide file tree
Showing 10 changed files with 206 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ public class SecurityConfig {
"/v*/users", POST,
"/v*/users/existence", GET,
"/v*/users/email", GET,
"/v*/administrative-area", GET
"/v*/administrative-area", GET,
"/v*/administrative-area/sgg", GET,
"/v*/administrative-area/sgg/emd", GET

);

@Bean
Expand Down
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());
}
}

This file was deleted.

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;
}
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;
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package com.ajou.hertz.domain.administrative_area.entity;

import com.ajou.hertz.common.entity.TimeTrackedBaseEntity;
import com.ajou.hertz.domain.administrative_area.constant.SidoList;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import lombok.AccessLevel;
Expand All @@ -18,15 +17,15 @@
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Entity
@Table(name = "adminitrative_area_sido")
public class Sido extends TimeTrackedBaseEntity{
@Table(name = "administrative_area_sido")
public class AdministrativeAreaSido extends TimeTrackedBaseEntity{

@Id
@Column(nullable = false, updatable = false)
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="administrative_area_sido_id", nullable = false, updatable = false)
private Long id;

@Enumerated(EnumType.STRING)
@Column(nullable = false)
private SidoList name;
private String name;
}

This file was deleted.

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);
}
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);
}
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> {
}

0 comments on commit e1f6337

Please sign in to comment.