Skip to content

Commit

Permalink
Merge pull request #9 from Timetris-Trendithon/mainpage
Browse files Browse the repository at this point in the history
✨Feat: 매일 0시마다 UserDate, Date 추가 스케줄러 구현
  • Loading branch information
Zena0128 authored Feb 18, 2024
2 parents 4757d83 + b8e6c37 commit 826e8bd
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
import org.springframework.scheduling.annotation.EnableScheduling;

@EnableScheduling
@SpringBootApplication(exclude = {SecurityAutoConfiguration.class})
public class TimetrisApplication {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.trendithon.timetris.domain.mainpage.domain;

import com.trendithon.timetris.domain.mainpage.dto.DateCreateDTO;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
Expand All @@ -21,4 +22,8 @@ public class Date {
private long id;
private LocalDate date;

public Date(DateCreateDTO dateCreateDTO){
this.date = dateCreateDTO.getLocalDate();
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.trendithon.timetris.domain.mainpage.domain;

import com.trendithon.timetris.domain.member.domain.User;
import com.trendithon.timetris.domain.mainpage.dto.UserDateCreateDTO;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
Expand All @@ -23,4 +24,9 @@ public class UserDate {
@JoinColumn(name = "dateId")
private Date date;

public UserDate(UserDateCreateDTO userDateCreateDTO){
this.user = userDateCreateDTO.getUser();
this.date = userDateCreateDTO.getDate();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.trendithon.timetris.domain.mainpage.dto;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.time.LocalDate;

@Getter
@AllArgsConstructor @NoArgsConstructor
public class DateCreateDTO {

private LocalDate localDate;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.trendithon.timetris.domain.mainpage.dto;

import com.trendithon.timetris.domain.login.domain.User;
import com.trendithon.timetris.domain.mainpage.domain.Date;
import com.trendithon.timetris.domain.mainpage.domain.UserDate;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@AllArgsConstructor @NoArgsConstructor
public class UserDateCreateDTO {

private User user;
private Date date;

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
@Service
public interface MainPageService {
MainPageDTO getMainPage(long userId);
void createUserDate();
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package com.trendithon.timetris.domain.mainpage.service;

import com.trendithon.timetris.domain.login.domain.User;
import com.trendithon.timetris.domain.login.repository.UserRepository;
import com.trendithon.timetris.domain.mainpage.domain.*;
import com.trendithon.timetris.domain.mainpage.dto.DateCreateDTO;
import com.trendithon.timetris.domain.mainpage.dto.MainPageDTO;
import com.trendithon.timetris.domain.mainpage.dto.UserDateCreateDTO;
import com.trendithon.timetris.domain.mainpage.repository.*;
import lombok.RequiredArgsConstructor;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
Expand All @@ -19,6 +24,7 @@ public class MainPageServiceImpl implements MainPageService{
private final SeeRepository seeRepository;
private final DateRepository dateRepository;
private final UserDateRepository userDateRepository;
private final UserRepository userRepository;

@Override
public MainPageDTO getMainPage(long userId) {
Expand All @@ -32,4 +38,20 @@ public MainPageDTO getMainPage(long userId) {

return MainPageDTO.from(planList, doList, see);
}

@Override
@Scheduled(cron = "0 0 0 * * *")
public void createUserDate() {
List<User> users = userRepository.findAll();
LocalDate localDate = LocalDate.now();
DateCreateDTO dateCreateDTO = new DateCreateDTO(localDate);
Date date = new Date(dateCreateDTO);
dateRepository.save(date);
users.stream()
.forEach(user -> {
UserDateCreateDTO userDateCreateDTO = new UserDateCreateDTO(user, date);
UserDate userDate = new UserDate(userDateCreateDTO);
userDateRepository.save(userDate);
});
}
}

0 comments on commit 826e8bd

Please sign in to comment.