From 56469496676c90d3ea64d7c38c7c75f6d8e67870 Mon Sep 17 00:00:00 2001 From: alsdl0629 Date: Sun, 10 Mar 2024 19:33:56 +0900 Subject: [PATCH 1/3] =?UTF-8?q?=E2=9A=99=EF=B8=8F=20::=20(#574)=20null=20?= =?UTF-8?q?=EA=B2=80=EC=82=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entity/BugAttachmentEntity.java | 2 -- .../persistence/mapper/BugReportMapper.java | 23 ++++++++++++------- .../webhook/slack/SlackAdapter.java | 2 +- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/jobis-infrastructure/src/main/java/team/retum/jobis/domain/bug/persistence/entity/BugAttachmentEntity.java b/jobis-infrastructure/src/main/java/team/retum/jobis/domain/bug/persistence/entity/BugAttachmentEntity.java index 4cb0dd2fd..be27964a2 100644 --- a/jobis-infrastructure/src/main/java/team/retum/jobis/domain/bug/persistence/entity/BugAttachmentEntity.java +++ b/jobis-infrastructure/src/main/java/team/retum/jobis/domain/bug/persistence/entity/BugAttachmentEntity.java @@ -2,7 +2,6 @@ import jakarta.persistence.Column; import jakarta.persistence.Embeddable; -import jakarta.validation.constraints.NotNull; import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Getter; @@ -14,7 +13,6 @@ @Embeddable public class BugAttachmentEntity { - @NotNull @Column(columnDefinition = "VARCHAR(300)") private String attachmentUrl; } diff --git a/jobis-infrastructure/src/main/java/team/retum/jobis/domain/bug/persistence/mapper/BugReportMapper.java b/jobis-infrastructure/src/main/java/team/retum/jobis/domain/bug/persistence/mapper/BugReportMapper.java index a95ab8fc0..f2b133270 100644 --- a/jobis-infrastructure/src/main/java/team/retum/jobis/domain/bug/persistence/mapper/BugReportMapper.java +++ b/jobis-infrastructure/src/main/java/team/retum/jobis/domain/bug/persistence/mapper/BugReportMapper.java @@ -22,9 +22,12 @@ public BugReportEntity toEntity(BugReport domain) { StudentEntity student = studentJpaRepository.findById(domain.getStudentId()) .orElseThrow(() -> StudentNotFoundException.EXCEPTION); - List bugAttachments = domain.getAttachment().attachmentUrls().stream() - .map(BugAttachmentEntity::new) - .toList(); + List bugAttachments = null; + if (domain.getAttachment().attachmentUrls() != null) { + bugAttachments = domain.getAttachment().attachmentUrls().stream() + .map(BugAttachmentEntity::new) + .toList(); + } return BugReportEntity.builder() .id(domain.getId()) @@ -37,11 +40,15 @@ public BugReportEntity toEntity(BugReport domain) { } public BugReport toDomain(BugReportEntity entity) { - BugAttachment bugAttachment = new BugAttachment( - entity.getAttachments().stream() - .map(BugAttachmentEntity::getAttachmentUrl) - .toList() - ); + BugAttachment bugAttachment = null; + + if (entity.getAttachments() != null) { + bugAttachment = new BugAttachment( + entity.getAttachments().stream() + .map(BugAttachmentEntity::getAttachmentUrl) + .toList() + ); + } return BugReport.builder() .id(entity.getId()) diff --git a/jobis-infrastructure/src/main/java/team/retum/jobis/thirdparty/webhook/slack/SlackAdapter.java b/jobis-infrastructure/src/main/java/team/retum/jobis/thirdparty/webhook/slack/SlackAdapter.java index 944bf8caa..0e911e822 100644 --- a/jobis-infrastructure/src/main/java/team/retum/jobis/thirdparty/webhook/slack/SlackAdapter.java +++ b/jobis-infrastructure/src/main/java/team/retum/jobis/thirdparty/webhook/slack/SlackAdapter.java @@ -57,7 +57,7 @@ public void sendExceptionInfo(HttpServletRequest request, Exception exception) { private List createBugReportSlackAttachments(BugReport bugReport, String writer) { BugAttachment bugAttachment = bugReport.getAttachment(); - if (bugAttachment.attachmentUrls().isEmpty()) { + if (bugAttachment == null || bugAttachment.attachmentUrls().isEmpty()) { return Collections.singletonList( createBugReportSlackAttachment(bugReport, writer, null, true) ); From 586d2bdedde1eb2752d3ac44037dfcc8ce2674d0 Mon Sep 17 00:00:00 2001 From: Kangmin Date: Sun, 10 Mar 2024 22:46:23 +0900 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=A7=A9=20::=20(#574)=20default=20empt?= =?UTF-8?q?y=20list?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../persistence/mapper/BugReportMapper.java | 23 +++++++------------ .../request/CreateBugReportWebRequest.java | 7 ++++++ .../webhook/slack/SlackAdapter.java | 2 +- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/jobis-infrastructure/src/main/java/team/retum/jobis/domain/bug/persistence/mapper/BugReportMapper.java b/jobis-infrastructure/src/main/java/team/retum/jobis/domain/bug/persistence/mapper/BugReportMapper.java index f2b133270..a95ab8fc0 100644 --- a/jobis-infrastructure/src/main/java/team/retum/jobis/domain/bug/persistence/mapper/BugReportMapper.java +++ b/jobis-infrastructure/src/main/java/team/retum/jobis/domain/bug/persistence/mapper/BugReportMapper.java @@ -22,12 +22,9 @@ public BugReportEntity toEntity(BugReport domain) { StudentEntity student = studentJpaRepository.findById(domain.getStudentId()) .orElseThrow(() -> StudentNotFoundException.EXCEPTION); - List bugAttachments = null; - if (domain.getAttachment().attachmentUrls() != null) { - bugAttachments = domain.getAttachment().attachmentUrls().stream() - .map(BugAttachmentEntity::new) - .toList(); - } + List bugAttachments = domain.getAttachment().attachmentUrls().stream() + .map(BugAttachmentEntity::new) + .toList(); return BugReportEntity.builder() .id(domain.getId()) @@ -40,15 +37,11 @@ public BugReportEntity toEntity(BugReport domain) { } public BugReport toDomain(BugReportEntity entity) { - BugAttachment bugAttachment = null; - - if (entity.getAttachments() != null) { - bugAttachment = new BugAttachment( - entity.getAttachments().stream() - .map(BugAttachmentEntity::getAttachmentUrl) - .toList() - ); - } + BugAttachment bugAttachment = new BugAttachment( + entity.getAttachments().stream() + .map(BugAttachmentEntity::getAttachmentUrl) + .toList() + ); return BugReport.builder() .id(entity.getId()) diff --git a/jobis-infrastructure/src/main/java/team/retum/jobis/domain/bug/presentation/dto/request/CreateBugReportWebRequest.java b/jobis-infrastructure/src/main/java/team/retum/jobis/domain/bug/presentation/dto/request/CreateBugReportWebRequest.java index d54623666..d0a33f9ac 100644 --- a/jobis-infrastructure/src/main/java/team/retum/jobis/domain/bug/presentation/dto/request/CreateBugReportWebRequest.java +++ b/jobis-infrastructure/src/main/java/team/retum/jobis/domain/bug/presentation/dto/request/CreateBugReportWebRequest.java @@ -8,7 +8,9 @@ import team.retum.jobis.domain.bug.dto.request.CreateBugReportRequest; import team.retum.jobis.domain.bug.model.DevelopmentArea; +import java.util.Collections; import java.util.List; +import java.util.Objects; @Getter @NoArgsConstructor @@ -28,6 +30,7 @@ public class CreateBugReportWebRequest { private List attachmentUrls; public CreateBugReportRequest toDomainRequest() { + setAttachmentUrls(attachmentUrls); return CreateBugReportRequest.builder() .title(this.title) .content(this.content) @@ -35,4 +38,8 @@ public CreateBugReportRequest toDomainRequest() { .attachmentUrls(this.attachmentUrls) .build(); } + + private void setAttachmentUrls(List attachmentUrls) { + this.attachmentUrls = Objects.requireNonNullElse(attachmentUrls, Collections.emptyList()); + } } diff --git a/jobis-infrastructure/src/main/java/team/retum/jobis/thirdparty/webhook/slack/SlackAdapter.java b/jobis-infrastructure/src/main/java/team/retum/jobis/thirdparty/webhook/slack/SlackAdapter.java index 0e911e822..944bf8caa 100644 --- a/jobis-infrastructure/src/main/java/team/retum/jobis/thirdparty/webhook/slack/SlackAdapter.java +++ b/jobis-infrastructure/src/main/java/team/retum/jobis/thirdparty/webhook/slack/SlackAdapter.java @@ -57,7 +57,7 @@ public void sendExceptionInfo(HttpServletRequest request, Exception exception) { private List createBugReportSlackAttachments(BugReport bugReport, String writer) { BugAttachment bugAttachment = bugReport.getAttachment(); - if (bugAttachment == null || bugAttachment.attachmentUrls().isEmpty()) { + if (bugAttachment.attachmentUrls().isEmpty()) { return Collections.singletonList( createBugReportSlackAttachment(bugReport, writer, null, true) ); From 233bfcec0217c164a1440ee396c045f534864cdf Mon Sep 17 00:00:00 2001 From: alsdl0629 Date: Mon, 11 Mar 2024 08:39:38 +0900 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=A7=A9=20::=20(#574)=20default=20empt?= =?UTF-8?q?y=20list?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/request/CreateBugReportWebRequest.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/jobis-infrastructure/src/main/java/team/retum/jobis/domain/bug/presentation/dto/request/CreateBugReportWebRequest.java b/jobis-infrastructure/src/main/java/team/retum/jobis/domain/bug/presentation/dto/request/CreateBugReportWebRequest.java index d0a33f9ac..556bf5a5c 100644 --- a/jobis-infrastructure/src/main/java/team/retum/jobis/domain/bug/presentation/dto/request/CreateBugReportWebRequest.java +++ b/jobis-infrastructure/src/main/java/team/retum/jobis/domain/bug/presentation/dto/request/CreateBugReportWebRequest.java @@ -30,16 +30,11 @@ public class CreateBugReportWebRequest { private List attachmentUrls; public CreateBugReportRequest toDomainRequest() { - setAttachmentUrls(attachmentUrls); return CreateBugReportRequest.builder() .title(this.title) .content(this.content) .developmentArea(this.developmentArea) - .attachmentUrls(this.attachmentUrls) + .attachmentUrls(Objects.requireNonNullElse(attachmentUrls, Collections.emptyList())) .build(); } - - private void setAttachmentUrls(List attachmentUrls) { - this.attachmentUrls = Objects.requireNonNullElse(attachmentUrls, Collections.emptyList()); - } }