-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAdminApprovalService.java
More file actions
94 lines (73 loc) · 3.56 KB
/
AdminApprovalService.java
File metadata and controls
94 lines (73 loc) · 3.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package cc.backend.admin.amateurShow.service;
import cc.backend.admin.amateurShow.dto.AdminAmateurShowRejectRequestDTO;
import cc.backend.admin.amateurShow.dto.AdminAmateurShowSummaryResponseDTO;
import cc.backend.admin.amateurShow.dto.AdminApprovalListResponseDTO;
import cc.backend.amateurShow.entity.AmateurShow;
import cc.backend.amateurShow.repository.AmateurShowRepository;
import cc.backend.apiPayLoad.code.status.ErrorStatus;
import cc.backend.apiPayLoad.exception.GeneralException;
import cc.backend.member.entity.Member;
import cc.backend.notice.event.ApproveCommitEvent;
import cc.backend.notice.event.RejectCommitEvent;
import lombok.RequiredArgsConstructor;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.data.domain.*;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class AdminApprovalService {
private final AmateurShowRepository amateurShowRepository;
private final ApplicationEventPublisher eventPublisher;
@Transactional
public AdminAmateurShowSummaryResponseDTO approveShow(Long showId) {
AmateurShow show = amateurShowRepository.findById(showId)
.orElseThrow(() -> new GeneralException(ErrorStatus.AMATEURSHOW_NOT_FOUND));
show.approve();
Member performer = show.getMember();
// 등록 승인 트랜잭션 커밋에 대해 이벤트 발행
eventPublisher.publishEvent(
new ApproveCommitEvent(show.getId(), performer.getId()
)
);
return AdminAmateurShowSummaryResponseDTO.from(show);
}
@Transactional
public AdminAmateurShowSummaryResponseDTO rejectShow(Long showId, AdminAmateurShowRejectRequestDTO dto) {
AmateurShow show = amateurShowRepository.findById(showId)
.orElseThrow(() -> new GeneralException(ErrorStatus.AMATEURSHOW_NOT_FOUND));
show.reject(dto.getRejectReason());
Member member = show.getMember();
// 등록 거부 커밋 트랜잭션 이벤트 발행
eventPublisher.publishEvent(
new RejectCommitEvent(show.getId(), member.getId(), show.getRejectReason()
)
);
return AdminAmateurShowSummaryResponseDTO.from(show);
}
public Slice<AdminApprovalListResponseDTO> getApprovalList(int page, int size, String keyword) {
Pageable pageable = PageRequest.of(page, size, Sort.by("id").ascending());
Page<AmateurShow> pageResult =
(keyword != null && !keyword.isBlank())
? amateurShowRepository.findByNameContainingIgnoreCase(keyword, pageable)
: amateurShowRepository.findAll(pageable);
List<AdminApprovalListResponseDTO> content = pageResult.getContent().stream()
.map(this::toApprovalDto)
.toList();
return new SliceImpl<>(content, pageable, pageResult.hasNext());
}
private AdminApprovalListResponseDTO toApprovalDto(AmateurShow show) {
Member registrant = show.getMember();
return AdminApprovalListResponseDTO.builder()
.showId(show.getId())
.username(registrant.getUsername())
.memberName(registrant.getName())
.email(registrant.getEmail())
.phone(registrant.getPhone())
.showName(show.getName())
.approvalStatus(show.getApprovalStatus().name())
.build();
}
}