From c304bbd279cfe6e448e0bda1e8f2e2a6b8a65907 Mon Sep 17 00:00:00 2001 From: Choo Date: Mon, 22 Jul 2024 19:32:10 +0900 Subject: [PATCH 01/11] =?UTF-8?q?chore:=20h2=20=ED=99=98=EA=B2=BD=EC=84=A4?= =?UTF-8?q?=EC=A0=95=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/main/resources/application.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/backend/src/main/resources/application.yml b/backend/src/main/resources/application.yml index 75d9d2db..b8c32556 100644 --- a/backend/src/main/resources/application.yml +++ b/backend/src/main/resources/application.yml @@ -1,3 +1,15 @@ spring: application: name: chongdae + h2: + console: + enabled: true + datasource: + url: jdbc:h2:mem:database + jpa: + show-sql: true + hibernate: + ddl-auto: create-drop + properties: + hibernate: + format_sql: true From 6f76cd219eea80dd720b5ae95a0a0a59496c40b3 Mon Sep 17 00:00:00 2001 From: Choo Date: Mon, 22 Jul 2024 19:34:12 +0900 Subject: [PATCH 02/11] =?UTF-8?q?docs:=20http=20client=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/http/http-client.env.json | 5 +++++ backend/http/offering.http | 2 ++ 2 files changed, 7 insertions(+) create mode 100644 backend/http/http-client.env.json create mode 100644 backend/http/offering.http diff --git a/backend/http/http-client.env.json b/backend/http/http-client.env.json new file mode 100644 index 00000000..86bbc23e --- /dev/null +++ b/backend/http/http-client.env.json @@ -0,0 +1,5 @@ +{ + "local": { + "base-url": "localhost:8080" + } +} diff --git a/backend/http/offering.http b/backend/http/offering.http new file mode 100644 index 00000000..c9184e5b --- /dev/null +++ b/backend/http/offering.http @@ -0,0 +1,2 @@ +### 공동구매 상세 조회 API +GET {{base-url}}/offerings From 9fd4a89586057b7eea5328127419a0071c0591d8 Mon Sep 17 00:00:00 2001 From: Choo Date: Mon, 22 Jul 2024 21:49:10 +0900 Subject: [PATCH 03/11] =?UTF-8?q?refactor:=20entity=20=EC=A0=91=EB=AF=B8?= =?UTF-8?q?=EC=96=B4=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chongdae/comment/repository/Comment.java | 4 ++-- .../OfferingEntity.java} | 16 ++++++++++++++-- .../OfferingMemberEntity.java} | 14 ++++++++++---- 3 files changed, 26 insertions(+), 8 deletions(-) rename backend/src/main/java/com/zzang/chongdae/offering/repository/{Offering.java => entity/OfferingEntity.java} (71%) rename backend/src/main/java/com/zzang/chongdae/offeringmember/repository/{OfferingMember.java => entity/OfferingMemberEntity.java} (62%) diff --git a/backend/src/main/java/com/zzang/chongdae/comment/repository/Comment.java b/backend/src/main/java/com/zzang/chongdae/comment/repository/Comment.java index 82c2d6e6..8959b31d 100644 --- a/backend/src/main/java/com/zzang/chongdae/comment/repository/Comment.java +++ b/backend/src/main/java/com/zzang/chongdae/comment/repository/Comment.java @@ -2,7 +2,7 @@ import com.zzang.chongdae.common.repository.BaseTimeEntity; import com.zzang.chongdae.member.repository.Member; -import com.zzang.chongdae.offering.repository.Offering; +import com.zzang.chongdae.offering.repository.entity.OfferingEntity; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; @@ -30,7 +30,7 @@ public class Comment extends BaseTimeEntity { private Member member; @ManyToOne - private Offering offering; + private OfferingEntity offering; @Column(length = 80) private String content; diff --git a/backend/src/main/java/com/zzang/chongdae/offering/repository/Offering.java b/backend/src/main/java/com/zzang/chongdae/offering/repository/entity/OfferingEntity.java similarity index 71% rename from backend/src/main/java/com/zzang/chongdae/offering/repository/Offering.java rename to backend/src/main/java/com/zzang/chongdae/offering/repository/entity/OfferingEntity.java index 7d8f140f..825a5a3e 100644 --- a/backend/src/main/java/com/zzang/chongdae/offering/repository/Offering.java +++ b/backend/src/main/java/com/zzang/chongdae/offering/repository/entity/OfferingEntity.java @@ -1,13 +1,16 @@ -package com.zzang.chongdae.offering.repository; +package com.zzang.chongdae.offering.repository.entity; import com.zzang.chongdae.common.repository.BaseTimeEntity; import com.zzang.chongdae.member.repository.Member; +import com.zzang.chongdae.offering.domain.OfferingPrice; +import com.zzang.chongdae.offering.domain.OfferingStatus; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; import jakarta.validation.constraints.NotNull; import java.math.BigDecimal; import java.time.LocalDateTime; @@ -21,8 +24,9 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) @AllArgsConstructor @EqualsAndHashCode(of = "id", callSuper = false) +@Table(name = "offering") @Entity -public class Offering extends BaseTimeEntity { +public class OfferingEntity extends BaseTimeEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @@ -60,4 +64,12 @@ public class Offering extends BaseTimeEntity { @NotNull private BigDecimal totalPrice; + + public OfferingPrice toOfferingPrice() { + return new OfferingPrice(totalCount, totalPrice); + } + + public OfferingStatus toOfferingStatus(int currentCount) { + return new OfferingStatus(deadline, totalCount, isManualConfirmed, currentCount); + } } diff --git a/backend/src/main/java/com/zzang/chongdae/offeringmember/repository/OfferingMember.java b/backend/src/main/java/com/zzang/chongdae/offeringmember/repository/entity/OfferingMemberEntity.java similarity index 62% rename from backend/src/main/java/com/zzang/chongdae/offeringmember/repository/OfferingMember.java rename to backend/src/main/java/com/zzang/chongdae/offeringmember/repository/entity/OfferingMemberEntity.java index 1758f6a6..2f7085d7 100644 --- a/backend/src/main/java/com/zzang/chongdae/offeringmember/repository/OfferingMember.java +++ b/backend/src/main/java/com/zzang/chongdae/offeringmember/repository/entity/OfferingMemberEntity.java @@ -1,13 +1,17 @@ -package com.zzang.chongdae.offeringmember.repository; +package com.zzang.chongdae.offeringmember.repository.entity; import com.zzang.chongdae.common.repository.BaseTimeEntity; import com.zzang.chongdae.member.repository.Member; -import com.zzang.chongdae.offering.repository.Offering; +import com.zzang.chongdae.offering.repository.entity.OfferingEntity; +import com.zzang.chongdae.offeringmember.domain.OfferingMemberRole; 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.ManyToOne; +import jakarta.persistence.Table; import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.EqualsAndHashCode; @@ -18,8 +22,9 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) @AllArgsConstructor @EqualsAndHashCode(of = "id", callSuper = false) +@Table(name = "offering_member") @Entity -public class OfferingMember extends BaseTimeEntity { +public class OfferingMemberEntity extends BaseTimeEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @@ -29,7 +34,8 @@ public class OfferingMember extends BaseTimeEntity { private Member member; @ManyToOne - private Offering offering; + private OfferingEntity offering; + @Enumerated(EnumType.STRING) private OfferingMemberRole role; } From 861f71133b9836b264e5ac93a7bf45cfd563b402 Mon Sep 17 00:00:00 2001 From: Choo Date: Mon, 22 Jul 2024 21:51:59 +0900 Subject: [PATCH 04/11] =?UTF-8?q?chore:=20dummy=20data=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/main/resources/application.yml | 1 + backend/src/main/resources/data.sql | 53 ++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 backend/src/main/resources/data.sql diff --git a/backend/src/main/resources/application.yml b/backend/src/main/resources/application.yml index b8c32556..342925e3 100644 --- a/backend/src/main/resources/application.yml +++ b/backend/src/main/resources/application.yml @@ -8,6 +8,7 @@ spring: url: jdbc:h2:mem:database jpa: show-sql: true + defer-datasource-initialization: true hibernate: ddl-auto: create-drop properties: diff --git a/backend/src/main/resources/data.sql b/backend/src/main/resources/data.sql new file mode 100644 index 00000000..ada7ba3b --- /dev/null +++ b/backend/src/main/resources/data.sql @@ -0,0 +1,53 @@ +INSERT INTO MEMBER (NICKNAME, CREATED_AT, UPDATED_AT) +VALUES ('dora', '2024-07-15 00:00:00', '2024-07-15 00:00:00'); + +INSERT INTO MEMBER (NICKNAME, CREATED_AT, UPDATED_AT) +VALUES ('poke', '2024-07-15 00:00:00', '2024-07-15 00:00:00'); + +INSERT INTO OFFERING (IS_MANUAL_CONFIRMED, TOTAL_COUNT, TOTAL_PRICE, CREATED_AT, UPDATED_AT, + MEMBER_ID, DEADLINE, DESCRIPTION, MEETING_ADDRESS, MEETING_ADDRESS_DETAIL, PRODUCT_URL, + THUMBNAIL_URL, TITLE) +VALUES (false, 5, 10000, '2024-07-15 00:00:00', '2024-07-15 00:00:00', + 1, '2024-08-01 00:00:00', '고양이 인형 공동구매해요', '서울시 동작구 보라매로 100', '101동 101호', 'www.naver.com', + 'https://file.notion.so/f/f/a98aa686-1767-4142-a9a2-f7303fcfa347/650b4cc1-0d39-4cac-9b2a-4db2782e73ec/Untitled.png?id=d002f22a-15bf-486c-b267-1ddc5f6ee3b3&table=block&spaceId=a98aa686-1767-4142-a9a2-f7303fcfa347&expirationTimestamp=1721174400000&signature=gdrQVGGE6z67DvZqeg93wnTB3_Kk3mK8ZxME5jqnWNk&downloadName=Untitled.png', + '공동구매해요'), + (false, 5, 50000, '2024-07-15 00:00:00', '2024-07-15 00:00:00', + 1, '2024-07-21 00:00:00', '뉴진스 굿즈 공동구매 하실 분 참여 부탁', '서울시 영등포구 국제금융로 39', '102동 2802호', 'www.google.com', + 'https://file.notion.so/f/f/a98aa686-1767-4142-a9a2-f7303fcfa347/650b4cc1-0d39-4cac-9b2a-4db2782e73ec/Untitled.png?id=d002f22a-15bf-486c-b267-1ddc5f6ee3b3&table=block&spaceId=a98aa686-1767-4142-a9a2-f7303fcfa347&expirationTimestamp=1721174400000&signature=gdrQVGGE6z67DvZqeg93wnTB3_Kk3mK8ZxME5jqnWNk&downloadName=Untitled.png', + '뉴진스 굿즈'), + (false, 4, 1000000, '2024-07-01 00:00:00', '2024-07-01 00:00:00', + 1, '2024-07-14 00:00:00', '에스파 굿즈 공동구매 하실 분 참여 부탁', '서울시 광진구 구의강변로3길 38', '302호', 'www.google.com', + 'https://file.notion.so/f/f/a98aa686-1767-4142-a9a2-f7303fcfa347/9857be7d-1897-49c2-933c-9e9b9d9aee81/Untitled.png?id=e1bb8445-7ac4-4f81-bc66-3ad3c1ba6159&table=block&spaceId=a98aa686-1767-4142-a9a2-f7303fcfa347&expirationTimestamp=1721196000000&signature=YBbWgz-VFlT4BGwFa_4AU3VzyvOFTA9MIr9q3cxTFW0&downloadName=Untitled.png', + '에스파 굿즈'), + (true, 10, 120000, '2024-07-01 00:00:00', '2024-07-01 00:00:00', + 1, '2024-07-14 00:00:00', '자동차 워셔액 공동구매 하실 분 참여 부탁', '경기도 고양시 일산서구 킨텍스로 240', '101동 4004호', 'www.google.com', + 'https://file.notion.so/f/f/a98aa686-1767-4142-a9a2-f7303fcfa347/a28e3c59-6217-4175-b998-d9c76554a804/Untitled.png?id=28a8bf97-391f-4b27-bd36-1f8a8bcb2a5a&table=block&spaceId=a98aa686-1767-4142-a9a2-f7303fcfa347&expirationTimestamp=1721196000000&signature=IU5zy22McSuXw9vZ8uvOHyih37IxZKgflGEneDORYnI&downloadName=Untitled.png', + '워셔액'), + (false, 8, 1000000, '2024-07-15 00:00:00', '2024-07-15 00:00:00', + 1, '2024-07-27 00:00:00', '투혼 초보만 참여 부탁', '서울시 광진구 구의강변로3길 38', '302호', 'www.google.com', + 'https://file.notion.so/f/f/a98aa686-1767-4142-a9a2-f7303fcfa347/0839d06c-b889-451f-9921-95ee1adabdd5/Untitled.png?id=9842e296-0b04-476e-a8f8-c13661d86885&table=block&spaceId=a98aa686-1767-4142-a9a2-f7303fcfa347&expirationTimestamp=1721196000000&signature=3JSVDiVuCzzDnvFscseEhJryxyHexQM5-aFTbzUIk1k&downloadName=Untitled.png', + '투혼 초보만 참여 부탁'), + (false, 8, 1000000, '2024-07-15 00:00:00', '2024-07-15 00:00:00', + 1, '2024-07-27 00:00:00', '세제 공동구매 고고혓', '서울시 광진구 구의강변로3길 38', '302호', 'www.google.com', + 'https://file.notion.so/f/f/a98aa686-1767-4142-a9a2-f7303fcfa347/cee508d0-4f38-4d79-9588-8fe3f23d67bf/Untitled.png?id=f5307c99-bee4-427b-9667-8d9facf43483&table=block&spaceId=a98aa686-1767-4142-a9a2-f7303fcfa347&expirationTimestamp=1721196000000&signature=AZBNut2gPe1YTLcLYcdpx-m6GthkjbPjVyfkUklbBUs&downloadName=Untitled.png', + '세제 공동구매 하실 분 참여 부탁'), + (false, 8, 1000000, '2024-07-15 00:00:00', '2024-07-15 00:00:00', + 1, '2024-07-27 00:00:00', '우테코 제 1회 해커톤 고생하셨읍니다', '서울시 광진구 구의강변로3길 38', '302호', 'www.google.com', + 'https://file.notion.so/f/f/a98aa686-1767-4142-a9a2-f7303fcfa347/46158c58-7e5d-4ef0-b238-75f17fc2770c/Untitled.png?id=b43bc84c-59f5-42e4-b2f5-c8f4bd5e012d&table=block&spaceId=a98aa686-1767-4142-a9a2-f7303fcfa347&expirationTimestamp=1721196000000&signature=D2E6CoexRBOGLbF6xkKJm5X3ZnbkKiS6RWoeL8TggbY&downloadName=Untitled.png', + '우테코 제 1회 해커톤 고생하셨읍니다'), + (true, 8, 1000000, '2024-07-15 00:00:00', '2024-07-15 00:00:00', + 1, '2024-07-27 00:00:00', '우테코 제 1회 해커톤 고생하셨읍니다', '서울시 광진구 구의강변로3길 38', '302호', 'www.google.com', + 'https://file.notion.so/f/f/a98aa686-1767-4142-a9a2-f7303fcfa347/650b4cc1-0d39-4cac-9b2a-4db2782e73ec/Untitled.png?id=d002f22a-15bf-486c-b267-1ddc5f6ee3b3&table=block&spaceId=a98aa686-1767-4142-a9a2-f7303fcfa347&expirationTimestamp=1721174400000&signature=gdrQVGGE6z67DvZqeg93wnTB3_Kk3mK8ZxME5jqnWNk&downloadName=Untitled.png', + '우테코 제 1회 해커톤 고생하셨읍니다'), + (false, 8, 1000000, '2024-07-15 00:00:00', '2024-07-15 00:00:00', + 1, '2024-07-27 00:00:00', '우테코 제 1회 해커톤 고생하셨읍니다', '서울시 광진구 구의강변로3길 38', '302호', 'www.google.com', + 'https://file.notion.so/f/f/a98aa686-1767-4142-a9a2-f7303fcfa347/650b4cc1-0d39-4cac-9b2a-4db2782e73ec/Untitled.png?id=d002f22a-15bf-486c-b267-1ddc5f6ee3b3&table=block&spaceId=a98aa686-1767-4142-a9a2-f7303fcfa347&expirationTimestamp=1721174400000&signature=gdrQVGGE6z67DvZqeg93wnTB3_Kk3mK8ZxME5jqnWNk&downloadName=Untitled.png', + '우테코 제 1회 해커톤 고생하셨읍니다'), + (false, 8, 1000000, '2024-07-15 00:00:00', '2024-07-15 00:00:00', + 1, '2024-07-27 00:00:00', '우테코 제 1회 해커톤 고생하셨읍니다', '서울시 광진구 구의강변로3길 38', '302호', 'www.google.com', + 'https://file.notion.so/f/f/a98aa686-1767-4142-a9a2-f7303fcfa347/650b4cc1-0d39-4cac-9b2a-4db2782e73ec/Untitled.png?id=d002f22a-15bf-486c-b267-1ddc5f6ee3b3&table=block&spaceId=a98aa686-1767-4142-a9a2-f7303fcfa347&expirationTimestamp=1721174400000&signature=gdrQVGGE6z67DvZqeg93wnTB3_Kk3mK8ZxME5jqnWNk&downloadName=Untitled.png', + '우테코 제 1회 해커톤 고생하셨읍니다'); + +INSERT INTO OFFERING_MEMBER (OFFERING_ID, MEMBER_ID, ROLE, CREATED_AT, UPDATED_AT) +VALUES (1, 1, 'PROPOSER', '2024-07-15 00:00:00', '2024-07-15 00:00:00'), + (1, 2, 'PARTICIPANT', '2024-07-15 00:00:00', '2024-07-15 00:00:00'); From 2e6981966a92da03fef70ab413f7182311b13709 Mon Sep 17 00:00:00 2001 From: Choo Date: Mon, 22 Jul 2024 21:52:09 +0900 Subject: [PATCH 05/11] =?UTF-8?q?docs:=20http=20client=20=EA=B0=92=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/http/offering.http | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/http/offering.http b/backend/http/offering.http index c9184e5b..34da215e 100644 --- a/backend/http/offering.http +++ b/backend/http/offering.http @@ -1,2 +1,2 @@ ### 공동구매 상세 조회 API -GET {{base-url}}/offerings +GET {{base-url}}/offerings/1 From 8af315cf475f1be99ff816b585f69c3dcb230745 Mon Sep 17 00:00:00 2001 From: Choo Date: Mon, 22 Jul 2024 21:53:47 +0900 Subject: [PATCH 06/11] =?UTF-8?q?refactor:=20repository=20=EC=99=80=20doma?= =?UTF-8?q?in=20=ED=8C=A8=ED=82=A4=EC=A7=80=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chongdae/offeringmember/domain/OfferingMemberRole.java | 6 ++++++ .../offeringmember/repository/OfferingMemberRole.java | 6 ------ 2 files changed, 6 insertions(+), 6 deletions(-) create mode 100644 backend/src/main/java/com/zzang/chongdae/offeringmember/domain/OfferingMemberRole.java delete mode 100644 backend/src/main/java/com/zzang/chongdae/offeringmember/repository/OfferingMemberRole.java diff --git a/backend/src/main/java/com/zzang/chongdae/offeringmember/domain/OfferingMemberRole.java b/backend/src/main/java/com/zzang/chongdae/offeringmember/domain/OfferingMemberRole.java new file mode 100644 index 00000000..279bb30e --- /dev/null +++ b/backend/src/main/java/com/zzang/chongdae/offeringmember/domain/OfferingMemberRole.java @@ -0,0 +1,6 @@ +package com.zzang.chongdae.offeringmember.domain; + +public enum OfferingMemberRole { + PROPOSER, + PARTICIPANT; // TODO: entity 패키지와 domain 패키지 중 위치 고민하기 (feat. vo) +} diff --git a/backend/src/main/java/com/zzang/chongdae/offeringmember/repository/OfferingMemberRole.java b/backend/src/main/java/com/zzang/chongdae/offeringmember/repository/OfferingMemberRole.java deleted file mode 100644 index be22b35d..00000000 --- a/backend/src/main/java/com/zzang/chongdae/offeringmember/repository/OfferingMemberRole.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.zzang.chongdae.offeringmember.repository; - -public enum OfferingMemberRole { - PROPOSER, - PARTICIPANT; -} From 985a8674e69015c8bad6fc76d093a832130fff7c Mon Sep 17 00:00:00 2001 From: Choo Date: Mon, 22 Jul 2024 21:54:26 +0900 Subject: [PATCH 07/11] =?UTF-8?q?feat:=20=EA=B3=B5=EB=8F=99=EA=B5=AC?= =?UTF-8?q?=EB=A7=A4=20=EC=83=81=EC=84=B8=20=EC=A1=B0=ED=9A=8C=20API=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/OfferingController.java | 22 ++++++++++ .../offering/domain/OfferingCondition.java | 9 ++++ .../offering/domain/OfferingPrice.java | 16 +++++++ .../offering/domain/OfferingStatus.java | 44 +++++++++++++++++++ .../repository/OfferingRepository.java | 7 +++ .../offering/service/OfferingService.java | 29 ++++++++++++ .../service/dto/OfferingDetailResponse.java | 42 ++++++++++++++++++ .../repository/OfferingMemberRepository.java | 10 +++++ 8 files changed, 179 insertions(+) create mode 100644 backend/src/main/java/com/zzang/chongdae/offering/controller/OfferingController.java create mode 100644 backend/src/main/java/com/zzang/chongdae/offering/domain/OfferingCondition.java create mode 100644 backend/src/main/java/com/zzang/chongdae/offering/domain/OfferingPrice.java create mode 100644 backend/src/main/java/com/zzang/chongdae/offering/domain/OfferingStatus.java create mode 100644 backend/src/main/java/com/zzang/chongdae/offering/repository/OfferingRepository.java create mode 100644 backend/src/main/java/com/zzang/chongdae/offering/service/OfferingService.java create mode 100644 backend/src/main/java/com/zzang/chongdae/offering/service/dto/OfferingDetailResponse.java create mode 100644 backend/src/main/java/com/zzang/chongdae/offeringmember/repository/OfferingMemberRepository.java diff --git a/backend/src/main/java/com/zzang/chongdae/offering/controller/OfferingController.java b/backend/src/main/java/com/zzang/chongdae/offering/controller/OfferingController.java new file mode 100644 index 00000000..4b28f4c0 --- /dev/null +++ b/backend/src/main/java/com/zzang/chongdae/offering/controller/OfferingController.java @@ -0,0 +1,22 @@ +package com.zzang.chongdae.offering.controller; + +import com.zzang.chongdae.offering.service.OfferingService; +import com.zzang.chongdae.offering.service.dto.OfferingDetailResponse; +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; + +@RequiredArgsConstructor +@Controller +public class OfferingController { + + private final OfferingService offeringService; + + @GetMapping("/offerings/{offering-id}") + public ResponseEntity getOfferingDetail(@PathVariable(value = "offering-id") Long id) { + OfferingDetailResponse response = offeringService.getOfferingDetail(id); + return ResponseEntity.ok(response); + } +} diff --git a/backend/src/main/java/com/zzang/chongdae/offering/domain/OfferingCondition.java b/backend/src/main/java/com/zzang/chongdae/offering/domain/OfferingCondition.java new file mode 100644 index 00000000..b69ad1d4 --- /dev/null +++ b/backend/src/main/java/com/zzang/chongdae/offering/domain/OfferingCondition.java @@ -0,0 +1,9 @@ +package com.zzang.chongdae.offering.domain; + +public enum OfferingCondition { + + FULL, + TIME_OUT, + CONFIRMED, + AVAILABLE; +} diff --git a/backend/src/main/java/com/zzang/chongdae/offering/domain/OfferingPrice.java b/backend/src/main/java/com/zzang/chongdae/offering/domain/OfferingPrice.java new file mode 100644 index 00000000..9d7e8865 --- /dev/null +++ b/backend/src/main/java/com/zzang/chongdae/offering/domain/OfferingPrice.java @@ -0,0 +1,16 @@ +package com.zzang.chongdae.offering.domain; + +import java.math.BigDecimal; +import java.math.RoundingMode; +import lombok.AllArgsConstructor; + +@AllArgsConstructor +public class OfferingPrice { + + private final Integer totalCount; + private final BigDecimal totalPrice; + + public BigDecimal calculateDividedPrice() { + return totalPrice.divide(BigDecimal.valueOf(totalCount), RoundingMode.HALF_UP); + } +} diff --git a/backend/src/main/java/com/zzang/chongdae/offering/domain/OfferingStatus.java b/backend/src/main/java/com/zzang/chongdae/offering/domain/OfferingStatus.java new file mode 100644 index 00000000..0de16f80 --- /dev/null +++ b/backend/src/main/java/com/zzang/chongdae/offering/domain/OfferingStatus.java @@ -0,0 +1,44 @@ +package com.zzang.chongdae.offering.domain; + +import java.time.LocalDateTime; +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public class OfferingStatus { + + private final LocalDateTime deadline; + private final int totalCount; + private final boolean isManualConfirmed; + private final int currentCount; + + public OfferingCondition decideOfferingStatus() { + if (isCountFull()) { + return OfferingCondition.FULL; + } + if (isDeadlineOver()) { + return OfferingCondition.TIME_OUT; + } + if (isManualConfirmed() || isAutoConfirmed()) { + return OfferingCondition.CONFIRMED; + } + return OfferingCondition.AVAILABLE; + } + + private boolean isCountFull() { + return this.totalCount == this.currentCount; + } + + private boolean isDeadlineOver() { + return LocalDateTime.now().isAfter(this.deadline); + } + + private boolean isAutoConfirmed() { + return isCountFull() && isDeadlineOver(); + } + + private boolean isManualConfirmed() { + return isManualConfirmed; + } +} diff --git a/backend/src/main/java/com/zzang/chongdae/offering/repository/OfferingRepository.java b/backend/src/main/java/com/zzang/chongdae/offering/repository/OfferingRepository.java new file mode 100644 index 00000000..50c748ea --- /dev/null +++ b/backend/src/main/java/com/zzang/chongdae/offering/repository/OfferingRepository.java @@ -0,0 +1,7 @@ +package com.zzang.chongdae.offering.repository; + +import com.zzang.chongdae.offering.repository.entity.OfferingEntity; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface OfferingRepository extends JpaRepository { +} diff --git a/backend/src/main/java/com/zzang/chongdae/offering/service/OfferingService.java b/backend/src/main/java/com/zzang/chongdae/offering/service/OfferingService.java new file mode 100644 index 00000000..a695932c --- /dev/null +++ b/backend/src/main/java/com/zzang/chongdae/offering/service/OfferingService.java @@ -0,0 +1,29 @@ +package com.zzang.chongdae.offering.service; + +import com.zzang.chongdae.offering.domain.OfferingPrice; +import com.zzang.chongdae.offering.domain.OfferingStatus; +import com.zzang.chongdae.offering.repository.OfferingRepository; +import com.zzang.chongdae.offering.repository.entity.OfferingEntity; +import com.zzang.chongdae.offering.service.dto.OfferingDetailResponse; +import com.zzang.chongdae.offeringmember.repository.OfferingMemberRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@RequiredArgsConstructor +@Service +public class OfferingService { + + private final OfferingRepository offeringRepository; + private final OfferingMemberRepository offeringMemberRepository; + + public OfferingDetailResponse getOfferingDetail(Long id) { + OfferingEntity offering = offeringRepository.findById(id) + .orElseThrow(); // TODO: 예외 처리하기 + + OfferingPrice offeringPrice = offering.toOfferingPrice(); + int currentCount = offeringMemberRepository.countByOffering(offering); + OfferingStatus offeringStatus = offering.toOfferingStatus(currentCount); + + return new OfferingDetailResponse(offering, offeringPrice, offeringStatus); + } +} diff --git a/backend/src/main/java/com/zzang/chongdae/offering/service/dto/OfferingDetailResponse.java b/backend/src/main/java/com/zzang/chongdae/offering/service/dto/OfferingDetailResponse.java new file mode 100644 index 00000000..7c13d304 --- /dev/null +++ b/backend/src/main/java/com/zzang/chongdae/offering/service/dto/OfferingDetailResponse.java @@ -0,0 +1,42 @@ +package com.zzang.chongdae.offering.service.dto; + +import com.zzang.chongdae.offering.domain.OfferingCondition; +import com.zzang.chongdae.offering.domain.OfferingPrice; +import com.zzang.chongdae.offering.domain.OfferingStatus; +import com.zzang.chongdae.offering.repository.entity.OfferingEntity; +import java.math.BigDecimal; +import java.time.LocalDateTime; + +public record OfferingDetailResponse(Long id, + String title, + String nickname, + String productUrl, + String meetingAddress, + String meetingAddressDetail, + String description, + LocalDateTime deadline, + Integer currentCount, + Integer totalCount, + String thumbnailUrl, + BigDecimal dividedPrice, + BigDecimal totalPrice, + OfferingCondition status) { + + public OfferingDetailResponse(OfferingEntity offering, OfferingPrice offeringPrice, OfferingStatus offeringStatus) { + this(offering.getId(), + offering.getTitle(), + offering.getMember().getNickname(), + offering.getProductUrl(), + offering.getMeetingAddress(), + offering.getMeetingAddressDetail(), + offering.getDescription(), + offering.getDeadline(), + offeringStatus.getCurrentCount(), + offering.getTotalCount(), + offering.getThumbnailUrl(), + offeringPrice.calculateDividedPrice(), + offering.getTotalPrice(), + offeringStatus.decideOfferingStatus() + ); + } +} diff --git a/backend/src/main/java/com/zzang/chongdae/offeringmember/repository/OfferingMemberRepository.java b/backend/src/main/java/com/zzang/chongdae/offeringmember/repository/OfferingMemberRepository.java new file mode 100644 index 00000000..d235ee94 --- /dev/null +++ b/backend/src/main/java/com/zzang/chongdae/offeringmember/repository/OfferingMemberRepository.java @@ -0,0 +1,10 @@ +package com.zzang.chongdae.offeringmember.repository; + +import com.zzang.chongdae.offering.repository.entity.OfferingEntity; +import com.zzang.chongdae.offeringmember.repository.entity.OfferingMemberEntity; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface OfferingMemberRepository extends JpaRepository { + + int countByOffering(OfferingEntity offering); +} From 695cdce7e0327797fe4375281cf38553307e3712 Mon Sep 17 00:00:00 2001 From: Choo Date: Mon, 22 Jul 2024 21:59:23 +0900 Subject: [PATCH 08/11] =?UTF-8?q?refactor:=20entity=20=EC=A0=91=EB=AF=B8?= =?UTF-8?q?=EC=96=B4=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{Comment.java => entity/CommentEntity.java} | 12 +++++++----- .../repository/{ => entity}/BaseTimeEntity.java | 4 ++-- .../{Member.java => entity/MemberEntity.java} | 10 ++++++---- .../offering/repository/entity/OfferingEntity.java | 6 +++--- .../repository/entity/OfferingMemberEntity.java | 6 +++--- 5 files changed, 21 insertions(+), 17 deletions(-) rename backend/src/main/java/com/zzang/chongdae/comment/repository/{Comment.java => entity/CommentEntity.java} (70%) rename backend/src/main/java/com/zzang/chongdae/common/repository/{ => entity}/BaseTimeEntity.java (92%) rename backend/src/main/java/com/zzang/chongdae/member/repository/{Member.java => entity/MemberEntity.java} (74%) diff --git a/backend/src/main/java/com/zzang/chongdae/comment/repository/Comment.java b/backend/src/main/java/com/zzang/chongdae/comment/repository/entity/CommentEntity.java similarity index 70% rename from backend/src/main/java/com/zzang/chongdae/comment/repository/Comment.java rename to backend/src/main/java/com/zzang/chongdae/comment/repository/entity/CommentEntity.java index 8959b31d..76dde289 100644 --- a/backend/src/main/java/com/zzang/chongdae/comment/repository/Comment.java +++ b/backend/src/main/java/com/zzang/chongdae/comment/repository/entity/CommentEntity.java @@ -1,7 +1,7 @@ -package com.zzang.chongdae.comment.repository; +package com.zzang.chongdae.comment.repository.entity; -import com.zzang.chongdae.common.repository.BaseTimeEntity; -import com.zzang.chongdae.member.repository.Member; +import com.zzang.chongdae.common.repository.entity.BaseTimeEntity; +import com.zzang.chongdae.member.repository.entity.MemberEntity; import com.zzang.chongdae.offering.repository.entity.OfferingEntity; import jakarta.persistence.Column; import jakarta.persistence.Entity; @@ -9,6 +9,7 @@ import jakarta.persistence.GenerationType; import jakarta.persistence.Id; import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.EqualsAndHashCode; @@ -19,15 +20,16 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) @AllArgsConstructor @EqualsAndHashCode(of = "id", callSuper = false) +@Table(name = "comment") @Entity -public class Comment extends BaseTimeEntity { +public class CommentEntity extends BaseTimeEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @ManyToOne - private Member member; + private MemberEntity member; @ManyToOne private OfferingEntity offering; diff --git a/backend/src/main/java/com/zzang/chongdae/common/repository/BaseTimeEntity.java b/backend/src/main/java/com/zzang/chongdae/common/repository/entity/BaseTimeEntity.java similarity index 92% rename from backend/src/main/java/com/zzang/chongdae/common/repository/BaseTimeEntity.java rename to backend/src/main/java/com/zzang/chongdae/common/repository/entity/BaseTimeEntity.java index 3b9c3a7b..6b61b36d 100644 --- a/backend/src/main/java/com/zzang/chongdae/common/repository/BaseTimeEntity.java +++ b/backend/src/main/java/com/zzang/chongdae/common/repository/entity/BaseTimeEntity.java @@ -1,4 +1,4 @@ -package com.zzang.chongdae.common.repository; +package com.zzang.chongdae.common.repository.entity; import jakarta.persistence.Column; import jakarta.persistence.EntityListeners; @@ -24,4 +24,4 @@ public abstract class BaseTimeEntity { @NotNull @Column private LocalDateTime updatedAt; -} \ No newline at end of file +} diff --git a/backend/src/main/java/com/zzang/chongdae/member/repository/Member.java b/backend/src/main/java/com/zzang/chongdae/member/repository/entity/MemberEntity.java similarity index 74% rename from backend/src/main/java/com/zzang/chongdae/member/repository/Member.java rename to backend/src/main/java/com/zzang/chongdae/member/repository/entity/MemberEntity.java index 0556a0e5..7653a503 100644 --- a/backend/src/main/java/com/zzang/chongdae/member/repository/Member.java +++ b/backend/src/main/java/com/zzang/chongdae/member/repository/entity/MemberEntity.java @@ -1,11 +1,12 @@ -package com.zzang.chongdae.member.repository; +package com.zzang.chongdae.member.repository.entity; -import com.zzang.chongdae.common.repository.BaseTimeEntity; +import com.zzang.chongdae.common.repository.entity.BaseTimeEntity; 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 jakarta.validation.constraints.NotNull; import lombok.AccessLevel; import lombok.AllArgsConstructor; @@ -17,8 +18,9 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) @AllArgsConstructor @EqualsAndHashCode(of = "id", callSuper = false) +@Table(name = "member") @Entity -public class Member extends BaseTimeEntity { +public class MemberEntity extends BaseTimeEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @@ -27,4 +29,4 @@ public class Member extends BaseTimeEntity { @NotNull @Column(unique = true) private String nickname; -} \ No newline at end of file +} diff --git a/backend/src/main/java/com/zzang/chongdae/offering/repository/entity/OfferingEntity.java b/backend/src/main/java/com/zzang/chongdae/offering/repository/entity/OfferingEntity.java index 825a5a3e..7fc506f9 100644 --- a/backend/src/main/java/com/zzang/chongdae/offering/repository/entity/OfferingEntity.java +++ b/backend/src/main/java/com/zzang/chongdae/offering/repository/entity/OfferingEntity.java @@ -1,7 +1,7 @@ package com.zzang.chongdae.offering.repository.entity; -import com.zzang.chongdae.common.repository.BaseTimeEntity; -import com.zzang.chongdae.member.repository.Member; +import com.zzang.chongdae.common.repository.entity.BaseTimeEntity; +import com.zzang.chongdae.member.repository.entity.MemberEntity; import com.zzang.chongdae.offering.domain.OfferingPrice; import com.zzang.chongdae.offering.domain.OfferingStatus; import jakarta.persistence.Column; @@ -33,7 +33,7 @@ public class OfferingEntity extends BaseTimeEntity { private Long id; @ManyToOne - private Member member; + private MemberEntity member; @NotNull private String title; diff --git a/backend/src/main/java/com/zzang/chongdae/offeringmember/repository/entity/OfferingMemberEntity.java b/backend/src/main/java/com/zzang/chongdae/offeringmember/repository/entity/OfferingMemberEntity.java index 2f7085d7..863a320f 100644 --- a/backend/src/main/java/com/zzang/chongdae/offeringmember/repository/entity/OfferingMemberEntity.java +++ b/backend/src/main/java/com/zzang/chongdae/offeringmember/repository/entity/OfferingMemberEntity.java @@ -1,7 +1,7 @@ package com.zzang.chongdae.offeringmember.repository.entity; -import com.zzang.chongdae.common.repository.BaseTimeEntity; -import com.zzang.chongdae.member.repository.Member; +import com.zzang.chongdae.common.repository.entity.BaseTimeEntity; +import com.zzang.chongdae.member.repository.entity.MemberEntity; import com.zzang.chongdae.offering.repository.entity.OfferingEntity; import com.zzang.chongdae.offeringmember.domain.OfferingMemberRole; import jakarta.persistence.Entity; @@ -31,7 +31,7 @@ public class OfferingMemberEntity extends BaseTimeEntity { private Long id; @ManyToOne - private Member member; + private MemberEntity member; @ManyToOne private OfferingEntity offering; From ecf56eaef2bac16b13c14c8715f48d0e61c7385c Mon Sep 17 00:00:00 2001 From: Choo Date: Mon, 22 Jul 2024 22:01:36 +0900 Subject: [PATCH 09/11] =?UTF-8?q?style:=20=ED=81=B4=EB=9E=98=EC=8A=A4=20?= =?UTF-8?q?=EC=BB=A8=EB=B2=A4=EC=85=98=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../zzang/chongdae/offeringmember/domain/OfferingMemberRole.java | 1 + 1 file changed, 1 insertion(+) diff --git a/backend/src/main/java/com/zzang/chongdae/offeringmember/domain/OfferingMemberRole.java b/backend/src/main/java/com/zzang/chongdae/offeringmember/domain/OfferingMemberRole.java index 279bb30e..a75233fd 100644 --- a/backend/src/main/java/com/zzang/chongdae/offeringmember/domain/OfferingMemberRole.java +++ b/backend/src/main/java/com/zzang/chongdae/offeringmember/domain/OfferingMemberRole.java @@ -1,6 +1,7 @@ package com.zzang.chongdae.offeringmember.domain; public enum OfferingMemberRole { + PROPOSER, PARTICIPANT; // TODO: entity 패키지와 domain 패키지 중 위치 고민하기 (feat. vo) } From 3aa8d0e9e7324db7120fae0f4aba4f187144d44e Mon Sep 17 00:00:00 2001 From: Choo Date: Mon, 22 Jul 2024 22:01:56 +0900 Subject: [PATCH 10/11] =?UTF-8?q?chore:=20h2=20console=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/main/resources/application.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/backend/src/main/resources/application.yml b/backend/src/main/resources/application.yml index 342925e3..2fb70b4b 100644 --- a/backend/src/main/resources/application.yml +++ b/backend/src/main/resources/application.yml @@ -1,9 +1,6 @@ spring: application: name: chongdae - h2: - console: - enabled: true datasource: url: jdbc:h2:mem:database jpa: From 8614fc4c0411d5fc3eaf401bcc744688e0d173d1 Mon Sep 17 00:00:00 2001 From: Choo Date: Mon, 22 Jul 2024 22:09:26 +0900 Subject: [PATCH 11/11] =?UTF-8?q?refactor:=20OfferingCondition=20enum?= =?UTF-8?q?=EA=B0=92=20=EA=B2=B0=EC=A0=95=EB=A1=9C=EC=A7=81=EC=9D=84=20enu?= =?UTF-8?q?m=20=EC=95=88=EC=9C=BC=EB=A1=9C=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../offering/domain/OfferingCondition.java | 13 ++++++++++++ .../offering/domain/OfferingStatus.java | 21 ++++++------------- .../service/dto/OfferingDetailResponse.java | 2 +- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/backend/src/main/java/com/zzang/chongdae/offering/domain/OfferingCondition.java b/backend/src/main/java/com/zzang/chongdae/offering/domain/OfferingCondition.java index b69ad1d4..e59f7693 100644 --- a/backend/src/main/java/com/zzang/chongdae/offering/domain/OfferingCondition.java +++ b/backend/src/main/java/com/zzang/chongdae/offering/domain/OfferingCondition.java @@ -6,4 +6,17 @@ public enum OfferingCondition { TIME_OUT, CONFIRMED, AVAILABLE; + + public static OfferingCondition decideBy(OfferingStatus offeringStatus) { + if (offeringStatus.isCountFull()) { + return OfferingCondition.FULL; + } + if (offeringStatus.isDeadlineOver()) { + return OfferingCondition.TIME_OUT; + } + if (offeringStatus.isManualConfirmed() || offeringStatus.isAutoConfirmed()) { + return OfferingCondition.CONFIRMED; + } + return OfferingCondition.AVAILABLE; + } } diff --git a/backend/src/main/java/com/zzang/chongdae/offering/domain/OfferingStatus.java b/backend/src/main/java/com/zzang/chongdae/offering/domain/OfferingStatus.java index 0de16f80..65c70020 100644 --- a/backend/src/main/java/com/zzang/chongdae/offering/domain/OfferingStatus.java +++ b/backend/src/main/java/com/zzang/chongdae/offering/domain/OfferingStatus.java @@ -13,32 +13,23 @@ public class OfferingStatus { private final boolean isManualConfirmed; private final int currentCount; - public OfferingCondition decideOfferingStatus() { - if (isCountFull()) { - return OfferingCondition.FULL; - } - if (isDeadlineOver()) { - return OfferingCondition.TIME_OUT; - } - if (isManualConfirmed() || isAutoConfirmed()) { - return OfferingCondition.CONFIRMED; - } - return OfferingCondition.AVAILABLE; + public OfferingCondition decideOfferingCondition() { + return OfferingCondition.decideBy(this); } - private boolean isCountFull() { + public boolean isCountFull() { return this.totalCount == this.currentCount; } - private boolean isDeadlineOver() { + public boolean isDeadlineOver() { return LocalDateTime.now().isAfter(this.deadline); } - private boolean isAutoConfirmed() { + public boolean isAutoConfirmed() { return isCountFull() && isDeadlineOver(); } - private boolean isManualConfirmed() { + public boolean isManualConfirmed() { return isManualConfirmed; } } diff --git a/backend/src/main/java/com/zzang/chongdae/offering/service/dto/OfferingDetailResponse.java b/backend/src/main/java/com/zzang/chongdae/offering/service/dto/OfferingDetailResponse.java index 7c13d304..ecf3151c 100644 --- a/backend/src/main/java/com/zzang/chongdae/offering/service/dto/OfferingDetailResponse.java +++ b/backend/src/main/java/com/zzang/chongdae/offering/service/dto/OfferingDetailResponse.java @@ -36,7 +36,7 @@ public OfferingDetailResponse(OfferingEntity offering, OfferingPrice offeringPri offering.getThumbnailUrl(), offeringPrice.calculateDividedPrice(), offering.getTotalPrice(), - offeringStatus.decideOfferingStatus() + offeringStatus.decideOfferingCondition() ); } }