сдала с горем пополам
This commit is contained in:
parent
3fe9a0dc90
commit
df4b320756
@ -58,9 +58,10 @@ public class BackendApplication implements CommandLineRunner {
|
||||
// final var cat3 = new CategorieEntity(null, "Хоррор", null);
|
||||
// final var cat4 = new CategorieEntity(null, "Мультитк", null);
|
||||
|
||||
final var cat5 = new CategorieEntity(null, "Опера", null);
|
||||
// final var cat5 = new CategorieEntity(null, "Опера", null);
|
||||
|
||||
final var mov1 = new MovieEntity(null, cat5, "певчая птичка", "null", "null", null);
|
||||
// final var mov1 = new MovieEntity(null, cat5, "певчая птичка", "null", "null",
|
||||
// null);
|
||||
|
||||
// admin.setRole(UserRole.ADMIN);
|
||||
// vasya.setRole(UserRole.USER);
|
||||
@ -99,7 +100,8 @@ public class BackendApplication implements CommandLineRunner {
|
||||
|
||||
_logger.info("The program is started, coun users is " + userService.getAll().size());
|
||||
_logger.info("The program is started, coun films is " + movieService.getAll(0).size());
|
||||
_logger.info("The program is started, coun categories is " + categorieService.getAll().size());
|
||||
// _logger.info("The program is started, coun categories is " +
|
||||
// categorieService.getAll().size());
|
||||
|
||||
}
|
||||
|
||||
|
@ -27,6 +27,7 @@ import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
||||
@Controller
|
||||
@ -144,6 +145,7 @@ public class MovieUserController {
|
||||
@PostMapping("/changeFavStatus/{id}")
|
||||
public String changeFavStatus(@PathVariable(name = "id") Integer movieId,
|
||||
@RequestParam(name = PAGE_ATTRIBUTE, defaultValue = "0") int page,
|
||||
RedirectAttributes redirectAttributes,
|
||||
Model model) {
|
||||
|
||||
boolean isFavorite = false;
|
||||
@ -175,7 +177,7 @@ public class MovieUserController {
|
||||
favoriteService.delete(delFav.getId());
|
||||
}
|
||||
|
||||
model.addAttribute(PAGE_ATTRIBUTE, page);
|
||||
redirectAttributes.addAttribute(PAGE_ATTRIBUTE, page);
|
||||
|
||||
return Constants.REDIRECT_VIEW + URL;
|
||||
}
|
||||
@ -183,6 +185,7 @@ public class MovieUserController {
|
||||
@PostMapping("/changeViewStatus/{id}")
|
||||
public String changeViewStatus(@PathVariable(name = "id") Integer movieId,
|
||||
@RequestParam(name = PAGE_ATTRIBUTE, defaultValue = "0") int page,
|
||||
RedirectAttributes redirectAttributes,
|
||||
Model model) {
|
||||
|
||||
boolean isViewed = false;
|
||||
@ -214,8 +217,7 @@ public class MovieUserController {
|
||||
viewedServise.delete(delView.getId());
|
||||
}
|
||||
|
||||
model.addAttribute(PAGE_ATTRIBUTE, page);
|
||||
|
||||
redirectAttributes.addAttribute(PAGE_ATTRIBUTE, page);
|
||||
return Constants.REDIRECT_VIEW + URL;
|
||||
}
|
||||
|
||||
|
@ -10,6 +10,7 @@ import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.Table;
|
||||
import jakarta.persistence.Transient;
|
||||
|
||||
@Entity
|
||||
@Table(name = "movies")
|
||||
@ -31,6 +32,17 @@ public class MovieEntity extends BaseEntity {
|
||||
@Column(nullable = true)
|
||||
private String image;
|
||||
|
||||
@Transient
|
||||
private boolean isFavorite;
|
||||
|
||||
public boolean isFavorite() {
|
||||
return isFavorite;
|
||||
}
|
||||
|
||||
public void setFavorite(boolean isFavorite) {
|
||||
this.isFavorite = isFavorite;
|
||||
}
|
||||
|
||||
public MovieEntity() {
|
||||
super();
|
||||
}
|
||||
@ -45,6 +57,11 @@ public class MovieEntity extends BaseEntity {
|
||||
this.image = image;
|
||||
}
|
||||
|
||||
public MovieEntity(MovieEntity entity, boolean isFavorite) {
|
||||
this(entity.id, entity.categorie, entity.description, entity.duration, entity.image, entity.name);
|
||||
this.isFavorite = isFavorite;
|
||||
}
|
||||
|
||||
public CategorieEntity getCategorie() {
|
||||
return categorie;
|
||||
}
|
||||
|
@ -25,7 +25,16 @@ public interface MovieRepository
|
||||
|
||||
Optional<MovieEntity> deleteByCategorieId(Integer categorieId);
|
||||
|
||||
// @Query("")
|
||||
|
||||
@Query("SELECT COUNT(DISTINCT v.user.id) FROM ViewedEntity v WHERE v.movie.id = :movieId")
|
||||
Integer getCountViews(@Param("movieId") Integer movieId);
|
||||
|
||||
@Query("select new (com.example.backend.movies.model.MovieEntity(m, (case when f.user.id = :userId then true else false end))) from MovieEntity m left join FavoriteEntity f on m.id=f.movie.id")
|
||||
List<MovieEntity> getAndSetFavoriteMovies(@Param("userId") Integer userId);
|
||||
|
||||
// select u.id, u.username,u.name,u.surname,(case when s.SUBSCRIBER_ID=1 then
|
||||
// true else false end)as"subscribed"
|
||||
// from USERS u left join SUBSCRIBES s on u.id=s.user_id;
|
||||
|
||||
}
|
@ -101,4 +101,9 @@ public class MovieService {
|
||||
return repository.getCountViews(movieId);
|
||||
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public List<MovieEntity> setAndGetFavorites(Integer userId) {
|
||||
return repository.getAndSetFavoriteMovies(userId);
|
||||
}
|
||||
}
|
||||
|
BIN
data.mv.db
BIN
data.mv.db
Binary file not shown.
@ -847,3 +847,19 @@ INSERT INTO "PUBLIC"."CATEGORIES_COPY_3_0"("ID", "NAME", "IMAGE") OVERRIDING SYS
|
||||
org.h2.jdbc.JdbcSQLDataException: Ошибка преобразования данных при конвертации "CAST(REPEAT(CHAR(0), 9861) AS BINARY VARYING /* table: -3 id: 21 */) (CATEGORIES_COPY_3_0: ""IMAGE"" CHARACTER VARYING(255))"
|
||||
Data conversion error converting "CAST(REPEAT(CHAR(0), 9861) AS BINARY VARYING /* table: -3 id: 21 */) (CATEGORIES_COPY_3_0: ""IMAGE"" CHARACTER VARYING(255))"; SQL statement:
|
||||
INSERT INTO "PUBLIC"."CATEGORIES_COPY_3_0"("ID", "NAME", "IMAGE") OVERRIDING SYSTEM VALUE SELECT "ID", "NAME", "IMAGE" FROM "PUBLIC"."CATEGORIES" [22018-224]
|
||||
2024-06-21 16:19:57.086526+04:00 jdbc[13]: exception
|
||||
org.h2.jdbc.JdbcSQLSyntaxErrorException: Синтаксическая ошибка в выражении SQL "select * from movies m join [*]left favorites f on m.id == f.movie_id"; ожидалось "identifier"
|
||||
Syntax error in SQL statement "select * from movies m join [*]left favorites f on m.id == f.movie_id"; expected "identifier"; SQL statement:
|
||||
select * from movies m join left favorites f on m.id == f.movie_id [42001-224]
|
||||
2024-06-21 16:20:14.022117+04:00 jdbc[13]: exception
|
||||
org.h2.jdbc.JdbcSQLSyntaxErrorException: Синтаксическая ошибка в выражении SQL "select * from movies m join [*]left favorites f on m.id = f.movie_id"; ожидалось "identifier"
|
||||
Syntax error in SQL statement "select * from movies m join [*]left favorites f on m.id = f.movie_id"; expected "identifier"; SQL statement:
|
||||
select * from movies m join left favorites f on m.id = f.movie_id [42001-224]
|
||||
2024-06-21 16:35:31.277808+04:00 jdbc[13]: exception
|
||||
org.h2.jdbc.JdbcSQLSyntaxErrorException: Синтаксическая ошибка в выражении SQL "select * from movies m left join [*]left favorites f on m.id == f.movie_id"; ожидалось "identifier"
|
||||
Syntax error in SQL statement "select * from movies m left join [*]left favorites f on m.id == f.movie_id"; expected "identifier"; SQL statement:
|
||||
select * from movies m left join left favorites f on m.id == f.movie_id [42001-224]
|
||||
2024-06-21 16:35:37.602519+04:00 jdbc[13]: exception
|
||||
org.h2.jdbc.JdbcSQLSyntaxErrorException: Синтаксическая ошибка в выражении SQL "select * from movies m left join favorites f on m.id =[*]= f.movie_id"; ожидалось "ALL (, ANY (, SOME ("
|
||||
Syntax error in SQL statement "select * from movies m left join favorites f on m.id =[*]= f.movie_id"; expected "ALL (, ANY (, SOME ("; SQL statement:
|
||||
select * from movies m left join favorites f on m.id == f.movie_id [42001-224]
|
||||
|
Loading…
x
Reference in New Issue
Block a user