-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
266 additions
and
120 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package soc.movies.entities; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Table; | ||
import java.time.OffsetDateTime; | ||
import org.jooq.Field; | ||
import org.jooq.SelectFieldOrAsterisk; | ||
import org.jooq.impl.DSL; | ||
|
||
@Entity | ||
@Table(name = "ratings") | ||
public class RatingEntity { | ||
|
||
@Column(name = "id") | ||
long id; | ||
|
||
@Column(name = "user_id") | ||
long userId; | ||
|
||
@Column(name = "movie_id") | ||
long movieId; | ||
|
||
@Column(name = "rating") | ||
double rating; | ||
|
||
@Column(name = "created_at") | ||
OffsetDateTime createdAt; | ||
|
||
public RatingEntity() { | ||
} | ||
|
||
public static Field<Long> idField() { | ||
return DSL.field("id", Long.class); | ||
} | ||
|
||
public static Field<OffsetDateTime> createdAtField() { | ||
return DSL.field("created_at", OffsetDateTime.class); | ||
} | ||
|
||
public static Field<Long> movieIdField() { | ||
return DSL.field("movie_id", Long.class); | ||
} | ||
|
||
public static Field<Long> userIdField() { | ||
return DSL.field("user_id", Long.class); | ||
} | ||
|
||
public static Field<Double> ratingField() { | ||
return DSL.field("rating", Double.class); | ||
} | ||
|
||
public static org.jooq.Table<org.jooq.Record> table() { | ||
return DSL.table("ratings"); | ||
} | ||
|
||
public static SelectFieldOrAsterisk[] asterisk() { | ||
return new SelectFieldOrAsterisk[]{ | ||
idField(), | ||
movieIdField(), | ||
userIdField(), | ||
ratingField(), | ||
createdAtField() | ||
}; | ||
} | ||
|
||
public long getId() { | ||
return id; | ||
} | ||
|
||
public long getUserId() { | ||
return userId; | ||
} | ||
|
||
public long getMovieId() { | ||
return movieId; | ||
} | ||
|
||
public double getRating() { | ||
return rating; | ||
} | ||
|
||
public OffsetDateTime getCreatedAt() { | ||
return createdAt; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/soc/movies/exceptions/InvalidRatingException.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,17 @@ | ||
package soc.movies.exceptions; | ||
|
||
import io.javalin.http.HttpStatus; | ||
import soc.movies.web.dto.ErrorResponse; | ||
|
||
public class InvalidRatingException extends MovieException { | ||
|
||
@Override | ||
public ErrorResponse buildResponse() { | ||
return ErrorResponse.build("Rating must be between 0 and 10"); | ||
} | ||
|
||
@Override | ||
public HttpStatus getStatus() { | ||
return HttpStatus.BAD_REQUEST; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/soc/movies/exceptions/RatingAlreadyExistsException.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,17 @@ | ||
package soc.movies.exceptions; | ||
|
||
import io.javalin.http.HttpStatus; | ||
import soc.movies.web.dto.ErrorResponse; | ||
|
||
public class RatingAlreadyExistsException extends MovieException { | ||
|
||
@Override | ||
public ErrorResponse buildResponse() { | ||
return ErrorResponse.build("Movie rating from this user already exists"); | ||
} | ||
|
||
@Override | ||
public HttpStatus getStatus() { | ||
return HttpStatus.CONFLICT; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package soc.movies.web.dto; | ||
|
||
public record RateMovieRequest(String username, double rating) { | ||
|
||
} |
Oops, something went wrong.