generated from yandex-praktikum/java-explore-with-me
-
Notifications
You must be signed in to change notification settings - Fork 0
Feature comments #8
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
Ilusha92
wants to merge
6
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
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/Ilusha92/java-explore-with-me/pull/8 |
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
36 changes: 36 additions & 0 deletions
36
...ce/src/main/java/ru/practicum/main_service/comment/controller/CommentAdminController.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,36 @@ | ||
| package ru.practicum.main_service.comment.controller; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.data.domain.PageRequest; | ||
| import org.springframework.http.HttpStatus; | ||
| import org.springframework.validation.annotation.Validated; | ||
| import org.springframework.web.bind.annotation.*; | ||
| import ru.practicum.main_service.MainCommonUtils; | ||
| import ru.practicum.main_service.comment.dto.CommentDto; | ||
| import ru.practicum.main_service.comment.service.CommentService; | ||
|
|
||
| import javax.validation.constraints.Positive; | ||
| import javax.validation.constraints.PositiveOrZero; | ||
| import java.util.List; | ||
|
|
||
| @RestController | ||
| @RequiredArgsConstructor | ||
| @RequestMapping("/admin/comments") | ||
| @Validated | ||
| public class CommentAdminController { | ||
| private final CommentService commentService; | ||
|
|
||
| @GetMapping | ||
| @ResponseStatus(HttpStatus.OK) | ||
| public List<CommentDto> getCommentsByAdmin( | ||
| @RequestParam(required = false, defaultValue = MainCommonUtils.PAGE_DEFAULT_FROM) @PositiveOrZero Integer from, | ||
| @RequestParam(required = false, defaultValue = MainCommonUtils.PAGE_DEFAULT_SIZE) @Positive Integer size) { | ||
| return commentService.getCommentsByAdmin(PageRequest.of(from / size, size)); | ||
| } | ||
|
|
||
| @DeleteMapping("/{commentId}") | ||
| @ResponseStatus(HttpStatus.NO_CONTENT) | ||
| public void deleteByAdmin(@PathVariable Long commentId) { | ||
| commentService.deleteByAdmin(commentId); | ||
| } | ||
| } | ||
57 changes: 57 additions & 0 deletions
57
.../src/main/java/ru/practicum/main_service/comment/controller/CommentPrivateController.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.main_service.comment.controller; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.data.domain.PageRequest; | ||
| import org.springframework.http.HttpStatus; | ||
| import org.springframework.validation.annotation.Validated; | ||
| import org.springframework.web.bind.annotation.*; | ||
| import ru.practicum.main_service.MainCommonUtils; | ||
| import ru.practicum.main_service.comment.dto.CommentDto; | ||
| import ru.practicum.main_service.comment.dto.NewCommentDto; | ||
| import ru.practicum.main_service.comment.service.CommentService; | ||
|
|
||
| import javax.validation.Valid; | ||
| import javax.validation.constraints.Positive; | ||
| import javax.validation.constraints.PositiveOrZero; | ||
| import java.util.List; | ||
|
|
||
| @RestController | ||
| @RequiredArgsConstructor | ||
| @RequestMapping("/users/{userId}/comments") | ||
| @Validated | ||
| public class CommentPrivateController { | ||
| private final CommentService commentService; | ||
|
|
||
| @PostMapping | ||
| @ResponseStatus(HttpStatus.CREATED) | ||
| public CommentDto createByPrivate(@PathVariable Long userId, | ||
| @RequestParam Long eventId, | ||
| @Valid @RequestBody NewCommentDto newCommentDto) { | ||
| return commentService.createByPrivate(userId, eventId, newCommentDto); | ||
| } | ||
|
|
||
| @PatchMapping("/{commentId}") | ||
| @ResponseStatus(HttpStatus.OK) | ||
| public CommentDto patchByPrivate(@PathVariable Long userId, | ||
| @PathVariable Long commentId, | ||
| @Valid @RequestBody NewCommentDto newCommentDto) { | ||
| return commentService.patchByPrivate(userId, commentId, newCommentDto); | ||
| } | ||
|
|
||
| @DeleteMapping("/{commentId}") | ||
| @ResponseStatus(HttpStatus.NO_CONTENT) | ||
| public void deleteByPrivate(@PathVariable Long userId, | ||
| @PathVariable Long commentId) { | ||
| commentService.deleteByPrivate(userId, commentId); | ||
| } | ||
|
|
||
| @GetMapping | ||
| @ResponseStatus(HttpStatus.OK) | ||
| public List<CommentDto> getCommentsByPrivate( | ||
| @PathVariable Long userId, | ||
| @RequestParam(required = false) Long eventId, | ||
| @RequestParam(required = false, defaultValue = MainCommonUtils.PAGE_DEFAULT_FROM) @PositiveOrZero Integer from, | ||
| @RequestParam(required = false, defaultValue = MainCommonUtils.PAGE_DEFAULT_SIZE) @Positive Integer size) { | ||
| return commentService.getCommentsByPrivate(userId, eventId, PageRequest.of(from / size, size)); | ||
| } | ||
| } |
37 changes: 37 additions & 0 deletions
37
...e/src/main/java/ru/practicum/main_service/comment/controller/CommentPublicController.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,37 @@ | ||
| package ru.practicum.main_service.comment.controller; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.data.domain.PageRequest; | ||
| import org.springframework.http.HttpStatus; | ||
| import org.springframework.validation.annotation.Validated; | ||
| import org.springframework.web.bind.annotation.*; | ||
| import ru.practicum.main_service.MainCommonUtils; | ||
| import ru.practicum.main_service.comment.dto.CommentDto; | ||
| import ru.practicum.main_service.comment.service.CommentService; | ||
|
|
||
| import javax.validation.constraints.Positive; | ||
| import javax.validation.constraints.PositiveOrZero; | ||
| import java.util.List; | ||
|
|
||
| @RestController | ||
| @RequiredArgsConstructor | ||
| @RequestMapping("/comments") | ||
| @Validated | ||
| public class CommentPublicController { | ||
| private final CommentService commentService; | ||
|
|
||
| @GetMapping | ||
| @ResponseStatus(HttpStatus.OK) | ||
| public List<CommentDto> getCommentsByPublic( | ||
| @RequestParam Long eventId, | ||
| @RequestParam(required = false, defaultValue = MainCommonUtils.PAGE_DEFAULT_FROM) @PositiveOrZero Integer from, | ||
| @RequestParam(required = false, defaultValue = MainCommonUtils.PAGE_DEFAULT_SIZE) @Positive Integer size) { | ||
| return commentService.getCommentsByPublic(eventId, PageRequest.of(from / size, size)); | ||
| } | ||
|
|
||
| @GetMapping("/{commentId}") | ||
| @ResponseStatus(HttpStatus.OK) | ||
| public CommentDto getCommentByPublic(@PathVariable Long commentId) { | ||
| return commentService.getCommentByPublic(commentId); | ||
| } | ||
| } |
26 changes: 26 additions & 0 deletions
26
main-service/src/main/java/ru/practicum/main_service/comment/dto/CommentDto.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,26 @@ | ||
| package ru.practicum.main_service.comment.dto; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonFormat; | ||
| import lombok.*; | ||
| import ru.practicum.main_service.MainCommonUtils; | ||
| import ru.practicum.main_service.user.dto.UserShortDto; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| @Getter | ||
| @Setter | ||
| @Builder | ||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
| public class CommentDto { | ||
| private Long id; | ||
| private String text; | ||
| private UserShortDto author; | ||
| private Long eventId; | ||
|
|
||
| @JsonFormat(pattern = MainCommonUtils.DT_FORMAT, shape = JsonFormat.Shape.STRING) | ||
| private LocalDateTime createdOn; | ||
|
|
||
| @JsonFormat(pattern = MainCommonUtils.DT_FORMAT, shape = JsonFormat.Shape.STRING) | ||
| private LocalDateTime editedOn; | ||
| } |
19 changes: 19 additions & 0 deletions
19
main-service/src/main/java/ru/practicum/main_service/comment/dto/NewCommentDto.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,19 @@ | ||
| package ru.practicum.main_service.comment.dto; | ||
|
|
||
| import lombok.*; | ||
| import ru.practicum.main_service.MainCommonUtils; | ||
|
|
||
| import javax.validation.constraints.NotBlank; | ||
| import javax.validation.constraints.Size; | ||
|
|
||
| @Getter | ||
| @Setter | ||
| @Builder | ||
| @ToString | ||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
| public class NewCommentDto { | ||
| @NotBlank | ||
| @Size(min = MainCommonUtils.MIN_LENGTH_COMMENT, max = MainCommonUtils.MAX_LENGTH_COMMENT) | ||
| private String text; | ||
| } |
13 changes: 13 additions & 0 deletions
13
main-service/src/main/java/ru/practicum/main_service/comment/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,13 @@ | ||
| package ru.practicum.main_service.comment.mapper; | ||
|
|
||
| import org.mapstruct.Mapper; | ||
| import org.mapstruct.Mapping; | ||
| import ru.practicum.main_service.comment.dto.CommentDto; | ||
| import ru.practicum.main_service.comment.model.Comment; | ||
| import ru.practicum.main_service.user.mapper.UserMapper; | ||
|
|
||
| @Mapper(componentModel = "spring", uses = {UserMapper.class}) | ||
| public interface CommentMapper { | ||
| @Mapping(target = "eventId", expression = "java(comment.getEvent().getId())") | ||
| CommentDto toCommentDto(Comment comment); | ||
| } |
42 changes: 42 additions & 0 deletions
42
main-service/src/main/java/ru/practicum/main_service/comment/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,42 @@ | ||
| package ru.practicum.main_service.comment.model; | ||
|
|
||
| import lombok.*; | ||
| import org.hibernate.annotations.OnDelete; | ||
| import org.hibernate.annotations.OnDeleteAction; | ||
| import ru.practicum.main_service.MainCommonUtils; | ||
| import ru.practicum.main_service.event.model.Event; | ||
| import ru.practicum.main_service.user.model.User; | ||
|
|
||
| import javax.persistence.*; | ||
| import java.time.LocalDateTime; | ||
|
|
||
| @Getter | ||
| @Setter | ||
| @Builder | ||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
| @Entity | ||
| @Table(name = "comments", schema = "public") | ||
| public class Comment { | ||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| private Long id; | ||
|
|
||
| @Column(length = MainCommonUtils.MAX_LENGTH_COMMENT, nullable = false) | ||
| private String text; | ||
|
|
||
| @ManyToOne(fetch = FetchType.EAGER) | ||
| @JoinColumn(name = "author_id", referencedColumnName = "id") | ||
| @OnDelete(action = OnDeleteAction.CASCADE) | ||
| private User author; | ||
|
|
||
| @ManyToOne(fetch = FetchType.LAZY) | ||
| @JoinColumn(name = "event_id", referencedColumnName = "id") | ||
| @OnDelete(action = OnDeleteAction.CASCADE) | ||
| private Event event; | ||
|
|
||
| @Column(nullable = false) | ||
| private LocalDateTime createdOn; | ||
|
|
||
| private LocalDateTime editedOn; | ||
| } |
15 changes: 15 additions & 0 deletions
15
...service/src/main/java/ru/practicum/main_service/comment/repository/CommentRepository.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,15 @@ | ||
| package ru.practicum.main_service.comment.repository; | ||
|
|
||
| import org.springframework.data.domain.Pageable; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
| import ru.practicum.main_service.comment.model.Comment; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public interface CommentRepository extends JpaRepository<Comment, Long> { | ||
| List<Comment> findAllByAuthorId(Long userId); | ||
|
|
||
| List<Comment> findAllByAuthorIdAndEventId(Long userId, Long eventId); | ||
|
|
||
| List<Comment> findAllByEventId(Long eventId, Pageable pageable); | ||
| } |
25 changes: 25 additions & 0 deletions
25
main-service/src/main/java/ru/practicum/main_service/comment/service/CommentService.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,25 @@ | ||
| package ru.practicum.main_service.comment.service; | ||
|
|
||
| import org.springframework.data.domain.Pageable; | ||
| import ru.practicum.main_service.comment.dto.CommentDto; | ||
| import ru.practicum.main_service.comment.dto.NewCommentDto; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public interface CommentService { | ||
| List<CommentDto> getCommentsByAdmin(Pageable pageable); | ||
|
|
||
| void deleteByAdmin(Long commentId); | ||
|
|
||
| List<CommentDto> getCommentsByPrivate(Long userId, Long eventId, Pageable pageable); | ||
|
|
||
| CommentDto createByPrivate(Long userId, Long eventId, NewCommentDto newCommentDto); | ||
|
|
||
| CommentDto patchByPrivate(Long userId, Long commentId, NewCommentDto newCommentDto); | ||
|
|
||
| void deleteByPrivate(Long userId, Long commentId); | ||
|
|
||
| List<CommentDto> getCommentsByPublic(Long eventId, Pageable pageable); | ||
|
|
||
| CommentDto getCommentByPublic(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.
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.
defaultValue уже подразумевает, что параметра может и не быть. Поэтому вполне можно не писать required = false