From 6a538523d4f23110d177e6d8b5a72a4cbfd3080d Mon Sep 17 00:00:00 2001 From: yeonjy Date: Sun, 21 Apr 2024 17:32:10 +0900 Subject: [PATCH 01/24] =?UTF-8?q?feat:=20DebateRoom=20Entity=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/debate/entity/DebateRoom.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 backend/core/src/main/java/com/rollthedice/backend/domain/debate/entity/DebateRoom.java diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/entity/DebateRoom.java b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/entity/DebateRoom.java new file mode 100644 index 00000000..fbba7bab --- /dev/null +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/entity/DebateRoom.java @@ -0,0 +1,27 @@ +package com.rollthedice.backend.domain.debate.entity; + +import com.rollthedice.backend.global.config.BaseTimeEntity; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@Entity +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class DebateRoom extends BaseTimeEntity { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + private String topic; + + @Builder + public DebateRoom(String topic) { + this.topic = topic; + } +} From 8a2e0f72fd9712bd9d82a9464ad673155d26afeb Mon Sep 17 00:00:00 2001 From: yeonjy Date: Mon, 22 Apr 2024 16:12:03 +0900 Subject: [PATCH 02/24] =?UTF-8?q?feat:=20DebateMessage=20Entity=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 --- .../domain/debate/entity/DebateMessage.java | 39 +++++++++++++++++++ .../domain/debate/entity/SenderType.java | 9 +++++ 2 files changed, 48 insertions(+) create mode 100644 backend/core/src/main/java/com/rollthedice/backend/domain/debate/entity/DebateMessage.java create mode 100644 backend/core/src/main/java/com/rollthedice/backend/domain/debate/entity/SenderType.java diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/entity/DebateMessage.java b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/entity/DebateMessage.java new file mode 100644 index 00000000..29a8d2de --- /dev/null +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/entity/DebateMessage.java @@ -0,0 +1,39 @@ +package com.rollthedice.backend.domain.debate.entity; + +import com.rollthedice.backend.domain.member.entity.Member; +import com.rollthedice.backend.global.config.BaseTimeEntity; +import jakarta.persistence.*; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@Entity +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class DebateMessage extends BaseTimeEntity { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + private String message; + + @Enumerated(EnumType.STRING) + private SenderType senderType; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "sender_id") + private Member sender; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "debate_room_id") + private DebateRoom debateRoom; + + @Builder + public DebateMessage(String message, SenderType senderType, DebateRoom debateRoom) { + this.message = message; + this.senderType = senderType; + this.debateRoom = debateRoom; + } + +} diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/entity/SenderType.java b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/entity/SenderType.java new file mode 100644 index 00000000..6d7ecfac --- /dev/null +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/entity/SenderType.java @@ -0,0 +1,9 @@ +package com.rollthedice.backend.domain.debate.entity; + +import lombok.Getter; + +@Getter +public enum SenderType { + HUMAN, + AI +} From b33e315c76535181b691264a258a1ff32da9497b Mon Sep 17 00:00:00 2001 From: yeonjy Date: Sat, 27 Apr 2024 23:22:10 +0900 Subject: [PATCH 03/24] =?UTF-8?q?feat:=20Debate=20api=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../debate/controller/DebateController.java | 21 +++++++++++++++++++ .../debate/dto/request/DebateRoomRequest.java | 16 ++++++++++++++ .../debate/service/DebateRoomService.java | 21 +++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 backend/core/src/main/java/com/rollthedice/backend/domain/debate/controller/DebateController.java create mode 100644 backend/core/src/main/java/com/rollthedice/backend/domain/debate/dto/request/DebateRoomRequest.java create mode 100644 backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateRoomService.java diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/controller/DebateController.java b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/controller/DebateController.java new file mode 100644 index 00000000..27299d8c --- /dev/null +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/controller/DebateController.java @@ -0,0 +1,21 @@ +package com.rollthedice.backend.domain.debate.controller; + +import com.rollthedice.backend.domain.debate.dto.request.DebateRoomRequest; +import com.rollthedice.backend.domain.debate.service.DebateRoomService; +import jakarta.validation.Valid; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.*; + +@RestController +@RequiredArgsConstructor +@RequestMapping("debates") +public class DebateController { + private final DebateRoomService debateRoomService; + + @ResponseStatus(HttpStatus.OK) + @PostMapping("") + public void saveDebateRoom(@RequestBody @Valid final DebateRoomRequest request) { + debateRoomService.saveDebateRoom(request); + } +} diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/dto/request/DebateRoomRequest.java b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/dto/request/DebateRoomRequest.java new file mode 100644 index 00000000..1d149faa --- /dev/null +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/dto/request/DebateRoomRequest.java @@ -0,0 +1,16 @@ +package com.rollthedice.backend.domain.debate.dto.request; + +import jakarta.validation.constraints.NotBlank; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class DebateRoomRequest { + @NotBlank + private String topic; +} diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateRoomService.java b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateRoomService.java new file mode 100644 index 00000000..9e8b9fbc --- /dev/null +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateRoomService.java @@ -0,0 +1,21 @@ +package com.rollthedice.backend.domain.debate.service; + +import com.rollthedice.backend.domain.debate.dto.request.DebateRoomRequest; +import com.rollthedice.backend.domain.debate.repository.DebateRoomRepository; +import com.rollthedice.backend.domain.member.query.AuthService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@RequiredArgsConstructor +@Service +public class DebateRoomService { + private final AuthService authService; + private final DebateRoomRepository debateRoomRepository; + + + @Transactional + public void saveDebateRoom(DebateRoomRequest request) { + + } +} From bf6d39672d19ed6c80e41cb4d5b1ce95b07c4db7 Mon Sep 17 00:00:00 2001 From: yeonjy Date: Sun, 28 Apr 2024 00:10:47 +0900 Subject: [PATCH 04/24] =?UTF-8?q?feat:=20DebateRoomRepository=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/debate/repository/DebateRoomRepository.java | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 backend/core/src/main/java/com/rollthedice/backend/domain/debate/repository/DebateRoomRepository.java diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/repository/DebateRoomRepository.java b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/repository/DebateRoomRepository.java new file mode 100644 index 00000000..3170f8af --- /dev/null +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/repository/DebateRoomRepository.java @@ -0,0 +1,10 @@ +package com.rollthedice.backend.domain.debate.repository; + +import com.rollthedice.backend.domain.debate.entity.DebateRoom; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface DebateRoomRepository extends JpaRepository { + +} From 431eb5552a76681705ac5104def170294963c45b Mon Sep 17 00:00:00 2001 From: yeonjy Date: Sun, 28 Apr 2024 00:11:23 +0900 Subject: [PATCH 05/24] =?UTF-8?q?feat:=20DebateRoom=20=EC=83=9D=EC=84=B1?= =?UTF-8?q?=20=EB=A1=9C=EC=A7=81=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/debate/controller/DebateController.java | 2 +- .../debate/dto/request/DebateRoomRequest.java | 3 +-- .../domain/debate/mapper/DebateRoomMapper.java | 13 +++++++++++++ .../domain/debate/service/DebateRoomService.java | 6 +++++- 4 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 backend/core/src/main/java/com/rollthedice/backend/domain/debate/mapper/DebateRoomMapper.java diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/controller/DebateController.java b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/controller/DebateController.java index 27299d8c..4b04142c 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/controller/DebateController.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/controller/DebateController.java @@ -13,7 +13,7 @@ public class DebateController { private final DebateRoomService debateRoomService; - @ResponseStatus(HttpStatus.OK) + @ResponseStatus(HttpStatus.CREATED) @PostMapping("") public void saveDebateRoom(@RequestBody @Valid final DebateRoomRequest request) { debateRoomService.saveDebateRoom(request); diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/dto/request/DebateRoomRequest.java b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/dto/request/DebateRoomRequest.java index 1d149faa..92f5bd0a 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/dto/request/DebateRoomRequest.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/dto/request/DebateRoomRequest.java @@ -1,6 +1,6 @@ package com.rollthedice.backend.domain.debate.dto.request; -import jakarta.validation.constraints.NotBlank; +import com.rollthedice.backend.domain.debate.entity.DebateRoom; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; @@ -11,6 +11,5 @@ @NoArgsConstructor @Builder public class DebateRoomRequest { - @NotBlank private String topic; } diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/mapper/DebateRoomMapper.java b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/mapper/DebateRoomMapper.java new file mode 100644 index 00000000..ea7df094 --- /dev/null +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/mapper/DebateRoomMapper.java @@ -0,0 +1,13 @@ +package com.rollthedice.backend.domain.debate.mapper; + +import com.rollthedice.backend.domain.debate.dto.request.DebateRoomRequest; +import com.rollthedice.backend.domain.debate.entity.DebateRoom; +import com.rollthedice.backend.domain.member.entity.Member; +import org.mapstruct.Mapper; +import org.mapstruct.MappingConstants; + +@Mapper(componentModel = MappingConstants.ComponentModel.SPRING) +public interface DebateRoomMapper { + + DebateRoom toEntity(final Member member, final DebateRoomRequest request); +} diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateRoomService.java b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateRoomService.java index 9e8b9fbc..6a318e2e 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateRoomService.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateRoomService.java @@ -1,7 +1,9 @@ package com.rollthedice.backend.domain.debate.service; import com.rollthedice.backend.domain.debate.dto.request.DebateRoomRequest; +import com.rollthedice.backend.domain.debate.mapper.DebateRoomMapper; import com.rollthedice.backend.domain.debate.repository.DebateRoomRepository; +import com.rollthedice.backend.domain.member.entity.Member; import com.rollthedice.backend.domain.member.query.AuthService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -11,11 +13,13 @@ @Service public class DebateRoomService { private final AuthService authService; + private final DebateRoomMapper debateRoomMapper; private final DebateRoomRepository debateRoomRepository; @Transactional public void saveDebateRoom(DebateRoomRequest request) { - + final Member member = authService.getMember(); + debateRoomRepository.save(debateRoomMapper.toEntity(member, request)); } } From d233a164f9c6ac92a88492b939371f0490cce078 Mon Sep 17 00:00:00 2001 From: yeonjy Date: Sun, 28 Apr 2024 01:09:45 +0900 Subject: [PATCH 06/24] =?UTF-8?q?feat:=20DebateMessageRepository=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 --- .../news/repository/DebateMessageRepository.java | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 backend/core/src/main/java/com/rollthedice/backend/domain/news/repository/DebateMessageRepository.java diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/news/repository/DebateMessageRepository.java b/backend/core/src/main/java/com/rollthedice/backend/domain/news/repository/DebateMessageRepository.java new file mode 100644 index 00000000..e84f3f9c --- /dev/null +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/news/repository/DebateMessageRepository.java @@ -0,0 +1,10 @@ +package com.rollthedice.backend.domain.news.repository; + +import com.rollthedice.backend.domain.debate.entity.DebateMessage; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface DebateMessageRepository extends JpaRepository { + +} From 3adee8573942ab972158ab138ffe93ba9f79e32d Mon Sep 17 00:00:00 2001 From: yeonjy Date: Sun, 28 Apr 2024 01:10:34 +0900 Subject: [PATCH 07/24] =?UTF-8?q?feat:=20human=20debate=20message=20?= =?UTF-8?q?=EC=A0=80=EC=9E=A5=20api=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/debate/controller/DebateController.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/controller/DebateController.java b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/controller/DebateController.java index 4b04142c..5f54255d 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/controller/DebateController.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/controller/DebateController.java @@ -1,6 +1,8 @@ package com.rollthedice.backend.domain.debate.controller; +import com.rollthedice.backend.domain.debate.dto.request.DebateMessageRequest; import com.rollthedice.backend.domain.debate.dto.request.DebateRoomRequest; +import com.rollthedice.backend.domain.debate.service.DebateMessageService; import com.rollthedice.backend.domain.debate.service.DebateRoomService; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; @@ -12,10 +14,17 @@ @RequestMapping("debates") public class DebateController { private final DebateRoomService debateRoomService; + private final DebateMessageService debateMessageService; @ResponseStatus(HttpStatus.CREATED) @PostMapping("") public void saveDebateRoom(@RequestBody @Valid final DebateRoomRequest request) { debateRoomService.saveDebateRoom(request); } + + @ResponseStatus(HttpStatus.CREATED) + @PostMapping("/{roomId}/human") + public void saveHumanDebateMessage(@PathVariable final Long roomId, @RequestBody final DebateMessageRequest request) { + debateMessageService.saveHumanDebateMessage(roomId, request); + } } From b4813a9982f49d5c49776ba2a4bb8ce98578321d Mon Sep 17 00:00:00 2001 From: yeonjy Date: Sun, 28 Apr 2024 01:11:05 +0900 Subject: [PATCH 08/24] =?UTF-8?q?feat:=20DebateMessage=20@Builder=EC=97=90?= =?UTF-8?q?=20sender=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/domain/debate/entity/DebateMessage.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/entity/DebateMessage.java b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/entity/DebateMessage.java index 29a8d2de..f4cb1a02 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/entity/DebateMessage.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/entity/DebateMessage.java @@ -30,9 +30,10 @@ public class DebateMessage extends BaseTimeEntity { private DebateRoom debateRoom; @Builder - public DebateMessage(String message, SenderType senderType, DebateRoom debateRoom) { + public DebateMessage(String message, SenderType senderType, Member sender, DebateRoom debateRoom) { this.message = message; this.senderType = senderType; + this.sender = sender; this.debateRoom = debateRoom; } From 6e338a219935e16256072d5d9efa4f7955b7134d Mon Sep 17 00:00:00 2001 From: yeonjy Date: Sun, 28 Apr 2024 01:11:36 +0900 Subject: [PATCH 09/24] =?UTF-8?q?feat:=20Human=20DebateMessage=20=EC=A0=80?= =?UTF-8?q?=EC=9E=A5=20=EB=A1=9C=EC=A7=81=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/request/DebateMessageRequest.java | 27 +++++++++++++++++ .../debate/service/DebateMessageService.java | 29 +++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 backend/core/src/main/java/com/rollthedice/backend/domain/debate/dto/request/DebateMessageRequest.java create mode 100644 backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateMessageService.java diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/dto/request/DebateMessageRequest.java b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/dto/request/DebateMessageRequest.java new file mode 100644 index 00000000..35ee7a8d --- /dev/null +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/dto/request/DebateMessageRequest.java @@ -0,0 +1,27 @@ +package com.rollthedice.backend.domain.debate.dto.request; + +import com.rollthedice.backend.domain.debate.entity.DebateMessage; +import com.rollthedice.backend.domain.debate.entity.DebateRoom; +import com.rollthedice.backend.domain.debate.entity.SenderType; +import com.rollthedice.backend.domain.member.entity.Member; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class DebateMessageRequest { + private String message; + + public DebateMessage toEntity(Member sender, DebateRoom debateRoom) { + return DebateMessage.builder() + .message(this.message) + .senderType(SenderType.HUMAN) + .sender(sender) + .debateRoom(debateRoom) + .build(); + } +} diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateMessageService.java b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateMessageService.java new file mode 100644 index 00000000..95ddba79 --- /dev/null +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateMessageService.java @@ -0,0 +1,29 @@ +package com.rollthedice.backend.domain.debate.service; + +import com.rollthedice.backend.domain.debate.dto.request.DebateMessageRequest; +import com.rollthedice.backend.domain.debate.entity.DebateMessage; +import com.rollthedice.backend.domain.debate.entity.DebateRoom; +import com.rollthedice.backend.domain.debate.entity.SenderType; +import com.rollthedice.backend.domain.debate.repository.DebateRoomRepository; +import com.rollthedice.backend.domain.member.entity.Member; +import com.rollthedice.backend.domain.member.query.AuthService; +import com.rollthedice.backend.domain.news.repository.DebateMessageRepository; +import jakarta.persistence.EntityNotFoundException; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@RequiredArgsConstructor +@Service +public class DebateMessageService { + private final AuthService authService; + private final DebateRoomRepository debateRoomRepository; + private final DebateMessageRepository debateMessageRepository; + + @Transactional + public void saveHumanDebateMessage(final Long roomId, DebateMessageRequest request) { + final Member member = authService.getMember(); + final DebateRoom debateRoom = debateRoomRepository.findById(roomId).orElseThrow(EntityNotFoundException::new); + debateMessageRepository.save(request.toEntity(member, debateRoom)); + } +} From b9ef067879a665a35bc5293ef227bb93deffb962 Mon Sep 17 00:00:00 2001 From: yeonjy Date: Sun, 28 Apr 2024 01:20:47 +0900 Subject: [PATCH 10/24] =?UTF-8?q?refactor:=20getDebateRoom=20=EC=B6=94?= =?UTF-8?q?=EC=B6=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/debate/service/DebateMessageService.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateMessageService.java b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateMessageService.java index 95ddba79..a7479665 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateMessageService.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateMessageService.java @@ -23,7 +23,14 @@ public class DebateMessageService { @Transactional public void saveHumanDebateMessage(final Long roomId, DebateMessageRequest request) { final Member member = authService.getMember(); - final DebateRoom debateRoom = debateRoomRepository.findById(roomId).orElseThrow(EntityNotFoundException::new); - debateMessageRepository.save(request.toEntity(member, debateRoom)); + debateMessageRepository.save(request.toEntity(member, getDebateRoom(roomId))); + } + + public void saveAIDebateMessage(Long roomId, DebateMessageRequest request) { + + } + + private DebateRoom getDebateRoom(final Long roomId) { + return debateRoomRepository.findById(roomId).orElseThrow(EntityNotFoundException::new); } } From a6e0f4a6618199502f3634b58d4bca8803aab124 Mon Sep 17 00:00:00 2001 From: yeonjy Date: Sun, 28 Apr 2024 01:29:50 +0900 Subject: [PATCH 11/24] =?UTF-8?q?feat:=20AI=20DebateMessage=20=EC=A0=80?= =?UTF-8?q?=EC=9E=A5=20api=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/domain/debate/controller/DebateController.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/controller/DebateController.java b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/controller/DebateController.java index 5f54255d..93097d7b 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/controller/DebateController.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/controller/DebateController.java @@ -27,4 +27,10 @@ public void saveDebateRoom(@RequestBody @Valid final DebateRoomRequest request) public void saveHumanDebateMessage(@PathVariable final Long roomId, @RequestBody final DebateMessageRequest request) { debateMessageService.saveHumanDebateMessage(roomId, request); } + + @ResponseStatus(HttpStatus.CREATED) + @PostMapping("/{roomId}/ai") + public void saveAIDebateMessage(@PathVariable final Long roomId, @RequestBody final DebateMessageRequest request) { + debateMessageService.saveAIDebateMessage(roomId, request); + } } From ab6cac4367a5d09ee15e393080a9729832978740 Mon Sep 17 00:00:00 2001 From: yeonjy Date: Sun, 28 Apr 2024 01:33:39 +0900 Subject: [PATCH 12/24] =?UTF-8?q?feat:=20AI=20DebateMessage=20=EC=A0=80?= =?UTF-8?q?=EC=9E=A5=20=EB=A1=9C=EC=A7=81=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../debate/dto/request/DebateMessageRequest.java | 10 +++++++++- .../domain/debate/service/DebateMessageService.java | 4 ++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/dto/request/DebateMessageRequest.java b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/dto/request/DebateMessageRequest.java index 35ee7a8d..214cbd01 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/dto/request/DebateMessageRequest.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/dto/request/DebateMessageRequest.java @@ -16,7 +16,7 @@ public class DebateMessageRequest { private String message; - public DebateMessage toEntity(Member sender, DebateRoom debateRoom) { + public DebateMessage toHumanMessageEntity(Member sender, DebateRoom debateRoom) { return DebateMessage.builder() .message(this.message) .senderType(SenderType.HUMAN) @@ -24,4 +24,12 @@ public DebateMessage toEntity(Member sender, DebateRoom debateRoom) { .debateRoom(debateRoom) .build(); } + + public DebateMessage toAIMessageEntity(DebateRoom debateRoom) { + return DebateMessage.builder() + .message(this.message) + .senderType(SenderType.AI) + .debateRoom(debateRoom) + .build(); + } } diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateMessageService.java b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateMessageService.java index a7479665..0f7e1671 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateMessageService.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateMessageService.java @@ -23,11 +23,11 @@ public class DebateMessageService { @Transactional public void saveHumanDebateMessage(final Long roomId, DebateMessageRequest request) { final Member member = authService.getMember(); - debateMessageRepository.save(request.toEntity(member, getDebateRoom(roomId))); + debateMessageRepository.save(request.toHumanMessageEntity(member, getDebateRoom(roomId))); } public void saveAIDebateMessage(Long roomId, DebateMessageRequest request) { - + debateMessageRepository.save(request.toAIMessageEntity(getDebateRoom(roomId))); } private DebateRoom getDebateRoom(final Long roomId) { From 3ebe842568ac95aad051e8dc52f66d391cae9ea4 Mon Sep 17 00:00:00 2001 From: yeonjy Date: Sun, 28 Apr 2024 15:13:26 +0900 Subject: [PATCH 13/24] =?UTF-8?q?refactor:=20DebateMessage=20sender=20colu?= =?UTF-8?q?mn=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/debate/dto/request/DebateMessageRequest.java | 4 +--- .../backend/domain/debate/entity/DebateMessage.java | 7 +------ .../domain/debate/service/DebateMessageService.java | 8 +------- 3 files changed, 3 insertions(+), 16 deletions(-) diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/dto/request/DebateMessageRequest.java b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/dto/request/DebateMessageRequest.java index 214cbd01..405a1d84 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/dto/request/DebateMessageRequest.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/dto/request/DebateMessageRequest.java @@ -3,7 +3,6 @@ import com.rollthedice.backend.domain.debate.entity.DebateMessage; import com.rollthedice.backend.domain.debate.entity.DebateRoom; import com.rollthedice.backend.domain.debate.entity.SenderType; -import com.rollthedice.backend.domain.member.entity.Member; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; @@ -16,11 +15,10 @@ public class DebateMessageRequest { private String message; - public DebateMessage toHumanMessageEntity(Member sender, DebateRoom debateRoom) { + public DebateMessage toHumanMessageEntity(DebateRoom debateRoom) { return DebateMessage.builder() .message(this.message) .senderType(SenderType.HUMAN) - .sender(sender) .debateRoom(debateRoom) .build(); } diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/entity/DebateMessage.java b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/entity/DebateMessage.java index f4cb1a02..91221c01 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/entity/DebateMessage.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/entity/DebateMessage.java @@ -21,19 +21,14 @@ public class DebateMessage extends BaseTimeEntity { @Enumerated(EnumType.STRING) private SenderType senderType; - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "sender_id") - private Member sender; - @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "debate_room_id") private DebateRoom debateRoom; @Builder - public DebateMessage(String message, SenderType senderType, Member sender, DebateRoom debateRoom) { + public DebateMessage(String message, SenderType senderType, DebateRoom debateRoom) { this.message = message; this.senderType = senderType; - this.sender = sender; this.debateRoom = debateRoom; } diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateMessageService.java b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateMessageService.java index 0f7e1671..a83cca11 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateMessageService.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateMessageService.java @@ -1,12 +1,8 @@ package com.rollthedice.backend.domain.debate.service; import com.rollthedice.backend.domain.debate.dto.request.DebateMessageRequest; -import com.rollthedice.backend.domain.debate.entity.DebateMessage; import com.rollthedice.backend.domain.debate.entity.DebateRoom; -import com.rollthedice.backend.domain.debate.entity.SenderType; import com.rollthedice.backend.domain.debate.repository.DebateRoomRepository; -import com.rollthedice.backend.domain.member.entity.Member; -import com.rollthedice.backend.domain.member.query.AuthService; import com.rollthedice.backend.domain.news.repository.DebateMessageRepository; import jakarta.persistence.EntityNotFoundException; import lombok.RequiredArgsConstructor; @@ -16,14 +12,12 @@ @RequiredArgsConstructor @Service public class DebateMessageService { - private final AuthService authService; private final DebateRoomRepository debateRoomRepository; private final DebateMessageRepository debateMessageRepository; @Transactional public void saveHumanDebateMessage(final Long roomId, DebateMessageRequest request) { - final Member member = authService.getMember(); - debateMessageRepository.save(request.toHumanMessageEntity(member, getDebateRoom(roomId))); + debateMessageRepository.save(request.toHumanMessageEntity(getDebateRoom(roomId))); } public void saveAIDebateMessage(Long roomId, DebateMessageRequest request) { From e81acab05c9dc5dad46b904b0a6ed49639cd8cfa Mon Sep 17 00:00:00 2001 From: yeonjy Date: Sun, 28 Apr 2024 16:03:43 +0900 Subject: [PATCH 14/24] =?UTF-8?q?feat:=20DebateRoom=20=EC=A0=84=EC=B2=B4?= =?UTF-8?q?=20=EC=A1=B0=ED=9A=8C=20api=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../debate/controller/DebateController.java | 10 ++++++++++ .../debate/dto/response/DebateRoomResponse.java | 15 +++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 backend/core/src/main/java/com/rollthedice/backend/domain/debate/dto/response/DebateRoomResponse.java diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/controller/DebateController.java b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/controller/DebateController.java index 93097d7b..c4f8988e 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/controller/DebateController.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/controller/DebateController.java @@ -2,13 +2,17 @@ import com.rollthedice.backend.domain.debate.dto.request.DebateMessageRequest; import com.rollthedice.backend.domain.debate.dto.request.DebateRoomRequest; +import com.rollthedice.backend.domain.debate.dto.response.DebateRoomResponse; import com.rollthedice.backend.domain.debate.service.DebateMessageService; import com.rollthedice.backend.domain.debate.service.DebateRoomService; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Pageable; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; +import java.util.List; + @RestController @RequiredArgsConstructor @RequestMapping("debates") @@ -22,6 +26,12 @@ public void saveDebateRoom(@RequestBody @Valid final DebateRoomRequest request) debateRoomService.saveDebateRoom(request); } + @ResponseStatus(HttpStatus.OK) + @GetMapping("") + public List getDebateRooms(final Pageable pageable) { + return debateRoomService.getDebateRooms(pageable); + } + @ResponseStatus(HttpStatus.CREATED) @PostMapping("/{roomId}/human") public void saveHumanDebateMessage(@PathVariable final Long roomId, @RequestBody final DebateMessageRequest request) { diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/dto/response/DebateRoomResponse.java b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/dto/response/DebateRoomResponse.java new file mode 100644 index 00000000..64eae208 --- /dev/null +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/dto/response/DebateRoomResponse.java @@ -0,0 +1,15 @@ +package com.rollthedice.backend.domain.debate.dto.response; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class DebateRoomResponse { + private Long id; + private String topic; +} From e8ad7683ffec1c8cab8f3ce6663b1b7043c992d1 Mon Sep 17 00:00:00 2001 From: yeonjy Date: Sun, 28 Apr 2024 16:04:18 +0900 Subject: [PATCH 15/24] =?UTF-8?q?feat:=20DebateRoom=EC=97=90=20Member=20?= =?UTF-8?q?=EC=BB=AC=EB=9F=BC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/domain/debate/entity/DebateRoom.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/entity/DebateRoom.java b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/entity/DebateRoom.java index fbba7bab..1d2603f8 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/entity/DebateRoom.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/entity/DebateRoom.java @@ -1,10 +1,8 @@ package com.rollthedice.backend.domain.debate.entity; +import com.rollthedice.backend.domain.member.entity.Member; import com.rollthedice.backend.global.config.BaseTimeEntity; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; +import jakarta.persistence.*; import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; @@ -20,8 +18,13 @@ public class DebateRoom extends BaseTimeEntity { private String topic; + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "member_id") + private Member member; + @Builder - public DebateRoom(String topic) { + public DebateRoom(Member member, String topic) { + this.member = member; this.topic = topic; } } From b9c6b049993a6686b22a75583a048a3c893e5328 Mon Sep 17 00:00:00 2001 From: yeonjy Date: Sun, 28 Apr 2024 16:04:56 +0900 Subject: [PATCH 16/24] =?UTF-8?q?feat:=20DebateRoom=20=EC=A0=84=EC=B2=B4?= =?UTF-8?q?=20=EC=A1=B0=ED=9A=8C=20=EB=A1=9C=EC=A7=81=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/debate/mapper/DebateRoomMapper.java | 3 +++ .../domain/debate/service/DebateRoomService.java | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/mapper/DebateRoomMapper.java b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/mapper/DebateRoomMapper.java index ea7df094..7e2f2bba 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/mapper/DebateRoomMapper.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/mapper/DebateRoomMapper.java @@ -1,6 +1,7 @@ package com.rollthedice.backend.domain.debate.mapper; import com.rollthedice.backend.domain.debate.dto.request.DebateRoomRequest; +import com.rollthedice.backend.domain.debate.dto.response.DebateRoomResponse; import com.rollthedice.backend.domain.debate.entity.DebateRoom; import com.rollthedice.backend.domain.member.entity.Member; import org.mapstruct.Mapper; @@ -10,4 +11,6 @@ public interface DebateRoomMapper { DebateRoom toEntity(final Member member, final DebateRoomRequest request); + + DebateRoomResponse toResponse(final DebateRoom room); } diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateRoomService.java b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateRoomService.java index 6a318e2e..01305fa3 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateRoomService.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateRoomService.java @@ -1,14 +1,19 @@ package com.rollthedice.backend.domain.debate.service; import com.rollthedice.backend.domain.debate.dto.request.DebateRoomRequest; +import com.rollthedice.backend.domain.debate.dto.response.DebateRoomResponse; import com.rollthedice.backend.domain.debate.mapper.DebateRoomMapper; import com.rollthedice.backend.domain.debate.repository.DebateRoomRepository; import com.rollthedice.backend.domain.member.entity.Member; import com.rollthedice.backend.domain.member.query.AuthService; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.List; +import java.util.stream.Collectors; + @RequiredArgsConstructor @Service public class DebateRoomService { @@ -22,4 +27,12 @@ public void saveDebateRoom(DebateRoomRequest request) { final Member member = authService.getMember(); debateRoomRepository.save(debateRoomMapper.toEntity(member, request)); } + + @Transactional(readOnly = true) + public List getDebateRooms(Pageable pageable) { + final Member member = authService.getMember(); + return debateRoomRepository.findAllByMemberOrderByCreatedAt(member, pageable).stream() + .map(debateRoomMapper::toResponse) + .collect(Collectors.toList()); + } } From d7acbc1fbfef8a14e741541ce201083ec45b335d Mon Sep 17 00:00:00 2001 From: yeonjy Date: Sun, 28 Apr 2024 16:06:20 +0900 Subject: [PATCH 17/24] =?UTF-8?q?feat:=20findAllByMember=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 --- .../domain/debate/repository/DebateRoomRepository.java | 6 +++++- .../backend/domain/debate/service/DebateRoomService.java | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/repository/DebateRoomRepository.java b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/repository/DebateRoomRepository.java index 3170f8af..76ef494c 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/repository/DebateRoomRepository.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/repository/DebateRoomRepository.java @@ -1,10 +1,14 @@ package com.rollthedice.backend.domain.debate.repository; import com.rollthedice.backend.domain.debate.entity.DebateRoom; +import com.rollthedice.backend.domain.member.entity.Member; +import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +import java.util.List; + @Repository public interface DebateRoomRepository extends JpaRepository { - + List findAllByMember(Member member, Pageable pageable); } diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateRoomService.java b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateRoomService.java index 01305fa3..67bccf3d 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateRoomService.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateRoomService.java @@ -31,7 +31,7 @@ public void saveDebateRoom(DebateRoomRequest request) { @Transactional(readOnly = true) public List getDebateRooms(Pageable pageable) { final Member member = authService.getMember(); - return debateRoomRepository.findAllByMemberOrderByCreatedAt(member, pageable).stream() + return debateRoomRepository.findAllByMember(member, pageable).stream() .map(debateRoomMapper::toResponse) .collect(Collectors.toList()); } From cc9604dc58739dd0a1b33a8f009a3bd93b8e8ece Mon Sep 17 00:00:00 2001 From: yeonjy Date: Sun, 28 Apr 2024 16:14:56 +0900 Subject: [PATCH 18/24] =?UTF-8?q?feat:=20DebateRoom=20=EC=82=AD=EC=A0=9C?= =?UTF-8?q?=20api=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/domain/debate/controller/DebateController.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/controller/DebateController.java b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/controller/DebateController.java index c4f8988e..53019513 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/controller/DebateController.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/controller/DebateController.java @@ -32,6 +32,12 @@ public List getDebateRooms(final Pageable pageable) { return debateRoomService.getDebateRooms(pageable); } + @ResponseStatus(HttpStatus.NO_CONTENT) + @DeleteMapping("/{roomId}") + public void deleteDebateRoom(@PathVariable final Long roomId) { + debateRoomService.deleteDebateRoom(roomId); + } + @ResponseStatus(HttpStatus.CREATED) @PostMapping("/{roomId}/human") public void saveHumanDebateMessage(@PathVariable final Long roomId, @RequestBody final DebateMessageRequest request) { From 26d3d950b0901d503142c966c823c0acebb44a52 Mon Sep 17 00:00:00 2001 From: yeonjy Date: Sun, 28 Apr 2024 16:15:33 +0900 Subject: [PATCH 19/24] =?UTF-8?q?feat:=20DebateRoom=20=EC=82=AD=EC=A0=9C?= =?UTF-8?q?=20=EB=A1=9C=EC=A7=81=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/domain/debate/service/DebateRoomService.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateRoomService.java b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateRoomService.java index 67bccf3d..b3da2357 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateRoomService.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateRoomService.java @@ -35,4 +35,8 @@ public List getDebateRooms(Pageable pageable) { .map(debateRoomMapper::toResponse) .collect(Collectors.toList()); } + + public void deleteDebateRoom(Long roomId) { + debateRoomRepository.deleteById(roomId); + } } From db3a828708282556531b16740270bc2eafbe8e4d Mon Sep 17 00:00:00 2001 From: yeonjy Date: Sun, 28 Apr 2024 16:41:07 +0900 Subject: [PATCH 20/24] =?UTF-8?q?feat:=20deleteAllDebateMessages=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 --- .../backend/domain/debate/service/DebateMessageService.java | 5 +++++ .../domain/news/repository/DebateMessageRepository.java | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateMessageService.java b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateMessageService.java index a83cca11..1a72f2e0 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateMessageService.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateMessageService.java @@ -27,4 +27,9 @@ public void saveAIDebateMessage(Long roomId, DebateMessageRequest request) { private DebateRoom getDebateRoom(final Long roomId) { return debateRoomRepository.findById(roomId).orElseThrow(EntityNotFoundException::new); } + + @Transactional + public void deleteAllDebateMessages(Long roomId) { + debateMessageRepository.deleteAllInBatchByDebateRoomId(roomId); + } } diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/news/repository/DebateMessageRepository.java b/backend/core/src/main/java/com/rollthedice/backend/domain/news/repository/DebateMessageRepository.java index e84f3f9c..7fccb19b 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/news/repository/DebateMessageRepository.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/news/repository/DebateMessageRepository.java @@ -6,5 +6,5 @@ @Repository public interface DebateMessageRepository extends JpaRepository { - + void deleteAllInBatchByDebateRoomId(final Long id); } From 808fa8d991ade751a8e6bde670aeda2ab10dbb46 Mon Sep 17 00:00:00 2001 From: yeonjy Date: Sun, 28 Apr 2024 16:41:57 +0900 Subject: [PATCH 21/24] =?UTF-8?q?feat:=20deleteAllDebateMessages=20?= =?UTF-8?q?=ED=98=B8=EC=B6=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/domain/debate/service/DebateRoomService.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateRoomService.java b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateRoomService.java index b3da2357..5a18f9a6 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateRoomService.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateRoomService.java @@ -20,6 +20,7 @@ public class DebateRoomService { private final AuthService authService; private final DebateRoomMapper debateRoomMapper; private final DebateRoomRepository debateRoomRepository; + private final DebateMessageService debateMessageService; @Transactional @@ -36,7 +37,9 @@ public List getDebateRooms(Pageable pageable) { .collect(Collectors.toList()); } + @Transactional public void deleteDebateRoom(Long roomId) { + debateMessageService.deleteAllDebateMessages(roomId); debateRoomRepository.deleteById(roomId); } } From 3a7c20c4cece0872c75d3c1a7be085b23b76b951 Mon Sep 17 00:00:00 2001 From: yeonjy Date: Sun, 28 Apr 2024 17:03:04 +0900 Subject: [PATCH 22/24] =?UTF-8?q?feat:=20DebateMessages=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20api=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/domain/debate/controller/DebateController.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/controller/DebateController.java b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/controller/DebateController.java index 53019513..090a3114 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/controller/DebateController.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/controller/DebateController.java @@ -2,6 +2,7 @@ import com.rollthedice.backend.domain.debate.dto.request.DebateMessageRequest; import com.rollthedice.backend.domain.debate.dto.request.DebateRoomRequest; +import com.rollthedice.backend.domain.debate.dto.response.DebateMessageResponse; import com.rollthedice.backend.domain.debate.dto.response.DebateRoomResponse; import com.rollthedice.backend.domain.debate.service.DebateMessageService; import com.rollthedice.backend.domain.debate.service.DebateRoomService; @@ -49,4 +50,10 @@ public void saveHumanDebateMessage(@PathVariable final Long roomId, @RequestBody public void saveAIDebateMessage(@PathVariable final Long roomId, @RequestBody final DebateMessageRequest request) { debateMessageService.saveAIDebateMessage(roomId, request); } + + @ResponseStatus(HttpStatus.OK) + @GetMapping("/{roomId}") + public List getDebateMessages(@PathVariable final Long roomId) { + return debateMessageService.getDebateMessages(roomId); + } } From 86ada1c2c0ac9850eb0cd086234f45ffb307adef Mon Sep 17 00:00:00 2001 From: yeonjy Date: Sun, 28 Apr 2024 17:03:36 +0900 Subject: [PATCH 23/24] =?UTF-8?q?feat:=20DebateMessages=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EB=A1=9C=EC=A7=81=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/response/DebateMessageResponse.java | 16 ++++++++++++++++ .../debate/mapper/DebateMessageMapper.java | 12 ++++++++++++ .../debate/service/DebateMessageService.java | 12 ++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 backend/core/src/main/java/com/rollthedice/backend/domain/debate/dto/response/DebateMessageResponse.java create mode 100644 backend/core/src/main/java/com/rollthedice/backend/domain/debate/mapper/DebateMessageMapper.java diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/dto/response/DebateMessageResponse.java b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/dto/response/DebateMessageResponse.java new file mode 100644 index 00000000..3e5ff3e5 --- /dev/null +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/dto/response/DebateMessageResponse.java @@ -0,0 +1,16 @@ +package com.rollthedice.backend.domain.debate.dto.response; + +import com.rollthedice.backend.domain.debate.entity.SenderType; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class DebateMessageResponse { + private String message; + private SenderType senderType; +} diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/mapper/DebateMessageMapper.java b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/mapper/DebateMessageMapper.java new file mode 100644 index 00000000..cffcb574 --- /dev/null +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/mapper/DebateMessageMapper.java @@ -0,0 +1,12 @@ +package com.rollthedice.backend.domain.debate.mapper; + +import com.rollthedice.backend.domain.debate.dto.request.DebateMessageRequest; +import com.rollthedice.backend.domain.debate.dto.response.DebateMessageResponse; +import com.rollthedice.backend.domain.debate.entity.DebateMessage; +import org.mapstruct.Mapper; +import org.mapstruct.MappingConstants; + +@Mapper(componentModel = MappingConstants.ComponentModel.SPRING) +public interface DebateMessageMapper { + DebateMessageResponse toResponse(DebateMessage debateMessage); +} diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateMessageService.java b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateMessageService.java index 1a72f2e0..3649fb78 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateMessageService.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateMessageService.java @@ -1,7 +1,9 @@ package com.rollthedice.backend.domain.debate.service; import com.rollthedice.backend.domain.debate.dto.request.DebateMessageRequest; +import com.rollthedice.backend.domain.debate.dto.response.DebateMessageResponse; import com.rollthedice.backend.domain.debate.entity.DebateRoom; +import com.rollthedice.backend.domain.debate.mapper.DebateMessageMapper; import com.rollthedice.backend.domain.debate.repository.DebateRoomRepository; import com.rollthedice.backend.domain.news.repository.DebateMessageRepository; import jakarta.persistence.EntityNotFoundException; @@ -9,11 +11,15 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.List; +import java.util.stream.Collectors; + @RequiredArgsConstructor @Service public class DebateMessageService { private final DebateRoomRepository debateRoomRepository; private final DebateMessageRepository debateMessageRepository; + private final DebateMessageMapper debateMessageMapper; @Transactional public void saveHumanDebateMessage(final Long roomId, DebateMessageRequest request) { @@ -32,4 +38,10 @@ private DebateRoom getDebateRoom(final Long roomId) { public void deleteAllDebateMessages(Long roomId) { debateMessageRepository.deleteAllInBatchByDebateRoomId(roomId); } + + public List getDebateMessages(Long roomId) { + return debateMessageRepository.findAllByDebateRoomId(roomId) + .stream().map(debateMessageMapper::toResponse) + .collect(Collectors.toList()); + } } From 475bc2d787adad73952df0dfc1f96b152dedfec5 Mon Sep 17 00:00:00 2001 From: yeonjy Date: Sun, 28 Apr 2024 17:03:58 +0900 Subject: [PATCH 24/24] =?UTF-8?q?feat:=20findAllByDebateRoomId=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 --- .../domain/news/repository/DebateMessageRepository.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/news/repository/DebateMessageRepository.java b/backend/core/src/main/java/com/rollthedice/backend/domain/news/repository/DebateMessageRepository.java index 7fccb19b..f2456e6f 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/news/repository/DebateMessageRepository.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/news/repository/DebateMessageRepository.java @@ -4,7 +4,11 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +import java.util.List; + @Repository public interface DebateMessageRepository extends JpaRepository { void deleteAllInBatchByDebateRoomId(final Long id); + + List findAllByDebateRoomId(final Long id); }