Skip to content

Commit

Permalink
Merge pull request #48 from goormthon-Univ/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
chaeeun-Han committed Mar 22, 2024
2 parents 0ce1b55 + 74875a7 commit bc85323
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/main/java/com/beotkkot/qtudy/domain/scrap/Scrap.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ public class Scrap {

@Id
private Long postId;

private String scrapAt;
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ public interface PostsRepository extends JpaRepository<Posts, Long> {

Posts findByPostId(Long postId);

@Query("SELECT p FROM Posts p WHERE p.postId IN :postIds")
@Query("SELECT p FROM Posts p JOIN Scrap s ON p.postId = s.postId WHERE s.postId IN :postIds ORDER BY s.scrapAt DESC")
List<Posts> findAllByPostId(List<Long> postIds);

@Query("SELECT p FROM Posts p WHERE p.postId IN :postIds")
@Query("SELECT p FROM Posts p JOIN Scrap s ON p.postId = s.postId WHERE s.postId IN :postIds ORDER BY s.scrapAt DESC")
Page<Posts> findByPostIds(@Param("postIds") List<Long> postIds, PageRequest pageRequest);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.SimpleDateFormat;
import java.time.Instant;
import java.util.*;

@Slf4j
Expand Down Expand Up @@ -314,9 +316,13 @@ public ResponseEntity<? super PutScrapResponseDto> putScrap(Long postId, Long ka

Scrap scrap = scrapRepo.findByPostIdAndUserId(postId, kakao_uid);

Date now = Date.from(Instant.now());
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String scrapDatetime = simpleDateFormat.format(now);

// 존재하지 않는다면 추가. 존재한다면 삭제
if (scrap == null) {
scrap = new Scrap(kakao_uid, postId);
scrap = new Scrap(kakao_uid, postId, scrapDatetime);
scrapRepo.save(scrap);
post.increaseScrapCount();
}
Expand Down

0 comments on commit bc85323

Please sign in to comment.