Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions HELP.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
# Read Me First
The following was discovered as part of building this project:

* The JVM level was changed from '11' to '17', review the [JDK Version Range](https://github.com/spring-projects/spring-framework/wiki/Spring-Framework-Versions#jdk-version-range) on the wiki for more details.

# Getting Started

### Reference Documentation
For further reference, please consider the following sections:

* [Official Apache Maven documentation](https://maven.apache.org/guides/index.html)
* [Spring Boot Maven Plugin Reference Guide](https://docs.spring.io/spring-boot/docs/3.1.3/maven-plugin/reference/html/)
* [Create an OCI image](https://docs.spring.io/spring-boot/docs/3.1.3/maven-plugin/reference/html/#build-image)
* [Spring Web](https://docs.spring.io/spring-boot/docs/3.1.3/reference/htmlsingle/index.html#web)
* [Spring Boot Maven Plugin Reference Guide](https://docs.spring.io/spring-boot/docs/2.7.13/maven-plugin/reference/html/)
* [Create an OCI image](https://docs.spring.io/spring-boot/docs/2.7.13/maven-plugin/reference/html/#build-image)
* [Spring Web](https://docs.spring.io/spring-boot/docs/2.7.13/reference/htmlsingle/#web)

### Guides
The following guides illustrate how to use some features concretely:
Expand Down
51 changes: 51 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,53 @@
# java-filmorate
Template repository for Filmorate project.

![Sheme data base for filmorate](db_filmorate.jpg)

В таблице User храняться все пльзователи приложения
В таблице Friends храняться все дружественные связи со статусом их подтвреждения

В таблице Film храняться все фильмы
В талице MPA храняться все рейтинги фильмов, а в Film добавляется только индекс нужного рейтинга
сделано так что бы убрать избыточность
В таблице genre храняться все жанры и так как связь к фильма многие ко многим выделена таблица для связи genre_film
В таблице likes храняться все id пользователе которым понравился фильма

Запросы

1.Для получения таблицы всей информации обо всех пользователях
SLECT *
FROM user;

2.Для получения таблицы всех пользователей и их друзей
SELECT u.name,
f.isApproved,
u2.name
FROM user u
JOIN friend f ON f.id_user1 = u.id;
JOIN user u2 ON u2.id = f.id_user2

2.Для получения таблицы конкретного пользователя и его друзей
SELECT u.name,
f.isApproved,
u2.name
FROM user u
JOIN friend f ON f.id_user1 = u.id;
JOIN user u2 ON u2.id = f.id_user2
WHERE u.id = {id}

3.Для полученя таблицы всех фильмов и информации о них
SELECT *
FROM film

4.Для получения таблицы всех пользователе кому понравился конкретный фильма
SELECT likes.id_user
FROM film f
JOIN likes_film likes ON likes.id_film = f.id
WHERE f.id = {id}

5.Для получения таблицы всех жанров конкретного фильма
SELECT g.name
FROM film f
JOIN genre_film gf ON gf.id_film = film.id
JOIN genre g ON g.id = gf.id_genre
WHERE f.id = {id}
Binary file added db_filmorate.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 32 additions & 14 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,58 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.15</version>
<version>2.7.13</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>ru.yandex.practicum.com.example</groupId>
<groupId>ru.yandex.practicum</groupId>
<artifactId>filmorate</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>filmorate</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.28</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<artifactId>spring-boot-starter-data-jdbc</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.20</version>
<scope>compile</scope>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package ru.yandex.practicum.filmorate;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
@AutoConfiguration
public class FilmorateApplication {

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package ru.yandex.practicum.filmorate.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import ru.yandex.practicum.filmorate.exception.NotFoundException;
import ru.yandex.practicum.filmorate.exception.ValidateException;
import ru.yandex.practicum.filmorate.model.Model;
import ru.yandex.practicum.filmorate.service.Service;

import java.util.List;

@RequiredArgsConstructor
public abstract class Controller<T extends Model> {

protected final Service<T> service;


public T add(T model) throws ValidateException {

return service.addModel(model);
}


public T update(T model) throws NotFoundException {
service.updateModel(model);
return model;
}

@GetMapping
public List<T> getModelList() {
return service.getModelList();
}

public T get(int id) throws NotFoundException {
T model = service.getModelById(id);

return model;
}
}
Original file line number Diff line number Diff line change
@@ -1,31 +1,36 @@
package ru.yandex.practicum.filmorate.controller;


import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import ru.yandex.practicum.filmorate.manager.FilmManager;
import ru.yandex.practicum.filmorate.exception.NotFoundException;
import ru.yandex.practicum.filmorate.exception.ValidateException;
import ru.yandex.practicum.filmorate.model.Film;
import ru.yandex.practicum.filmorate.service.Service;

import javax.validation.Valid;

import java.util.List;
@Slf4j
@RequestMapping("/films")
public class FilmController extends Controller<Film> {

@RestController
@RequestMapping ("/films")
public class FilmController {
FilmManager filmManager = new FilmManager();

@GetMapping
private List<Film> getFilm() {
return filmManager.getFilmsList();
public FilmController(Service<Film> service) {
super(service);
}

@PostMapping
public Film add(@RequestBody @Valid Film model) throws ValidateException {
return super.add(model);
}

@PutMapping
private Film update(@RequestBody Film film) {
return filmManager.updateFilm(film);
public Film update(@RequestBody @Valid Film model) throws NotFoundException {
return super.update(model);
}

@PostMapping
private Film add(@RequestBody Film film) {
return filmManager.addFilm(film);
@GetMapping("/{id}")
public Film get(@PathVariable int id) throws NotFoundException {
return super.get(id);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package ru.yandex.practicum.filmorate.controller;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;
import ru.yandex.practicum.filmorate.exception.NotFoundException;
import ru.yandex.practicum.filmorate.model.Film;
import ru.yandex.practicum.filmorate.model.FilmLikes;
import ru.yandex.practicum.filmorate.service.ManageLikeFilmService;
import ru.yandex.practicum.filmorate.service.ServiceFilm;

import java.util.List;

@RestController
public class FilmLikeController extends FilmController {
protected static final String USE_SERVICE = "ManageLikeFilmService";
private final ManageLikeFilmService manageLikeFilmService;

public FilmLikeController(@Qualifier(USE_SERVICE) ServiceFilm filmService) {
super(filmService);
manageLikeFilmService = (ManageLikeFilmService) filmService;
}

@PutMapping("/{id}/like/{userId}")
public void setLike(@PathVariable int id, @PathVariable int userId) {
manageLikeFilmService.addLike(new FilmLikes(id, userId));
}

@DeleteMapping("/{id}/like/{userId}")
public void deleteLike(@PathVariable int id, @PathVariable int userId) throws NotFoundException {
manageLikeFilmService.deleteLike(new FilmLikes(id, userId));
}

@GetMapping("/popular")
public List<Film> getFilmsPopular(@RequestParam(defaultValue = "10") int count) {

return manageLikeFilmService.getFilmsPopular(count);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package ru.yandex.practicum.filmorate.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import ru.yandex.practicum.filmorate.exception.NotFoundException;
import ru.yandex.practicum.filmorate.model.Genre;
import ru.yandex.practicum.filmorate.service.ServiceFilm;

import java.util.List;

@RestController
@RequestMapping("/genres")
@RequiredArgsConstructor
public class GenresController {
private final ServiceFilm filmService;

@GetMapping("/{id}")
public Genre getGenreByID(@PathVariable int id) throws NotFoundException {
return filmService.getGenre(id);
}

@GetMapping
public List<Genre> getGenreList() {
return filmService.getGenreList();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package ru.yandex.practicum.filmorate.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import ru.yandex.practicum.filmorate.exception.NotFoundException;
import ru.yandex.practicum.filmorate.model.Mpa;
import ru.yandex.practicum.filmorate.service.ServiceFilm;

import java.util.List;

@RestController
@RequestMapping("/mpa")
@RequiredArgsConstructor
public class MpaController {
private final ServiceFilm filmService;

@GetMapping
public List<Mpa> getMpaList() {
return filmService.getMpaList();
}

@GetMapping("/{id}")
public Mpa getMpaById(@PathVariable int id) throws NotFoundException {
return filmService.getMpa(id);
}

}
Loading