Skip to content

Commit

Permalink
Merge pull request #87 from Team-UMC/feature/#86/schedule-dummy-data
Browse files Browse the repository at this point in the history
[FEAT] ์Šค์ผ€์ค„ ๋”๋ฏธ ๋ฐ์ดํ„ฐ ๋ฐ ์Šค์ผ€์ค„ ์กฐํšŒ API ์ˆ˜์ •
  • Loading branch information
junseokkim authored Feb 18, 2024
2 parents 31bdddf + 97bbcb8 commit 55788b4
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ public class ScheduleController {
@ApiResponses(value = {
@ApiResponse(responseCode = "COMMON200", description = "์„ฑ๊ณต")
})
public BaseResponse<ScheduleInfoSummaryLists> getScheduleLists(@RequestParam LocalDate date) {
public BaseResponse<ScheduleInfoSummaryLists> getScheduleLists(@CurrentMember Member member,
@RequestParam LocalDate date) {

return BaseResponse.onSuccess((scheduleService.getScheduleLists(date)));
return BaseResponse.onSuccess((scheduleService.getScheduleLists(member, date)));
}

@Operation(summary = "์ผ์ • ์กฐํšŒ(์ƒ์„ธ์กฐํšŒ)", description = "ํ™ˆํ™”๋ฉด์˜ ๋‹ฌ๋ ฅ์—์„œ ์ผ์ •์„ ์ƒ์„ธ์กฐํšŒํ•˜๋Š” API์ž…๋‹ˆ๋‹ค.")
Expand All @@ -55,8 +56,9 @@ public BaseResponse<ScheduleDetail> getScheduleDetail(@CurrentMember Member memb
@ApiResponses(value = {
@ApiResponse(responseCode = "COMMON200", description = "์„ฑ๊ณต")
})
public BaseResponse<ScheduleInfoSummariesInCalendar> getSchedule(@RequestParam LocalDate date) {
public BaseResponse<ScheduleInfoSummariesInCalendar> getSchedule(@CurrentMember Member member,
@RequestParam LocalDate date) {

return BaseResponse.onSuccess(scheduleService.getCalendarByMonth(date));
return BaseResponse.onSuccess(scheduleService.getCalendarByMonth(member, date));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import java.util.UUID;

@Tag(name = "์šด์˜์ง„ ์Šค์ผ€์ค„ API", description = "์šด์˜์ง„ ์Šค์ผ€์ค„ ๊ด€๋ จ API")
@Tag(name = "์šด์˜์ง„ ์ผ์ • API", description = "์šด์˜์ง„ ์ผ์ • ๊ด€๋ จ API")
@RestController
@RequiredArgsConstructor
@RequestMapping("/staff/schedules")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,11 @@
import java.util.UUID;

public interface ScheduleService {
ScheduleInfoSummariesInCalendar getCalendarByMonth(LocalDate date);
ScheduleInfoSummariesInCalendar getCalendarByMonth(Member member, LocalDate date);
ScheduleId createSchedule(Member member, CreateSchedule request);
ScheduleId updateSchedule(Member member, UUID scheduleId, UpdateSchedule request);

ScheduleId deleteSchedule(Member member, UUID scheduleId);

ScheduleInfoSummaryLists getScheduleLists(LocalDate date);

ScheduleInfoSummaryLists getScheduleLists(Member member, LocalDate date);
ScheduleDetail getScheduleDetail(Member member, UUID scheduleId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.umc.networkingService.domain.board.entity.HostType;
import com.umc.networkingService.domain.member.entity.Member;
import com.umc.networkingService.domain.member.service.MemberService;
import com.umc.networkingService.domain.schedule.dto.request.ScheduleRequest.CreateSchedule;
import com.umc.networkingService.domain.schedule.dto.request.ScheduleRequest.UpdateSchedule;
import com.umc.networkingService.domain.schedule.dto.response.ScheduleResponse.*;
Expand All @@ -25,19 +26,29 @@ public class ScheduleServiceImpl implements ScheduleService {
private final ScheduleRepository scheduleRepository;
private final ScheduleMapper scheduleMapper;

private final MemberService memberService;

@Override
public ScheduleInfoSummariesInCalendar getCalendarByMonth(LocalDate date) {
public ScheduleInfoSummariesInCalendar getCalendarByMonth(Member loginMember, LocalDate date) {

Member member = memberService.loadEntity(loginMember.getId());

List<Schedule> schedulesLists = validateSchedules(member,
scheduleRepository.findSchedulesByYearAndMonth(date));

return scheduleMapper.toScheduleInfoSummariesInCalendar(
scheduleRepository.findSchedulesByYearAndMonth(date).stream()
.map(schedule -> scheduleMapper.toScheduleInfoSummaryInCalendar(schedule))
schedulesLists.stream()
.map(scheduleMapper::toScheduleInfoSummaryInCalendar)
.toList());
}

@Override
public ScheduleInfoSummaryLists getScheduleLists(LocalDate date) {
public ScheduleInfoSummaryLists getScheduleLists(Member loginMember, LocalDate date) {

Member member = memberService.loadEntity(loginMember.getId());

List<Schedule> schedulesLists = scheduleRepository.findSchedulesByYearAndMonth(date);
List<Schedule> schedulesLists = validateSchedules(member,
scheduleRepository.findSchedulesByYearAndMonth(date));

List<ScheduleInfoSummary> campusSchedules = filterSchedulesByHostType(schedulesLists, HostType.CAMPUS);

Expand All @@ -51,13 +62,36 @@ public ScheduleInfoSummaryLists getScheduleLists(LocalDate date) {
private List<ScheduleInfoSummary> filterSchedulesByHostType(List<Schedule> schedules, HostType hostType) {
return schedules.stream()
.filter(schedule -> schedule.getHostType().equals(hostType))
.map(schedule -> scheduleMapper.toScheduleInfoSummary(schedule))
.map(scheduleMapper::toScheduleInfoSummary)
.toList();
}

private List<Schedule> validateSchedules(Member member, List<Schedule> schedules) {
return schedules.stream()
.filter(schedule -> validateScheduleUniversityAndBranch(member, schedule))
.filter(schedule -> validateScheduleSemester(member, schedule))
.toList();
}

private boolean validateScheduleUniversityAndBranch(Member member, Schedule schedule) {
if (schedule.getHostType().equals(HostType.CENTER))
return true;
if (schedule.getHostType().equals(HostType.BRANCH)
&& member.getBranch() == schedule.getWriter().getBranch())
return true;
return schedule.getHostType().equals(HostType.CAMPUS)
&& member.getUniversity() == schedule.getWriter().getUniversity();
}

private boolean validateScheduleSemester(Member member, Schedule schedule) {
return member.getSemesters().stream()
.anyMatch(memberSemester -> schedule.getSemesterPermission().contains(memberSemester));
}

@Override
public ScheduleDetail getScheduleDetail(Member member, UUID scheduleId) {
Schedule schedule = scheduleRepository.findById(scheduleId).orElseThrow(() -> new RestApiException(ScheduleErrorCode.EMPTY_SCHEDULE));
Schedule schedule = scheduleRepository.findById(scheduleId)
.orElseThrow(() -> new RestApiException(ScheduleErrorCode.EMPTY_SCHEDULE));

return scheduleMapper.toScheduleDetail(schedule);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
public class TestController {
private final TestService testService;

@Operation(summary = "dummy Board ์ƒ์„ฑ API", description = "๋ณด๋“œ ๋”๋ฏธ๋ฐ์ดํ„ฐ๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค. ํšŒ์› ๊ฐ€์ž… ์™„๋ฃŒ ํ›„ ์‚ฌ์šฉํ•ด์ฃผ์„ธ์š”!")
@Operation(summary = "dummy Board, Schedule ์ƒ์„ฑ API", description = "๋ณด๋“œ, ์Šค์ผ€์ค„ ๋”๋ฏธ๋ฐ์ดํ„ฐ๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค. ํšŒ์› ๊ฐ€์ž… ์™„๋ฃŒ ํ›„ ์‚ฌ์šฉํ•ด์ฃผ์„ธ์š”!")
@ApiResponses(value = {
@ApiResponse(responseCode = "COMMON200", description = "์„ฑ๊ณต")
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import com.umc.networkingService.domain.member.repository.SemesterPartRepository;
import com.umc.networkingService.domain.member.service.AuthService;
import com.umc.networkingService.domain.member.service.MemberService;
import com.umc.networkingService.domain.schedule.dto.request.ScheduleRequest;
import com.umc.networkingService.domain.schedule.service.ScheduleService;
import com.umc.networkingService.domain.university.entity.University;
import com.umc.networkingService.domain.university.service.UniversityService;
import com.umc.networkingService.global.common.enums.Role;
Expand All @@ -29,6 +31,7 @@
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import java.time.LocalDateTime;
import java.util.*;

import static com.umc.networkingService.domain.board.dto.request.BoardRequest.BoardCreateRequest;
Expand All @@ -46,6 +49,7 @@ public class TestService {

private final BoardService boardService;
private final BoardFileService boardFileService;
private final ScheduleService scheduleService;

private final AmazonS3Client amazonS3Client;
@Value("${cloud.aws.s3.bucket}")
Expand All @@ -70,6 +74,7 @@ public String createDummyBoard(Member member) {
createOB(members, HostType.CENTER);
createNoticeAndWorkbook(members);

members.forEach(this::createSchedules);

return "๋”๋ฏธ๋ฐ์ดํ„ฐ ์ƒ์„ฑ ์™„๋ฃŒ";
}
Expand Down Expand Up @@ -126,6 +131,7 @@ public List<Member> createDummyMember(Member loginMember) {
return members;
}


public List<SemesterPart> createSemesterPart(Member member, MemberDummyInfo memberInfo) {
List<SemesterPart> semesterParts = new ArrayList<>();
for (int i = 0; i < memberInfo.getSemesters().size(); i++)
Expand Down Expand Up @@ -246,5 +252,70 @@ private List<String> getDummyImages(String bucketName) {
return fileUrls;
}

private void createSchedules(Member member) {
Optional<HostType> hostType = getHostType(member);
if (hostType.isPresent()) {
createDemoDaySchedule(member, hostType.get());
createHackathonSchedule(member, hostType.get());
createDiningSchedule(member, hostType.get());
}
}

private void createDemoDaySchedule(Member member, HostType hostType) {
ScheduleRequest.CreateSchedule request = ScheduleRequest.CreateSchedule.builder()
.title("UMC 5๊ธฐ ๋ฐ๋ชจ๋ฐ์ด")
.content("๋ฐ๋ชจ๋ฐ์ด๊ฐ€ ์ฝ” ์•ž์œผ๋กœ ๋‹ค๊ฐ€์™”์Šต๋‹ˆ๋‹น")
.startDateTime(LocalDateTime.of(2024, 2, 19, 0,0))
.endDateTime(LocalDateTime.of(2024, 2, 21,23,59))
.semesterPermission(List.of(Semester.FIFTH, Semester.FOURTH, Semester.THIRD, Semester.SECOND, Semester.FIRST))
.hostType(hostType)
.placeSetting("์˜ฌ๋Œ“๋งˆ์ธ๋“œ ๋ฌธ๋ž˜์ ")
.build();
scheduleService.createSchedule(member, request);
}

private void createDiningSchedule(Member member, HostType hostType) {
int day = getRandomNumber();
ScheduleRequest.CreateSchedule request = ScheduleRequest.CreateSchedule.builder()
.title("ํšŒ์‹")
.content("์—ฌ๋Ÿฌ๋ถ„๋“ค ํšŒ์‹ ๋งŽ์ด ์ฐธ์—ฌํ•ด์ฃผ์„ธ์š”")
.startDateTime(LocalDateTime.of(2024, 2, day, 18,0))
.endDateTime(LocalDateTime.of(2024, 2, day,23,59))
.semesterPermission(List.of(Semester.FIFTH))
.hostType(hostType)
.placeSetting("์žฅ์†Œ ๋ฏธ์ •")
.build();
scheduleService.createSchedule(member, request);
}

private void createHackathonSchedule(Member member, HostType hostType) {
int day = getRandomNumber();
ScheduleRequest.CreateSchedule request = ScheduleRequest.CreateSchedule.builder()
.title("UMC ํ—ค์ปคํ†ค")
.content("ํ—ค์ปคํ†ค ์šฐ์Šน ์ƒ๊ธˆ ๋ฐฑ๋งŒ์›!!!")
.startDateTime(LocalDateTime.of(2024, 2, day, 14,0))
.endDateTime(LocalDateTime.of(2024, 2, day + 1,14,0))
.semesterPermission(List.of(Semester.FIFTH, Semester.FOURTH, Semester.THIRD, Semester.SECOND, Semester.FIRST))
.hostType(hostType)
.placeSetting("ํ—ค์ปคํ†ค ์žฅ์†Œ")
.build();
scheduleService.createSchedule(member, request);
}

private Optional<HostType> getHostType(Member member) {
int rolePriority = member.getRole().getPriority();
if (rolePriority > 4)
return Optional.empty();
if (rolePriority > 3)
return Optional.of(HostType.CAMPUS);
if (rolePriority > 2)
return Optional.of(HostType.BRANCH);
return Optional.of(HostType.CENTER);
}

// 1 ~ 29 ์ค‘ ๋žœ๋ค ์ˆซ์ž ์ƒ์„ฑ
private int getRandomNumber() {
Random random = new Random();
return random.nextInt(28) + 1;
}
}

0 comments on commit 55788b4

Please sign in to comment.