Skip to content

Commit

Permalink
Chore. 더미 상품 생성 sql
Browse files Browse the repository at this point in the history
  • Loading branch information
Miensoap committed Jun 24, 2024
1 parent 3aaca32 commit 1117d4d
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
54 changes: 54 additions & 0 deletions BE/src/main/resources/sql/mock_product.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
-- Tx : Manual
DELIMITER $$

DROP PROCEDURE IF EXISTS InsertProducts;
CREATE PROCEDURE InsertProducts(
IN accommodation_id BIGINT,
IN startDate DATE,
IN endDate DATE
)
BEGIN
DECLARE currentDate DATE;
DECLARE randomPrice INT;

SET currentDate = startDate;

WHILE currentDate <= endDate DO
SET randomPrice = FLOOR(100000 + RAND() * (1000000 - 100000));
INSERT INTO PRODUCT (date, price, status, accommodation_id, createdAt, lastModifiedAt)
VALUES (currentDate, randomPrice, 'OPEN', accommodation_id, NOW(6), NOW(6));
SET currentDate = DATE_ADD(currentDate, INTERVAL 1 DAY);
END WHILE;
END $$

-- 모든 숙소에 대한 상품 등록
DROP PROCEDURE IF EXISTS InsertProductsForAllAccommodations $$

-- Create the InsertProductsForAllAccommodations procedure
CREATE PROCEDURE InsertProductsForAllAccommodations(
IN startDate DATE,
IN endDate DATE
)
BEGIN
DECLARE done INT DEFAULT 0;
DECLARE accommodation_id BIGINT;
DECLARE cur CURSOR FOR SELECT id FROM ACCOMMODATION;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;

OPEN cur;

read_loop: LOOP
FETCH cur INTO accommodation_id;
IF done THEN
LEAVE read_loop;
END IF;
CALL InsertProducts(accommodation_id, startDate, endDate);
END LOOP;

CLOSE cur;
END $$

DELIMITER ;

# CALL InsertProducts(51, '2024-07-01', '2024-12-31');
CALL InsertProductsForAllAccommodations('2024-07-01', '2024-12-31');
3 changes: 2 additions & 1 deletion BE/src/test/java/team07/airbnb/integration/FavoriteTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.context.annotation.Profile;
import org.springframework.test.context.ActiveProfiles;
import team07.airbnb.data.accommodation.dto.request.AccommodationCreateRequest;
import team07.airbnb.data.accommodation.dto.response.AccommodationListResponse;
import team07.airbnb.data.product.dto.request.ProductCreateRequest;
Expand All @@ -23,7 +24,7 @@
import static org.assertj.core.api.Assertions.assertThat;

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@Profile("test")
@ActiveProfiles("test")
public class FavoriteTest {

@Autowired
Expand Down

0 comments on commit 1117d4d

Please sign in to comment.