Skip to content

Commit

Permalink
Merge pull request #45 from TEAM-DHS/feat/program
Browse files Browse the repository at this point in the history
[FEAT] 신청자 리스트 조회 API
  • Loading branch information
xyzwv authored Nov 23, 2023
2 parents 3dcef66 + 6a53e05 commit dddcc4d
Show file tree
Hide file tree
Showing 10 changed files with 160 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.efub.dhs.domain.member.service;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.efub.dhs.domain.member.entity.Member;
import com.efub.dhs.domain.member.repository.MemberRepository;
import com.efub.dhs.global.utils.SecurityUtils;

import lombok.RequiredArgsConstructor;

@Service
@Transactional
@RequiredArgsConstructor
public class MemberService {
private final MemberRepository memberRepository;

public Member getCurrentUser() {
String username = SecurityUtils.getCurrentUsername();
return memberRepository.findByUsername(username)
.orElseThrow(() -> new IllegalArgumentException("해당 아이디의 회원을 찾을 수 없습니다."));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@
import com.efub.dhs.domain.program.dto.response.ProgramCreationResponseDto;
import com.efub.dhs.domain.program.dto.response.ProgramDetailResponseDto;
import com.efub.dhs.domain.program.dto.response.ProgramListResponseDto;
import com.efub.dhs.domain.program.dto.response.ProgramRegisteredResponseDto;
import com.efub.dhs.domain.program.dto.response.ProgramOutlineResponseDto;
import com.efub.dhs.domain.program.dto.response.ProgramRegisteredResponseDto;
import com.efub.dhs.domain.program.dto.response.ProgramRegistrationResponseDto;
import com.efub.dhs.domain.program.entity.Program;
import com.efub.dhs.domain.program.service.ProgramMemberService;
import com.efub.dhs.domain.program.service.ProgramService;
import com.efub.dhs.domain.registration.dto.RegistrationResponseDto;
import com.efub.dhs.domain.registration.entity.Registration;
import com.efub.dhs.domain.registration.service.RegistrationService;

import lombok.RequiredArgsConstructor;

Expand All @@ -36,6 +39,7 @@ public class ProgramController {

private final ProgramService programService;
private final ProgramMemberService programMemberService;
private final RegistrationService registrationService;

@GetMapping("/{programId}")
@ResponseStatus(value = HttpStatus.OK)
Expand Down Expand Up @@ -70,8 +74,8 @@ public ProgramListResponseDto findProgramLiked(@RequestParam int page) {
@GetMapping("/registered")
public ProgramRegisteredResponseDto findProgramRegistered(@RequestParam int page) {
return programMemberService.findProgramRegistered(page);
}
}

@GetMapping
public ProgramListResponseDto findProgramList(@RequestParam int page, ProgramListRequestDto requestDto) {
return programService.findProgramList(page, requestDto);
Expand All @@ -81,4 +85,10 @@ public ProgramListResponseDto findProgramList(@RequestParam int page, ProgramLis
public List<ProgramOutlineResponseDto> findProgramPopular() {
return programService.findProgramPopular();
}

@GetMapping("/{programId}/registrations")
public List<RegistrationResponseDto> findRegistratorList(@PathVariable Long programId) {
Program program = programService.getProgram(programId);
return registrationService.findRegistratorList(program);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import com.efub.dhs.domain.heart.service.HeartService;
import com.efub.dhs.domain.member.entity.Member;
import com.efub.dhs.domain.member.service.MemberService;
import com.efub.dhs.domain.program.dto.PageInfoDto;
import com.efub.dhs.domain.program.dto.response.ProgramListResponseDto;
import com.efub.dhs.domain.program.dto.response.ProgramOutlineResponseDto;
Expand All @@ -33,10 +34,11 @@ public class ProgramMemberService {
private final RegistrationRepository registrationRepository;
private final ProgramService programService;
private final HeartService heartService;
private final MemberService memberService;

@Transactional(readOnly = true)
public ProgramListResponseDto findProgramCreated(int page) {
Member currentUser = programService.getCurrentUser();
Member currentUser = memberService.getCurrentUser();
Page<Program> programPage = programRepository.findAllByHost(currentUser, PageRequest.of(page, PAGE_SIZE));
PageInfoDto pageInfoDto = PageInfoDto.createProgramPageInfoDto(programPage);
List<ProgramOutlineResponseDto> programOutlineResponseDtoList =
Expand All @@ -46,7 +48,7 @@ public ProgramListResponseDto findProgramCreated(int page) {

@Transactional(readOnly = true)
public ProgramListResponseDto findProgramLiked(int page) {
Member currentUser = programService.getCurrentUser();
Member currentUser = memberService.getCurrentUser();
Page<Program> programPage = programRepository.findAllProgramLiked(currentUser, PageRequest.of(page, PAGE_SIZE));
PageInfoDto pageInfoDto = PageInfoDto.createProgramPageInfoDto(programPage);
List<ProgramOutlineResponseDto> programOutlineResponseDtoList =
Expand All @@ -56,7 +58,7 @@ public ProgramListResponseDto findProgramLiked(int page) {

@Transactional(readOnly = true)
public ProgramRegisteredResponseDto findProgramRegistered(int page) {
Member currentUser = programService.getCurrentUser();
Member currentUser = memberService.getCurrentUser();
Page<Registration> registrationPage = registrationRepository.findRegisteredPrograms(
currentUser, PageRequest.of(page, PAGE_SIZE));
PageInfoDto pageInfoDto = PageInfoDto.createRegistrationPageInfoDto(registrationPage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import com.efub.dhs.domain.heart.service.HeartService;
import com.efub.dhs.domain.member.entity.Member;
import com.efub.dhs.domain.member.repository.MemberRepository;
import com.efub.dhs.domain.member.service.MemberService;
import com.efub.dhs.domain.program.dto.GoalDto;
import com.efub.dhs.domain.program.dto.HostDto;
import com.efub.dhs.domain.program.dto.ImageDto;
Expand All @@ -34,7 +34,6 @@
import com.efub.dhs.domain.program.repository.ProgramRepository;
import com.efub.dhs.domain.registration.entity.Registration;
import com.efub.dhs.domain.registration.service.RegistrationService;
import com.efub.dhs.global.utils.SecurityUtils;

import lombok.RequiredArgsConstructor;

Expand All @@ -48,17 +47,11 @@ public class ProgramService {
private final ProgramRepository programRepository;
private final ProgramImageRepository programImageRepository;
private final NoticeRepository noticeRepository;
private final MemberRepository memberRepository;
private final MemberService memberService;
private final HeartService heartService;
private final RegistrationService registrationService;

public Member getCurrentUser() {
String username = SecurityUtils.getCurrentUsername();
return memberRepository.findByUsername(username)
.orElseThrow(() -> new IllegalArgumentException("해당 아이디의 회원을 찾을 수 없습니다."));
}

private Program getProgram(Long programId) {
public Program getProgram(Long programId) {
return programRepository.findById(programId)
.orElseThrow(() -> new IllegalArgumentException("해당 ID의 행사를 찾을 수 없습니다."));
}
Expand All @@ -67,7 +60,7 @@ private Program getProgram(Long programId) {
public ProgramDetailResponseDto findProgramById(Long programId) {
Program program = getProgram(programId);

Member currentUser = getCurrentUser();
Member currentUser = memberService.getCurrentUser();

Integer remainingDays = calculateRemainingDays(program.getDeadline());

Expand Down Expand Up @@ -136,7 +129,7 @@ public List<ProgramOutlineResponseDto> convertToProgramOutlineResponseDtoList(
}

public Long createProgram(ProgramCreationRequestDto requestDto) {
Member currentUser = getCurrentUser();
Member currentUser = memberService.getCurrentUser();
Program program = requestDto.toEntity(currentUser);
Long programId = programRepository.save(program).getProgramId();
List<ProgramImage> images = program.getImages();
Expand All @@ -145,14 +138,14 @@ public Long createProgram(ProgramCreationRequestDto requestDto) {
}

public Registration registerProgram(Long programId, ProgramRegistrationRequestDto requestDto) {
Member currentUser = getCurrentUser();
Member currentUser = memberService.getCurrentUser();
Program program = getProgram(programId);
Registration registration = requestDto.toEntity(currentUser, program);
return registrationService.saveRegistration(registration);
}

public ProgramListResponseDto findProgramList(int page, ProgramListRequestDto requestDto) {
Member currentUser = getCurrentUser();
Member currentUser = memberService.getCurrentUser();
Page<Program> programPage = programRepository.findProgramListByFilter(requestDto,
PageRequest.of(page, PAGE_SIZE));
PageInfoDto pageInfoDto = PageInfoDto.createProgramPageInfoDto(programPage);
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/com/efub/dhs/domain/registration/dto/PaymentDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.efub.dhs.domain.registration.dto;

import java.time.LocalDateTime;

import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class PaymentDto {

private Boolean check;
private String name;
private LocalDateTime date;
private String price;

public PaymentDto(Boolean check, String name, LocalDateTime date, String price) {
this.check = check;
this.name = name;
this.date = date;
this.price = price;
}
}
24 changes: 24 additions & 0 deletions src/main/java/com/efub/dhs/domain/registration/dto/RefundDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.efub.dhs.domain.registration.dto;

import com.efub.dhs.domain.registration.entity.RefundStatus;

import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class RefundDto {

private String status;
private String bank;
private String account;
private String name;

public RefundDto(RefundStatus refundStatus, String bank, String account, String name) {
this.status = RefundStatus.to(refundStatus);
this.bank = bank;
this.account = account;
this.name = name;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.efub.dhs.domain.registration.dto;

import com.efub.dhs.domain.registration.entity.Registration;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor(access = AccessLevel.PROTECTED)
public class RegistrationResponseDto {

private String name;
private String phone;
private PaymentDto payment;
private RefundDto refund;

public static RegistrationResponseDto from(Registration registration) {
return new RegistrationResponseDto(
registration.getRegistrantName(),
registration.getRegistrantPhone(),
new PaymentDto(registration.getDepositCheck(), registration.getDepositName(),
registration.getDepositDate(), registration.getDepositAmount()),
new RefundDto(registration.getRefundStatus(), registration.getRefundBank(),
registration.getRefundAccount(), registration.getRefundName())
);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.efub.dhs.domain.registration.entity;

import java.util.Arrays;

import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
Expand All @@ -9,4 +11,15 @@ public enum RefundStatus {
COMPLETED("환불완료");

private final String name;

public static RefundStatus from(String name) {
return Arrays.stream(RefundStatus.values())
.filter(refundStatus -> refundStatus.name.equals(name))
.findFirst()
.orElseThrow(() -> new IllegalArgumentException("Invalid RefundStatus name: " + name));
}

public static String to(RefundStatus refundStatus) {
return refundStatus.name;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.efub.dhs.domain.registration.repository;

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
Expand All @@ -15,4 +17,6 @@ public interface RegistrationRepository extends JpaRepository<Registration, Long

@Query(value = "select r from Registration r join fetch Program p on r.program=p where r.member=?1")
Page<Registration> findRegisteredPrograms(Member registrant, Pageable pageable);

List<Registration> findAllByProgram(Program program);
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
package com.efub.dhs.domain.registration.service;

import java.util.List;
import java.util.stream.Collectors;

import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.server.ResponseStatusException;

import com.efub.dhs.domain.member.entity.Member;
import com.efub.dhs.domain.member.service.MemberService;
import com.efub.dhs.domain.program.entity.Program;
import com.efub.dhs.domain.registration.dto.RegistrationResponseDto;
import com.efub.dhs.domain.registration.entity.Registration;
import com.efub.dhs.domain.registration.repository.RegistrationRepository;

Expand All @@ -16,6 +23,7 @@
public class RegistrationService {

private final RegistrationRepository registrationRepository;
private final MemberService memberService;

@Transactional(readOnly = true)
public Boolean existsByMemberAndProgram(Member member, Program program) {
Expand All @@ -26,4 +34,15 @@ public Boolean existsByMemberAndProgram(Member member, Program program) {
public Registration saveRegistration(Registration registration) {
return registrationRepository.save(registration);
}

@Transactional(readOnly = true)
public List<RegistrationResponseDto> findRegistratorList(Program program) {
Member member = memberService.getCurrentUser();
if (member.equals(program.getHost())) {
List<Registration> registrationList = registrationRepository.findAllByProgram(program);
return registrationList.stream().map(RegistrationResponseDto::from).collect(Collectors.toList());
} else {
throw new ResponseStatusException(HttpStatus.FORBIDDEN);
}
}
}

0 comments on commit dddcc4d

Please sign in to comment.