-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from Jhsysng/feat/reminder
feat/reminder
- Loading branch information
Showing
13 changed files
with
380 additions
and
3 deletions.
There are no files selected for viewing
Submodule 2024_BEOTKKOTTHON_TEAM_24_BE_ENV
updated
from 16086a to f71ad7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package goorm.reinput.reminder.domain; | ||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@Getter | ||
@NoArgsConstructor(access = lombok.AccessLevel.PROTECTED) | ||
public class Question { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
private String question; | ||
|
||
public Question(String question) { | ||
this.question = question; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/main/java/goorm/reinput/reminder/domain/dto/ReminderQuestionQueryDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package goorm.reinput.reminder.domain.dto; | ||
|
||
import goorm.reinput.insight.domain.HashTag; | ||
import lombok.*; | ||
|
||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
|
||
@Data | ||
@RequiredArgsConstructor | ||
public class ReminderQuestionQueryDto { | ||
private String reminderQuestion; | ||
private Long insightId; | ||
private Long reminderId; | ||
private String insightTitle; | ||
private String insightMainImage; | ||
private LocalDateTime lastRemindedAt; | ||
private List<String> insightTagList; | ||
|
||
@Builder | ||
public ReminderQuestionQueryDto(String reminderQuestion, Long insightId, Long reminderId, String insightTitle, String insightMainImage, List<String> insightTagList) { | ||
this.reminderQuestion = reminderQuestion; | ||
this.insightId = insightId; | ||
this.reminderId = reminderId; | ||
this.insightTitle = insightTitle; | ||
this.insightMainImage = insightMainImage; | ||
this.insightTagList = insightTagList; | ||
} | ||
|
||
|
||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/goorm/reinput/reminder/domain/dto/ReminderQuestionResponseDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package goorm.reinput.reminder.domain.dto; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.List; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
public class ReminderQuestionResponseDto { | ||
private boolean todayClear; | ||
private List<ReminderQuestionQueryDto> reminderQuestionList; | ||
|
||
@Builder | ||
public ReminderQuestionResponseDto(boolean todayClear, List<ReminderQuestionQueryDto> reminderQuestionList) { | ||
this.todayClear = todayClear; | ||
this.reminderQuestionList = reminderQuestionList; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/goorm/reinput/reminder/repository/QuestionRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package goorm.reinput.reminder.repository; | ||
|
||
import goorm.reinput.reminder.domain.Question; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface QuestionRepository extends JpaRepository<Question, Long> { | ||
@Query(value = "SELECT * FROM question ORDER BY RAND() LIMIT 1", nativeQuery = true) | ||
Question findRandomQuestion(); | ||
} |
100 changes: 100 additions & 0 deletions
100
src/main/java/goorm/reinput/reminder/repository/impl/CustomReminderRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package goorm.reinput.reminder.repository.impl; | ||
|
||
import com.querydsl.core.types.Projections; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import goorm.reinput.insight.domain.HashTag; | ||
import goorm.reinput.reminder.domain.RemindType; | ||
import goorm.reinput.reminder.domain.Reminder; | ||
import goorm.reinput.reminder.domain.ReminderQuestion; | ||
import goorm.reinput.reminder.domain.dto.ReminderQuestionQueryDto; | ||
import jakarta.persistence.EntityManager; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.time.DayOfWeek; | ||
import java.time.LocalDate; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import static goorm.reinput.insight.domain.QHashTag.hashTag; | ||
import static goorm.reinput.insight.domain.QInsight.insight; | ||
import static goorm.reinput.reminder.domain.QReminder.reminder; | ||
import static goorm.reinput.reminder.domain.QReminderDate.reminderDate; | ||
|
||
|
||
@Repository | ||
@Slf4j | ||
public class CustomReminderRepository { | ||
private final EntityManager em; | ||
private final JPAQueryFactory queryFactory; | ||
|
||
public CustomReminderRepository(EntityManager em) { | ||
this.em = em; | ||
this.queryFactory = new JPAQueryFactory(this.em); | ||
} | ||
//๊ฐ์ฅ ์ฝ์ ์ค๋๋ ๋ฆฌ๋ง์ธ๋ 5๊ฐ๋ง ์กฐํ, insight์ reminder question join | ||
public List<ReminderQuestionQueryDto> findOldestReminderDto(Long userId) { | ||
// ํด๋น user์ reminder ์ค ๊ฐ์ฅ ์ค๋๋ 5๊ฐ๋ฅผ ์กฐํ | ||
List<ReminderQuestionQueryDto> results = queryFactory | ||
.select(Projections.fields(ReminderQuestionQueryDto.class, | ||
reminder.reminderQuestion.reminderQuestion.as("reminderQuestion"), | ||
insight.insightId.as("insightId"), | ||
reminder.reminderId.as("reminderId"), | ||
insight.insightTitle.as("insightTitle"), | ||
insight.insightMainImage.as("insightMainImage"), | ||
reminder.lastRemindedAt.as("lastRemindedAt") | ||
)) | ||
.from(reminder) | ||
.join(reminder.insight, insight) | ||
.where(insight.folder.user.userId.eq(userId)) | ||
.orderBy(reminder.lastRemindedAt.asc()) | ||
.limit(5) | ||
.fetch(); | ||
results.forEach(dto -> { | ||
List<String> tags = queryFactory | ||
.select(hashTag.hashTagName) | ||
.from(hashTag) | ||
.where(hashTag.insight.insightId.eq(dto.getInsightId())) | ||
.fetch(); | ||
dto.setInsightTagList(tags); | ||
}); | ||
|
||
return results; | ||
} | ||
|
||
public List<Reminder> findOldestReminders(Long userId) { | ||
return queryFactory | ||
.selectFrom(reminder) | ||
.orderBy(reminder.lastRemindedAt.asc()) | ||
.where(reminder.isEnable.isTrue().and(insight.folder.user.userId.eq(userId))) | ||
.join(reminder.insight, insight) | ||
.limit(5) | ||
.fetch(); | ||
} | ||
|
||
// ๋ฆฌ๋ง์ธ๋ํ ์ธ์ฌ์ดํธ ์กฐํ | ||
public List<Reminder> findRemindersToNotify(Long userId) { | ||
|
||
// ์ค๋ ๋ ์ง์ ์์ผ | ||
LocalDate today = LocalDate.now(); | ||
DayOfWeek todayDayOfWeek = today.getDayOfWeek(); | ||
int todayMonthDay = today.getDayOfMonth(); | ||
|
||
return queryFactory | ||
.selectFrom(reminder) | ||
.join(reminder.reminderDate, reminderDate) | ||
.join(reminder.insight, insight) | ||
.where(reminder.isEnable.isTrue().and(insight.folder.user.userId.eq(userId)) | ||
.and(reminderDate.remindType.eq(RemindType.DEFAULT) | ||
.and(reminder.lastRemindedAt.after(LocalDate.now().minusDays(1).atStartOfDay()) | ||
.or(reminder.lastRemindedAt.after(LocalDate.now().minusWeeks(1).atStartOfDay())) | ||
.or(reminder.lastRemindedAt.after(LocalDate.now().minusMonths(1).atStartOfDay())))) | ||
.or(reminderDate.remindType.eq(RemindType.WEEK) | ||
.and(reminderDate.remindDays.contains(todayDayOfWeek.getValue()))) | ||
.or(reminderDate.remindType.eq(RemindType.MONTH) | ||
.and(reminderDate.remindDays.contains(todayMonthDay)))) | ||
.fetch(); | ||
|
||
} | ||
} |
37 changes: 36 additions & 1 deletion
37
src/main/java/goorm/reinput/reminder/service/ReminderService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,51 @@ | ||
package goorm.reinput.reminder.service; | ||
|
||
import goorm.reinput.reminder.domain.Reminder; | ||
import goorm.reinput.reminder.domain.ReminderQuestion; | ||
import goorm.reinput.reminder.domain.dto.ReminderQuestionQueryDto; | ||
import goorm.reinput.reminder.domain.dto.ReminderQuestionResponseDto; | ||
import goorm.reinput.reminder.repository.QuestionRepository; | ||
import goorm.reinput.reminder.repository.ReminderRepository; | ||
import goorm.reinput.reminder.repository.impl.CustomReminderRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Repository; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
|
||
@Slf4j | ||
@RequiredArgsConstructor | ||
@Service | ||
public class ReminderService { | ||
|
||
private final ReminderRepository reminderRepository; | ||
private final CustomReminderRepository customReminderRepository; | ||
private final QuestionRepository questionRepository; | ||
|
||
private void makeReminderQuestionList(Long userId) { | ||
log.info("makeReminderQuestionList start"); | ||
List<Reminder> reminders = customReminderRepository.findOldestReminders(userId); | ||
|
||
//์ค๋๋ ๋ฆฌ๋ง์ธ๋์ค reminderQuestion์ด ์๋ ๊ฒฝ์ฐ ์ง๋ฌธ์ ์์ฑํ๊ณ ์์ผ๋ฉด ๊ทธ๋๋ก ๊ฐ์ ธ์จ๋ค. | ||
for (Reminder reminder : reminders) { | ||
if (reminder.getReminderQuestion() == null) { | ||
ReminderQuestion question = ReminderQuestion.builder() | ||
.reminder(reminder) | ||
.reminderQuestion(questionRepository.findRandomQuestion().getQuestion()) | ||
.build(); | ||
} | ||
} | ||
|
||
} | ||
//todo: get Older reminer | ||
// private ReminderQuestionResponseDto getOlderReminder(Long userId){ | ||
// | ||
// makeReminderQuestionList(); | ||
// | ||
// List<ReminderQuestionQueryDto> reminderQuestionQueryDtos = customReminderRepository.findOldestReminderDto(userId); | ||
// | ||
// | ||
// | ||
// } | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/goorm/reinput/reminder/util/QuestionInitializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package goorm.reinput.reminder.util; | ||
|
||
import goorm.reinput.reminder.domain.Question; | ||
import goorm.reinput.reminder.repository.QuestionRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.boot.CommandLineRunner; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class QuestionInitializer implements CommandLineRunner { | ||
private final QuestionRepository questionRepository; | ||
|
||
@Override | ||
public void run(String... args) throws Exception { | ||
List<String> questions = Arrays.asList( | ||
"์ด ์ธ์ฌ์ดํธ๋ฅผ ์ด๋ค ์ฌ๋์๊ฒ ์ถ์ฒํด์ฃผ๊ณ ์ถ๋์?", | ||
"์ด ์ธ์ฌ์ดํธ๋ฅผ ์ฒ์ ๋ฐ๊ฒฌํ์ ๋ ๋ฌด์์ด ๊ฐ์ฅ ์ธ์ ๊น์๋์?", | ||
"์ด ์ธ์ฌ์ดํธ๋ฅผ ์ค์ ๋ก ์ ์ฉํด ๋ณธ ๊ฒฝํ์ด ์๋์?", | ||
"์ด ์ธ์ฌ์ดํธ๋ฅผ ํตํด ๋ฐฐ์ด ๊ฒ์ ๋ค๋ฅธ ์ฌ๋์๊ฒ ์ด๋ป๊ฒ ์ค๋ช ํ๊ณ ์ถ๋์?", | ||
"์ด ์ธ์ฌ์ดํธ๋ฅผ ํตํด ์ด๋ค ์๋ก์ด ๊ด์ ์ด๋ ๋ฐฉ๋ฒ์ ๋ฐฐ์ ๋์?" | ||
); | ||
|
||
questions.forEach(question -> questionRepository.save(new Question(question))); | ||
} | ||
} |
Oops, something went wrong.