Skip to content

Commit

Permalink
feat: get popup detail & category info & region info
Browse files Browse the repository at this point in the history
  • Loading branch information
essential2189 committed Jan 13, 2024
1 parent 1690617 commit 4409c84
Show file tree
Hide file tree
Showing 44 changed files with 1,343 additions and 387 deletions.
6 changes: 3 additions & 3 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ services:
# ports:
# - "8080:8080"
# environment:
# SPRING_DATASOURCE_URL: jdbc:mysql://db_mysql:3306/today_popup?useSSL=false&allowPublicKeyRetrieval=true&characterEncoding=UTF-8&serverTimezone=UTC
# SPRING_DATASOURCE_URL: jdbc:mysql://db_mysql:3306/today_popup?useSSL=false&allowPublicKeyRetrieval=true&characterEncoding=UTF-8&serverTimezone=KST
# SPRING_DATASOURCE_USERNAME: root
# SPRING_DATASOURCE_PASSWORD: root
# SPRING_DATASOURCE_DRIVER_CLASS_NAME: com.mysql.cj.jdbc.Driver
# TZ: UTC
# TZ: KST
# depends_on:
# - db_mysql
# networks:
Expand All @@ -31,7 +31,7 @@ services:
MYSQL_DATABASE: today_popup
MYSQL_USER: todaypopup
MYSQL_PASSWORD: todaypopup
TZ: UTC
TZ: KST
ports:
- "3306:3306"
volumes:
Expand Down
16 changes: 9 additions & 7 deletions database/ddl.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
CREATE TABLE IF NOT EXISTS `popup` (
`id` BIGINT NOT NULL,
`id` BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
`title` VARCHAR(255) NOT NULL COMMENT '제목',
`thumbnail` TEXT NOT NULL COMMENT '썸네일 URL',
`start_date` DATE NULL COMMENT '팝업 시작일',
Expand All @@ -12,33 +12,35 @@ CREATE TABLE IF NOT EXISTS `popup` (
);

CREATE TABLE IF NOT EXISTS `category` (
`id` INT NOT NULL,
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
`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 `region` (
`id` INT NOT NULL,
`city` VARCHAR(50) NOT NULL COMMENT '',
`district` VARCHAR(50) NOT NULL COMMENT '',
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
`sido` VARCHAR(50) NOT NULL COMMENT '/도',
`sigungu` 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 `image` (
`id` BIGINT NOT NULL,
`id` BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
`url` TEXT NOT NULL COMMENT '이미지 URL',
`popup_id` BIGINT NOT NULL COMMENT '팝업 ID',
`create_date` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
`update_date` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);

CREATE TABLE IF NOT EXISTS `popup_info` (
`id` BIGINT NOT NULL,
`id` BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
`url_link` TEXT NULL COMMENT '공식 URL 링크 (홈페이지, 인스타 등)',
`introduction` TEXT NULL COMMENT '소개',
`address` TEXT NULL COMMENT '주소',
`start_time` TIME NULL COMMENT '시작 시간',
`end_time` TIME NULL COMMENT '종료 시간',
`create_date` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
`update_date` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);
1,023 changes: 813 additions & 210 deletions database/initdb.d/init.sql

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/main/java/com/todaypopup/todaypopup/SpringConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ public class SpringConfig {

@PostConstruct
void started() {
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
TimeZone.setDefault(TimeZone.getTimeZone("KST"));
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.todaypopup.todaypopup.dto;
package com.todaypopup.todaypopup.core.dto;

import lombok.Builder;
import lombok.Data;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.todaypopup.todaypopup.dto;
package com.todaypopup.todaypopup.core.dto;

import lombok.Builder;
import lombok.Data;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.todaypopup.todaypopup.dto;
package com.todaypopup.todaypopup.core.dto;

import java.util.List;
import lombok.Builder;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.todaypopup.todaypopup.model;
package com.todaypopup.todaypopup.core.model;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import jakarta.persistence.Column;
import jakarta.persistence.MappedSuperclass;
import jakarta.persistence.PrePersist;
Expand All @@ -9,6 +10,7 @@

@Getter
@MappedSuperclass
@JsonIgnoreProperties(value = {"createDate", "updateDate"})
public abstract class BaseTimeEntity {

@Column(name = "create_date")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.todaypopup.todaypopup.model;
package com.todaypopup.todaypopup.core.model;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.todaypopup.todaypopup.model;
package com.todaypopup.todaypopup.core.model;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.todaypopup.todaypopup.model;
package com.todaypopup.todaypopup.core.model;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
Expand All @@ -7,11 +7,13 @@
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.OneToMany;
import jakarta.persistence.OneToOne;
import jakarta.persistence.Table;
import jakarta.persistence.Temporal;
import jakarta.persistence.TemporalType;
import java.util.Date;
import java.util.List;
import lombok.Data;
import lombok.EqualsAndHashCode;

Expand Down Expand Up @@ -50,4 +52,8 @@ public class PopupEntity extends BaseTimeEntity {
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "info_id", referencedColumnName = "id")
private PopupInfoEntity popupInfo;

@OneToMany(fetch = FetchType.LAZY)
@JoinColumn(name = "popup_id", referencedColumnName = "id")
private List<ImageEntity> images;
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.todaypopup.todaypopup.model;
package com.todaypopup.todaypopup.core.model;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import java.util.Date;
import lombok.Data;
import lombok.EqualsAndHashCode;

Expand All @@ -27,4 +28,10 @@ public class PopupInfoEntity extends BaseTimeEntity {

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

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

@Column(name = "end_time")
private Date endTime;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.todaypopup.todaypopup.model;
package com.todaypopup.todaypopup.core.model;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
Expand All @@ -19,9 +19,9 @@ public class RegionEntity extends BaseTimeEntity {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;

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

@Column(name = "district", nullable = false)
private String district;
@Column(name = "sigungu", nullable = false)
private String sigungu;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.todaypopup.todaypopup.util;
package com.todaypopup.todaypopup.core.util;

import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.todaypopup.todaypopup.util;
package com.todaypopup.todaypopup.core.util;

import java.text.SimpleDateFormat;
import java.util.Date;
Expand Down Expand Up @@ -27,4 +27,15 @@ public static String parseDateToDateOnly(Date date) {

return kstFormat.format(date);
}

public static String parseDateToTimeOnly(Date date) {
if (date == null) {
return null;
}

SimpleDateFormat kstFormat = new SimpleDateFormat("HH:mm:ss");
kstFormat.setTimeZone(TimeZone.getTimeZone("Asia/Seoul"));

return kstFormat.format(date);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.todaypopup.todaypopup.domain.category.controller;

import com.todaypopup.todaypopup.domain.category.dto.GetCategoryInfoRequestDto;
import com.todaypopup.todaypopup.domain.category.dto.GetCategoryInfoResponseDto;
import com.todaypopup.todaypopup.domain.category.service.CategoryService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class CategoryController {

private final CategoryService categoryService;

public CategoryController(CategoryService categoryService) {
this.categoryService = categoryService;
}

@GetMapping("/v1/category")
public ResponseEntity<GetCategoryInfoResponseDto> getCategoryInfo(
@ModelAttribute GetCategoryInfoRequestDto queryDto) throws Exception {

GetCategoryInfoResponseDto response = this.categoryService.GetCategoryInfo(queryDto);

return ResponseEntity.ok().body(response);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.todaypopup.todaypopup.domain.category.dto;

import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

@Data
@SuperBuilder
@NoArgsConstructor
public class GetCategoryInfoRequestDto {

private Long categoryId;
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.todaypopup.todaypopup.domain.category.dto;

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

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

private List<CategoryEntity> categoryList;
private Optional<CategoryEntity> category;

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

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

public interface CategoryRepository extends JpaRepository<CategoryEntity, Long> {

@Override
List<CategoryEntity> findAll();

@Override
Optional<CategoryEntity> findById(Long aLong);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.todaypopup.todaypopup.domain.category.service;

import com.todaypopup.todaypopup.domain.category.dto.GetCategoryInfoRequestDto;
import com.todaypopup.todaypopup.domain.category.dto.GetCategoryInfoResponseDto;

public interface CategoryService {

GetCategoryInfoResponseDto GetCategoryInfo(GetCategoryInfoRequestDto queryDto) throws Exception;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.todaypopup.todaypopup.domain.category.service;

import com.todaypopup.todaypopup.domain.category.dto.GetCategoryInfoRequestDto;
import com.todaypopup.todaypopup.domain.category.dto.GetCategoryInfoResponseDto;
import com.todaypopup.todaypopup.domain.category.repository.CategoryRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class CategoryServiceImpl implements CategoryService {

private final CategoryRepository categoryRepository;

public CategoryServiceImpl(CategoryRepository categoryRepository) {
this.categoryRepository = categoryRepository;
}

@Override
public GetCategoryInfoResponseDto GetCategoryInfo(GetCategoryInfoRequestDto queryDto) {
if (queryDto.getCategoryId() == null) {
return GetCategoryInfoResponseDto.builder()
.categoryList(this.categoryRepository.findAll())
.build();
}

return GetCategoryInfoResponseDto.builder()
.category(this.categoryRepository.findById(queryDto.getCategoryId()))
.build();
}

}
Loading

0 comments on commit 4409c84

Please sign in to comment.