Skip to content

Commit

Permalink
fix: sido & sigungu & lat & lng
Browse files Browse the repository at this point in the history
  • Loading branch information
essential2189 committed Jan 21, 2024
1 parent 4409c84 commit aa09798
Show file tree
Hide file tree
Showing 24 changed files with 287 additions and 471 deletions.
18 changes: 14 additions & 4 deletions database/ddl.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ CREATE TABLE IF NOT EXISTS `popup` (
`start_date` DATE NULL COMMENT '팝업 시작일',
`end_date` DATE NULL COMMENT '팝업 종료일',
`category_id` INT NOT NULL COMMENT '카테고리 ID',
`region_id` INT NOT NULL COMMENT '지역 ID',
`sido_id` INT NOT NULL COMMENT '시/도 ID',
`sigungu_id` INT NOT NULL COMMENT '시/군/구 ID',
`info_id` BIGINT NOT NULL COMMENT '팝업 상세 정보 ID',
`create_date` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
`update_date` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
Expand All @@ -18,10 +19,17 @@ CREATE TABLE IF NOT EXISTS `category` (
`update_date` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);

CREATE TABLE IF NOT EXISTS `region` (
CREATE TABLE IF NOT EXISTS `sido` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
`sido` VARCHAR(50) NOT NULL COMMENT '시/도',
`sigungu` VARCHAR(50) NOT NULL COMMENT '시/군/구',
`name` VARCHAR(50) NOT NULL COMMENT '시/도',
`create_date` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
`update_date` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);

CREATE TABLE IF NOT EXISTS `sigungu` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
`name` VARCHAR(50) NOT NULL COMMENT '시/군/구',
`sido_id` VARCHAR(50) NOT NULL COMMENT '시/도 ID',
`create_date` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
`update_date` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);
Expand All @@ -39,6 +47,8 @@ CREATE TABLE IF NOT EXISTS `popup_info` (
`url_link` TEXT NULL COMMENT '공식 URL 링크 (홈페이지, 인스타 등)',
`introduction` TEXT NULL COMMENT '소개',
`address` TEXT NULL COMMENT '주소',
`lat` TEXT NULL COMMENT '위도',
`lng` TEXT NULL COMMENT '경도',
`start_time` TIME NULL COMMENT '시작 시간',
`end_time` TIME NULL COMMENT '종료 시간',
`create_date` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
Expand Down
468 changes: 58 additions & 410 deletions database/initdb.d/init.sql

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,12 @@ public class PopupEntity extends BaseTimeEntity {
private CategoryEntity category;

@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "region_id", referencedColumnName = "id", insertable = false, updatable = false)
private RegionEntity region;
@JoinColumn(name = "sido_id", referencedColumnName = "id", insertable = false, updatable = false)
private SidoEntity sido;

@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "sigungu_id", referencedColumnName = "id", insertable = false, updatable = false)
private SigunguEntity sigungu;

@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "info_id", referencedColumnName = "id")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ public class PopupInfoEntity extends BaseTimeEntity {
@Column(name = "address")
private String address;

@Column(name = "lat")
private String lat;

@Column(name = "lng")
private String lng;

@Column(name = "start_time")
private Date startTime;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,25 @@
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import java.util.List;
import lombok.Data;
import lombok.EqualsAndHashCode;

@Data
@EqualsAndHashCode(callSuper = true)
@Entity(name = "region")
@Table(name = "region")
public class RegionEntity extends BaseTimeEntity {
@Entity(name = "sido")
@Table(name = "sido")
public class SidoEntity extends BaseTimeEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
private Long id;

@Column(name = "sido", nullable = false)
private String sido;
@Column(name = "name", nullable = false)
private String name;

@Column(name = "sigungu", nullable = false)
private String sigungu;
@OneToMany(mappedBy = "sido")
private List<SigunguEntity> sigungus;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.todaypopup.todaypopup.core.model;

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.Data;
import lombok.EqualsAndHashCode;

@Data
@EqualsAndHashCode(callSuper = true)
@Entity(name = "sigungu")
@Table(name = "sigungu")
public class SigunguEntity extends BaseTimeEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(name = "name", nullable = false)
private String name;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "sido_id", referencedColumnName = "id")
private SidoEntity sido;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public class GetPopupDetailResponseDto {
private String endTime;
private String urlLink;
private String introduction;
private String address;
private String sido;
private String sigungu;
private LocationDto location;

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
public class GetPopupsRequestDto extends PaginationQueryDto {

private Integer category;
private Integer region;
private Integer sidoId;
private Integer sigunguId;

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
@Data
@Builder
public class GetPopupsResponseDto {

private Long id;
private String thumbnail;
private String title;
private String startDate;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.todaypopup.todaypopup.domain.popup.dto;

import lombok.Builder;
import lombok.Data;

@Data
@Builder
public class LocationDto {

private String address;
private String lat;
private String lng;

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@ public List<PopupEntity> getPopups(GetPopupsRequestDto queryDto) throws Exceptio
if (queryDto.getCategory() != null) {
predicates.add(cb.equal(popup.get("category").get("id"), queryDto.getCategory()));
}
if (queryDto.getRegion() != null) {
predicates.add(cb.equal(popup.get("region").get("id"), queryDto.getRegion()));
if (queryDto.getSidoId() != null) {
predicates.add(cb.equal(popup.get("sido").get("id"), queryDto.getSidoId()));
}
if (queryDto.getSigunguId() != null) {
predicates.add(cb.equal(popup.get("sigungu").get("id"), queryDto.getSigunguId()));
}

// Cursor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.todaypopup.todaypopup.domain.popup.dto.GetPopupDetailResponseDto;
import com.todaypopup.todaypopup.domain.popup.dto.GetPopupsRequestDto;
import com.todaypopup.todaypopup.domain.popup.dto.GetPopupsResponseDto;
import com.todaypopup.todaypopup.domain.popup.dto.LocationDto;
import com.todaypopup.todaypopup.domain.popup.repository.ImageRepository;
import com.todaypopup.todaypopup.domain.popup.repository.PopupRepository;
import com.todaypopup.todaypopup.domain.popup.repository.PopupRepositoryCustom;
Expand Down Expand Up @@ -65,7 +66,7 @@ public PaginationResponseDto<GetPopupsResponseDto> getPopups(GetPopupsRequestDto
public GetPopupDetailResponseDto getPopupDetail(Long popupId) throws Exception {
Optional<PopupEntity> popupOptional = popupRepository.findById(popupId);

if (!popupOptional.isPresent()) {
if (popupOptional.isEmpty()) {
throw new IllegalArgumentException("Invalid popupId");
}

Expand All @@ -75,6 +76,12 @@ public GetPopupDetailResponseDto getPopupDetail(Long popupId) throws Exception {
.map(ImageEntity::getUrl)
.collect(Collectors.toList());

LocationDto location = LocationDto.builder()
.address(popup.getPopupInfo().getAddress())
.lat(popup.getPopupInfo().getLat())
.lng(popup.getPopupInfo().getLng())
.build();

return GetPopupDetailResponseDto.builder()
.images(imageUrls)
.category(popup.getCategory().getName())
Expand All @@ -85,7 +92,9 @@ public GetPopupDetailResponseDto getPopupDetail(Long popupId) throws Exception {
.endTime(DateUtil.parseDateToTimeOnly(popup.getPopupInfo().getEndTime()))
.urlLink(popup.getPopupInfo().getUrlLink())
.introduction(popup.getPopupInfo().getIntroduction())
.address(popup.getPopupInfo().getAddress())
.sido(popup.getSido().getName())
.sigungu(popup.getSigungu().getName())
.location(location)
.build();
}

Expand Down Expand Up @@ -117,12 +126,13 @@ private String getNextCursorValue(List<PopupEntity> popups, GetPopupsRequestDto

public List<GetPopupsResponseDto> convertToDtoList(List<PopupEntity> popupEntities) {
return popupEntities.stream().map(popup -> GetPopupsResponseDto.builder()
.id(popup.getId())
.thumbnail(popup.getThumbnail())
.title(popup.getTitle())
.startDate(DateUtil.parseDateToDateOnly(popup.getStartDate()))
.endDate(DateUtil.parseDateToDateOnly(popup.getEndDate()))
.sido(popup.getRegion().getSido())
.sigungu(popup.getRegion().getSigungu())
.sido(popup.getSido().getName())
.sigungu(popup.getSigungu().getName())
.category(popup.getCategory().getName())
.build()).collect(Collectors.toList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.todaypopup.todaypopup.domain.region.dto.GetRegionInfoRequestDto;
import com.todaypopup.todaypopup.domain.region.dto.GetRegionInfoResponseDto;
import com.todaypopup.todaypopup.domain.region.service.RegionService;
import java.util.List;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
Expand All @@ -18,10 +19,10 @@ public RegionController(RegionService regionService) {
}

@GetMapping("/v1/region")
public ResponseEntity<GetRegionInfoResponseDto> getRegionInfo(
public ResponseEntity<List<GetRegionInfoResponseDto>> getRegionInfo(
@ModelAttribute GetRegionInfoRequestDto queryDto) throws Exception {

GetRegionInfoResponseDto response = this.regionService.getRegionInfo(queryDto);
List<GetRegionInfoResponseDto> response = this.regionService.getRegionInfo(queryDto);

return ResponseEntity.ok().body(response);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
@NoArgsConstructor
public class GetRegionInfoRequestDto {

private Long regionId;
private Long sidoId;
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.todaypopup.todaypopup.domain.region.dto;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.todaypopup.todaypopup.core.model.RegionEntity;
import java.util.List;
import java.util.Optional;
import lombok.Builder;
import lombok.Data;

Expand All @@ -12,6 +10,7 @@
@JsonInclude(JsonInclude.Include.NON_NULL)
public class GetRegionInfoResponseDto {

private List<RegionEntity> regionList;
private Optional<RegionEntity> region;
private Long sidoId;
private String sidoName;
private List<SigunguDto> sigunguList;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.todaypopup.todaypopup.domain.region.dto;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Builder;
import lombok.Data;

@Data
@Builder
@JsonInclude(JsonInclude.Include.NON_NULL)
public class SigunguDto {

private Long sigunguId;
private String sigunguName;
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.todaypopup.todaypopup.domain.region.repository;

import com.todaypopup.todaypopup.core.model.SidoEntity;
import org.springframework.data.jpa.repository.JpaRepository;

public interface SidoRepository extends JpaRepository<SidoEntity, Long> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.todaypopup.todaypopup.domain.region.repository;

import com.todaypopup.todaypopup.core.model.SigunguEntity;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;

public interface SigunguRepository extends JpaRepository<SigunguEntity, Long> {
List<SigunguEntity> findBySidoId(Long sidoId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

import com.todaypopup.todaypopup.domain.region.dto.GetRegionInfoRequestDto;
import com.todaypopup.todaypopup.domain.region.dto.GetRegionInfoResponseDto;
import java.util.List;

public interface RegionService {

GetRegionInfoResponseDto getRegionInfo(GetRegionInfoRequestDto queryDto) throws Exception;
List<GetRegionInfoResponseDto> getRegionInfo(GetRegionInfoRequestDto queryDto) throws Exception;
}
Loading

0 comments on commit aa09798

Please sign in to comment.