forked from SWYP-3-Reading-everywhere/readeve-BackEnd
-
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.
Merge branch 'dev' of https://github.com/dltjdgh0428/readeve-BackEnd …
…into dev
- Loading branch information
Showing
14 changed files
with
346 additions
and
77 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.book_everywhere.likes.entity; | ||
|
||
import com.book_everywhere.auth.entity.User; | ||
import com.book_everywhere.review.entity.Review; | ||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import jakarta.persistence.*; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.hibernate.annotations.CreationTimestamp; | ||
import org.hibernate.annotations.Fetch; | ||
|
||
import java.sql.Timestamp; | ||
|
||
@Builder | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Getter | ||
@Entity | ||
@Table( | ||
name="likes", | ||
uniqueConstraints={ | ||
@UniqueConstraint( | ||
name = "likes_uk", | ||
columnNames={"review_id", "user_id"} | ||
) | ||
} | ||
) | ||
public class Likes { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "review_id") | ||
private Review review; | ||
|
||
@JsonIgnoreProperties({"reviews"}) | ||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "user_id") | ||
private User user; | ||
|
||
@CreationTimestamp | ||
private Timestamp createAt; | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/com/book_everywhere/likes/repository/LikesRepository.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,24 @@ | ||
package com.book_everywhere.likes.repository; | ||
|
||
import com.book_everywhere.likes.entity.Likes; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Modifying; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
|
||
|
||
public interface LikesRepository extends JpaRepository<Likes, Long> { | ||
|
||
@Modifying | ||
@Query(value = "INSERT INTO likes(review_id, user_id) VALUES(:reviewId, :userId)", nativeQuery = true) | ||
void mLike(@Param("userId") Long userId, @Param("reviewId") Long reviewId); | ||
|
||
@Modifying | ||
@Query(value = "DELETE FROM likes WHERE review_id = :reviewId AND user_id = :userId", nativeQuery = true) | ||
void mUnLike(@Param("userId") Long userId, @Param("reviewId") Long reviewId); | ||
|
||
Long countByReviewId(@Param("reviewId") Long reviewId); | ||
|
||
boolean existsByUserIdAndReviewId(Long userId, Long reviewId); | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/book_everywhere/likes/service/LikesService.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,11 @@ | ||
package com.book_everywhere.likes.service; | ||
|
||
public interface LikesService { | ||
|
||
|
||
void 좋아요(Long socialId,Long review_id); | ||
|
||
void 좋아요취소(Long socialId,Long review_id); | ||
|
||
|
||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/com/book_everywhere/likes/service/LikesServiceImpl.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,34 @@ | ||
package com.book_everywhere.likes.service; | ||
|
||
import com.book_everywhere.auth.entity.User; | ||
import com.book_everywhere.auth.repository.UserRepository; | ||
import com.book_everywhere.likes.entity.Likes; | ||
import com.book_everywhere.likes.repository.LikesRepository; | ||
import com.book_everywhere.review.entity.Review; | ||
import com.book_everywhere.review.repository.ReviewRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
|
||
@RequiredArgsConstructor | ||
@Transactional | ||
@Service | ||
public class LikesServiceImpl implements LikesService { | ||
|
||
private final LikesRepository likesRepository; | ||
private final UserRepository userRepository; | ||
|
||
@Override | ||
public void 좋아요(Long socialId, Long review_id) { | ||
User user = userRepository.findBySocialId(socialId).orElseThrow(); | ||
likesRepository.mLike(user.getId(),review_id); | ||
} | ||
|
||
@Override | ||
public void 좋아요취소(Long socialId, Long review_id) { | ||
User user = userRepository.findBySocialId(socialId).orElseThrow(); | ||
likesRepository.mUnLike(user.getId(), review_id); | ||
} | ||
|
||
} |
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
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
Oops, something went wrong.