-
Notifications
You must be signed in to change notification settings - Fork 1
Добавление нового функционала: #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Chizhara
wants to merge
5
commits into
main
Choose a base branch
from
develop
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
src/main/java/ru/yandex/practicum/filmorate/controller/DirectorController.java
This file contains hidden or 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,50 @@ | ||
| 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.model.Director; | ||
| import ru.yandex.practicum.filmorate.service.DirectorService; | ||
|
|
||
| import javax.validation.Valid; | ||
| import java.util.List; | ||
|
|
||
| @Slf4j | ||
| @RestController | ||
| @RequiredArgsConstructor | ||
| @RequestMapping("/directors") | ||
| public class DirectorController { | ||
|
|
||
| private final DirectorService directorService; | ||
|
|
||
| @GetMapping | ||
| public List<Director> getAll() { | ||
| log.info("GET-запрос к эндпоинту: '/directors'"); | ||
| return directorService.getAll(); | ||
| } | ||
|
|
||
| @GetMapping("/{directorId}") | ||
| public Director findDirector(@PathVariable("directorId") long directorId) { | ||
| log.info("GET-запрос к эндпоинту: '/directors/{directorId}'"); | ||
| return directorService.findById(directorId); | ||
| } | ||
|
|
||
| @PostMapping | ||
| public Director createDirector(@Valid @RequestBody Director director) { | ||
| log.info("POST-запрос к эндпоинту: '/directors'"); | ||
| return directorService.create(director); | ||
| } | ||
|
|
||
| @PutMapping | ||
| public Director updateDirector(@Valid @RequestBody Director director) { | ||
| log.info("PUT-запрос к эндпоинту: '/directors'"); | ||
| return directorService.update(director); | ||
| } | ||
|
|
||
| @DeleteMapping("/{directorId}") | ||
| public Director deleteDirector(@PathVariable("directorId") long directorId) { | ||
| log.info("DELETE-запрос к эндпоинту: '/directors/{directorId}'"); | ||
| return directorService.delete(directorId); | ||
| } | ||
|
|
||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
77 changes: 77 additions & 0 deletions
77
src/main/java/ru/yandex/practicum/filmorate/controller/ReviewsController.java
This file contains hidden or 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,77 @@ | ||
| package ru.yandex.practicum.filmorate.controller; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.validation.annotation.Validated; | ||
| import org.springframework.web.bind.annotation.*; | ||
| import ru.yandex.practicum.filmorate.model.Review; | ||
| import ru.yandex.practicum.filmorate.service.impl.BaseReviewService; | ||
|
|
||
| import javax.validation.Valid; | ||
| import java.util.List; | ||
|
|
||
| @Slf4j | ||
| @Validated | ||
| @RestController | ||
| @RequiredArgsConstructor | ||
| @RequestMapping("/reviews") | ||
| public class ReviewsController { | ||
|
|
||
| private final BaseReviewService reviewService; | ||
|
|
||
| @GetMapping() | ||
| public List<Review> getAll(@RequestParam(required = false) Long filmId, | ||
| @RequestParam(defaultValue = "10", required = false) Integer count) { | ||
| log.info("GET-запрос к эндпоинту: '/reviews?filmId={filmId}&count={count}'"); | ||
| return reviewService.getAll(filmId, count); | ||
| } | ||
|
|
||
| @GetMapping("/{id}") | ||
| public Review getReview(@PathVariable("id") long id) { | ||
| log.info("GET-запрос к эндпоинту: '/reviews/{id}'"); | ||
| return reviewService.getReview(id); | ||
| } | ||
|
|
||
| @PostMapping() | ||
| public Review create(@Valid @RequestBody Review review) { | ||
| log.info("POST-запрос к эндпоинту: '/reviews'"); | ||
| return reviewService.create(review); | ||
| } | ||
|
|
||
| @PutMapping() | ||
| public Review update(@Valid @RequestBody Review review) { | ||
| log.info("PUT-запрос к эндпоинту: '/reviews'"); | ||
| return reviewService.update(review); | ||
| } | ||
|
|
||
| @DeleteMapping("/{id}") | ||
| public void remove(@PathVariable("id") long id) { | ||
| log.info("DELETE-запрос к эндпоинту: '/reviews/{id}'"); | ||
| reviewService.remove(id); | ||
| } | ||
|
|
||
| @PutMapping("/{id}/like/{userId}") | ||
| public void addLike(@PathVariable("id") long id, @PathVariable("userId") long userId) { | ||
| log.info("PUT-запрос к эндпоинту: '/reviews/{id}/like/{userId}'"); | ||
| reviewService.addLike(id, userId); | ||
| } | ||
|
|
||
| @DeleteMapping("/{id}/like/{userId}") | ||
| public void removeLike(@PathVariable("id") long id, @PathVariable("userId") long userId) { | ||
| log.info("DELETE-запрос к эндпоинту: '/reviews/{id}/like/{userId}'"); | ||
| reviewService.removeLike(id, userId); | ||
| } | ||
|
|
||
| @PutMapping("/{id}/dislike/{userId}") | ||
| public void addDislike(@PathVariable("id") long id, @PathVariable("userId") long userId) { | ||
| log.info("PUT-запрос к эндпоинту: '/reviews/{id}/dislike/{userId}'"); | ||
| reviewService.addDislike(id, userId); | ||
| } | ||
|
|
||
| @DeleteMapping("/{id}/dislike/{userId}") | ||
| public void removeDislike(@PathVariable("id") long id, @PathVariable("userId") long userId) { | ||
| log.info("PUT-запрос к эндпоинту: '/reviews/{id}/dislike/{userId}'"); | ||
| reviewService.removeDislike(id, userId); | ||
| } | ||
|
|
||
| } |
This file contains hidden or 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
16 changes: 16 additions & 0 deletions
16
src/main/java/ru/yandex/practicum/filmorate/dao/DirectorRepository.java
This file contains hidden or 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,16 @@ | ||
| package ru.yandex.practicum.filmorate.dao; | ||
|
|
||
| import ru.yandex.practicum.filmorate.model.Director; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Optional; | ||
| import java.util.Set; | ||
|
|
||
| public interface DirectorRepository extends Repository<Director> { | ||
|
|
||
| Optional<Director> findById(long id); | ||
|
|
||
| void delete(long directorId); | ||
|
|
||
| Set<Director> findByIds(List<Long> ids); | ||
| } |
12 changes: 12 additions & 0 deletions
12
src/main/java/ru/yandex/practicum/filmorate/dao/EventRepository.java
This file contains hidden or 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,12 @@ | ||
| package ru.yandex.practicum.filmorate.dao; | ||
|
|
||
| import ru.yandex.practicum.filmorate.model.Event; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public interface EventRepository { | ||
|
|
||
| List<Event> getNewsFeed(long userId); | ||
|
|
||
| void saveFeed(Event event); | ||
| } |
17 changes: 17 additions & 0 deletions
17
src/main/java/ru/yandex/practicum/filmorate/dao/FilmDirectorsRepository.java
This file contains hidden or 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 ru.yandex.practicum.filmorate.dao; | ||
|
|
||
| import ru.yandex.practicum.filmorate.model.Director; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
|
|
||
| public interface FilmDirectorsRepository { | ||
| Map<Long, Set<Director>> findDirectorsByFilmIds(List<Long> filmIds); | ||
|
|
||
| Set<Director> findDirectorsByFilmId(long filmId); | ||
|
|
||
| void setFilmDirectors(long filmId, Set<Director> directors); | ||
|
|
||
| void deleteFilmDirectors(long filmId, Set<Director> directors); | ||
| } |
10 changes: 10 additions & 0 deletions
10
src/main/java/ru/yandex/practicum/filmorate/dao/FilmRepository.java
This file contains hidden or 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 |
|---|---|---|
| @@ -1,14 +1,24 @@ | ||
| package ru.yandex.practicum.filmorate.dao; | ||
|
|
||
| import ru.yandex.practicum.filmorate.enums.SearchFilmBy; | ||
| import ru.yandex.practicum.filmorate.model.Film; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Optional; | ||
| import java.util.Set; | ||
|
|
||
| public interface FilmRepository extends Repository<Film> { | ||
|
|
||
| List<Film> getAll(); | ||
|
|
||
| Optional<Film> getFilm(long filmId); | ||
|
|
||
| void deleteFilm(long filmId); | ||
|
|
||
| List<Film> getSortedByYearFilmsOfDirector(long directorId); | ||
|
|
||
| List<Film> getSortedByLikesFilmsOfDirector(long directorId); | ||
|
|
||
| List<Film> searchFilmByNameAndDirectors(String query, Set<SearchFilmBy> by); | ||
|
|
||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.