From 7c2479d8c0a975c17b726dc05e278edcaf00cebc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=95=88=EC=A0=95=ED=9B=84?= Date: Sat, 10 Feb 2024 11:41:43 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=ED=88=AC=ED=91=9C=20=EB=A7=88=EA=B0=90?= =?UTF-8?q?=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/koa/apimodule/command/api/VoteController.java | 6 ++++++ .../vote/application/service/VoteSaveUseCase.java | 10 ++++++++-- .../com/koa/coremodule/vote/domain/entity/Vote.java | 5 +++++ .../koa/coremodule/vote/domain/entity/VoteStatus.java | 5 +++++ .../vote/domain/service/VoteSaveService.java | 8 ++++++++ 5 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 core-module/src/main/java/com/koa/coremodule/vote/domain/entity/VoteStatus.java diff --git a/api-module/src/main/java/com/koa/apimodule/command/api/VoteController.java b/api-module/src/main/java/com/koa/apimodule/command/api/VoteController.java index cd30e7cf..ab58fe1c 100644 --- a/api-module/src/main/java/com/koa/apimodule/command/api/VoteController.java +++ b/api-module/src/main/java/com/koa/apimodule/command/api/VoteController.java @@ -51,5 +51,11 @@ public ApplicationResponse attendVote(Long voteItemId) { /** * 투표 마감 처리 */ + @PutMapping("/finished") + public ApplicationResponse voteFinished(Long voteId) { + + voteSaveUseCase.finishVote(voteId); + return ApplicationResponse.ok(null, "투표 마감 처리되었습니다."); + } } diff --git a/core-module/src/main/java/com/koa/coremodule/vote/application/service/VoteSaveUseCase.java b/core-module/src/main/java/com/koa/coremodule/vote/application/service/VoteSaveUseCase.java index 51f0e023..d2763628 100644 --- a/core-module/src/main/java/com/koa/coremodule/vote/application/service/VoteSaveUseCase.java +++ b/core-module/src/main/java/com/koa/coremodule/vote/application/service/VoteSaveUseCase.java @@ -12,6 +12,7 @@ import com.koa.coremodule.vote.domain.entity.Vote; import com.koa.coremodule.vote.domain.entity.VoteItem; import com.koa.coremodule.vote.domain.entity.VoteItemRecord; +import com.koa.coremodule.vote.domain.entity.VoteStatus; import com.koa.coremodule.vote.domain.exception.VoteException; import com.koa.coremodule.vote.domain.service.VoteQueryService; import com.koa.coremodule.vote.domain.service.VoteSaveService; @@ -23,6 +24,7 @@ @Service @RequiredArgsConstructor +@Transactional public class VoteSaveUseCase { private final MemberUtils memberUtils; @@ -32,7 +34,6 @@ public class VoteSaveUseCase { private final MemberQueryService memberQueryService; private final VoteMapper voteMapper; - @Transactional public Long saveVote(VoteRequest voteRequest) { // 투표 제목 저장 Vote voteEntity = voteMapper.toVoteEntity(voteRequest.title()); @@ -44,6 +45,7 @@ public Long saveVote(VoteRequest voteRequest) { Vote vote = Vote.builder() .voteTitle(voteEntity.getVoteTitle()) .notice(notice) + .status(VoteStatus.PRESENT) .build(); // Vote 엔티티 저장 @@ -63,7 +65,6 @@ public Long saveVote(VoteRequest voteRequest) { return vote.getId(); } - @Transactional public Long attendVote(Long voteItemId) { Member memberRequest = memberUtils.getAccessMember(); @@ -82,4 +83,9 @@ public Long attendVote(Long voteItemId) { return voteItemRecord.getId(); } + public void finishVote(Long voteId) { + + voteSaveService.finishVote(voteId); + } + } diff --git a/core-module/src/main/java/com/koa/coremodule/vote/domain/entity/Vote.java b/core-module/src/main/java/com/koa/coremodule/vote/domain/entity/Vote.java index ec8e69ab..4fbed2bf 100644 --- a/core-module/src/main/java/com/koa/coremodule/vote/domain/entity/Vote.java +++ b/core-module/src/main/java/com/koa/coremodule/vote/domain/entity/Vote.java @@ -18,9 +18,14 @@ public class Vote extends BaseEntity { private Long id; private String voteTitle; + private VoteStatus status; @OneToOne(fetch = FetchType.LAZY) @JoinColumn(name = "notice_id") private Notice notice; + public void updateStatus() { + this.status = VoteStatus.FINISHED; + } + } diff --git a/core-module/src/main/java/com/koa/coremodule/vote/domain/entity/VoteStatus.java b/core-module/src/main/java/com/koa/coremodule/vote/domain/entity/VoteStatus.java new file mode 100644 index 00000000..b9794932 --- /dev/null +++ b/core-module/src/main/java/com/koa/coremodule/vote/domain/entity/VoteStatus.java @@ -0,0 +1,5 @@ +package com.koa.coremodule.vote.domain.entity; + +public enum VoteStatus { + PRESENT, FINISHED +} diff --git a/core-module/src/main/java/com/koa/coremodule/vote/domain/service/VoteSaveService.java b/core-module/src/main/java/com/koa/coremodule/vote/domain/service/VoteSaveService.java index 0ed10d34..d5d2aec2 100644 --- a/core-module/src/main/java/com/koa/coremodule/vote/domain/service/VoteSaveService.java +++ b/core-module/src/main/java/com/koa/coremodule/vote/domain/service/VoteSaveService.java @@ -1,8 +1,10 @@ package com.koa.coremodule.vote.domain.service; +import com.koa.commonmodule.exception.Error; import com.koa.coremodule.vote.domain.entity.Vote; import com.koa.coremodule.vote.domain.entity.VoteItem; import com.koa.coremodule.vote.domain.entity.VoteItemRecord; +import com.koa.coremodule.vote.domain.exception.VoteException; import com.koa.coremodule.vote.domain.repository.VoteItemRepository; import com.koa.coremodule.vote.domain.repository.VoteRecordRepository; import com.koa.coremodule.vote.domain.repository.VoteRepository; @@ -31,4 +33,10 @@ public VoteItemRecord saveVoteRecord(VoteItemRecord voteItemRecord) { return voteRecordRepository.save(voteItemRecord); } + public void finishVote(Long voteId) { + + Vote vote = voteRepository.findById(voteId).orElseThrow(() -> new VoteException(Error.VOTE_NOT_FOUND)); + vote.updateStatus(); + } + }