-
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 #6 from Grilled-sausage/feat/survey
선호도 조사 관련 기능 구현
- Loading branch information
Showing
22 changed files
with
548 additions
and
7 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
src/main/java/com/grilledsausage/molva/api/controller/preference/PreferenceController.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.grilledsausage.molva.api.controller.preference; | ||
|
||
import com.grilledsausage.molva.api.dto.preference.FilmmakerPreferenceResponseDto; | ||
import com.grilledsausage.molva.api.entity.user.User; | ||
import com.grilledsausage.molva.api.service.preference.PreferenceService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RequiredArgsConstructor | ||
@RestController | ||
@RequestMapping("/api/preference") | ||
public class PreferenceController { | ||
|
||
private final PreferenceService preferenceService; | ||
|
||
@PostMapping("/filmmaker") | ||
public ResponseEntity<FilmmakerPreferenceResponseDto> preferFilmmaker(@AuthenticationPrincipal User user, @RequestBody Long filmmakerId) { | ||
|
||
return ResponseEntity.ok(FilmmakerPreferenceResponseDto.from(preferenceService.preferFilmmaker(user, filmmakerId))); | ||
|
||
} | ||
|
||
@DeleteMapping("/filmmaker") | ||
public ResponseEntity<String> cancelPreferringFilmmaker(@AuthenticationPrincipal User user, @RequestBody Long filmmakerId) { | ||
|
||
preferenceService.cancelPreferringFilmmaker(user, filmmakerId); | ||
|
||
return ResponseEntity.ok("success"); | ||
|
||
} | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/com/grilledsausage/molva/api/controller/rating/RatingController.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,36 @@ | ||
package com.grilledsausage.molva.api.controller.rating; | ||
|
||
import com.grilledsausage.molva.api.dto.rating.MovieRatingRequestDto; | ||
import com.grilledsausage.molva.api.dto.rating.MovieRatingResponseDto; | ||
import com.grilledsausage.molva.api.entity.user.User; | ||
import com.grilledsausage.molva.api.service.rating.RatingService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RequiredArgsConstructor | ||
@RestController | ||
@RequestMapping("/api/rating") | ||
public class RatingController { | ||
|
||
private final RatingService ratingService; | ||
|
||
@PostMapping("/movie") | ||
public ResponseEntity<MovieRatingResponseDto> rateMovie(@AuthenticationPrincipal User user, @RequestBody MovieRatingRequestDto movieRatingRequestDto) { | ||
|
||
return ResponseEntity.ok(MovieRatingResponseDto.from(ratingService.rateMovie(user, movieRatingRequestDto))); | ||
|
||
} | ||
|
||
@DeleteMapping("/movie") | ||
public ResponseEntity<String> cancelRatingMovie(@AuthenticationPrincipal User user, @RequestBody Long movieId) { | ||
|
||
ratingService.cancelRatingMovie(user, movieId); | ||
|
||
return ResponseEntity.ok("success"); | ||
|
||
} | ||
|
||
|
||
} |
45 changes: 45 additions & 0 deletions
45
...main/java/com/grilledsausage/molva/api/dto/preference/FilmmakerPreferenceResponseDto.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,45 @@ | ||
package com.grilledsausage.molva.api.dto.preference; | ||
|
||
|
||
import com.grilledsausage.molva.api.entity.preference.Preference; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
|
||
@Data | ||
public class FilmmakerPreferenceResponseDto { | ||
|
||
private Long id; | ||
|
||
private Long code; | ||
|
||
private String name; | ||
|
||
private String type; | ||
|
||
private String image; | ||
|
||
private Boolean isInSurvey; | ||
|
||
@Builder | ||
public FilmmakerPreferenceResponseDto(Long id, Long code, String name, String type, String image, Boolean isInSurvey) { | ||
this.id = id; | ||
this.code = code; | ||
this.name = name; | ||
this.type = type; | ||
this.image = image; | ||
this.isInSurvey = isInSurvey; | ||
} | ||
|
||
public static FilmmakerPreferenceResponseDto from(Preference preference) { | ||
return FilmmakerPreferenceResponseDto | ||
.builder() | ||
.id(preference.getFilmmaker().getId()) | ||
.code(preference.getFilmmaker().getCode()) | ||
.name(preference.getFilmmaker().getName()) | ||
.type(preference.getFilmmaker().getType()) | ||
.image(preference.getFilmmaker().getImage()) | ||
.isInSurvey(preference.getFilmmaker().getIsInSurvey()) | ||
.build(); | ||
} | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/grilledsausage/molva/api/dto/rating/MovieRatingRequestDto.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,12 @@ | ||
package com.grilledsausage.molva.api.dto.rating; | ||
|
||
import lombok.Data; | ||
|
||
@Data | ||
public class MovieRatingRequestDto { | ||
|
||
Long movieId; | ||
|
||
Double movieRating; | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/com/grilledsausage/molva/api/dto/rating/MovieRatingResponseDto.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,40 @@ | ||
package com.grilledsausage.molva.api.dto.rating; | ||
|
||
import com.grilledsausage.molva.api.entity.rating.Rating; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
|
||
@Data | ||
public class MovieRatingResponseDto { | ||
|
||
private Long id; | ||
|
||
private Long code; | ||
|
||
private String name; | ||
|
||
private String image; | ||
|
||
private Double rating; | ||
|
||
@Builder | ||
public MovieRatingResponseDto(Long id, Long code, String name, String image, Double rating) { | ||
this.id = id; | ||
this.code = code; | ||
this.name = name; | ||
this.image = image; | ||
this.rating = rating; | ||
} | ||
|
||
public static MovieRatingResponseDto from(Rating rating) { | ||
return MovieRatingResponseDto | ||
.builder() | ||
.id(rating.getMovie().getId()) | ||
.code(rating.getMovie().getCode()) | ||
.name(rating.getMovie().getName()) | ||
.image(rating.getMovie().getImage()) | ||
.rating(rating.getUserRating()) | ||
.build(); | ||
} | ||
|
||
} |
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
36 changes: 36 additions & 0 deletions
36
src/main/java/com/grilledsausage/molva/api/entity/preference/Preference.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,36 @@ | ||
package com.grilledsausage.molva.api.entity.preference; | ||
|
||
import com.grilledsausage.molva.api.entity.filmmaker.Filmmaker; | ||
import com.grilledsausage.molva.api.entity.user.User; | ||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import javax.persistence.*; | ||
|
||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Entity | ||
@Table(name = "Preference") | ||
public class Preference { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "pref_id") | ||
private Long id; | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "user_id", nullable = false) | ||
private User user; | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "filmmaker_id", nullable = false) | ||
private Filmmaker filmmaker; | ||
|
||
@Builder | ||
public Preference(User user, Filmmaker filmmaker) { | ||
this.user = user; | ||
this.filmmaker = filmmaker; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/grilledsausage/molva/api/entity/preference/PreferenceRepository.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,13 @@ | ||
package com.grilledsausage.molva.api.entity.preference; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.Optional; | ||
|
||
public interface PreferenceRepository extends JpaRepository<Preference, Long> { | ||
|
||
Optional<Preference> findByUser_IdAndFilmmaker_Id(Long userId, Long filmmaker_id); | ||
|
||
Boolean existsByUser_IdAndFilmmaker_Id(Long userId, Long filmmaker_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
Oops, something went wrong.