Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BE / refactor] 프로그램 생성시 10개의 Detail 생성 #40

Merged
merged 4 commits into from
Nov 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
@AllArgsConstructor
@NoArgsConstructor
public class MetricsUpdateRequestDTO {
private String userId;
private String patient_id;
private Long pno;
private Long vno;
private int ord;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@

public interface ProgramRepository extends JpaRepository<Program, Long> {

@Query("SELECT p from Program p where p.patient.mid = :userId")
Optional<Program> findByUserId(@Param("userId") String userId);
@Query("SELECT p from Program p where p.patient.mid = :patient_id")
Optional<Program> findByPatientId(@Param("patient_id") String patient_id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
@Service
@Transactional
@RequiredArgsConstructor
public class ProgramServiceImpl implements ProgramService{
public class ProgramServiceImpl implements ProgramService {
private final StaffRepository staffRepository;
private final PatientRepository patientRepository;
private final VideoRepository videoRepository;
Expand All @@ -35,32 +35,26 @@ public class ProgramServiceImpl implements ProgramService{
@Override
public String createProgramAndDetail(ProgramRequestDTO requestDTO) {
String adminId = requestDTO.getStaff_id();
String userId = requestDTO.getPatient_id();
String patient_id = requestDTO.getPatient_id();

Staff staff = staffRepository.findById(adminId)
.orElseThrow(() -> new NotFoundException("not found admin for Id : " + adminId));
Patient patient = patientRepository.findById(userId)
.orElseThrow(() -> new NotFoundException("not found user for Id : " + userId));
Patient patient = patientRepository.findById(patient_id)
.orElseThrow(() -> new NotFoundException("not found user for Id : " + patient_id));

Program program = Program.builder()
.staff(staff)
.patient(patient)
.description(requestDTO.getDescription())
.description("")
.build();

Program savedProgram = programRepository.save(program);

for (Map.Entry<Integer, Long> entry : requestDTO.getOrd_map().entrySet()) {
int ord = entry.getKey();
Long vno = entry.getValue();

Video video = videoRepository.findById(vno)
.orElseThrow(() -> new RuntimeException("Video not found for Id : " + vno));

for (int i = 1; i <= 10; i++) {
ProgramDetail programDetail = ProgramDetail.builder()
.program(savedProgram)
.video(video)
.ord(ord)
.video(null)
.ord(i)
.build();

VideoMetrics videoMetrics = VideoMetrics.builder()
Expand All @@ -80,13 +74,12 @@ public String createProgramAndDetail(ProgramRequestDTO requestDTO) {
@Override
public String updateProgramAndDetail(ProgramRequestDTO requestDTO, String patient_id) {
String adminId = requestDTO.getStaff_id();
String userId = requestDTO.getPatient_id();

staffRepository.findById(adminId)
.orElseThrow(() -> new NotFoundException("not found admin for adminId : " + adminId));
patientRepository.findById(userId)
.orElseThrow(() -> new NotFoundException("not found user for userId : " + userId));
Program program = programRepository.findByUserId(patient_id)
patientRepository.findById(patient_id)
.orElseThrow(() -> new NotFoundException("not found user for patient_id : " + patient_id));
Program program = programRepository.findByPatientId(patient_id)
.orElseThrow(() -> new NotFoundException("not found for patient_id : " + patient_id));

program.changeDescription(requestDTO.getDescription()); // change description
Expand All @@ -112,14 +105,14 @@ public String updateProgramAndDetail(ProgramRequestDTO requestDTO, String patien

@Override
public String updateMetrics(MetricsUpdateRequestDTO metricsUpdateRequestDTO) {
String userId = metricsUpdateRequestDTO.getUserId();
String patient_id = metricsUpdateRequestDTO.getPatient_id();
Long pno = metricsUpdateRequestDTO.getPno();
Long vno = metricsUpdateRequestDTO.getVno();
int ord = metricsUpdateRequestDTO.getOrd();
double metrics = metricsUpdateRequestDTO.getMetrics();

patientRepository.findById(userId)
.orElseThrow(() -> new NotFoundException("not found user for Id : " + userId));
patientRepository.findById(patient_id)
.orElseThrow(() -> new NotFoundException("not found user for Id : " + patient_id));

programRepository.findById(pno)
.orElseThrow(() -> new NotFoundException("not found for Id : " + pno));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
public class VideoController {
private final VideoService videoService;

@GetMapping("/list/{userId}")
@GetMapping("/list/{patient_id}")
public Pair<String, VideoPageResponseDTO<ProgramResponseDTO>> getListByUser(VideoPageRequestDTO pageRequestDTO,
@PathVariable("userId") String userId) {
return videoService.getVideoListByUser(pageRequestDTO, userId);
@PathVariable("patient_id") String patient_id) {
return videoService.getVideoListByUser(pageRequestDTO, patient_id);
}

@GetMapping("/list")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public interface VideoService {
VideoPageResponseDTO<VideoResponseDTO> getVideoListByAdmin(VideoPageRequestDTO requestDTO);

Pair<String, VideoPageResponseDTO<ProgramResponseDTO>> getVideoListByUser(VideoPageRequestDTO requestDTO,
String userId);
String patient_id);

VideoDetailResponseDTO getVideo(Long vno);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ public VideoPageResponseDTO<VideoResponseDTO> getVideoListByAdmin(VideoPageReque

@Override
public Pair<String, VideoPageResponseDTO<ProgramResponseDTO>> getVideoListByUser(VideoPageRequestDTO requestDTO,
String userId) {
Program program = programRepository.findByUserId(userId)
.orElseThrow(() -> new NotFoundException("not found program for userId : " + userId));
String patient_id) {
Program program = programRepository.findByPatientId(patient_id)
.orElseThrow(() -> new NotFoundException("not found program for patient_id : " + patient_id));

Pageable pageable = requestDTO.getPageable();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,23 +93,9 @@ void setUp() {
@Test
@Rollback(value = false)
void createProgramAndDetail() {
Map<Integer, Long> ord_map = new HashMap<>();
ord_map.put(1, 10L);
ord_map.put(2, 10L);
ord_map.put(3, 3L);
ord_map.put(4, 3L);
ord_map.put(5, 1L);
ord_map.put(6, 1L);
ord_map.put(7, 3L);
ord_map.put(8, 6L);
ord_map.put(9, 6L);
ord_map.put(10, 9L);

ProgramRequestDTO programRequestDTO = ProgramRequestDTO.builder()
.staff_id("ldh")
.patient_id("jyp")
.description("몸이 아프다구요!")
.ord_map(ord_map)
.build();

String result = programService.createProgramAndDetail(programRequestDTO);
Expand All @@ -120,10 +106,10 @@ void createProgramAndDetail() {
@Rollback(value = false)
void updateMetrics() {
MetricsUpdateRequestDTO requestDTO = MetricsUpdateRequestDTO.builder()
.userId(patient.getMid())
.patient_id(patient.getMid())
.pno(1L)
.vno(3L)
.ord(7)
.ord(2)
.metrics(83.2)
.build();

Expand Down
Loading