Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
12 commits
Select commit Hold shift + click to select a range
466cb1b
Первая реализация тз 12ого спринта.
slavakorg Apr 26, 2025
c261b6f
Первая реализация тз 12ого спринта. исправления для автотестов
slavakorg Apr 26, 2025
04d68e5
Первая реализация тз 12ого спринта. исправления для автотестов
slavakorg Apr 26, 2025
a06eaac
Вторая реализация тз 12ого спринта.
slavakorg Apr 26, 2025
e9b544c
Третья реализация тз 12ого спринта.
slavakorg Apr 26, 2025
a9e4c47
Третья реализация тз 12ого спринта. исправления для автотестов
slavakorg Apr 26, 2025
1c7e07a
Третья реализация тз 12ого спринта. исправления для автотестов 2
slavakorg Apr 26, 2025
7dc8fdc
Третья реализация тз 12ого спринта. исправления для автотестов 3
slavakorg Apr 26, 2025
7b0c1e4
Третья реализация тз 12ого спринта. исправления для автотестов
slavakorg Apr 26, 2025
5bda6b2
Третья реализация тз 12ого спринта. исправления для автотестов
slavakorg Apr 26, 2025
502b0e8
Третья реализация тз 12ого спринта. исправления для автотестов
slavakorg Apr 26, 2025
d37c10f
Третья реализация тз 12ого спринта. исправления для автотестов
slavakorg Apr 26, 2025
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
Binary file modified FilmorateDatabase.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 5 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,6 @@ user_id integer (Первичный ключ): Идентификатор пол

friend_id integer (Внешний ключ): Идентификатор другого пользователя(потенциального друга).

status_id integer (Внешний ключ): Идентификатор статуса дружбы между пользователями.

## Таблица friendship_status.

### Хранит информацию о статусах дружбы.

status_id integer (Первичный ключ): Идентификатор статуса дружбы между пользователями.

status_name varchar: Наименование статуса.

## Таблица film_likes.

### Хранит информацию о лайках, которые пользователи поставили фильмам.
Expand All @@ -66,21 +56,21 @@ user_id integer (Первичный ключ): Идентификатор пол

film_id integer (Внешний ключ): Идентификатор фильма.

## Таблица film_ganres.
## Таблица film_genres.

### Хранит информацию о жанре фильма.

film_id integer (Первичный ключ): Идентификатор фильма.

ganre_id integer (Внешний ключ): Идентификатор жанра.
genre_id integer (Внешний ключ): Идентификатор жанра.

## Таблица ganre.
## Таблица genre.

### Хранит информацию о жанрах.

ganre_id integer (Первичный ключ): Идентификатор жанра.
genre_id integer (Первичный ключ): Идентификатор жанра.

ganre_name varchar: Наименование жанра.
genre_name varchar: Наименование жанра.

## Таблица mpa.

Expand Down
23 changes: 19 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<java.version>21</java.version>
</properties>
<dependencies>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
Expand All @@ -26,17 +27,31 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>

</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;


@SpringBootApplication
public class FilmorateApplication {
public static void main(String[] args) {
SpringApplication.run(FilmorateApplication.class, args);

}


}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.http.HttpStatus;
import ru.yandex.practicum.filmorate.exception.DataNotFoundException;
import ru.yandex.practicum.filmorate.model.ErrorResponse;
Expand Down Expand Up @@ -32,5 +33,12 @@ public ErrorResponse handleNotFoundException(final DataNotFoundException e) {

}

}
@ExceptionHandler
@ResponseStatus(HttpStatus.NOT_FOUND)
public ErrorResponse emptyData(final EmptyResultDataAccessException e) {
log.info("404 {}", e.getMessage());
return new ErrorResponse(e.getMessage());

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;
Expand All @@ -12,7 +13,6 @@


import java.util.Collection;
import java.util.List;


@RestController
Expand All @@ -28,9 +28,14 @@ public Collection<Film> getFilms() {
return filmService.getFilms();
}

@GetMapping(path = "/films/{id}")
public Film getFilmById(@PathVariable("id") int id) {
return filmService.getFilmById(id);
}


@PostMapping(path = "/films")
public Film createFilm(@Valid @RequestBody Film film) throws ValidationException {
public Film createFilm(@Valid @RequestBody Film film) throws ValidationException, DataNotFoundException {
return filmService.createFilm(film);

}
Expand All @@ -53,9 +58,9 @@ public void deleteLike(@PathVariable("id") int id, @PathVariable("userId") int u
}

@GetMapping(path = "/films/popular")
public List<Film> getPopularFilms(@RequestParam(defaultValue = "10") int count) {
public Collection<Film> getPopularFilms(@RequestParam(defaultValue = "10") int count) {
return filmService.getPopularFilms(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 lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import ru.yandex.practicum.filmorate.exception.DataNotFoundException;
import ru.yandex.practicum.filmorate.model.Genre;
import ru.yandex.practicum.filmorate.service.GenreService;

import java.util.Collection;

@RestController
@RequestMapping
@Slf4j
@RequiredArgsConstructor
public class GenreController {
private final GenreService genreService;

@GetMapping(path = "/genres/{id}")
public Genre getGenreById(@PathVariable("id") int id) throws DataNotFoundException {
return genreService.getGenreById(id);

}

@GetMapping(path = "/genres")
public Collection<Genre> getGenres() {
return genreService.getGenres();

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

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
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.DataNotFoundException;
import ru.yandex.practicum.filmorate.model.Mpa;
import ru.yandex.practicum.filmorate.service.MpaService;

import java.util.Collection;

@RestController
@RequestMapping
@Slf4j
@RequiredArgsConstructor
public class MpaController {

private final MpaService mpaService;

@GetMapping(path = "/mpa/{id}")
public Mpa getMpaById(@PathVariable("id") int id) throws DataNotFoundException {
return mpaService.getById(id);

}

@GetMapping(path = "/mpa")
public Collection<Mpa> getAllMpa() {
return mpaService.getAllMpa();

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ public List<User> getUserFriends(@PathVariable("id") int id) throws DataNotFound
public List<User> getCommonFriends(@PathVariable("id") int id, @PathVariable("otherId") int otherId) throws DataNotFoundException {
return userService.getCommonFriends(id, otherId);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ public class DataNotFoundException extends Exception {
public DataNotFoundException(String message) {
super(message);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ public class ValidationException extends Exception {
public ValidationException(String message) {
super(message);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ public String toString() {
return
"error= " + error;
}
}
}
22 changes: 12 additions & 10 deletions src/main/java/ru/yandex/practicum/filmorate/model/Film.java
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
package ru.yandex.practicum.filmorate.model;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import jakarta.validation.constraints.NotNull;
import lombok.*;

import java.time.LocalDate;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

import java.util.LinkedHashSet;


@Getter
@Setter
@RequiredArgsConstructor
@AllArgsConstructor
@NoArgsConstructor
@ToString
@EqualsAndHashCode(of = "id")
public class Film {
private Integer id;
private String name;
private String description;
@NotNull
private LocalDate releaseDate;
private Long duration;
@NotNull
private Mpa mpa;
private Set<Integer> likes = new HashSet<>();
private Collection<Genre> genres;
private LinkedHashSet<Genre> genres;


}
}

This file was deleted.

10 changes: 5 additions & 5 deletions src/main/java/ru/yandex/practicum/filmorate/model/Genre.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package ru.yandex.practicum.filmorate.model;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.*;

@Setter
@Getter
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode
public class Genre {

private int id;
private Integer id;
private String name;
}
}
4 changes: 2 additions & 2 deletions src/main/java/ru/yandex/practicum/filmorate/model/Mpa.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
@Setter
@NoArgsConstructor
public class Mpa {
private int id;
private Integer id;

private String name;
}
}
9 changes: 5 additions & 4 deletions src/main/java/ru/yandex/practicum/filmorate/model/User.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package ru.yandex.practicum.filmorate.model;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.*;

import java.time.LocalDate;
import java.util.HashSet;
import java.util.Set;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@ToString
@EqualsAndHashCode
public class User {
private Set<Integer> friendsList = new HashSet<>();
private Integer id;
Expand All @@ -19,4 +20,4 @@ public class User {
private String name;
private LocalDate birthday;

}
}
Loading