Skip to content

Commit

Permalink
Merge pull request #138 from Team-B1ND/Feat/#137
Browse files Browse the repository at this point in the history
Feat/#137
  • Loading branch information
GayeongKimm authored Nov 18, 2024
2 parents b2f4153 + 5a7732e commit 631ce02
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
.requestMatchers(GET, "/member/my").authenticated()
.requestMatchers(GET, "/member/check/broadcast-club-member").hasAnyRole(STUDENT, ADMIN)
.requestMatchers(GET, "/member/**").hasAnyRole(TEACHER, ADMIN)
.requestMatchers(PATCH, "/member/student/info/**").hasAnyRole(TEACHER, ADMIN)
.requestMatchers(PATCH, "/member/student/info/**").hasAnyRole(STUDENT, ADMIN)
.requestMatchers(PATCH, "/member/teacher/info/**").hasAnyRole(TEACHER, ADMIN)
.requestMatchers(PATCH, "/member/status/**").hasRole(ADMIN)
.requestMatchers(PATCH, "/member/active/**").hasRole(ADMIN)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;

@Service
@RequiredArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import b1nd.dodam.restapi.member.application.data.res.MemberInfoRes;
import b1nd.dodam.restapi.support.data.ResponseData;
import lombok.RequiredArgsConstructor;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

Expand Down Expand Up @@ -60,7 +59,9 @@ private MemberInfoRes getMemberInfo(Member member) {
}

public ResponseData<List<MemberInfoRes>> getAll(){
return ResponseData.ok("모든 멤버 정보 조회 성공", memberRepository.findByStatusOrderByStudent(ActiveStatus.ACTIVE).parallelStream()
return ResponseData.ok("모든 멤버 정보 조회 성공",
memberRepository.findByStatusOrderByStudent(ActiveStatus.ACTIVE)
.parallelStream()
.map(this::getMemberInfo)
.toList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
import b1nd.dodam.core.util.ZonedDateTimeUtil;
import b1nd.dodam.domain.rds.member.entity.Member;
import b1nd.dodam.domain.rds.member.entity.Student;
import b1nd.dodam.domain.rds.member.enumeration.ActiveStatus;
import b1nd.dodam.domain.rds.member.repository.StudentRepository;
import b1nd.dodam.domain.rds.member.repository.TeacherRepository;
import b1nd.dodam.domain.rds.outsleeping.entity.OutSleeping;
import b1nd.dodam.domain.rds.outsleeping.exception.NotOutSleepingApplicantException;
import b1nd.dodam.domain.rds.outsleeping.service.OutSleepingService;
import b1nd.dodam.domain.rds.support.enumeration.ApprovalStatus;
import b1nd.dodam.restapi.auth.infrastructure.security.support.MemberAuthenticationHolder;
import b1nd.dodam.restapi.member.application.data.res.MemberInfoRes;
import b1nd.dodam.restapi.outsleeping.application.data.req.ApplyOutSleepingReq;
import b1nd.dodam.restapi.outsleeping.application.data.req.RejectOutSleepingReq;
import b1nd.dodam.restapi.outsleeping.application.data.res.OutSleepingRes;
Expand Down Expand Up @@ -84,6 +86,23 @@ public ResponseData<List<OutSleepingRes>> getValid() {
return ResponseData.ok("유효한 외박 조회 성공", OutSleepingRes.of(outSleepingService.getValid(now)));
}

@Transactional(readOnly = true)
public ResponseData<List<MemberInfoRes>> getRemainder() {
LocalDate now = ZonedDateTimeUtil.nowToLocalDate();

List<Student> studentList = studentRepository.findAllByIdNotIn(
outSleepingService.getValid(now)
.stream()
.map(OutSleeping::getStudent)
.map(Student::getId)
.toList(), ActiveStatus.ACTIVE);

return ResponseData.ok("잔류 학생 조회 성공", studentList
.stream()
.map(student -> MemberInfoRes.of(student.getMember(), student, null))
.toList());
}

@Transactional(readOnly = true)
public ResponseData<List<OutSleepingRes>> getByEndAt(LocalDate endAt){
return ResponseData.ok("종료일 기준 외박 조회 성공", OutSleepingRes.of(outSleepingService.getByEndAt(endAt)));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package b1nd.dodam.restapi.outsleeping.presentation;

import b1nd.dodam.restapi.member.application.data.res.MemberInfoRes;
import b1nd.dodam.restapi.outsleeping.application.OutSleepingUseCase;
import b1nd.dodam.restapi.outsleeping.application.data.req.ApplyOutSleepingReq;
import b1nd.dodam.restapi.outsleeping.application.data.req.RejectOutSleepingReq;
Expand Down Expand Up @@ -61,4 +62,9 @@ public ResponseData<List<OutSleepingRes>> getValid() {
return useCase.getValid();
}

@GetMapping("/residual")
public ResponseData<List<MemberInfoRes>> getResidual() {
return useCase.getRemainder();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;


import java.util.List;
import java.util.Optional;

Expand Down Expand Up @@ -47,4 +46,8 @@ default List<Student> getByIds(List<Integer> ids) {

@Query("SELECT m FROM student s JOIN s.member m WHERE s.grade = :grade")
List<Member> findMembersByGrade(@Param("grade") int grade);

@Query("SELECT s FROM student s WHERE s.id NOT IN :ids AND s.member.status = :activeStatus")
List<Student> findAllByIdNotIn(@Param("ids") List<Integer> ids, @Param("activeStatus") ActiveStatus activeStatus);

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import b1nd.dodam.domain.rds.member.entity.Student;
import b1nd.dodam.domain.rds.outsleeping.entity.OutSleeping;
import b1nd.dodam.domain.rds.outsleeping.exception.OutSleepingNotFoundException;
import b1nd.dodam.domain.rds.support.enumeration.ApprovalStatus;
import org.springframework.data.jpa.repository.EntityGraph;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
Expand All @@ -19,11 +20,12 @@ default OutSleeping getById(Long id) {
}

@EntityGraph(attributePaths = {"student.member"})
@Query("select o from OutSleeping o where :date between o.startAt and o.endAt " +
@Query("select o from OutSleeping o " +
"where :date between o.startAt and o.endAt " +
"and o.endAt > :date " +
"and o.status = 'ALLOWED' " +
"and o.status = :approvalStatus " +
"order by o.student.grade, o.student.room, o.student.number")
List<OutSleeping> findByDate(@Param("date") LocalDate date);
List<OutSleeping> findByDate(@Param("date") LocalDate date, @Param("approvalStatus") ApprovalStatus approvalStatus);

@EntityGraph(attributePaths = {"student.member"})
List<OutSleeping> findByEndAtGreaterThanEqual(LocalDate endAt);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ public OutSleeping getById(Long id) {
}

public List<OutSleeping> getValid(LocalDate now) {
return getByDate(now).parallelStream().toList();
return getByDate(now, ApprovalStatus.ALLOWED).parallelStream().toList();
}

public List<OutSleeping> getByDate(LocalDate date) {
return repository.findByDate(date);
public List<OutSleeping> getByDate(LocalDate date, ApprovalStatus approvalStatus) {
return repository.findByDate(date, approvalStatus);
}

public List<OutSleeping> getByEndAt(LocalDate endAt){
Expand Down

0 comments on commit 631ce02

Please sign in to comment.