-
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 pull request #18 from syyling/feat/13
[feat] 보고싶어요 도메인 추가, 생성/취소 기능 추가
- Loading branch information
Showing
7 changed files
with
159 additions
and
0 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
src/main/java/com/mookive/mookive_backend/heart/application/service/HeartCreateService.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,39 @@ | ||
package com.mookive.mookive_backend.heart.application.service; | ||
|
||
import com.mookive.mookive_backend.heart.domain.entity.Heart; | ||
import com.mookive.mookive_backend.heart.domain.service.HeartDeleteService; | ||
import com.mookive.mookive_backend.heart.domain.service.HeartQueryService; | ||
import com.mookive.mookive_backend.heart.domain.service.HeartSaveService; | ||
import com.mookive.mookive_backend.movie.domain.entity.Movie; | ||
import com.mookive.mookive_backend.movie.domain.service.MovieQueryService; | ||
import com.mookive.mookive_backend.user.domain.entity.User; | ||
import com.mookive.mookive_backend.user.domain.service.UserQueryService; | ||
import jakarta.transaction.Transactional; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional | ||
public class HeartCreateService { | ||
|
||
private final HeartQueryService heartQueryService; | ||
private final HeartSaveService heartSaveService; | ||
private final HeartDeleteService heartDeleteService; | ||
private final UserQueryService userQueryService; | ||
private final MovieQueryService movieQueryService; | ||
|
||
public void createHeart(Long userId, Long movieId) { | ||
if (heartQueryService.existsByUserIdAndMovieId(userId, movieId)) { | ||
heartDeleteService.deleteByUserIdAndMovieId(userId, movieId); | ||
} else { | ||
User user = userQueryService.findById(userId); | ||
Movie movie = movieQueryService.findById(movieId); | ||
Heart heart = Heart.builder() | ||
.user(user) | ||
.movie(movie) | ||
.build(); | ||
heartSaveService.save(heart); | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/com/mookive/mookive_backend/heart/domain/entity/Heart.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 com.mookive.mookive_backend.heart.domain.entity; | ||
|
||
import com.mookive.mookive_backend.movie.domain.entity.Movie; | ||
import com.mookive.mookive_backend.user.domain.entity.User; | ||
import jakarta.persistence.*; | ||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class Heart { | ||
|
||
@Id @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "movie_id") | ||
private Movie movie; | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "user_id") | ||
private User user; | ||
|
||
@Builder | ||
public Heart(Movie movie, User user) { | ||
this.movie = movie; | ||
this.user = user; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/mookive/mookive_backend/heart/domain/repository/HeartRepository.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.mookive.mookive_backend.heart.domain.repository; | ||
|
||
import com.mookive.mookive_backend.heart.domain.entity.Heart; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface HeartRepository extends JpaRepository<Heart, Long> { | ||
|
||
void deleteByUserIdAndMovieId(Long userId, Long movieId); | ||
|
||
boolean existsByUserIdAndMovieId(Long userId, Long movieId); | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/com/mookive/mookive_backend/heart/domain/service/HeartDeleteService.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,19 @@ | ||
package com.mookive.mookive_backend.heart.domain.service; | ||
|
||
|
||
import com.mookive.mookive_backend.heart.domain.repository.HeartRepository; | ||
import jakarta.transaction.Transactional; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional | ||
public class HeartDeleteService { | ||
|
||
private final HeartRepository heartRepository; | ||
|
||
public void deleteByUserIdAndMovieId(Long userId, Long movieId) { | ||
heartRepository.deleteByUserIdAndMovieId(userId, movieId); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/com/mookive/mookive_backend/heart/domain/service/HeartQueryService.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,19 @@ | ||
package com.mookive.mookive_backend.heart.domain.service; | ||
|
||
|
||
import com.mookive.mookive_backend.heart.domain.repository.HeartRepository; | ||
import jakarta.transaction.Transactional; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional | ||
public class HeartQueryService { | ||
|
||
private final HeartRepository heartRepository; | ||
|
||
public boolean existsByUserIdAndMovieId(Long userId, Long movieId) { | ||
return heartRepository.existsByUserIdAndMovieId(userId, movieId); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/com/mookive/mookive_backend/heart/domain/service/HeartSaveService.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 com.mookive.mookive_backend.heart.domain.service; | ||
|
||
import com.mookive.mookive_backend.heart.domain.entity.Heart; | ||
import com.mookive.mookive_backend.heart.domain.repository.HeartRepository; | ||
import jakarta.transaction.Transactional; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional | ||
public class HeartSaveService { | ||
|
||
private final HeartRepository heartRepository; | ||
|
||
public void save(Heart heart) { | ||
heartRepository.save(heart); | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/com/mookive/mookive_backend/heart/presentation/HeartController.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,19 @@ | ||
package com.mookive.mookive_backend.heart.presentation; | ||
|
||
import com.mookive.mookive_backend.heart.application.service.HeartCreateService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
public class HeartController { | ||
|
||
private final HeartCreateService heartCreateService; | ||
|
||
@PostMapping("/heart") | ||
public void createHeart(@RequestParam Long userId, @RequestParam Long movieId) { | ||
heartCreateService.createHeart(userId, movieId); | ||
} | ||
} |