Skip to content

Commit

Permalink
✨ Feat : 올해와 다음 해의 생일 일정을 생성 메서드 구현
Browse files Browse the repository at this point in the history
<footer>
- 관련: #294
  • Loading branch information
joowojr committed Sep 19, 2024
1 parent 1d9a331 commit 5d37431
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public class CategoryMaker {

private static final Long BASE_PERSONAL_PALETTE_ID = ColorChip.getBaseCategoryPaletteId();
private static final Long BASE_MEETING_PALETTE_ID = ColorChip.getBaseMeetingCategoryPaletteId();

private static final Long BASE_BIRTHDAY_PALETTE_ID = ColorChip.getBaseBirthdayCategoryPaletteId();

private final PaletteService paletteService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,25 @@
import com.namo.spring.db.mysql.domains.schedule.service.ScheduleService;
import com.namo.spring.db.mysql.domains.schedule.type.Period;
import com.namo.spring.db.mysql.domains.schedule.type.ScheduleType;
import com.namo.spring.db.mysql.domains.user.entity.Member;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.List;

import static com.namo.spring.application.external.api.schedule.converter.ScheduleConverter.toBirthdaySchedule;
import static com.namo.spring.application.external.api.schedule.converter.ScheduleConverter.toSchedule;

@Component
@RequiredArgsConstructor
public class ScheduleMaker {
private static final int PERSONAL_SCHEDULE_TYPE = ScheduleType.PERSONAL.getValue();
private static final int MEETING_SCHEDULE_TYPE = ScheduleType.MEETING.getValue();
private static final LocalTime BIRTHDAY_SCHEDULE_START_TIME = LocalTime.of(8,0,0);
private static final LocalTime BIRTHDAY_SCHEDULE_END_TIME = LocalTime.of(9,0,0);

private final ScheduleService scheduleService;
private final ImageUrlProperties imageUrlProperties;
Expand All @@ -34,4 +43,32 @@ public Schedule createMeetingSchedule(MeetingScheduleRequest.PostMeetingSchedule
return scheduleService.createSchedule(schedule);
}

/**
* 회원 가입 단계에서
* 유저의 올해 / 다음 해의 생일 일정을 생성합니다.
* @param member
*/
public void createBirthdaySchedules(Member member){
int currentYear = LocalDate.now().getYear();
String title = member.getNickname() + "님의 생일";
Period currentYearPeriod = toPeriodOfBirthdaySchedule(member, currentYear);
Period nextYearPeriod = toPeriodOfBirthdaySchedule(member, currentYear+1);
Schedule currentYearBirthday = toBirthdaySchedule(title, currentYearPeriod);
Schedule nextYearBirthday = toBirthdaySchedule(title, nextYearPeriod);
scheduleService.createSchedules(List.of(currentYearBirthday, nextYearBirthday));
}

/**
* 생일 일정의 기본 설정 period를 반환합니다.
* 시작일시 -> 생일 당일 오전 8시
* 종료일시 -> 생일 당일 오전 9시
* @param member
* @param year
* @return 생일 일정 기간
*/
private Period toPeriodOfBirthdaySchedule(Member member, int year){
LocalDateTime startDateTime = LocalDateTime.of(member.getBirthday().withYear(year), BIRTHDAY_SCHEDULE_START_TIME);
LocalDateTime endDatetime = LocalDateTime.of(member.getBirthday().withYear(year), BIRTHDAY_SCHEDULE_END_TIME);
return Period.of(startDateTime, endDatetime);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ public Schedule createSchedule(Schedule schedule) {
return scheduleRepository.save(schedule);
}

@Transactional
public void createSchedules(List<Schedule> schedule) {
scheduleRepository.saveAll(schedule);
}

@Transactional(readOnly = true)
public Optional<Schedule> readSchedule(Long id) {
return scheduleRepository.findById(id);
Expand Down

0 comments on commit 5d37431

Please sign in to comment.