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
464 changes: 0 additions & 464 deletions .Postman/Stats-server.postman_collection.json

This file was deleted.

2 changes: 2 additions & 0 deletions README.md
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class CategoryDto {
private Long id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
@Getter
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class NewCategoryDto {
@NotNull(message = "Название категории не может быть пустым")
@NotBlank(message = "Название категории не может быть пустым")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
import ru.practicum.category.dto.NewCategoryDto;
import ru.practicum.category.model.Category;

public class CategoryMapper {
public final class CategoryMapper {
private CategoryMapper() {

}

public static Category toCategory(NewCategoryDto dto) {
return Category.builder()
.name(dto.getName())
Expand Down
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,

This comment was marked as resolved.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Спасибо что подсказал. Не дружу с английским. Поэтому и названия кривые

@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);
}
}
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);
}
}
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;
}
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;
}
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();
}
}
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;
}
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;
}
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);
}
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);
}
Loading