Skip to content

Commit

Permalink
Merge branch 'feature/duplicate-update' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeongh00 committed Feb 10, 2024
2 parents 1e37600 + 7c2479d commit f131bea
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,11 @@ public ApplicationResponse<Long> attendVote(Long voteItemId) {
/**
* 투표 마감 처리
*/
@PutMapping("/finished")
public ApplicationResponse<Void> voteFinished(Long voteId) {

voteSaveUseCase.finishVote(voteId);
return ApplicationResponse.ok(null, "투표 마감 처리되었습니다.");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -23,6 +24,7 @@

@Service
@RequiredArgsConstructor
@Transactional
public class VoteSaveUseCase {

private final MemberUtils memberUtils;
Expand All @@ -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());
Expand All @@ -44,6 +45,7 @@ public Long saveVote(VoteRequest voteRequest) {
Vote vote = Vote.builder()
.voteTitle(voteEntity.getVoteTitle())
.notice(notice)
.status(VoteStatus.PRESENT)
.build();

// Vote 엔티티 저장
Expand All @@ -63,7 +65,6 @@ public Long saveVote(VoteRequest voteRequest) {
return vote.getId();
}

@Transactional
public Long attendVote(Long voteItemId) {

Member memberRequest = memberUtils.getAccessMember();
Expand All @@ -82,4 +83,9 @@ public Long attendVote(Long voteItemId) {
return voteItemRecord.getId();
}

public void finishVote(Long voteId) {

voteSaveService.finishVote(voteId);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.koa.coremodule.vote.domain.entity;

public enum VoteStatus {
PRESENT, FINISHED
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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();
}

}

0 comments on commit f131bea

Please sign in to comment.