Skip to content
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

Refactor : shop 조회 response에 updated_at 추가 #212

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/java/koreatech/in/domain/Shop/ShopProfile.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import java.time.DayOfWeek;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

Expand All @@ -29,6 +30,7 @@ public class ShopProfile {
private List<ShopCategory> shop_categories;
private List<MenuCategory> menu_categories;
private Boolean is_deleted;
private Date updated_at;

@Getter
public static final class Open {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package koreatech.in.dto.normal.shop.response;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Builder;
import lombok.Getter;

import java.time.DayOfWeek;
import java.util.Date;
import java.util.List;

@Getter @Builder
Expand Down Expand Up @@ -49,6 +51,10 @@ public class ShopResponse {
@ApiModelProperty(notes = "상점에 있는 메뉴 카테고리 리스트", required = true)
private List<MenuCategory> menu_categories;

@ApiModelProperty(value = "업데이트 일자", example = "2023-01-01 12:01:02", required = true)
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Seoul")
private Date updated_at;

Comment on lines +54 to +57
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@Getter @Builder
@ApiModel("Open_4")
public static class Open {
Expand Down
12 changes: 12 additions & 0 deletions src/main/resources/db/migration/V72.000_create_trigger_opens.sql
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

V72.000_ 가 아니라
V72.000__ 로 해야 (언더바 2개) flyway 동작이 가능합니다 😅

컨벤션 유의해주세요~

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
DELIMITER $$

CREATE TRIGGER update_shop_updated_at_opens
AFTER UPDATE
ON shop_opens
FOR EACH ROW

BEGIN
UPDATE shops SET updated_at = NEW.updated_at WHERE shops.id = NEW.shop_id;
END $$

DELIMITER ;
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
DELIMITER $$

CREATE TRIGGER update_shop_updated_at_category
AFTER UPDATE
ON shop_category_map
FOR EACH ROW

BEGIN
UPDATE shops SET updated_at = NEW.updated_at WHERE shops.id = NEW.shop_id;
END $$

DELIMITER ;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

마지막 라인에 뉴 라인이 추가되어야 할 것 같아요

12 changes: 12 additions & 0 deletions src/main/resources/db/migration/V72.002_create_trigger_images.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
DELIMITER $$

CREATE TRIGGER update_shop_updated_at_images
AFTER UPDATE
ON shop_images
FOR EACH ROW

BEGIN
UPDATE shops SET updated_at = NEW.updated_at WHERE shops.id = NEW.shop_id;
END $$

DELIMITER ;
12 changes: 12 additions & 0 deletions src/main/resources/db/migration/V72.003_create_trigger_menus.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
DELIMITER $$

CREATE TRIGGER update_shop_updated_at_menus
AFTER UPDATE
ON shop_menus
FOR EACH ROW

BEGIN
UPDATE shops SET updated_at = NEW.updated_at WHERE shops.id = NEW.shop_id;
END $$

DELIMITER ;
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
DELIMITER $$

CREATE TRIGGER update_shop_updated_at_menus_category
AFTER UPDATE
ON shop_menu_category_map
FOR EACH ROW

BEGIN
UPDATE shop_menus SET updated_at = NEW.updated_at WHERE shop_menus.id = NEW.shop_menu_id;
END $$

DELIMITER ;
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
DELIMITER $$

CREATE TRIGGER update_shop_updated_at_menus_detatils
AFTER UPDATE
ON shop_menu_details
FOR EACH ROW

BEGIN
UPDATE shop_menus SET updated_at = NEW.updated_at WHERE shop_menus.id = NEW.shop_menu_id;
END $$

DELIMITER ;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

트리거를 이용하여 메뉴, 이미지, 카테고리가 update될 때 상점의 updated_at이 변경되도록 수정됐다고 이해했는데

update될 때만 변경되면 될까요?
create, delete에도 트리거가 필요하지 않을까요?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

create, delete 때도 필요할 것 같습니다.. 추가하겠습니다!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shop_opens 테이블의 경우에는 soft delete인데 delete에 관한 트리거를 추가할 필요가 있을까요?

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
DELIMITER $$

CREATE TRIGGER update_shop_updated_at_menus_images
AFTER UPDATE
ON shop_menu_images
FOR EACH ROW

BEGIN
UPDATE shop_menus SET updated_at = NEW.updated_at WHERE shop_menus.id = NEW.shop_menu_id;
END $$

DELIMITER ;
2 changes: 2 additions & 0 deletions src/main/resources/mapper/normal/ShopMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
`t1`.`pay_card` AS `shops.pay_card`,
`t1`.`pay_bank` AS `shops.pay_bank`,
`t1`.`is_deleted` AS `shops.is_deleted`,
`t1`.`updated_at` AS `shops.updated_at`,

# shop_opens
`t2`.`day_of_week` AS `shop_opens.day_of_week`,
Expand Down Expand Up @@ -642,6 +643,7 @@
<result property="pay_card" column="shops.pay_card"/>
<result property="pay_bank" column="shops.pay_bank"/>
<result property="is_deleted" column="shops.is_deleted"/>
<result property="updated_at" column="shops.updated_at"/>

<collection property="open" javaType="list" ofType="koreatech.in.domain.Shop.ShopProfile$Open">
<result property="day_of_week" column="shop_opens.day_of_week" />
Expand Down