-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Feature/#14
- Loading branch information
Showing
10 changed files
with
207 additions
and
16 deletions.
There are no files selected for viewing
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
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
10 changes: 10 additions & 0 deletions
10
src/main/java/com/unit/daybook/domain/board/repository/ReadBoardRepository.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,10 @@ | ||
package com.unit.daybook.domain.board.repository; | ||
|
||
import com.unit.daybook.domain.board.entity.ReadBoard; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface ReadBoardRepository extends JpaRepository<ReadBoard, Long> { | ||
|
||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/com/unit/daybook/domain/board/repository/ReadBoardRepositoryCustom.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,4 @@ | ||
package com.unit.daybook.domain.board.repository; | ||
|
||
public interface ReadBoardRepositoryCustom { | ||
} |
48 changes: 48 additions & 0 deletions
48
src/main/java/com/unit/daybook/domain/board/repository/ReadBoardRepositoryImpl.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,48 @@ | ||
package com.unit.daybook.domain.board.repository; | ||
|
||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
|
||
import static com.unit.daybook.domain.board.entity.QBoard.board; | ||
import static com.unit.daybook.domain.board.entity.QReadBoard.readBoard; | ||
import static com.unit.daybook.domain.member.domain.QMember.member; | ||
|
||
@Repository | ||
@RequiredArgsConstructor | ||
public class ReadBoardRepositoryImpl implements BoardRepositoryCustom { | ||
private final JPAQueryFactory queryFactory; | ||
|
||
public List<Long> findBoardsByMemberId(Long memberId) { | ||
|
||
List<Long> boards = queryFactory | ||
.select(readBoard.board.boardId) | ||
.from(readBoard) | ||
.innerJoin(readBoard.member, member) | ||
.where( | ||
member.id.eq(memberId) | ||
) | ||
.fetch(); | ||
|
||
return boards; | ||
} | ||
|
||
public List<Long> findTodayBoardsByMemberId(Long memberId) { | ||
LocalDate currentDate = LocalDateTime.now().toLocalDate(); // 현재 날짜의 일자만 추출 | ||
|
||
return queryFactory | ||
.select(readBoard.readBoardId) | ||
.from(readBoard) | ||
.innerJoin(readBoard.board, board) | ||
.innerJoin(readBoard.member, member) | ||
.where( | ||
member.id.eq(memberId) | ||
.and(readBoard.createdAt.between(currentDate.atStartOfDay(), currentDate.atStartOfDay().plusDays(1).minusNanos(1)) | ||
)) | ||
.fetch(); | ||
} | ||
} |
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
27 changes: 27 additions & 0 deletions
27
src/main/java/com/unit/daybook/scheduler/todayBoardsScheduler.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,27 @@ | ||
package com.unit.daybook.scheduler; | ||
|
||
import com.unit.daybook.domain.board.service.BoardService; | ||
import com.unit.daybook.domain.member.domain.Member; | ||
import com.unit.daybook.domain.member.repository.MemberRepository; | ||
import com.unit.daybook.domain.member.repository.MemberRepositoryImpl; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.scheduling.annotation.Scheduled; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
|
||
@RequiredArgsConstructor | ||
@Component | ||
public class todayBoardsScheduler { | ||
private final BoardService boardService; | ||
private final MemberRepository memberRepository; | ||
@Scheduled(cron = "0 0 0 * * *", zone = "Asia/Seoul") | ||
public void run() { | ||
System.out.println(LocalDateTime.now().toString()); | ||
List<Long> memberIds = memberRepository.findAll().stream().map(Member::getId).toList(); | ||
|
||
boardService.batchReadBoard(); | ||
|
||
} | ||
} |