-
Notifications
You must be signed in to change notification settings - Fork 0
Feature comments #3
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
SugarFoxy
wants to merge
13
commits into
main
Choose a base branch
from
feature_comments
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
13 commits
Select commit
Hold shift + click to select a range
d551e6e
feat: Добавила возможность коментировать события
AshKeeper c7ceb2e
feat: Добавила возможность включать и отключать коментарии
AshKeeper 49e4f02
fix: Настройка
AshKeeper 6b79c5e
feat: Добавила Postman тесты
AshKeeper a550ce9
Style: поправила код
AshKeeper a31c02d
Style: поправила код
AshKeeper b49f3c3
ссылка на пул
SugarFoxy 0a07c55
fix: исправления после ревью
AshKeeper 5bf2732
Merge remote-tracking branch 'origin/feature_comments' into feature_c…
AshKeeper d04c6ae
fix: настройка
AshKeeper 58a1e15
fix: настройка
AshKeeper 7440203
fix: исправления после ревью
AshKeeper 3208b6e
fix: настройка
AshKeeper 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
This file was deleted.
Oops, something went wrong.
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,2 +1,4 @@ | ||
| # java-explore-with-me | ||
| Template repository for ExploreWithMe project. | ||
| --- | ||
| https://github.com/SugarFoxy/java-explore-with-me/pull/3 |
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
57 changes: 57 additions & 0 deletions
57
...rvice/src/main/java/ru/practicum/events/comments/controller/ControllerPrivateComment.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,57 @@ | ||
| package ru.practicum.events.comments.controller; | ||
|
|
||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.http.HttpStatus; | ||
| import org.springframework.web.bind.annotation.*; | ||
| import ru.practicum.events.comments.dto.InCommentDto; | ||
| import ru.practicum.events.comments.dto.OutCommentDto; | ||
| import ru.practicum.events.comments.service.CommentPrivateService; | ||
| import ru.practicum.util.exception.handler.CustomExceptionHandler; | ||
|
|
||
| @RestController | ||
| @RequestMapping("/users/{userId}/comments") | ||
| @CustomExceptionHandler | ||
| public class ControllerPrivateComment { | ||
| private final CommentPrivateService service; | ||
|
|
||
| @Autowired | ||
| public ControllerPrivateComment(CommentPrivateService service) { | ||
| this.service = service; | ||
| } | ||
|
|
||
| @PostMapping | ||
| @ResponseStatus(HttpStatus.CREATED) | ||
| public OutCommentDto createComment(@PathVariable Long userId, | ||
| @RequestBody InCommentDto dto) { | ||
| return service.createComment(userId, dto); | ||
| } | ||
|
|
||
| @PatchMapping("/{commentId}") | ||
| public OutCommentDto updateComment(@PathVariable Long userId, | ||
| @PathVariable Long commentId, | ||
| @RequestBody InCommentDto dto) { | ||
| return service.updateComment(userId, commentId, dto); | ||
| } | ||
|
|
||
| @DeleteMapping("/{commentId}") | ||
| @ResponseStatus(HttpStatus.NO_CONTENT) | ||
| public void deleteComment(@PathVariable Long userId, | ||
| @PathVariable Long commentId) { | ||
| service.deleteComment(userId, commentId); | ||
| } | ||
|
|
||
| @PostMapping("/{commentId}/like") | ||
| @ResponseStatus(HttpStatus.CREATED) | ||
| public OutCommentDto leaveRating(@PathVariable Long userId, | ||
| @PathVariable Long commentId, | ||
| @RequestParam Boolean grade) { | ||
| return service.leaveRating(userId, commentId, grade); | ||
| } | ||
|
|
||
| @DeleteMapping("/{commentId}/like") | ||
| @ResponseStatus(HttpStatus.NO_CONTENT) | ||
| public void deleteRating(@PathVariable Long userId, | ||
| @PathVariable Long commentId) { | ||
| service.deleteRating(userId, commentId); | ||
| } | ||
| } | ||
35 changes: 35 additions & 0 deletions
35
...ervice/src/main/java/ru/practicum/events/comments/controller/ControllerPublicComment.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,35 @@ | ||
| package ru.practicum.events.comments.controller; | ||
|
|
||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RequestParam; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
| import ru.practicum.events.comments.dto.OutCommentDto; | ||
| import ru.practicum.events.comments.service.CommentPublicService; | ||
| import ru.practicum.util.exception.handler.CustomExceptionHandler; | ||
|
|
||
| import javax.validation.constraints.NotNull; | ||
| import javax.validation.constraints.Positive; | ||
| import javax.validation.constraints.PositiveOrZero; | ||
| import java.util.List; | ||
|
|
||
| @RestController | ||
| @RequestMapping("/comment") | ||
| @CustomExceptionHandler | ||
| public class ControllerPublicComment { | ||
| private final CommentPublicService service; | ||
|
|
||
| @Autowired | ||
| public ControllerPublicComment(CommentPublicService service) { | ||
| this.service = service; | ||
| } | ||
|
|
||
| @GetMapping | ||
| public List<OutCommentDto> getCommentByEvent(@NotNull @RequestParam Long eventId, | ||
| @RequestParam(defaultValue = "false") Boolean rating, | ||
| @PositiveOrZero @RequestParam(defaultValue = "0") Integer from, | ||
| @Positive @RequestParam(defaultValue = "10") Integer size) { | ||
| return service.getCommentByEvent(eventId, rating, from, size); | ||
| } | ||
| } |
17 changes: 17 additions & 0 deletions
17
main-service/src/main/java/ru/practicum/events/comments/dto/InCommentDto.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.practicum.events.comments.dto; | ||
|
|
||
| import lombok.*; | ||
|
|
||
| import javax.validation.constraints.NotBlank; | ||
| import javax.validation.constraints.NotNull; | ||
|
|
||
| @Setter | ||
| @Getter | ||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
| public class InCommentDto { | ||
| @NotNull | ||
| @NotBlank | ||
| private String text; | ||
| private Long eventId; | ||
| } |
17 changes: 17 additions & 0 deletions
17
main-service/src/main/java/ru/practicum/events/comments/dto/OutCommentDto.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.practicum.events.comments.dto; | ||
|
|
||
| import lombok.*; | ||
| import ru.practicum.users.dto.UserShortDto; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| @Setter | ||
| @Getter | ||
| @Builder | ||
| public class OutCommentDto { | ||
| private Long id; | ||
| private UserShortDto commentator; | ||
| private String text; | ||
| private LocalDateTime commentTime; | ||
| private Long rating; | ||
| } |
44 changes: 44 additions & 0 deletions
44
main-service/src/main/java/ru/practicum/events/comments/mapper/CommentMapper.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,44 @@ | ||
| package ru.practicum.events.comments.mapper; | ||
|
|
||
| import ru.practicum.events.comments.dto.InCommentDto; | ||
| import ru.practicum.events.comments.dto.OutCommentDto; | ||
| import ru.practicum.events.comments.model.Comment; | ||
| import ru.practicum.events.event.model.Event; | ||
| import ru.practicum.users.mapper.UserMapper; | ||
| import ru.practicum.users.model.User; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| public final class CommentMapper { | ||
| private CommentMapper() { | ||
|
|
||
| } | ||
|
|
||
| public static OutCommentDto toDto(Comment comment) { | ||
| return OutCommentDto.builder() | ||
| .commentator(UserMapper.toShortDto(comment.getCommentator())) | ||
| .commentTime(comment.getCommentTime()) | ||
| .id(comment.getId()) | ||
| .text(comment.getText()) | ||
| .build(); | ||
| } | ||
|
|
||
| public static OutCommentDto toDto(Comment comment, Long rating) { | ||
| return OutCommentDto.builder() | ||
| .commentator(UserMapper.toShortDto(comment.getCommentator())) | ||
| .commentTime(comment.getCommentTime()) | ||
| .id(comment.getId()) | ||
| .text(comment.getText()) | ||
| .rating(rating) | ||
| .build(); | ||
| } | ||
|
|
||
| public static Comment toComment(InCommentDto dto, LocalDateTime time, User commentator, Event event) { | ||
| return Comment.builder() | ||
| .commentator(commentator) | ||
| .text(dto.getText()) | ||
| .commentTime(time) | ||
| .event(event) | ||
| .build(); | ||
| } | ||
| } |
31 changes: 31 additions & 0 deletions
31
main-service/src/main/java/ru/practicum/events/comments/model/Comment.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,31 @@ | ||
| package ru.practicum.events.comments.model; | ||
|
|
||
| import lombok.*; | ||
| import ru.practicum.events.event.model.Event; | ||
| import ru.practicum.users.model.User; | ||
|
|
||
| import javax.persistence.*; | ||
| import java.time.LocalDateTime; | ||
|
|
||
| @Setter | ||
| @Getter | ||
| @Builder | ||
| @AllArgsConstructor | ||
| @NoArgsConstructor | ||
| @Entity | ||
| @Table(name = "comments") | ||
| public class Comment { | ||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| private Long id; | ||
| @Column(name = "comment_text") | ||
| private String text; | ||
| @ManyToOne() | ||
| @JoinColumn(name = "user_id") | ||
| private User commentator; | ||
| @ManyToOne() | ||
| @JoinColumn(name = "event_id") | ||
| private Event event; | ||
| @Column(name = "comment_time") | ||
| private LocalDateTime commentTime; | ||
| } |
27 changes: 27 additions & 0 deletions
27
main-service/src/main/java/ru/practicum/events/comments/rating/model/Grade.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,27 @@ | ||
| package ru.practicum.events.comments.rating.model; | ||
|
|
||
| import lombok.*; | ||
| import ru.practicum.events.comments.model.Comment; | ||
| import ru.practicum.users.model.User; | ||
|
|
||
| import javax.persistence.*; | ||
|
|
||
| @Setter | ||
| @Getter | ||
| @Builder | ||
| @AllArgsConstructor | ||
| @NoArgsConstructor | ||
| @Entity | ||
| @Table(name = "rating") | ||
| public class Grade { | ||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| private Long id; | ||
| @ManyToOne() | ||
| @JoinColumn(name = "user_id") | ||
| private User rater; | ||
| @ManyToOne() | ||
| @JoinColumn(name = "comment_id") | ||
| private Comment comment; | ||
| private Boolean grade; | ||
| } |
14 changes: 14 additions & 0 deletions
14
main-service/src/main/java/ru/practicum/events/comments/rating/storage/RatingRepository.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,14 @@ | ||
| package ru.practicum.events.comments.rating.storage; | ||
|
|
||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
| import ru.practicum.events.comments.model.Comment; | ||
| import ru.practicum.events.comments.rating.model.Grade; | ||
| import ru.practicum.users.model.User; | ||
|
|
||
| public interface RatingRepository extends JpaRepository<Grade, Long> { | ||
| Long countGradeByCommentAndGrade(Comment comment, Boolean grade); | ||
|
|
||
| Boolean existsByCommentAndRater(Comment comment, User rater); | ||
|
|
||
| void deleteByCommentAndRater(Comment comment, User user); | ||
| } |
16 changes: 16 additions & 0 deletions
16
main-service/src/main/java/ru/practicum/events/comments/service/CommentPrivateService.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.practicum.events.comments.service; | ||
|
|
||
| import ru.practicum.events.comments.dto.InCommentDto; | ||
| import ru.practicum.events.comments.dto.OutCommentDto; | ||
|
|
||
| public interface CommentPrivateService { | ||
| OutCommentDto createComment(Long userId, InCommentDto dto); | ||
|
|
||
| OutCommentDto updateComment(Long userId, Long commentId, InCommentDto dto); | ||
|
|
||
| void deleteComment(Long userId, Long commentId); | ||
|
|
||
| OutCommentDto leaveRating(Long userId, Long commentId, Boolean grade); | ||
|
|
||
| void deleteRating(Long userId, Long commentId); | ||
| } |
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.
This comment was marked as resolved.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Спасибо что подсказал. Не дружу с английским. Поэтому и названия кривые