Skip to content

Commit

Permalink
Merge pull request #6 from Grilled-sausage/feat/survey
Browse files Browse the repository at this point in the history
선호도 조사 관련 기능 구현
  • Loading branch information
mingeun0507 authored Dec 22, 2022
2 parents 051dd6e + 89ed0b9 commit f8c3957
Show file tree
Hide file tree
Showing 22 changed files with 548 additions and 7 deletions.
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");

}

}
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");

}


}
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();
}

}
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;

}
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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class Filmmaker {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "filmmaker_id", nullable = false)
@Column(name = "filmmaker_id")
private Long id;

@Column(name = "code", nullable = false, unique = true)
Expand All @@ -40,8 +40,7 @@ public class Filmmaker {
private List<Participation> participations = new ArrayList<>();

@Builder
public Filmmaker(Long id, Long code, String name, String type, String image, Boolean isInSurvey) {
this.id = id;
public Filmmaker(Long code, String name, String type, String image, Boolean isInSurvey) {
this.code = code;
this.name = name;
this.type = type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class Movie {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "rating_id")
@Column(name = "movie_id")
private Long id;

@Column(name = "code", unique = true, nullable = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.grilledsausage.molva.api.entity.filmmaker.Filmmaker;
import com.grilledsausage.molva.api.entity.movie.Movie;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

Expand All @@ -16,7 +17,7 @@ public class Participation {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "participation_id", nullable = false)
@Column(name = "participation_id")
private Long id;

@ManyToOne
Expand All @@ -27,4 +28,9 @@ public class Participation {
@JoinColumn(name = "filmmaker_id", nullable = false)
private Filmmaker filmmaker;

@Builder
public Participation(Movie movie, Filmmaker filmmaker) {
this.movie = movie;
this.filmmaker = filmmaker;
}
}
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;
}
}
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);

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.grilledsausage.molva.api.entity.movie.Movie;
import com.grilledsausage.molva.api.entity.user.User;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

Expand All @@ -11,12 +12,12 @@
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Entity
@Table(name = "Reservation")
@Table(name = "Rating")
public class Rating {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "rating_id", nullable = false)
@Column(name = "rating_id")
private Long id;

@ManyToOne
Expand All @@ -30,4 +31,14 @@ public class Rating {
@Column(name = "user_rating", nullable = false)
private Double userRating;

public void setUserRating(Double userRating) {
this.userRating = userRating;
}

@Builder
public Rating(User user, Movie movie, Double userRating) {
this.user = user;
this.movie = movie;
this.userRating = userRating;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

import org.springframework.data.jpa.repository.JpaRepository;

import java.util.Optional;

public interface RatingRepository extends JpaRepository<Rating, Long> {

Optional<Rating> findByUser_IdAndMovie_Id(Long userId, Long movieId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.grilledsausage.molva.api.entity.movie.Movie;
import com.grilledsausage.molva.api.entity.user.User;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

Expand All @@ -27,4 +28,9 @@ public class Reservation {
@JoinColumn(name = "movie_id", nullable = false)
private Movie movie;

@Builder
public Reservation(User user, Movie movie) {
this.user = user;
this.movie = movie;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.grilledsausage.molva.api.entity.user;

import com.grilledsausage.molva.api.entity.preference.Preference;
import com.grilledsausage.molva.api.entity.rating.Rating;
import com.grilledsausage.molva.api.entity.reservation.Reservation;
import lombok.AccessLevel;
Expand Down Expand Up @@ -46,6 +47,9 @@ public class User implements UserDetails {
@OneToMany(mappedBy = "user", fetch = FetchType.LAZY)
private List<Rating> ratings = new ArrayList<>();

@OneToMany(mappedBy = "user", fetch = FetchType.LAZY)
private List<Preference> preferences = new ArrayList<>();

@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
List<String> roles = new ArrayList<>();
Expand Down
Loading

0 comments on commit f8c3957

Please sign in to comment.