Skip to content

Commit

Permalink
Merge pull request #74 from sswu-meets/feat/change-schedule-list-api
Browse files Browse the repository at this point in the history
feat: 유저가 참여하고 있는 일정 리스트 조회 API의 반환 형식 수정
  • Loading branch information
yujung7768903 authored May 23, 2023
2 parents c76bfc2 + bb6f512 commit c7870aa
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public Long saveTuneDate(@LoginUser SessionUser sessionUser, @RequestBody TuneSc
@ApiImplicitParam(name = "scheduleNo", value = "일정 번호")
@GetMapping("/schedule/userlist/{scheduleNo}")
public List<UserResponseDto> getUserListOfSchedule(@PathVariable Long scheduleNo) {
return scheduleService.getUserListOfSchedule(scheduleNo);
return scheduleService.getUserListByScheduleNo(scheduleNo);
}

@ApiOperation(value = "모임 일정 조회")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@
import com.sswu.meets.domain.schedule.Schedule;
import com.sswu.meets.domain.user.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface AttendanceRepository extends JpaRepository<Attendance, Long> {
List<Attendance> findAttendanceByUser (User user);
@Query("select a "
+ "from Attendance a "
+ "join fetch a.schedule "
+ "where a.user = :user ")
List<Attendance> findAttendanceByUser (@Param("user") User user);

List<Attendance> findAttendanceBySchedule (Schedule schedule);
}
21 changes: 0 additions & 21 deletions src/main/java/com/sswu/meets/dto/ScheduleResponseDto.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.sswu.meets.dto.schedule.response;

import com.sswu.meets.domain.schedule.Schedule;
import lombok.Builder;
import lombok.Getter;

import java.time.LocalDate;
import java.time.LocalTime;
import java.util.List;
import java.util.stream.Collectors;

@Getter
public class ScheduleResponseDto {
private Long no;
private Long meetingNo;
private String scheduleName;
private LocalDate fixStartDate; // 고정 일정인 경우 시작 날짜
private LocalDate fixEndDate; // 고정 일정인 경우 종료 날짜
private List<LocalDate> tuneDateList; // 종료 일정인 경우 날짜 리스트
private LocalTime startTime;
private LocalTime endTime;
private Boolean dateTuneState;
private Boolean placeTuneState;
private List<String> participants;

@Builder
public ScheduleResponseDto(
Schedule schedule,
LocalDate fixStartDate,
LocalDate fixEndDate,
List<LocalDate> tuneDateList
) {
this.no = schedule.getScheduleNo();
this.meetingNo = schedule.getMeeting() != null ? schedule.getMeeting().getMeeting_no() : null;
this.scheduleName = schedule.getScheduleName();
this.fixStartDate = fixStartDate;
this.fixEndDate = fixEndDate;
this.tuneDateList = tuneDateList;
this.startTime = schedule.getStartTime();
this.endTime = schedule.getEndTime();
this.dateTuneState = schedule.getDateTuneState();
this.placeTuneState = schedule.getPlaceTuneState();
this.participants = schedule.getAttendanceList().stream()
.map(a -> a.getUser().getName())
.collect(Collectors.toList());
}

}
44 changes: 41 additions & 3 deletions src/main/java/com/sswu/meets/service/ScheduleService.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,17 @@
import com.sswu.meets.domain.meeting.MeetingRepository;
import com.sswu.meets.domain.schedule.Schedule;
import com.sswu.meets.domain.schedule.ScheduleRepository;
import com.sswu.meets.domain.scheduleDateFix.ScheduleDateFix;
import com.sswu.meets.domain.scheduleDateFix.ScheduleDateFixRepository;
import com.sswu.meets.domain.scheduleDateTune.ScheduleDateTuneRepository;
import com.sswu.meets.domain.user.UserRepository;
import com.sswu.meets.dto.*;
import com.sswu.meets.dto.schedule.response.ScheduleResponseDto;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.time.LocalDate;
import java.util.List;
import java.util.stream.Collectors;

Expand All @@ -25,6 +30,8 @@ public class ScheduleService {
private final AttendanceRepository attendanceRepository;
private final ScheduleDateTuneService scheduleDateTuneService;
private final ScheduleDateFixService scheduleDateFixService;
private final ScheduleDateFixRepository scheduleDateFixRepository;
private final ScheduleDateTuneRepository scheduleDateTuneRepository;

// 고정 일정 등록
@Transactional
Expand Down Expand Up @@ -63,7 +70,14 @@ public Long saveTuneDate(SessionUser sessionUser, TuneScheduleSaveRequestDto tun
}

// 일정에 참여하는 유저 조회
public List<UserResponseDto> getUserListOfSchedule(Long scheduleNo) {
public List<String> getUserNameListBySchedule(Schedule schedule) {
return attendanceRepository.findAttendanceBySchedule(schedule).stream()
.map(p -> p.getUser().getName())
.collect(Collectors.toList());
}

// 일정 번호로 일정에 참여하는 유저 조회
public List<UserResponseDto> getUserListByScheduleNo(Long scheduleNo) {
Schedule schedule = scheduleRepository.getById(scheduleNo);
return attendanceRepository.findAttendanceBySchedule(schedule).stream()
.map(p -> p.getUser())
Expand All @@ -77,20 +91,44 @@ public List<ScheduleResponseDto> getScheduleList(Long meetingNo) {
Meeting meeting = meetingRepository.getById(meetingNo);

return scheduleRepository.findByMeeting(meeting).stream()
.map(ScheduleResponseDto::new)
.map(this::getSchedule)
.collect(Collectors.toList());
}

// 일정 상세 조회
@Transactional
public ScheduleResponseDto getSchedule(Long scheduleNo, String scheduleCode) {
return scheduleRepository.findByScheduleNoAndScheduleCode(scheduleNo, scheduleCode)
.map(ScheduleResponseDto::new)
.map(this::getSchedule)
.orElseThrow(() -> new IllegalArgumentException(
"해당 일정은 존재하지 않습니다. scheduleNo: " + scheduleNo + ", scheduleCode: " + scheduleCode
));
}

// 일정 상세 조회
@Transactional
public ScheduleResponseDto getSchedule(Schedule schedule) {
// 조율 일정인 경우
if (schedule.getDateTuneState()) {
List<LocalDate> tuneDateList = scheduleDateTuneRepository.findBySchedule(schedule).stream()
.map(s -> s.getTuneDate())
.collect(Collectors.toList());

return ScheduleResponseDto.builder()
.schedule(schedule)
.tuneDateList(tuneDateList)
.build();
}

// 고정 일정인 경우
ScheduleDateFix scheduleDateFix = scheduleDateFixRepository.findBySchedule(schedule);
return ScheduleResponseDto.builder()
.schedule(schedule)
.fixStartDate(scheduleDateFix.getStartDate())
.fixEndDate(scheduleDateFix.getEndDate())
.build();
}

// 일정 수정
@Transactional
public Boolean update(Long scheduleNo, ScheduleUpdateRequestDto scheduleUpdateRequestDto) {
Expand Down
13 changes: 8 additions & 5 deletions src/main/java/com/sswu/meets/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.sswu.meets.domain.user.User;
import com.sswu.meets.domain.user.UserRepository;
import com.sswu.meets.dto.*;
import com.sswu.meets.dto.schedule.response.ScheduleResponseDto;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
Expand All @@ -24,6 +25,7 @@
@Service
public class UserService {
private final UserRepository userRepository;
private final ScheduleService scheduleService;
private final ParticipationRepository participationRepository;
private final AttendanceRepository attendanceRepository;
private RestTemplate restTemplate = new RestTemplate();
Expand Down Expand Up @@ -61,20 +63,21 @@ public List<MeetingResponseDto> getMeetingList(Long userNo) {
}

// 유저가 참여하고 있는 일정 조회
// 해당 일정에 참여하고 있는 모든 유저 조회
@Transactional
public List<ScheduleResponseDto> getScheduleList(SessionUser sessionUser) {
return attendanceRepository.findAttendanceByUser(userRepository.getById(sessionUser.getUserNo())).stream()
.map(p -> p.getSchedule())
.map(ScheduleResponseDto::new)
User user = userRepository.getById(sessionUser.getUserNo());
return attendanceRepository.findAttendanceByUser(user).stream()
.map(a -> scheduleService.getSchedule(a.getSchedule()))
.collect(Collectors.toList());
}

@Transactional
public boolean update(Long userNo, UserUpdateRequestDto userSaveRequestDto) {
try{
try {
userRepository.save(userSaveRequestDto.toEntity());
return true;
}catch (IllegalArgumentException e){
} catch (IllegalArgumentException e) {
log.error("error: {}", e.getMessage());
return false;
}
Expand Down

0 comments on commit c7870aa

Please sign in to comment.