Skip to content

Commit

Permalink
⚙️ :: (8452)공지 첨부물 nullable
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyoil2 committed Nov 14, 2024
1 parent 2a95648 commit 18e6f7a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ public CompanyCountResponse countCompanies(
.limit(1000)
.build();


return new CompanyCountResponse(
queryCompanyPort.getByConditions(filter).stream().toList().size()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import team.retum.jobis.domain.notice.model.NoticeAttachment;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

@Getter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import team.retum.jobis.domain.notice.model.NoticeAttachment;
import team.retum.jobis.domain.notice.spi.CommandNoticePort;

import java.util.List;

@RequiredArgsConstructor
@UseCase
public class CreateNoticeUseCase {
Expand All @@ -17,12 +19,15 @@ public class CreateNoticeUseCase {
private final PublishEventPort publishEventPort;

public void execute(CreateNoticeRequest request) {
List<NoticeAttachment> attachments = request.getAttachments().stream()
.filter(attachment -> attachment.getUrl() != null && attachment.getType() != null) // URL과 Type이 null이 아닌 경우만 필터링
.map(attachment -> new NoticeAttachment(attachment.getUrl(), attachment.getType()))
.toList();

Notice savedNotice = commandNoticePort.save(Notice.builder()
.title(request.getTitle())
.content(request.getContent())
.attachments(request.getAttachments().stream()
.map(attachment -> new NoticeAttachment(attachment.getUrl(), attachment.getType()))
.toList())
.attachments(attachments)
.build());

publishEventPort.publishEvent(new NoticePostedEvent(savedNotice));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@
public class NoticeMapper {

public NoticeEntity toEntity(Notice domain) {
List<NoticeAttachmentEntity> attachments = domain.getAttachments().stream()
.map(attachment -> new NoticeAttachmentEntity(attachment.getUrl(), attachment.getType()))
.toList();
List<NoticeAttachmentEntity> attachments = null;

if (domain.getAttachments() != null && !domain.getAttachments().isEmpty()) {
attachments = domain.getAttachments().stream()
.map(attachment -> new NoticeAttachmentEntity(attachment.getUrl(), attachment.getType()))
.toList();
}

return NoticeEntity.builder()
.id(domain.getId())
Expand All @@ -27,9 +31,13 @@ public NoticeEntity toEntity(Notice domain) {
}

public Notice toDomain(NoticeEntity entity) {
List<NoticeAttachment> attachments = entity.getAttachments().stream()
.map(attachment -> new NoticeAttachment(attachment.getAttachmentUrl(), attachment.getType()))
.toList();
List<NoticeAttachment> attachments = null;

if (entity.getAttachments() != null && !entity.getAttachments().isEmpty()) {
attachments = entity.getAttachments().stream()
.map(attachment -> new NoticeAttachment(attachment.getAttachmentUrl(), attachment.getType()))
.toList();
}

return Notice.builder()
.id(entity.getId())
Expand Down

0 comments on commit 18e6f7a

Please sign in to comment.