-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAdminAmateurShowService.java
More file actions
72 lines (54 loc) · 2.8 KB
/
AdminAmateurShowService.java
File metadata and controls
72 lines (54 loc) · 2.8 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
package cc.backend.admin.amateurShow.service;
import cc.backend.admin.amateurShow.dto.AdminAmateurShowListResponseDTO;
import cc.backend.admin.amateurShow.dto.AdminAmateurShowReviseRequestDTO;
import cc.backend.admin.amateurShow.dto.AdminAmateurShowSummaryResponseDTO;
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 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 AdminAmateurShowService {
private final AmateurShowRepository amateurShowRepository;
private final ApplicationEventPublisher eventPublisher;
public Slice<AdminAmateurShowListResponseDTO> getShowList(int page, int size, String keyword){
Pageable pageable = PageRequest.of(page, size, Sort.by("id").ascending());
Page<AmateurShow> pageResult;
if (keyword != null && !keyword.isBlank()) {
pageResult = amateurShowRepository.findByNameContainingIgnoreCase(keyword, pageable);
} else {
pageResult = amateurShowRepository.findAll(pageable);
}
List<AdminAmateurShowListResponseDTO> rows = pageResult.getContent().stream()
.map(this::toListDto)
.toList();
return new SliceImpl<>(rows, pageable, pageResult.hasNext());
}
private AdminAmateurShowListResponseDTO toListDto(AmateurShow show){
return AdminAmateurShowListResponseDTO.builder()
.showId(show.getId())
.showName(show.getName())
.createdAt(show.getCreatedAt())
.performerName(show.getPerformerName())
.amateurShowStatus(show.getStatus().toString()).build();
}
public AdminAmateurShowSummaryResponseDTO getShowSummary(Long showId) {
AmateurShow show = amateurShowRepository.findById(showId)
.orElseThrow(() -> new GeneralException(ErrorStatus.AMATEURSHOW_NOT_FOUND));
return AdminAmateurShowSummaryResponseDTO.from(show);
}
@Transactional
public AdminAmateurShowSummaryResponseDTO reviseShow(Long showId, AdminAmateurShowReviseRequestDTO dto) {
AmateurShow show = amateurShowRepository.findById(showId)
.orElseThrow(() -> new GeneralException(ErrorStatus.AMATEURSHOW_NOT_FOUND));
show.reviseShowInfo(dto.getHashtag(), dto.getSummary(), dto.getAccount(), dto.getContact());
return AdminAmateurShowSummaryResponseDTO.from(show);
}
}