delete scheduler
This commit is contained in:
@@ -16,5 +16,5 @@ public interface PostCommandRepository extends CrudRepository<Post, Long> {
|
|||||||
void deleteById(Long id);
|
void deleteById(Long id);
|
||||||
void delete(Post post);
|
void delete(Post post);
|
||||||
|
|
||||||
List<Post> findAllByExpiredAt(LocalDateTime expiredAt);
|
List<Post> findAllByExpiredAtLessThanAndDeletedAtIsNull(LocalDateTime expiredAt);
|
||||||
}
|
}
|
||||||
@@ -44,7 +44,7 @@ public class Post implements Serializable {
|
|||||||
public Post(Long id, LocalDateTime createdAt, LocalDateTime expiredAt, String content, UserEntity writer){
|
public Post(Long id, LocalDateTime createdAt, LocalDateTime expiredAt, String content, UserEntity writer){
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.createdAt = createdAt;
|
this.createdAt = createdAt;
|
||||||
this.expiredAt = expiredAt.plusHours(24);
|
this.expiredAt = expiredAt;
|
||||||
this.deletedAt = null;
|
this.deletedAt = null;
|
||||||
this.content = content;
|
this.content = content;
|
||||||
this.writer = writer;
|
this.writer = writer;
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package com.example.oneul.domain.post.service.command;
|
package com.example.oneul.domain.post.service.command;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
import javax.servlet.http.HttpSession;
|
import javax.servlet.http.HttpSession;
|
||||||
|
|
||||||
import com.example.oneul.domain.post.dao.PostCommandRepository;
|
import com.example.oneul.domain.post.dao.PostCommandRepository;
|
||||||
@@ -26,10 +28,13 @@ public class PostCommnadServiceImpl implements PostCommandService{
|
|||||||
@Override
|
@Override
|
||||||
public Post createPost(Post post, HttpSession httpSession){
|
public Post createPost(Post post, HttpSession httpSession){
|
||||||
UserEntity userEntity = (UserEntity) httpSession.getAttribute("user");
|
UserEntity userEntity = (UserEntity) httpSession.getAttribute("user");
|
||||||
|
LocalDateTime createdAt = LocalDateTime.now();
|
||||||
|
|
||||||
Post postEntity = postCommandRepository.save(
|
Post postEntity = postCommandRepository.save(
|
||||||
Post.builder()
|
Post.builder()
|
||||||
.content(post.getContent())
|
.content(post.getContent())
|
||||||
|
.createdAt(createdAt)
|
||||||
|
.expiredAt(createdAt.plusHours(24))
|
||||||
.writer(userEntity)
|
.writer(userEntity)
|
||||||
.build());
|
.build());
|
||||||
|
|
||||||
|
|||||||
@@ -47,12 +47,12 @@ public class BatchConfig {
|
|||||||
return stepBuilderFactory.get("step")
|
return stepBuilderFactory.get("step")
|
||||||
.tasklet((contribution, chunkContext) -> {
|
.tasklet((contribution, chunkContext) -> {
|
||||||
LocalDateTime expiredAt = LocalDateTime.now();
|
LocalDateTime expiredAt = LocalDateTime.now();
|
||||||
List<Post> posts = postCommandRepository.findAllByExpiredAt(expiredAt);
|
List<Post> posts = postCommandRepository.findAllByExpiredAtLessThanAndDeletedAtIsNull(expiredAt);
|
||||||
// posts.stream().forEach(post -> {
|
posts.stream().forEach(post -> {
|
||||||
// post.setDeletedAt(expiredAt);
|
post.setDeletedAt(expiredAt);
|
||||||
// });
|
});
|
||||||
// // TODO: Query DB 한테 알려줘야함
|
// TODO: Query DB 한테 알려줘야함
|
||||||
// postCommandRepository.saveAll(posts);
|
postCommandRepository.saveAll(posts);
|
||||||
log.info(expiredAt + " posts(" + posts.size() + ") are deleted.");
|
log.info(expiredAt + " posts(" + posts.size() + ") are deleted.");
|
||||||
return RepeatStatus.FINISHED;
|
return RepeatStatus.FINISHED;
|
||||||
}).build();
|
}).build();
|
||||||
|
|||||||
@@ -20,10 +20,9 @@ public class LoginCheckInterceptor implements HandlerInterceptor{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||||
log.info("login check prehandler");
|
|
||||||
HttpSession httpSession = request.getSession(false);
|
HttpSession httpSession = request.getSession(false);
|
||||||
if(httpSession == null){
|
if(httpSession == null){
|
||||||
log.info("no session");
|
log.info("sessionless user access");
|
||||||
response.sendRedirect(loginPage);
|
response.sendRedirect(loginPage);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -35,6 +34,7 @@ public class LoginCheckInterceptor implements HandlerInterceptor{
|
|||||||
response.sendRedirect(loginPage);
|
response.sendRedirect(loginPage);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
log.info(userEntity.toString() + " is access");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user