├── README.md
├── ewm-stat-service
├── stat_client
│ ├── src
│ │ └── main
│ │ │ ├── resources
│ │ │ └── application.properties
│ │ │ └── java
│ │ │ └── ru
│ │ │ └── practicum
│ │ │ └── client
│ │ │ ├── StatClient.java
│ │ │ └── BaseClient.java
│ ├── Dockerfile
│ ├── .gitignore
│ └── pom.xml
├── stat_dto
│ ├── src
│ │ └── main
│ │ │ └── java
│ │ │ └── ru
│ │ │ └── practicum
│ │ │ └── dto
│ │ │ ├── Validator.java
│ │ │ ├── StatResponseDto.java
│ │ │ └── StatDto.java
│ ├── .gitignore
│ └── pom.xml
├── stat_server
│ ├── Dockerfile
│ ├── src
│ │ └── main
│ │ │ ├── java
│ │ │ └── ru
│ │ │ │ └── practicum
│ │ │ │ ├── exception
│ │ │ │ ├── WrongTimeException.java
│ │ │ │ ├── ErrorResponse.java
│ │ │ │ └── ErrorHandler.java
│ │ │ │ ├── utill
│ │ │ │ └── Constants.java
│ │ │ │ ├── StatServerApplication.java
│ │ │ │ ├── service
│ │ │ │ ├── StatService.java
│ │ │ │ └── StatServiceImpl.java
│ │ │ │ ├── model
│ │ │ │ ├── Stat.java
│ │ │ │ └── mapper
│ │ │ │ │ └── StatMapper.java
│ │ │ │ ├── controller
│ │ │ │ └── StatServiceController.java
│ │ │ │ └── repository
│ │ │ │ └── StatServiceRepository.java
│ │ │ └── resources
│ │ │ ├── schema.sql
│ │ │ └── application.properties
│ ├── .gitignore
│ └── pom.xml
├── .gitignore
└── pom.xml
├── lombok.config
├── ewm-main-service
├── src
│ └── main
│ │ ├── java
│ │ └── ru
│ │ │ └── practicum
│ │ │ ├── main
│ │ │ ├── event
│ │ │ │ ├── status
│ │ │ │ │ ├── State.java
│ │ │ │ │ ├── AdminEventStatus.java
│ │ │ │ │ └── UserEventStatus.java
│ │ │ │ ├── dto
│ │ │ │ │ ├── EventCommentDto.java
│ │ │ │ │ ├── RequestShortDto.java
│ │ │ │ │ ├── RequestShortUpdateDto.java
│ │ │ │ │ ├── EventDto.java
│ │ │ │ │ ├── EventShortDto.java
│ │ │ │ │ ├── EventAdminDto.java
│ │ │ │ │ ├── PatchEventDto.java
│ │ │ │ │ ├── EventFullDto.java
│ │ │ │ │ ├── EventRequestDto.java
│ │ │ │ │ ├── EventFullWithComment.java
│ │ │ │ │ ├── EventFullWithCommentDto.java
│ │ │ │ │ ├── UpdateEventDto.java
│ │ │ │ │ └── AdminEventRequestDto.java
│ │ │ │ ├── location
│ │ │ │ │ ├── dto
│ │ │ │ │ │ └── LocationDto.java
│ │ │ │ │ ├── repository
│ │ │ │ │ │ └── LocationMainServiceRepository.java
│ │ │ │ │ ├── mapper
│ │ │ │ │ │ └── LocationMapper.java
│ │ │ │ │ └── model
│ │ │ │ │ │ └── Location.java
│ │ │ │ ├── service
│ │ │ │ │ ├── EventAdminService.java
│ │ │ │ │ ├── EventPublicService.java
│ │ │ │ │ ├── EventPrivateService.java
│ │ │ │ │ ├── EventPublicServiceImpl.java
│ │ │ │ │ └── EventAdminServiceImpl.java
│ │ │ │ ├── repository
│ │ │ │ │ └── EventMainServiceRepository.java
│ │ │ │ ├── controller
│ │ │ │ │ ├── EventAdminController.java
│ │ │ │ │ ├── EventPublicController.java
│ │ │ │ │ └── EventPrivateController.java
│ │ │ │ ├── model
│ │ │ │ │ └── Event.java
│ │ │ │ └── mapper
│ │ │ │ │ └── EventMapper.java
│ │ │ ├── request
│ │ │ │ ├── Status.java
│ │ │ │ ├── dto
│ │ │ │ │ ├── RequestShortDto.java
│ │ │ │ │ ├── RequestUpdateDto.java
│ │ │ │ │ ├── RequestDto.java
│ │ │ │ │ └── ConfirmedRequestShortDto.java
│ │ │ │ ├── service
│ │ │ │ │ ├── RequestService.java
│ │ │ │ │ └── RequestServiceImpl.java
│ │ │ │ ├── repository
│ │ │ │ │ └── RequestMainServiceRepository.java
│ │ │ │ ├── model
│ │ │ │ │ └── Request.java
│ │ │ │ ├── mapper
│ │ │ │ │ └── RequestMapper.java
│ │ │ │ └── controller
│ │ │ │ │ └── RequestController.java
│ │ │ ├── exception
│ │ │ │ ├── NotUniqueException.java
│ │ │ │ ├── ConflictException.java
│ │ │ │ ├── NotFoundException.java
│ │ │ │ ├── StatParseException.java
│ │ │ │ ├── BadRequestException.java
│ │ │ │ └── handler
│ │ │ │ │ ├── ErrorResponse.java
│ │ │ │ │ └── MainServiceHandler.java
│ │ │ ├── user
│ │ │ │ ├── dto
│ │ │ │ │ ├── UserDto.java
│ │ │ │ │ ├── AdminUserDto.java
│ │ │ │ │ ├── UserShortDto.java
│ │ │ │ │ └── UserDtoReceived.java
│ │ │ │ ├── service
│ │ │ │ │ ├── UserService.java
│ │ │ │ │ └── UserServiceImpl.java
│ │ │ │ ├── repository
│ │ │ │ │ └── UserMainServiceRepository.java
│ │ │ │ ├── model
│ │ │ │ │ └── User.java
│ │ │ │ ├── mapper
│ │ │ │ │ └── UserMapper.java
│ │ │ │ └── controller
│ │ │ │ │ └── UserController.java
│ │ │ ├── category
│ │ │ │ ├── service
│ │ │ │ │ ├── CategoryPublicService.java
│ │ │ │ │ ├── CategoryAdminService.java
│ │ │ │ │ ├── CategoryPublicServiceImpl.java
│ │ │ │ │ └── CategoryAdminServiceImpl.java
│ │ │ │ ├── repository
│ │ │ │ │ └── CategoryMainServiceRepository.java
│ │ │ │ ├── dto
│ │ │ │ │ └── CategoryDto.java
│ │ │ │ ├── model
│ │ │ │ │ └── Category.java
│ │ │ │ ├── mapper
│ │ │ │ │ └── CategoryMapper.java
│ │ │ │ └── controller
│ │ │ │ │ ├── CategoryPublicController.java
│ │ │ │ │ └── CategoryAdminController.java
│ │ │ ├── comment
│ │ │ │ ├── service
│ │ │ │ │ ├── AdminCommentService.java
│ │ │ │ │ ├── CommentService.java
│ │ │ │ │ ├── PrivateCommentService.java
│ │ │ │ │ ├── AdminCommentServiceImpl.java
│ │ │ │ │ ├── CommentServiceImpl.java
│ │ │ │ │ └── PrivateCommentServiceImpl.java
│ │ │ │ ├── dto
│ │ │ │ │ ├── CommentShortDto.java
│ │ │ │ │ ├── CommentCreateDto.java
│ │ │ │ │ ├── CommentCountDto.java
│ │ │ │ │ └── CommentDto.java
│ │ │ │ ├── model
│ │ │ │ │ └── Comment.java
│ │ │ │ ├── repository
│ │ │ │ │ └── CommentMainServiceRepository.java
│ │ │ │ ├── controller
│ │ │ │ │ ├── PublicCommentController.java
│ │ │ │ │ ├── AdminCommentController.java
│ │ │ │ │ └── PrivateCommentController.java
│ │ │ │ └── mapper
│ │ │ │ │ └── CommentMapper.java
│ │ │ ├── compilation
│ │ │ │ ├── service
│ │ │ │ │ ├── CompilationPublicService.java
│ │ │ │ │ ├── CompilationAdminService.java
│ │ │ │ │ ├── CompilationPublicServiceImpl.java
│ │ │ │ │ └── CompilationAdminServiceImpl.java
│ │ │ │ ├── dto
│ │ │ │ │ ├── CompilationShortDto.java
│ │ │ │ │ ├── CompilationDto.java
│ │ │ │ │ └── NewCompilationDto.java
│ │ │ │ ├── repository
│ │ │ │ │ └── CompilationMainServiceRepository.java
│ │ │ │ ├── model
│ │ │ │ │ └── Compilation.java
│ │ │ │ ├── mapper
│ │ │ │ │ └── CompilationMapper.java
│ │ │ │ └── controller
│ │ │ │ │ ├── CompilationPublicController.java
│ │ │ │ │ └── CompilationAdminController.java
│ │ │ ├── stat
│ │ │ │ └── service
│ │ │ │ │ ├── StatService.java
│ │ │ │ │ └── StatServiceImpl.java
│ │ │ └── util
│ │ │ │ └── Util.java
│ │ │ └── MainServiceApp.java
│ │ └── resources
│ │ ├── application.properties
│ │ └── schema.sql
├── Dockerfile
└── pom.xml
├── .github
└── workflows
│ ├── api-tests.yml
│ └── wait-for-it.sh
├── suppressions.xml
├── .gitignore
├── docker-compose.yml
├── ewm-stats-service-spec.json
└── pom.xml
/README.md:
--------------------------------------------------------------------------------
1 | # java-explore-with-me
2 | Template repository for ExploreWithMe project.
3 |
--------------------------------------------------------------------------------
/ewm-stat-service/stat_client/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | server.port=9091
2 |
3 | stats-service.url=http://localhost:9090
--------------------------------------------------------------------------------
/lombok.config:
--------------------------------------------------------------------------------
1 | config.stopBubbling = true
2 | lombok.anyconstructor.addconstructorproperties = false
3 | lombok.addLombokGeneratedAnnotation = true
4 | lombok.addSuppressWarnings = false
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/event/status/State.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.event.status;
2 |
3 | public enum State {
4 | PENDING,
5 | PUBLISHED,
6 | CANCELED
7 | }
8 |
--------------------------------------------------------------------------------
/.github/workflows/api-tests.yml:
--------------------------------------------------------------------------------
1 | name: Explore With Me API Tests
2 |
3 | on:
4 | pull_request:
5 |
6 | jobs:
7 | build:
8 | uses: yandex-praktikum/java-explore-with-me/.github/workflows/api-tests.yml@ci
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/event/status/AdminEventStatus.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.event.status;
2 |
3 | public enum AdminEventStatus {
4 | PUBLISH_EVENT,
5 | REJECT_EVENT
6 | }
7 |
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/event/status/UserEventStatus.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.event.status;
2 |
3 | public enum UserEventStatus {
4 |
5 | SEND_TO_REVIEW,
6 | CANCEL_REVIEW
7 | }
8 |
--------------------------------------------------------------------------------
/ewm-stat-service/stat_client/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM amazoncorretto:11
2 | ENV JAVA_TOOL_OPTIONS -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:9191
3 | COPY target/*.jar app.jar
4 | ENTRYPOINT ["java","-jar","/app.jar"]
--------------------------------------------------------------------------------
/ewm-stat-service/stat_dto/src/main/java/ru/practicum/dto/Validator.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.dto;
2 |
3 | public interface Validator {
4 |
5 | interface Create {}
6 |
7 | interface Update {}
8 | }
9 |
10 |
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/request/Status.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.request;
2 |
3 | public enum Status {
4 |
5 | CONFIRMED,
6 | PENDING,
7 | REJECTED,
8 | CANCELED
9 | }
10 |
--------------------------------------------------------------------------------
/ewm-main-service/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM amazoncorretto:11
2 | ENV JAVA_TOOL_OPTIONS -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:8081
3 | ENV TZ=Europe/Moscow
4 | COPY target/*.jar app.jar
5 | ENTRYPOINT ["java","-jar","/app.jar"]
--------------------------------------------------------------------------------
/ewm-stat-service/stat_server/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM amazoncorretto:11
2 | ENV JAVA_TOOL_OPTIONS -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:9091
3 | ENV TZ=Europe/Moscow
4 | COPY target/*.jar app.jar
5 | ENTRYPOINT ["java","-jar","/app.jar"]
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/exception/NotUniqueException.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.exception;
2 |
3 | public class NotUniqueException extends RuntimeException {
4 | public NotUniqueException(String message) {
5 | super(message);
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/exception/ConflictException.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.exception;
2 |
3 | public class ConflictException extends RuntimeException {
4 | public ConflictException(final String massage) {
5 | super(massage);
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/exception/NotFoundException.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.exception;
2 |
3 | public class NotFoundException extends RuntimeException {
4 | public NotFoundException(final String massage) {
5 | super(massage);
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/exception/StatParseException.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.exception;
2 |
3 | public class StatParseException extends RuntimeException {
4 | public StatParseException(final String massage) {
5 | super(massage);
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/exception/BadRequestException.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.exception;
2 |
3 | public class BadRequestException extends RuntimeException {
4 | public BadRequestException(final String massage) {
5 | super(massage);
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/ewm-stat-service/stat_server/src/main/java/ru/practicum/exception/WrongTimeException.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.exception;
2 |
3 | public class WrongTimeException extends RuntimeException {
4 | public WrongTimeException(final String massage) {
5 | super(massage);
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/suppressions.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/user/dto/UserDto.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.user.dto;
2 |
3 | import lombok.*;
4 |
5 |
6 | @Data
7 | @Builder
8 | @AllArgsConstructor
9 | @NoArgsConstructor
10 | public class UserDto {
11 |
12 | private Long id;
13 |
14 | private String name;
15 | }
16 |
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/event/dto/EventCommentDto.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.event.dto;
2 |
3 | import lombok.*;
4 |
5 | @Getter
6 | @Setter
7 | @Builder
8 | @AllArgsConstructor
9 | @NoArgsConstructor
10 | public class EventCommentDto {
11 |
12 | private long id;
13 |
14 | private String title;
15 | }
16 |
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/event/location/dto/LocationDto.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.event.location.dto;
2 |
3 |
4 | import lombok.*;
5 |
6 | @Data
7 | @Builder
8 | @AllArgsConstructor
9 | @NoArgsConstructor
10 | public class LocationDto {
11 |
12 | private double lat;
13 |
14 | private double lon;
15 | }
16 |
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/user/dto/AdminUserDto.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.user.dto;
2 |
3 | import lombok.*;
4 |
5 | @Data
6 | @Builder
7 | @AllArgsConstructor
8 | @NoArgsConstructor
9 | public class AdminUserDto {
10 | private Long id;
11 |
12 | private String name;
13 |
14 | private String email;
15 | }
16 |
--------------------------------------------------------------------------------
/ewm-stat-service/stat_server/src/main/java/ru/practicum/utill/Constants.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.utill;
2 |
3 | import java.time.format.DateTimeFormatter;
4 |
5 | public class Constants {
6 |
7 | public static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
8 | public static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
9 | }
10 |
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/MainServiceApp.java:
--------------------------------------------------------------------------------
1 | package ru.practicum;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class MainServiceApp {
8 | public static void main(String[] args) {
9 | SpringApplication.run(MainServiceApp.class, args);
10 | }
11 | }
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/request/dto/RequestShortDto.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.request.dto;
2 |
3 | import lombok.Builder;
4 | import lombok.Data;
5 | import ru.practicum.main.request.Status;
6 |
7 | import java.util.List;
8 |
9 |
10 | @Data
11 | @Builder
12 | public class RequestShortDto {
13 | private List requestIds;
14 |
15 | private Status status;
16 | }
17 |
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/category/service/CategoryPublicService.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.category.service;
2 |
3 | import ru.practicum.main.category.dto.CategoryDto;
4 |
5 | import java.util.List;
6 |
7 | public interface CategoryPublicService {
8 | List readAllCategories(Integer from, Integer size);
9 |
10 | CategoryDto readCategoryById(Long catId);
11 | }
12 |
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/comment/service/AdminCommentService.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.comment.service;
2 |
3 |
4 | import ru.practicum.main.comment.dto.CommentDto;
5 |
6 | import java.util.List;
7 |
8 | public interface AdminCommentService {
9 | void delete(Long comId);
10 |
11 | List search(String text);
12 |
13 | List findAllById(Long userId);
14 | }
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/event/dto/RequestShortDto.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.event.dto;
2 |
3 | import lombok.*;
4 | import ru.practicum.main.request.Status;
5 |
6 | import java.util.List;
7 |
8 | @Data
9 | @Builder
10 | @AllArgsConstructor
11 | @NoArgsConstructor
12 | public class RequestShortDto {
13 |
14 | private List requestIds;
15 |
16 | private Status status;
17 | }
18 |
--------------------------------------------------------------------------------
/ewm-stat-service/stat_server/src/main/java/ru/practicum/exception/ErrorResponse.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.exception;
2 |
3 | import lombok.AllArgsConstructor;
4 | import lombok.Data;
5 |
6 | @Data
7 | @AllArgsConstructor
8 | public class ErrorResponse {
9 |
10 | private String status;
11 |
12 | private String reason;
13 |
14 | private String message;
15 |
16 | private String timestamp;
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/category/service/CategoryAdminService.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.category.service;
2 |
3 | import ru.practicum.main.category.dto.CategoryDto;
4 |
5 | public interface CategoryAdminService {
6 | CategoryDto createCategory(CategoryDto categoryDto);
7 |
8 | void deleteCategory(Long catId);
9 |
10 | CategoryDto updateCategory(Long catId, CategoryDto categoryDto);
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/ewm-stat-service/stat_server/src/main/java/ru/practicum/StatServerApplication.java:
--------------------------------------------------------------------------------
1 | package ru.practicum;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class StatServerApplication {
8 | public static void main(String[] args) {
9 | SpringApplication.run(StatServerApplication.class, args);
10 | }
11 | }
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/compilation/service/CompilationPublicService.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.compilation.service;
2 |
3 | import ru.practicum.main.compilation.dto.CompilationDto;
4 |
5 | import java.util.List;
6 |
7 | public interface CompilationPublicService {
8 | CompilationDto readCompilationById(Long compId);
9 |
10 | List readAllCompilations(Boolean pinned, int from, int size);
11 | }
12 |
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/request/service/RequestService.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.request.service;
2 |
3 | import ru.practicum.main.request.dto.RequestDto;
4 |
5 | import java.util.List;
6 |
7 | public interface RequestService {
8 | RequestDto createRequest(Long userId, Long eventId);
9 |
10 | List readAllRequests(Long userId);
11 |
12 | RequestDto cancelRequest(Long userId, Long requestId);
13 | }
14 |
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/user/service/UserService.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.user.service;
2 |
3 | import ru.practicum.main.user.dto.AdminUserDto;
4 | import ru.practicum.main.user.model.User;
5 |
6 | import java.util.List;
7 |
8 | public interface UserService {
9 | AdminUserDto createUser(User user);
10 |
11 | void deleteUser(Long userId);
12 |
13 | List readUsers(List idList, int from, int size);
14 | }
15 |
--------------------------------------------------------------------------------
/ewm-stat-service/stat_server/src/main/resources/schema.sql:
--------------------------------------------------------------------------------
1 | CREATE TABLE IF NOT EXISTS stat (
2 | id BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL,
3 | app VARCHAR(50) NOT NULL,
4 | uri VARCHAR(50) NOT NULL,
5 | ip VARCHAR(15) NOT NULL,
6 | time_stamp TIMESTAMP NOT NULL,
7 | CONSTRAINT pk_stat PRIMARY KEY (id)
8 | );
9 |
10 |
11 |
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/comment/service/CommentService.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.comment.service;
2 |
3 |
4 | import ru.practicum.main.comment.dto.CommentDto;
5 | import ru.practicum.main.comment.dto.CommentShortDto;
6 |
7 | import java.util.List;
8 |
9 | public interface CommentService {
10 |
11 | CommentDto getComment(Long comId);
12 |
13 | List getCommentsByEvent(Long eventId, int from, int size);
14 | }
15 |
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/request/dto/RequestUpdateDto.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.request.dto;
2 |
3 | import lombok.Data;
4 | import ru.practicum.main.request.model.Request;
5 |
6 | import java.util.ArrayList;
7 | import java.util.List;
8 |
9 | @Data
10 | public class RequestUpdateDto {
11 |
12 | private List conformedRequest = new ArrayList<>();
13 |
14 | private List canselRequest = new ArrayList<>();
15 | }
16 |
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/comment/dto/CommentShortDto.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.comment.dto;
2 |
3 | import lombok.*;
4 | import ru.practicum.main.user.dto.UserDto;
5 |
6 | @Getter
7 | @Setter
8 | @Builder
9 | @AllArgsConstructor
10 | @NoArgsConstructor
11 | public class CommentShortDto {
12 |
13 | private long id;
14 |
15 | private String text;
16 |
17 | private UserDto author;
18 |
19 | private String createTime;
20 | }
21 |
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/user/dto/UserShortDto.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.user.dto;
2 |
3 | import lombok.*;
4 |
5 | import javax.validation.constraints.NotEmpty;
6 | import javax.validation.constraints.NotNull;
7 |
8 | @Builder
9 | @Getter
10 | @Setter
11 | @NoArgsConstructor
12 | @AllArgsConstructor
13 | public class UserShortDto { // Добавил
14 | @NotNull
15 | private Long id;
16 | @NotEmpty
17 | private String name;
18 | }
19 |
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/comment/dto/CommentCreateDto.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.comment.dto;
2 |
3 | import lombok.*;
4 |
5 | import javax.validation.constraints.NotBlank;
6 | import javax.validation.constraints.Size;
7 |
8 | @Getter
9 | @Setter
10 | @Builder
11 | @AllArgsConstructor
12 | @NoArgsConstructor
13 | public class CommentCreateDto {
14 |
15 | @NotBlank
16 | @Size(min = 1, max = 1000)
17 | private String text;
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/comment/dto/CommentCountDto.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.comment.dto;
2 |
3 | import lombok.Getter;
4 | import lombok.Setter;
5 |
6 | @Getter
7 | @Setter
8 | public class CommentCountDto {
9 |
10 | private Long eventId;
11 |
12 | private Long commentCount;
13 |
14 | public CommentCountDto(Long eventId, Long commentCount) {
15 | this.eventId = eventId;
16 | this.commentCount = commentCount;
17 | }
18 | }
--------------------------------------------------------------------------------
/ewm-stat-service/stat_server/src/main/java/ru/practicum/service/StatService.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.service;
2 |
3 | import ru.practicum.dto.StatDto;
4 | import ru.practicum.dto.StatResponseDto;
5 |
6 | import java.time.LocalDateTime;
7 | import java.util.List;
8 |
9 | public interface StatService {
10 |
11 | StatDto createStat(StatDto statDto);
12 |
13 | List readStat(LocalDateTime start, LocalDateTime end, List uris, boolean unique);
14 | }
15 |
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/event/location/repository/LocationMainServiceRepository.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.event.location.repository;
2 |
3 | import org.springframework.data.jpa.repository.JpaRepository;
4 | import ru.practicum.main.event.location.model.Location;
5 |
6 | import java.util.Optional;
7 |
8 | public interface LocationMainServiceRepository extends JpaRepository {
9 | Optional findByLatAndLon(double lat, double lon);
10 | }
11 |
--------------------------------------------------------------------------------
/ewm-stat-service/stat_dto/src/main/java/ru/practicum/dto/StatResponseDto.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.dto;
2 |
3 | import lombok.*;
4 |
5 | @Data
6 | @Builder
7 | @NoArgsConstructor
8 | public class StatResponseDto {
9 |
10 | private String app;
11 |
12 | private String uri;
13 |
14 | private long hits;
15 |
16 | public StatResponseDto(String app, String uri, long hits) {
17 | this.app = app;
18 | this.uri = uri;
19 | this.hits = hits;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/request/dto/RequestDto.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.request.dto;
2 |
3 | import lombok.*;
4 | import ru.practicum.main.request.Status;
5 |
6 | import java.time.LocalDateTime;
7 |
8 | @Data
9 | @Builder
10 | @AllArgsConstructor
11 | @NoArgsConstructor
12 | public class RequestDto {
13 | private LocalDateTime created;
14 |
15 | private Long event;
16 |
17 | private Long id;
18 |
19 | private Long requester;
20 |
21 | private Status status;
22 | }
23 |
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/stat/service/StatService.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.stat.service;
2 |
3 | import ru.practicum.main.event.model.Event;
4 |
5 | import javax.servlet.http.HttpServletRequest;
6 | import java.util.Collection;
7 | import java.util.Map;
8 |
9 | public interface StatService {
10 |
11 | Map toConfirmedRequest(Collection list);
12 |
13 | Map toView(Collection list);
14 |
15 | void addHits(HttpServletRequest request);
16 | }
17 |
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/compilation/dto/CompilationShortDto.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.compilation.dto;
2 |
3 | import lombok.*;
4 | import ru.practicum.main.event.dto.EventDto;
5 |
6 | import java.util.List;
7 |
8 |
9 | @Data
10 | @Builder
11 | @AllArgsConstructor
12 | @NoArgsConstructor
13 | public class CompilationShortDto {
14 |
15 | private List events;
16 |
17 | private Long id;
18 |
19 | private Boolean pinned;
20 |
21 | private String title;
22 |
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/event/dto/RequestShortUpdateDto.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.event.dto;
2 |
3 | import lombok.*;
4 | import ru.practicum.main.request.dto.RequestDto;
5 |
6 | import java.util.ArrayList;
7 | import java.util.List;
8 |
9 | @Data
10 | @Builder
11 | @AllArgsConstructor
12 | @NoArgsConstructor
13 | public class RequestShortUpdateDto {
14 |
15 | private List confirmedRequests = new ArrayList<>();
16 |
17 | private List rejectedRequests = new ArrayList<>();
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | HELP.md
2 | target/
3 | !.mvn/wrapper/maven-wrapper.jar
4 | !**/src/mainservice/**/target/
5 | !**/src/test/**/target/
6 |
7 | ### STS ###
8 | .apt_generated
9 | .classpath
10 | .factorypath
11 | .project
12 | .settings
13 | .springBeans
14 | .sts4-cache
15 |
16 | ### IntelliJ IDEA ###
17 | .idea
18 | *.iws
19 | *.iml
20 | *.ipr
21 |
22 | ### NetBeans ###
23 | /nbproject/private/
24 | /nbbuild/
25 | /dist/
26 | /nbdist/
27 | /.nb-gradle/
28 | build/
29 | !**/src/main/**/build/
30 | !**/src/test/**/build/
31 |
32 | ### VS Code ###
33 | .vscode/
34 |
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/compilation/service/CompilationAdminService.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.compilation.service;
2 |
3 | import ru.practicum.main.compilation.dto.CompilationDto;
4 | import ru.practicum.main.compilation.dto.NewCompilationDto;
5 |
6 | public interface CompilationAdminService {
7 | CompilationDto createCompilation(NewCompilationDto newCompilationDto);
8 |
9 | void deleteCompilation(Long compId);
10 |
11 | CompilationDto updateCompilation(Long compId, NewCompilationDto newCompilationDto);
12 | }
13 |
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/comment/dto/CommentDto.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.comment.dto;
2 |
3 | import lombok.*;
4 | import ru.practicum.main.event.dto.EventCommentDto;
5 | import ru.practicum.main.user.dto.UserDto;
6 |
7 | @Getter
8 | @Setter
9 | @Builder
10 | @AllArgsConstructor
11 | @NoArgsConstructor
12 | public class CommentDto {
13 |
14 | private long id;
15 |
16 | private String text;
17 |
18 | private UserDto author;
19 |
20 | private EventCommentDto event;
21 |
22 | private String createTime;
23 | }
24 |
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/exception/handler/ErrorResponse.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.exception.handler;
2 |
3 | import lombok.Data;
4 |
5 | @Data
6 | public class ErrorResponse {
7 |
8 | private String status;
9 | private String reason;
10 | private String message;
11 | private String timestamp;
12 |
13 |
14 | public ErrorResponse(String status, String reason, String message, String timestamp) {
15 | this.status = status;
16 | this.reason = reason;
17 | this.message = message;
18 | this.timestamp = timestamp;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/request/dto/ConfirmedRequestShortDto.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.request.dto;
2 |
3 | import lombok.Getter;
4 | import lombok.NoArgsConstructor;
5 | import lombok.Setter;
6 |
7 | @Getter
8 | @Setter
9 | @NoArgsConstructor
10 | public class ConfirmedRequestShortDto {
11 |
12 | private Long eventId;
13 |
14 | private Long confirmedRequestsCount;
15 |
16 | public ConfirmedRequestShortDto(Long eventId, Long confirmedRequestsCount) {
17 | this.eventId = eventId;
18 | this.confirmedRequestsCount = confirmedRequestsCount;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/compilation/dto/CompilationDto.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.compilation.dto;
2 |
3 | import lombok.AllArgsConstructor;
4 | import lombok.Builder;
5 | import lombok.Data;
6 | import lombok.NoArgsConstructor;
7 | import ru.practicum.main.event.dto.EventShortDto;
8 |
9 | import java.util.List;
10 |
11 | @Data
12 | @Builder
13 | @AllArgsConstructor
14 | @NoArgsConstructor
15 | public class CompilationDto {
16 |
17 | private List events;
18 |
19 | private Long id;
20 |
21 | private Boolean pinned;
22 |
23 | private String title;
24 | }
25 |
--------------------------------------------------------------------------------
/ewm-stat-service/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 | !**/src/main/**/target/
4 | !**/src/test/**/target/
5 |
6 | ### IntelliJ IDEA ###
7 | .idea/modules.xml
8 | .idea/jarRepositories.xml
9 | .idea/compiler.xml
10 | .idea/libraries/
11 | *.iws
12 | *.iml
13 | *.ipr
14 |
15 | ### Eclipse ###
16 | .apt_generated
17 | .classpath
18 | .factorypath
19 | .project
20 | .settings
21 | .springBeans
22 | .sts4-cache
23 |
24 | ### NetBeans ###
25 | /nbproject/private/
26 | /nbbuild/
27 | /dist/
28 | /nbdist/
29 | /.nb-gradle/
30 | build/
31 | !**/src/main/**/build/
32 | !**/src/test/**/build/
33 |
34 | ### VS Code ###
35 | .vscode/
36 |
37 | ### Mac OS ###
38 | .DS_Store
--------------------------------------------------------------------------------
/ewm-stat-service/stat_dto/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 | !**/src/main/**/target/
4 | !**/src/test/**/target/
5 |
6 | ### IntelliJ IDEA ###
7 | .idea/modules.xml
8 | .idea/jarRepositories.xml
9 | .idea/compiler.xml
10 | .idea/libraries/
11 | *.iws
12 | *.iml
13 | *.ipr
14 |
15 | ### Eclipse ###
16 | .apt_generated
17 | .classpath
18 | .factorypath
19 | .project
20 | .settings
21 | .springBeans
22 | .sts4-cache
23 |
24 | ### NetBeans ###
25 | /nbproject/private/
26 | /nbbuild/
27 | /dist/
28 | /nbdist/
29 | /.nb-gradle/
30 | build/
31 | !**/src/main/**/build/
32 | !**/src/test/**/build/
33 |
34 | ### VS Code ###
35 | .vscode/
36 |
37 | ### Mac OS ###
38 | .DS_Store
--------------------------------------------------------------------------------
/ewm-stat-service/stat_client/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 | !**/src/main/**/target/
4 | !**/src/test/**/target/
5 |
6 | ### IntelliJ IDEA ###
7 | .idea/modules.xml
8 | .idea/jarRepositories.xml
9 | .idea/compiler.xml
10 | .idea/libraries/
11 | *.iws
12 | *.iml
13 | *.ipr
14 |
15 | ### Eclipse ###
16 | .apt_generated
17 | .classpath
18 | .factorypath
19 | .project
20 | .settings
21 | .springBeans
22 | .sts4-cache
23 |
24 | ### NetBeans ###
25 | /nbproject/private/
26 | /nbbuild/
27 | /dist/
28 | /nbdist/
29 | /.nb-gradle/
30 | build/
31 | !**/src/main/**/build/
32 | !**/src/test/**/build/
33 |
34 | ### VS Code ###
35 | .vscode/
36 |
37 | ### Mac OS ###
38 | .DS_Store
--------------------------------------------------------------------------------
/ewm-stat-service/stat_server/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 | !**/src/main/**/target/
4 | !**/src/test/**/target/
5 |
6 | ### IntelliJ IDEA ###
7 | .idea/modules.xml
8 | .idea/jarRepositories.xml
9 | .idea/compiler.xml
10 | .idea/libraries/
11 | *.iws
12 | *.iml
13 | *.ipr
14 |
15 | ### Eclipse ###
16 | .apt_generated
17 | .classpath
18 | .factorypath
19 | .project
20 | .settings
21 | .springBeans
22 | .sts4-cache
23 |
24 | ### NetBeans ###
25 | /nbproject/private/
26 | /nbbuild/
27 | /dist/
28 | /nbdist/
29 | /.nb-gradle/
30 | build/
31 | !**/src/main/**/build/
32 | !**/src/test/**/build/
33 |
34 | ### VS Code ###
35 | .vscode/
36 |
37 | ### Mac OS ###
38 | .DS_Store
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/category/repository/CategoryMainServiceRepository.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.category.repository;
2 |
3 | import org.springframework.data.domain.Pageable;
4 | import org.springframework.data.jpa.repository.JpaRepository;
5 | import org.springframework.data.jpa.repository.Query;
6 | import ru.practicum.main.category.model.Category;
7 |
8 | import java.util.List;
9 |
10 | public interface CategoryMainServiceRepository extends JpaRepository {
11 |
12 | boolean existsByName(String name);
13 |
14 | @Query("SELECT c " +
15 | "FROM Category c ")
16 | List findAllCategories(Pageable pageable);
17 | }
18 |
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/event/service/EventAdminService.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.event.service;
2 |
3 | import ru.practicum.main.event.status.State;
4 | import ru.practicum.main.event.dto.AdminEventRequestDto;
5 | import ru.practicum.main.event.dto.EventFullDto;
6 |
7 | import java.time.LocalDateTime;
8 | import java.util.List;
9 |
10 | public interface EventAdminService {
11 |
12 | EventFullDto updateAdminEvent(Long eventId, AdminEventRequestDto requestAdminDto);
13 |
14 | List readAdminEvents(List users, List states, List categories,
15 | LocalDateTime start, LocalDateTime end, int from, int size);
16 | }
17 |
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/category/dto/CategoryDto.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.category.dto;
2 |
3 | import lombok.AllArgsConstructor;
4 | import lombok.Builder;
5 | import lombok.Data;
6 | import lombok.NoArgsConstructor;
7 | import ru.practicum.dto.Validator;
8 |
9 | import javax.validation.constraints.NotBlank;
10 | import javax.validation.constraints.Size;
11 |
12 | @Data
13 | @Builder
14 | @NoArgsConstructor
15 | @AllArgsConstructor
16 | public class CategoryDto {
17 |
18 | private Long id;
19 |
20 | @NotBlank(groups = {Validator.Create.class, Validator.Update.class})
21 | @Size(min = 1, max = 50, groups = {Validator.Create.class, Validator.Update.class})
22 | private String name;
23 | }
24 |
--------------------------------------------------------------------------------
/ewm-stat-service/stat_server/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | server.port=9090
2 |
3 | spring.jpa.hibernate.ddl-auto=none
4 | spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQL10Dialect
5 | spring.jpa.properties.hibernate.format_sql=true
6 | spring.sql.init.mode=always
7 |
8 | #---
9 | spring.datasource.driverClassName=org.postgresql.Driver
10 | spring.datasource.url=jdbc:postgresql://stats_service-db:5432/stat_db
11 | spring.datasource.username=asd
12 | spring.datasource.password=123
13 |
14 | #---
15 | spring.config.activate.on-profile=ci,test
16 | spring.datasource.driverClassName=org.h2.Driver
17 | spring.datasource.url=jdbc:h2:mem:stat_db
18 | spring.datasource.username=test
19 | spring.datasource.password=test
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/comment/service/PrivateCommentService.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.comment.service;
2 |
3 |
4 | import ru.practicum.main.comment.dto.CommentDto;
5 | import ru.practicum.main.comment.dto.CommentCreateDto;
6 | import ru.practicum.main.event.model.Event;
7 |
8 | import java.util.Collection;
9 | import java.util.Map;
10 |
11 | public interface PrivateCommentService {
12 |
13 | CommentDto createComment(Long userId, Long eventId, CommentCreateDto commentDto);
14 |
15 | void deleteComment(Long userId, Long comId);
16 |
17 | CommentDto patchComment(Long userId, Long comId, CommentCreateDto commentCreateDto);
18 |
19 | Map getCommentCount(Collection list);
20 | }
21 |
--------------------------------------------------------------------------------
/ewm-stat-service/stat_server/src/main/java/ru/practicum/model/Stat.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.model;
2 |
3 | import lombok.*;
4 |
5 | import javax.persistence.*;
6 | import java.time.LocalDateTime;
7 |
8 | @Data
9 | @Builder
10 | @EqualsAndHashCode
11 | @Entity
12 | @AllArgsConstructor
13 | @NoArgsConstructor
14 | public class Stat {
15 |
16 | @Id
17 | @GeneratedValue(strategy = GenerationType.IDENTITY)
18 | @Column(name = "id")
19 | private long statId;
20 |
21 | @Column(name = "app")
22 | private String app;
23 |
24 | @Column(name = "ip")
25 | private String ip;
26 |
27 | @Column(name = "time_stamp")
28 | private LocalDateTime timestamp;
29 |
30 | @Column(name = "uri")
31 | private String uri;
32 | }
33 |
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/category/model/Category.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.category.model;
2 |
3 | import lombok.*;
4 |
5 | import javax.persistence.*;
6 |
7 | @Getter
8 | @Setter
9 | @Builder
10 | @Entity
11 | @AllArgsConstructor
12 | @NoArgsConstructor
13 | @Table(name = "categories")
14 | public class Category {
15 |
16 | @Id
17 | @GeneratedValue(strategy = GenerationType.IDENTITY)
18 | @Column(name = "id")
19 | private Long id;
20 |
21 | @Column(name = "cat_name")
22 | private String name;
23 |
24 | @Override
25 | public String toString() {
26 | return "Categories{" +
27 | "id=" + id +
28 | ", name='" + name + '\'' +
29 | '}';
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/event/service/EventPublicService.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.event.service;
2 |
3 | import ru.practicum.main.event.dto.EventFullDto;
4 | import ru.practicum.main.event.dto.EventShortDto;
5 |
6 | import javax.servlet.http.HttpServletRequest;
7 | import java.time.LocalDateTime;
8 | import java.util.List;
9 |
10 | public interface EventPublicService {
11 | List readPublicEvents(String text, List categories, Boolean paid, LocalDateTime rangeStart,
12 | LocalDateTime rangeEnd, Boolean onlyAvailable, String sort, Integer from, Integer size, HttpServletRequest request);
13 |
14 | EventFullDto getPublicEvent(Long id, HttpServletRequest request);
15 | }
16 |
--------------------------------------------------------------------------------
/ewm-main-service/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | main.port=8080
2 | stats-service.url=http://stats-server:9090
3 | main_app=ewm-main-service
4 | spring.jpa.hibernate.ddl-auto=none
5 | spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQL10Dialect
6 | spring.jpa.properties.hibernate.format_sql=true
7 | spring.sql.init.mode=always
8 |
9 | #---
10 | spring.datasource.driverClassName=org.postgresql.Driver
11 | spring.datasource.url=${MAIN_DB}
12 | spring.datasource.username=${MAIN_USER}
13 | spring.datasource.password=${MAIN_PASSWORD}
14 |
15 | spring.config.activate.on-profile=ci,test
16 | spring.datasource.driverClassName=org.h2.Driver
17 | spring.datasource.url=jdbc:h2:mem:ewm_db
18 | spring.datasource.username=test
19 | spring.datasource.password=test
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/compilation/repository/CompilationMainServiceRepository.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.compilation.repository;
2 |
3 | import org.springframework.data.domain.Pageable;
4 | import org.springframework.data.jpa.repository.JpaRepository;
5 | import org.springframework.data.jpa.repository.Query;
6 | import ru.practicum.main.compilation.model.Compilation;
7 |
8 | import java.util.List;
9 |
10 | public interface CompilationMainServiceRepository extends JpaRepository {
11 |
12 |
13 | @Query("SELECT c " +
14 | "FROM Compilation c " +
15 | "WHERE c.pinned = ?1")
16 | List findAllByPinned(Boolean pinned, Pageable pageable);
17 |
18 | boolean existsByTitle(String title);
19 | }
20 |
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/event/dto/EventDto.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.event.dto;
2 |
3 | import lombok.*;
4 | import ru.practicum.main.category.model.Category;
5 | import ru.practicum.main.user.model.User;
6 |
7 | import java.time.LocalDateTime;
8 |
9 | @Getter
10 | @Setter
11 | @Builder
12 | @AllArgsConstructor
13 | @NoArgsConstructor
14 | public class EventDto {
15 | private Long id;
16 |
17 | private String annotation;
18 |
19 | private Category category;
20 |
21 | private Long confirmedRequests;
22 |
23 | private LocalDateTime eventDate;
24 |
25 | private User initiator;
26 |
27 | private Boolean paid;
28 |
29 | private String title;
30 |
31 | private Long views;
32 |
33 | private Long commentCount;
34 | }
35 |
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/event/dto/EventShortDto.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.event.dto;
2 |
3 | import lombok.Builder;
4 | import lombok.Getter;
5 | import lombok.Setter;
6 | import ru.practicum.main.category.dto.CategoryDto;
7 | import ru.practicum.main.user.dto.UserShortDto;
8 |
9 | @Getter
10 | @Setter
11 | @Builder
12 | public class EventShortDto {
13 | private Long id;
14 |
15 | private String annotation;
16 |
17 | private CategoryDto category;
18 |
19 | private Long confirmedRequests;
20 |
21 | private String eventDate;
22 |
23 | private UserShortDto initiator;
24 |
25 | private Boolean paid;
26 |
27 | private String title;
28 |
29 | private Long views;
30 |
31 | private Long commentCount;
32 |
33 | }
34 |
35 |
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/user/repository/UserMainServiceRepository.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.user.repository;
2 |
3 | import org.springframework.data.domain.Pageable;
4 | import org.springframework.data.jpa.repository.JpaRepository;
5 | import org.springframework.data.jpa.repository.Query;
6 | import ru.practicum.main.user.model.User;
7 |
8 | import java.util.List;
9 |
10 | public interface UserMainServiceRepository extends JpaRepository {
11 |
12 | @Query("SELECT u " +
13 | "FROM User u " +
14 | "WHERE u.id IN ?1 ")
15 | List findAllById(List id, Pageable pageable);
16 |
17 | @Query("SELECT u " +
18 | "FROM User u")
19 | List findAllUser(Pageable pageable);
20 |
21 | Boolean existsByEmail(String email);
22 | }
23 |
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/user/dto/UserDtoReceived.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.user.dto;
2 |
3 | import lombok.*;
4 | import ru.practicum.dto.Validator;
5 |
6 | import javax.validation.constraints.Email;
7 | import javax.validation.constraints.NotBlank;
8 | import javax.validation.constraints.Size;
9 |
10 | @Data
11 | @Builder
12 | @AllArgsConstructor
13 | @NoArgsConstructor
14 | public class UserDtoReceived {
15 |
16 | private Long id;
17 |
18 | @Email(groups = {Validator.Create.class})
19 | @Size(min = 6, max = 254, groups = {Validator.Create.class})
20 | @NotBlank(groups = {Validator.Create.class})
21 | private String email;
22 |
23 | @NotBlank(groups = {Validator.Create.class})
24 | @Size(min = 2, max = 250, groups = {Validator.Create.class})
25 | private String name;
26 | }
27 |
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/compilation/dto/NewCompilationDto.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.compilation.dto;
2 |
3 | import lombok.AllArgsConstructor;
4 | import lombok.Builder;
5 | import lombok.Data;
6 | import lombok.NoArgsConstructor;
7 | import ru.practicum.dto.Validator;
8 |
9 | import javax.validation.constraints.NotBlank;
10 | import javax.validation.constraints.Size;
11 | import java.util.HashSet;
12 | import java.util.Set;
13 |
14 | @Data
15 | @Builder
16 | @AllArgsConstructor
17 | @NoArgsConstructor
18 | public class NewCompilationDto {
19 |
20 | private Set events = new HashSet<>();
21 |
22 | private Boolean pinned;
23 |
24 | @NotBlank(groups = {Validator.Create.class})
25 | @Size(max = 50, groups = {Validator.Create.class, Validator.Update.class})
26 | private String title;
27 | }
28 |
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/event/location/mapper/LocationMapper.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.event.location.mapper;
2 |
3 | import lombok.experimental.UtilityClass;
4 | import ru.practicum.main.event.location.dto.LocationDto;
5 | import ru.practicum.main.event.location.model.Location;
6 |
7 | @UtilityClass
8 | public class LocationMapper {
9 | public Location toLocation(LocationDto locationDto) {
10 | return Location.builder()
11 | .lon(locationDto.getLon())
12 | .lat(locationDto.getLat())
13 | .build();
14 | }
15 |
16 | public LocationDto toLocationDto(Location location) {
17 | return LocationDto.builder()
18 | .lat(location.getLat())
19 | .lon(location.getLon())
20 | .build();
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/event/dto/EventAdminDto.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.event.dto;
2 |
3 | import lombok.*;
4 | import ru.practicum.main.event.status.AdminEventStatus;
5 | import ru.practicum.main.event.location.model.Location;
6 |
7 | import java.time.LocalDateTime;
8 |
9 |
10 |
11 | @Data
12 | @Builder
13 | @AllArgsConstructor
14 | @NoArgsConstructor
15 | public class EventAdminDto {
16 |
17 | private String annotation;
18 |
19 | private Long category;
20 |
21 | private String description;
22 |
23 | private LocalDateTime eventDate;
24 |
25 | private Location location;
26 |
27 | private Boolean paid;
28 |
29 | private Integer participantLimit;
30 |
31 | private Boolean requestModeration;
32 |
33 | private String title;
34 |
35 | private AdminEventStatus stateAction;
36 | }
37 |
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/user/model/User.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.user.model;
2 |
3 | import lombok.*;
4 |
5 | import javax.persistence.*;
6 |
7 | @Getter
8 | @Setter
9 | @Builder
10 | @Entity
11 | @AllArgsConstructor
12 | @NoArgsConstructor
13 | @Table(name = "users")
14 | public class User {
15 |
16 | @Id
17 | @GeneratedValue(strategy = GenerationType.IDENTITY)
18 | @Column(name = "id")
19 | private Long id;
20 |
21 | @Column(name = "user_name")
22 | private String name;
23 |
24 | @Column(name = "email")
25 | private String email;
26 |
27 |
28 | @Override
29 | public String toString() {
30 | return "User{" +
31 | "id=" + id +
32 | ", name='" + name + '\'' +
33 | ", email='" + email + '\'' +
34 | '}';
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/event/location/model/Location.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.event.location.model;
2 |
3 |
4 | import lombok.*;
5 |
6 | import javax.persistence.*;
7 |
8 | @Getter
9 | @Setter
10 | @Builder
11 | @Entity
12 | @AllArgsConstructor
13 | @NoArgsConstructor
14 | @Table(name = "location")
15 | public class Location {
16 |
17 | @Id
18 | @GeneratedValue(strategy = GenerationType.IDENTITY)
19 | @Column(name = "id")
20 | private Long id;
21 |
22 | @Column(name = "lat")
23 | private double lat;
24 |
25 | @Column(name = "lon")
26 | private double lon;
27 |
28 | @Override
29 | public String toString() {
30 | return "Location{" +
31 | "id=" + id +
32 | ", lat='" + lat + '\'' +
33 | ", lon='" + lon + '\'' +
34 | '}';
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/ewm-stat-service/stat_server/src/main/java/ru/practicum/model/mapper/StatMapper.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.model.mapper;
2 |
3 | import ru.practicum.dto.StatDto;
4 | import ru.practicum.model.Stat;
5 |
6 |
7 | public class StatMapper {
8 | private StatMapper() {
9 | }
10 |
11 | public static Stat toStat(StatDto statDto) {
12 |
13 | return Stat.builder()
14 | .ip(statDto.getIp())
15 | .uri(statDto.getUri())
16 | .timestamp(statDto.getTimestamp())
17 | .app(statDto.getApp())
18 | .build();
19 | }
20 |
21 | public static StatDto toStatDto(Stat stat) {
22 | return StatDto.builder()
23 | .timestamp(stat.getTimestamp())
24 | .app(stat.getApp())
25 | .uri(stat.getUri())
26 | .ip(stat.getIp())
27 | .build();
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/util/Util.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.util;
2 |
3 | import org.springframework.data.domain.PageRequest;
4 | import org.springframework.data.domain.Sort;
5 |
6 | public class Util {
7 |
8 | public static final String TIME_STRING = "yyyy-MM-dd HH:mm:ss";
9 |
10 | private Util() {
11 |
12 | }
13 |
14 | public static PageRequest createPageRequestAsc(int from, int size) {
15 | return PageRequest.of(from, size, Sort.Direction.ASC, "id");
16 | }
17 |
18 | public static PageRequest createPageRequestDesc(String sortBy, int from, int size) {
19 | return PageRequest.of(from > 0 ? from / size : 0, size, Sort.by(sortBy).descending());
20 | }
21 |
22 | public static PageRequest createPageRequestAsc(String sortBy, int from, int size) {
23 | return PageRequest.of(from > 0 ? from / size : 0, size, Sort.by(sortBy).ascending());
24 | }
25 |
26 | }
27 |
28 |
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/event/dto/PatchEventDto.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.event.dto;
2 |
3 | import lombok.AllArgsConstructor;
4 | import lombok.Builder;
5 | import lombok.Data;
6 | import lombok.NoArgsConstructor;
7 | import ru.practicum.main.event.location.model.Location;
8 | import ru.practicum.main.event.status.UserEventStatus;
9 |
10 | import java.time.LocalDateTime;
11 |
12 |
13 | @Data
14 | @Builder
15 | @AllArgsConstructor
16 | @NoArgsConstructor
17 | public class PatchEventDto {
18 |
19 | private String annotation;
20 |
21 | private Long category;
22 |
23 | private String description;
24 |
25 | private LocalDateTime eventDate;
26 |
27 | private Location location;
28 |
29 | private Boolean paid;
30 |
31 | private Integer participantLimit;
32 |
33 | private Boolean requestModeration;
34 |
35 | private String title;
36 |
37 | private UserEventStatus stateAction;
38 | }
39 |
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/comment/model/Comment.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.comment.model;
2 |
3 | import lombok.*;
4 | import ru.practicum.main.event.model.Event;
5 | import ru.practicum.main.user.model.User;
6 |
7 | import javax.persistence.*;
8 | import java.time.LocalDateTime;
9 |
10 | @Getter
11 | @Setter
12 | @Builder
13 | @Entity
14 | @AllArgsConstructor
15 | @NoArgsConstructor
16 | @Table(name = "comments")
17 | public class Comment {
18 |
19 | @Id
20 | @GeneratedValue(strategy = GenerationType.IDENTITY)
21 | private Long id;
22 |
23 | @Column(name = "textual_content")
24 | private String text;
25 |
26 | @ManyToOne
27 | @JoinColumn(name = "author_id")
28 | private User author;
29 |
30 | @ManyToOne
31 | @JoinColumn(name = "event_id")
32 | private Event event;
33 |
34 | @Column(name = "create_time")
35 | private LocalDateTime createTime;
36 |
37 | @Column(name = "patch_time")
38 | private LocalDateTime patchTime;
39 | }
40 |
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/category/mapper/CategoryMapper.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.category.mapper;
2 |
3 | import lombok.experimental.UtilityClass;
4 | import ru.practicum.main.category.dto.CategoryDto;
5 | import ru.practicum.main.category.model.Category;
6 |
7 | import java.util.List;
8 | import java.util.stream.Collectors;
9 |
10 | @UtilityClass
11 | public class CategoryMapper {
12 |
13 | public CategoryDto toCategoryDto(Category category) {
14 | return CategoryDto.builder()
15 | .id(category.getId())
16 | .name(category.getName())
17 | .build();
18 | }
19 |
20 | public Category toCategories(CategoryDto categoryDto) {
21 | return Category.builder()
22 | .name(categoryDto.getName())
23 | .build();
24 | }
25 |
26 | public List toListCategoriesDto(List list) {
27 | return list.stream().map(CategoryMapper::toCategoryDto).collect(Collectors.toList());
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/ewm-stat-service/stat_dto/src/main/java/ru/practicum/dto/StatDto.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.dto;
2 |
3 | import com.fasterxml.jackson.annotation.JsonFormat;
4 | import lombok.*;
5 |
6 | import javax.validation.constraints.NotBlank;
7 | import javax.validation.constraints.NotNull;
8 | import javax.validation.constraints.Size;
9 | import java.time.LocalDateTime;
10 |
11 | @Data
12 | @AllArgsConstructor
13 | @NoArgsConstructor
14 | @Builder
15 | public class StatDto {
16 |
17 | @NotBlank(groups = Validator.Create.class)
18 | @Size(max = 50, groups = Validator.Create.class)
19 | private String app;
20 |
21 | @NotBlank(groups = Validator.Create.class)
22 | @Size(max = 50, groups = Validator.Create.class)
23 | private String uri;
24 |
25 | @NotBlank(groups = Validator.Create.class)
26 | @Size(max = 15, groups = Validator.Create.class)
27 | private String ip;
28 |
29 | @NotNull(groups = Validator.Create.class)
30 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", shape = JsonFormat.Shape.STRING)
31 | private LocalDateTime timestamp;
32 | }
33 |
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/request/repository/RequestMainServiceRepository.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.request.repository;
2 |
3 | import org.springframework.data.jpa.repository.JpaRepository;
4 | import org.springframework.data.jpa.repository.Query;
5 | import ru.practicum.main.request.dto.ConfirmedRequestShortDto;
6 | import ru.practicum.main.request.model.Request;
7 |
8 | import java.util.List;
9 |
10 | public interface RequestMainServiceRepository extends JpaRepository {
11 |
12 | @Query("SELECT new ru.practicum.main.request.dto.ConfirmedRequestShortDto(r.event.id , count(r.id)) " +
13 | "FROM Request r " +
14 | "WHERE r.event.id in ?1 " +
15 | "AND r.status = 'CONFIRMED' " +
16 | "GROUP BY r.event.id ")
17 | List countByEventId(List longs);
18 |
19 | boolean existsByRequesterIdAndEventId(long userId, long eventId);
20 |
21 | List findAllByRequesterId(long userId);
22 |
23 | List findAllByEventId(long eventId);
24 | }
25 |
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/event/service/EventPrivateService.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.event.service;
2 |
3 | import ru.practicum.main.request.dto.RequestDto;
4 | import ru.practicum.main.event.dto.RequestShortDto;
5 | import ru.practicum.main.event.dto.RequestShortUpdateDto;
6 | import ru.practicum.main.event.dto.EventFullDto;
7 | import ru.practicum.main.event.dto.EventRequestDto;
8 | import ru.practicum.main.event.dto.UpdateEventDto;
9 |
10 | import java.util.List;
11 |
12 | public interface EventPrivateService {
13 | EventFullDto createEvent(Long userId, EventRequestDto eventRequestDto);
14 |
15 | List readEventByUserId(Long userId, int from, int size);
16 |
17 | EventFullDto readEventByUserIdAndEventId(Long userId, Long eventId);
18 |
19 | EventFullDto updateEvent(Long userId, Long eventId, UpdateEventDto receivedDto);
20 |
21 | List readRequestByUserIdAndEventId(Long userId, Long eventId);
22 |
23 | RequestShortUpdateDto updateRequestByOwner(Long userId, Long eventId, RequestShortDto requestShortDto);
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/event/dto/EventFullDto.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.event.dto;
2 |
3 | import lombok.*;
4 | import ru.practicum.main.category.dto.CategoryDto;
5 | import ru.practicum.main.event.location.dto.LocationDto;
6 | import ru.practicum.main.event.status.State;
7 | import ru.practicum.main.user.dto.UserDto;
8 |
9 | @Data
10 | @Builder
11 | @AllArgsConstructor
12 | @NoArgsConstructor
13 | public class EventFullDto {
14 | private Long id;
15 |
16 | private String annotation;
17 |
18 | private CategoryDto category;
19 |
20 | private String createdOn;
21 |
22 | private String description;
23 |
24 | private String eventDate;
25 |
26 | private UserDto initiator;
27 |
28 | private LocationDto location;
29 |
30 | private Boolean paid;
31 |
32 | private Integer participantLimit;
33 |
34 | private Boolean requestModeration;
35 |
36 | private State state;
37 |
38 | private String title;
39 |
40 | private Long views;
41 |
42 | private Long confirmedRequests;
43 |
44 | private String publishedOn;
45 | }
46 |
--------------------------------------------------------------------------------
/ewm-stat-service/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | ru.practicum
8 | explore-with-me
9 | 0.0.1-SNAPSHOT
10 | ../pom.xml
11 |
12 |
13 |
14 | Stat server
15 |
16 | stat_client
17 | stat_dto
18 | stat_server
19 |
20 |
21 | ewm-stat-service
22 | pom
23 |
24 |
25 | 11
26 | 11
27 | UTF-8
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/comment/repository/CommentMainServiceRepository.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.comment.repository;
2 |
3 | import org.springframework.data.domain.Pageable;
4 | import org.springframework.data.jpa.repository.JpaRepository;
5 | import org.springframework.data.jpa.repository.Query;
6 | import ru.practicum.main.comment.dto.CommentCountDto;
7 | import ru.practicum.main.comment.model.Comment;
8 |
9 | import java.util.List;
10 |
11 |
12 | public interface CommentMainServiceRepository extends JpaRepository {
13 |
14 | List findAllByEventId(Long eventId, Pageable pageable);
15 |
16 | @Query("select new ru.practicum.main.comment.dto.CommentCountDto(c.event.id, count(c.id)) " +
17 | "from Comment as c " +
18 | "where c.event.id in ?1 " +
19 | "group by c.event.id")
20 | List findAllCommentCount(List listEventId);
21 |
22 | @Query("select c " +
23 | "from Comment as c " +
24 | "where lower(c.text) like concat('%', lower(?1), '%') ")
25 | List findAllByText(String text);
26 |
27 | List findAllByAuthorId(Long userId);
28 | }
29 |
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/compilation/model/Compilation.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.compilation.model;
2 |
3 | import lombok.*;
4 | import ru.practicum.main.event.model.Event;
5 |
6 | import javax.persistence.*;
7 | import java.util.Set;
8 |
9 | @Getter
10 | @Setter
11 | @Builder
12 | @Entity
13 | @AllArgsConstructor
14 | @NoArgsConstructor
15 | @Table(name = "compilations")
16 | public class Compilation {
17 |
18 | @Id
19 | @GeneratedValue(strategy = GenerationType.IDENTITY)
20 | @Column(name = "id")
21 | private Long id;
22 |
23 | @Column(name = "pinned")
24 | private Boolean pinned;
25 |
26 | @Column(name = "title")
27 | private String title;
28 |
29 | @ManyToMany
30 | @JoinTable(name = "compilations_events",
31 | joinColumns = @JoinColumn(name = "compilations_id"),
32 | inverseJoinColumns = @JoinColumn(name = "events_id"))
33 | private Set events;
34 |
35 | @Override
36 | public String toString() {
37 | return "Compilations{" +
38 | "id=" + id +
39 | ", pinned=" + pinned +
40 | ", title='" + title + '\'' +
41 | ", events=" + events +
42 | '}';
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/event/dto/EventRequestDto.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.event.dto;
2 |
3 | import com.fasterxml.jackson.annotation.JsonFormat;
4 | import lombok.*;
5 | import ru.practicum.main.event.location.dto.LocationDto;
6 |
7 | import javax.validation.Valid;
8 | import javax.validation.constraints.*;
9 | import java.time.LocalDateTime;
10 |
11 | @Data
12 | @Builder
13 | @AllArgsConstructor
14 | @NoArgsConstructor
15 | public class EventRequestDto {
16 |
17 | @NotBlank
18 | @Size(min = 20, max = 2000)
19 | private String annotation;
20 |
21 | @NotNull
22 | private Long category;
23 |
24 | @NotBlank
25 | @Size(min = 20, max = 7000)
26 | private String description;
27 |
28 | @Future
29 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", shape = JsonFormat.Shape.STRING)
30 | @NotNull
31 | private LocalDateTime eventDate;
32 |
33 | @Valid
34 | @NotNull
35 | private LocationDto location;
36 |
37 | private boolean paid;
38 |
39 | @PositiveOrZero
40 | private int participantLimit = 0;
41 |
42 | @NotNull
43 | private boolean requestModeration = true;
44 |
45 | @NotBlank
46 | @Size(min = 3, max = 120)
47 | private String title;
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/event/dto/EventFullWithComment.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.event.dto;
2 |
3 | import lombok.AllArgsConstructor;
4 | import lombok.Builder;
5 | import lombok.Data;
6 | import lombok.NoArgsConstructor;
7 | import ru.practicum.main.category.model.Category;
8 | import ru.practicum.main.comment.model.Comment;
9 | import ru.practicum.main.event.location.model.Location;
10 | import ru.practicum.main.event.status.State;
11 | import ru.practicum.main.user.model.User;
12 |
13 | import java.util.List;
14 |
15 | @Data
16 | @Builder
17 | @AllArgsConstructor
18 | @NoArgsConstructor
19 | public class EventFullWithComment {
20 | private Long id;
21 |
22 | private String annotation;
23 |
24 | private Category category;
25 |
26 | private String createdOn;
27 |
28 | private String description;
29 |
30 | private String eventDate;
31 |
32 | private User initiator;
33 |
34 | private Location location;
35 |
36 | private Boolean paid;
37 |
38 | private Integer participantLimit;
39 |
40 | private Boolean requestModeration;
41 |
42 | private State state;
43 |
44 | private String title;
45 |
46 | private Long views;
47 |
48 | private Long confirmedRequests;
49 |
50 | private String publishedOn;
51 |
52 | private List comments;
53 | }
54 |
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/request/model/Request.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.request.model;
2 |
3 | import lombok.*;
4 | import ru.practicum.main.request.Status;
5 | import ru.practicum.main.event.model.Event;
6 | import ru.practicum.main.user.model.User;
7 |
8 | import javax.persistence.*;
9 | import java.time.LocalDateTime;
10 |
11 | @Getter
12 | @Setter
13 | @Builder
14 | @Entity
15 | @AllArgsConstructor
16 | @NoArgsConstructor
17 | @Table(name = "request")
18 | public class Request {
19 |
20 | @Id
21 | @GeneratedValue(strategy = GenerationType.IDENTITY)
22 | @Column(name = "id")
23 | private long id;
24 |
25 | @Column(name = "created")
26 | private LocalDateTime created;
27 |
28 | @ManyToOne
29 | @JoinColumn(name = "event_id")
30 | private Event event;
31 |
32 | @ManyToOne
33 | @JoinColumn(name = "requester_id")
34 | private User requester;
35 |
36 | @Column(name = "status")
37 | @Enumerated(EnumType.STRING)
38 | private Status status;
39 |
40 | @Override
41 | public String toString() {
42 | return "Request{" +
43 | "id=" + id +
44 | ", created=" + created +
45 | ", event=" + event +
46 | ", requester=" + requester +
47 | ", status=" + status +
48 | '}';
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/event/dto/EventFullWithCommentDto.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.event.dto;
2 |
3 | import lombok.AllArgsConstructor;
4 | import lombok.Builder;
5 | import lombok.Data;
6 | import lombok.NoArgsConstructor;
7 | import ru.practicum.main.category.dto.CategoryDto;
8 | import ru.practicum.main.comment.dto.CommentShortDto;
9 | import ru.practicum.main.event.location.dto.LocationDto;
10 | import ru.practicum.main.event.status.State;
11 | import ru.practicum.main.user.dto.UserDto;
12 |
13 | import java.util.List;
14 |
15 | @Data
16 | @Builder
17 | @AllArgsConstructor
18 | @NoArgsConstructor
19 | public class EventFullWithCommentDto {
20 | private Long id;
21 |
22 | private String annotation;
23 |
24 | private CategoryDto category;
25 |
26 | private String createdOn;
27 |
28 | private String description;
29 |
30 | private String eventDate;
31 |
32 | private UserDto initiator;
33 |
34 | private LocationDto location;
35 |
36 | private Boolean paid;
37 |
38 | private Integer participantLimit;
39 |
40 | private Boolean requestModeration;
41 |
42 | private State state;
43 |
44 | private String title;
45 |
46 | private Long views;
47 |
48 | private Long confirmedRequests;
49 |
50 | private String publishedOn;
51 |
52 | private List comments;
53 | }
54 |
--------------------------------------------------------------------------------
/docker-compose.yml:
--------------------------------------------------------------------------------
1 | version: '3.8'
2 | services:
3 |
4 | stats-server:
5 | build: ./ewm-stat-service/stat_server
6 |
7 | image:
8 | stat_server:latest
9 | container_name: stat_server
10 |
11 | ports:
12 | - "9090:9090"
13 | - "9091:9091"
14 |
15 | depends_on:
16 | - stats_service-db
17 | environment:
18 | - STAT_URL_DB=jdbc:postgresql://state_server-db:5432/stat_db
19 | - STAT_USERNAME_DB=asd
20 | - STAT_PASSWORD_DB=123
21 |
22 |
23 | stats_service-db:
24 | image: postgres:15-alpine
25 | container_name: stat_server-db
26 | ports:
27 | - "6666:5432"
28 | environment:
29 | - POSTGRES_DB=stat_db
30 | - POSTGRES_USER=asd
31 | - POSTGRES_PASSWORD=123
32 |
33 |
34 | ewm-service:
35 | build: ./ewm-main-service
36 | image:
37 | ewm-service:latest
38 | container_name: ewm-service
39 |
40 | ports:
41 | - "8080:8080"
42 | - "8081:8081"
43 |
44 | depends_on:
45 | - ewm-db
46 | environment:
47 | - MAIN_DB=jdbc:postgresql://postgres-main-db:5432/ewm_db
48 | - MAIN_USER=postgres
49 | - MAIN_PASSWORD=123
50 |
51 | ewm-db:
52 | image: postgres:15
53 | container_name: postgres-main-db
54 | ports:
55 | - "6464:5432"
56 | environment:
57 | - POSTGRES_DB=ewm_db
58 | - POSTGRES_USER=postgres
59 | - POSTGRES_PASSWORD=123
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/event/dto/UpdateEventDto.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.event.dto;
2 |
3 | import com.fasterxml.jackson.annotation.JsonFormat;
4 | import lombok.*;
5 | import ru.practicum.dto.Validator;
6 | import ru.practicum.main.event.location.dto.LocationDto;
7 | import ru.practicum.main.event.status.UserEventStatus;
8 |
9 | import javax.validation.constraints.Future;
10 | import javax.validation.constraints.PositiveOrZero;
11 | import javax.validation.constraints.Size;
12 | import java.time.LocalDateTime;
13 |
14 | @Data
15 | @Builder
16 | @AllArgsConstructor
17 | @NoArgsConstructor
18 | public class UpdateEventDto {
19 |
20 | @Size(min = 20, max = 2000, groups = Validator.Update.class)
21 | private String annotation;
22 |
23 | private Long category;
24 |
25 | @Size(min = 20, max = 7000, groups = Validator.Update.class)
26 | private String description;
27 |
28 | @Future(groups = Validator.Update.class)
29 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", shape = JsonFormat.Shape.STRING)
30 | private LocalDateTime eventDate;
31 |
32 | private LocationDto location;
33 |
34 | private Boolean paid;
35 |
36 | @PositiveOrZero(groups = Validator.Update.class)
37 | private Integer participantLimit;
38 |
39 | private Boolean requestModeration;
40 |
41 | @Size(min = 3, max = 120, groups = Validator.Update.class)
42 | private String title;
43 |
44 | private UserEventStatus stateAction;
45 | }
46 |
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/event/dto/AdminEventRequestDto.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.event.dto;
2 |
3 | import com.fasterxml.jackson.annotation.JsonFormat;
4 | import lombok.AllArgsConstructor;
5 | import lombok.Builder;
6 | import lombok.Data;
7 | import lombok.NoArgsConstructor;
8 | import ru.practicum.dto.Validator;
9 | import ru.practicum.main.event.location.dto.LocationDto;
10 | import ru.practicum.main.event.status.AdminEventStatus;
11 |
12 | import javax.validation.constraints.Future;
13 | import javax.validation.constraints.PositiveOrZero;
14 | import javax.validation.constraints.Size;
15 | import java.time.LocalDateTime;
16 |
17 |
18 | @Data
19 | @Builder
20 | @AllArgsConstructor
21 | @NoArgsConstructor
22 | public class AdminEventRequestDto {
23 |
24 | @Size(min = 20, max = 2000, groups = Validator.Update.class)
25 | private String annotation;
26 |
27 | private Long category;
28 |
29 | @Size(min = 20, max = 7000, groups = Validator.Update.class)
30 | private String description;
31 |
32 | @Future(groups = Validator.Update.class)
33 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", shape = JsonFormat.Shape.STRING)
34 | private LocalDateTime eventDate;
35 |
36 | private LocationDto location;
37 |
38 | private Boolean paid;
39 |
40 | @PositiveOrZero(groups = Validator.Update.class)
41 | private Integer participantLimit;
42 |
43 | private Boolean requestModeration;
44 |
45 | @Size(min = 3, max = 120, groups = Validator.Update.class)
46 | private String title;
47 |
48 | private AdminEventStatus stateAction;
49 | }
50 |
--------------------------------------------------------------------------------
/ewm-stat-service/stat_dto/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | ru.practicum
8 | ewm-stat-service
9 | 0.0.1-SNAPSHOT
10 | ../pom.xml
11 |
12 |
13 | stat_dto
14 |
15 |
16 |
17 | org.projectlombok
18 | lombok
19 | true
20 |
21 |
22 |
23 | org.springframework.boot
24 | spring-boot-configuration-processor
25 | true
26 |
27 |
28 |
29 | jakarta.validation
30 | jakarta.validation-api
31 |
32 |
33 | com.fasterxml.jackson.core
34 | jackson-annotations
35 |
36 |
37 | org.springframework
38 | spring-context
39 |
40 |
41 |
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/category/controller/CategoryPublicController.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.category.controller;
2 |
3 | import lombok.RequiredArgsConstructor;
4 | import lombok.extern.slf4j.Slf4j;
5 | import org.springframework.http.ResponseEntity;
6 | import org.springframework.validation.annotation.Validated;
7 | import org.springframework.web.bind.annotation.*;
8 | import ru.practicum.main.category.dto.CategoryDto;
9 | import ru.practicum.main.category.service.CategoryPublicService;
10 |
11 | import javax.validation.constraints.Positive;
12 | import javax.validation.constraints.PositiveOrZero;
13 | import java.util.List;
14 |
15 | @RestController
16 | @RequiredArgsConstructor
17 | @Validated
18 | @RequestMapping(path = "/categories")
19 | @Slf4j
20 | public class CategoryPublicController {
21 |
22 | private final CategoryPublicService service;
23 |
24 | @GetMapping
25 | public ResponseEntity> readAllCategories(@RequestParam(defaultValue = "0") @PositiveOrZero int from,
26 | @RequestParam(defaultValue = "10") @Positive int size) {
27 | log.info("Calling the POST request to - /categories - endpoint");
28 | return ResponseEntity
29 | .ok(service.readAllCategories(from, size));
30 | }
31 |
32 | @GetMapping("/{catId}")
33 | public ResponseEntity readCategoryById(@PathVariable Long catId) {
34 | log.info("Calling the GET request to - /categories/{catId} - endpoint");
35 | return ResponseEntity
36 | .ok(service.readCategoryById(catId));
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/user/mapper/UserMapper.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.user.mapper;
2 |
3 | import lombok.experimental.UtilityClass;
4 | import ru.practicum.main.user.dto.AdminUserDto;
5 | import ru.practicum.main.user.dto.UserDto;
6 | import ru.practicum.main.user.dto.UserDtoReceived;
7 | import ru.practicum.main.user.dto.UserShortDto;
8 | import ru.practicum.main.user.model.User;
9 |
10 | import java.util.List;
11 | import java.util.stream.Collectors;
12 |
13 | @UtilityClass
14 | public class UserMapper {
15 |
16 | public UserDto toUserDto(User user) {
17 | return UserDto.builder()
18 | .name(user.getName())
19 | .id(user.getId())
20 | .build();
21 | }
22 |
23 | public User toUser(UserDtoReceived userDto) {
24 | return User.builder()
25 | .email(userDto.getEmail())
26 | .name(userDto.getName())
27 | .build();
28 | }
29 |
30 | public static UserShortDto toUserShortDto(User user) {
31 | return UserShortDto.builder()
32 | .id(user.getId())
33 | .name(user.getName())
34 | .build();
35 | }
36 |
37 | public AdminUserDto toAdminUserDto(User newUser) {
38 | return AdminUserDto.builder()
39 | .email(newUser.getEmail())
40 | .id(newUser.getId())
41 | .name(newUser.getName())
42 | .build();
43 | }
44 |
45 | public List toListAdminUserDto(List users) {
46 | return users.stream().map(UserMapper::toAdminUserDto).collect(Collectors.toList());
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/comment/controller/PublicCommentController.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.comment.controller;
2 |
3 | import lombok.RequiredArgsConstructor;
4 | import lombok.extern.slf4j.Slf4j;
5 | import org.springframework.http.ResponseEntity;
6 | import org.springframework.web.bind.annotation.GetMapping;
7 | import org.springframework.web.bind.annotation.PathVariable;
8 | import org.springframework.web.bind.annotation.RequestParam;
9 | import org.springframework.web.bind.annotation.RestController;
10 | import ru.practicum.main.comment.dto.CommentDto;
11 | import ru.practicum.main.comment.dto.CommentShortDto;
12 | import ru.practicum.main.comment.service.CommentService;
13 |
14 | import java.util.List;
15 |
16 |
17 | @RestController
18 | @RequiredArgsConstructor
19 | @Slf4j
20 | public class PublicCommentController {
21 |
22 | private final CommentService service;
23 |
24 | @GetMapping("/comment/{comId}")
25 | public ResponseEntity getById(@PathVariable Long comId) {
26 | log.info("Calling the GET request to /comment/{comId}endpoint");
27 | return ResponseEntity.ok(service.getComment(comId));
28 | }
29 |
30 | @GetMapping("/events/{eventId}/comment")
31 | public ResponseEntity> getByEventId(@PathVariable Long eventId,
32 | @RequestParam(defaultValue = "0") int from,
33 | @RequestParam(defaultValue = "10") int size) {
34 | log.info("Calling the GET request to /events/{eventId}/comment");
35 | return ResponseEntity.ok(service.getCommentsByEvent(eventId, from, size));
36 | }
37 | }
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/comment/controller/AdminCommentController.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.comment.controller;
2 |
3 | import lombok.RequiredArgsConstructor;
4 | import lombok.extern.slf4j.Slf4j;
5 | import org.springframework.http.HttpStatus;
6 | import org.springframework.http.ResponseEntity;
7 | import org.springframework.web.bind.annotation.*;
8 | import ru.practicum.main.comment.dto.CommentDto;
9 | import ru.practicum.main.comment.service.AdminCommentService;
10 |
11 | import java.util.List;
12 |
13 |
14 | @RestController
15 | @RequestMapping(path = "/admin")
16 | @RequiredArgsConstructor
17 | @Slf4j
18 | public class AdminCommentController {
19 |
20 | private final AdminCommentService adminCommentService;
21 |
22 |
23 | @GetMapping("comment/search")
24 | public ResponseEntity> search(@RequestParam String text) {
25 | log.info("Calling the GET request to /admin/comment/search endpoint");
26 | return ResponseEntity.ok(adminCommentService.search(text));
27 | }
28 |
29 | @GetMapping("users/{userId}/comment")
30 | public ResponseEntity> get(@PathVariable Long userId) {
31 | log.info("Calling the GET request to admin/users/{userId}/comment endpoint");
32 | return ResponseEntity.ok(adminCommentService.findAllById(userId));
33 | }
34 |
35 | @DeleteMapping("comment/{comId}")
36 | @ResponseStatus(HttpStatus.NO_CONTENT)
37 | public ResponseEntity delete(@PathVariable Long comId) {
38 | log.info("Calling the GET request to admin/comment/{comId} endpoint");
39 | adminCommentService.delete(comId);
40 | return ResponseEntity
41 | .status(HttpStatus.NO_CONTENT)
42 | .body("Comment deleted by admin: " + comId);
43 | }
44 | }
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/compilation/mapper/CompilationMapper.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.compilation.mapper;
2 |
3 | import lombok.experimental.UtilityClass;
4 | import ru.practicum.main.compilation.dto.CompilationDto;
5 | import ru.practicum.main.compilation.model.Compilation;
6 | import ru.practicum.main.event.dto.EventShortDto;
7 | import ru.practicum.main.event.mapper.EventMapper;
8 |
9 | import java.util.ArrayList;
10 | import java.util.List;
11 | import java.util.stream.Collectors;
12 |
13 | @UtilityClass
14 | public class CompilationMapper {
15 |
16 | public CompilationDto toCompilationsDtoFromCompilation(Compilation compilation) {
17 | return CompilationDto.builder()
18 | .events(EventMapper.toListEventShortDto(EventMapper.toListEventShort(new ArrayList<>(compilation.getEvents()))))
19 | .id(compilation.getId())
20 | .pinned(compilation.getPinned())
21 | .title(compilation.getTitle())
22 | .build();
23 | }
24 |
25 | public static CompilationDto toCompilationDto(Compilation compilation) {
26 | List eventShortDtoList = compilation.getEvents().stream()
27 | .map(EventMapper::toEventShortDto)
28 | .collect(Collectors.toList());
29 |
30 | return CompilationDto.builder()
31 | .id(compilation.getId())
32 | .pinned(compilation.getPinned())
33 | .title(compilation.getTitle())
34 | .events(eventShortDtoList)
35 | .build();
36 | }
37 |
38 | public static List toCompilationDtoList(List compilations) {
39 | return compilations.stream()
40 | .map(CompilationMapper::toCompilationDto)
41 | .collect(Collectors.toList());
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/compilation/controller/CompilationPublicController.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.compilation.controller;
2 |
3 | import lombok.RequiredArgsConstructor;
4 | import lombok.extern.slf4j.Slf4j;
5 | import org.springframework.http.ResponseEntity;
6 | import org.springframework.validation.annotation.Validated;
7 | import org.springframework.web.bind.annotation.*;
8 | import ru.practicum.main.compilation.dto.CompilationDto;
9 | import ru.practicum.main.compilation.service.CompilationPublicService;
10 |
11 | import javax.validation.constraints.Positive;
12 | import javax.validation.constraints.PositiveOrZero;
13 | import java.util.List;
14 |
15 | @RestController
16 | @Validated
17 | @RequestMapping("/compilations")
18 | @RequiredArgsConstructor
19 | @Slf4j
20 | public class CompilationPublicController {
21 |
22 | private final CompilationPublicService service;
23 |
24 | @GetMapping("/{compId}")
25 | public ResponseEntity getCompilationById(@PathVariable Long compId) {
26 | log.info("Calling the GET request to /compilations/{compId} endpoint");
27 | CompilationDto response = service.readCompilationById(compId);
28 | return ResponseEntity.ok(response);
29 |
30 |
31 | }
32 |
33 | @GetMapping
34 | public ResponseEntity> getCompilation(@RequestParam(required = false) Boolean pinned,
35 | @RequestParam(defaultValue = "0") @PositiveOrZero int from,
36 | @RequestParam(defaultValue = "10") @Positive int size) {
37 | log.info("Calling the GET request to /compilations endpoint");
38 | List list = service.readAllCompilations(pinned, from, size);
39 | return ResponseEntity.ok(list);
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/request/mapper/RequestMapper.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.request.mapper;
2 |
3 | import lombok.experimental.UtilityClass;
4 | import ru.practicum.main.event.dto.RequestShortUpdateDto;
5 | import ru.practicum.main.request.dto.RequestDto;
6 | import ru.practicum.main.request.dto.RequestShortDto;
7 | import ru.practicum.main.request.dto.RequestUpdateDto;
8 | import ru.practicum.main.request.model.Request;
9 |
10 | import java.util.List;
11 | import java.util.stream.Collectors;
12 |
13 | @UtilityClass
14 | public class RequestMapper {
15 |
16 | public RequestDto toRequestDto(Request request) {
17 | return RequestDto.builder()
18 | .requester(request.getRequester().getId())
19 | .id(request.getId())
20 | .created(request.getCreated())
21 | .event(request.getEvent().getId())
22 | .status(request.getStatus())
23 | .build();
24 | }
25 |
26 | public List toListRequestDto(List requests) {
27 | return requests.stream().map(RequestMapper::toRequestDto).collect(Collectors.toList());
28 | }
29 |
30 | public RequestShortDto toRequestShort(ru.practicum.main.event.dto.RequestShortDto shortDto) {
31 | return RequestShortDto.builder()
32 | .requestIds(shortDto.getRequestIds())
33 | .status(shortDto.getStatus())
34 | .build();
35 | }
36 |
37 | public RequestShortUpdateDto toRequestShortUpdateDto(RequestUpdateDto requestShort) {
38 | return RequestShortUpdateDto.builder()
39 | .rejectedRequests(RequestMapper.toListRequestDto(requestShort.getCanselRequest()))
40 | .confirmedRequests(RequestMapper.toListRequestDto(requestShort.getConformedRequest()))
41 | .build();
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/request/controller/RequestController.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.request.controller;
2 |
3 | import lombok.RequiredArgsConstructor;
4 | import lombok.extern.slf4j.Slf4j;
5 | import org.springframework.http.HttpStatus;
6 | import org.springframework.http.ResponseEntity;
7 | import org.springframework.validation.annotation.Validated;
8 | import org.springframework.web.bind.annotation.*;
9 | import ru.practicum.main.request.dto.RequestDto;
10 | import ru.practicum.main.request.service.RequestService;
11 |
12 | import java.util.List;
13 |
14 | @RestController
15 | @Validated
16 | @RequestMapping("/users/")
17 | @RequiredArgsConstructor
18 | @Slf4j
19 | public class RequestController {
20 |
21 | private final RequestService requestService;
22 |
23 | @PostMapping("/{userId}/requests")
24 | @ResponseStatus(HttpStatus.CREATED)
25 | public ResponseEntity createRequest(@PathVariable Long userId, @RequestParam Long eventId) {
26 | log.info("Calling the POST request to /users/{userId}/requests endpoint");
27 | return ResponseEntity.status(HttpStatus.CREATED).body(requestService.createRequest(userId, eventId));
28 | }
29 |
30 | @GetMapping("/{userId}/requests")
31 | public ResponseEntity> getRequests(@PathVariable Long userId) {
32 | log.info("Calling the GET request to /users/{userId}/requests endpoint");
33 | return ResponseEntity.ok(requestService.readAllRequests(userId));
34 | }
35 |
36 | @PatchMapping("/{userId}/requests/{requestId}/cancel")
37 | public ResponseEntity canselRequest(@PathVariable Long userId, @PathVariable Long requestId) {
38 | log.info("Calling the PATCH request to /users/{userId}/requests/{requestId}/cancel");
39 | return ResponseEntity.ok(requestService.cancelRequest(userId, requestId));
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/ewm-main-service/src/main/java/ru/practicum/main/category/service/CategoryPublicServiceImpl.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.main.category.service;
2 |
3 | import lombok.RequiredArgsConstructor;
4 | import lombok.extern.slf4j.Slf4j;
5 | import org.springframework.stereotype.Service;
6 | import org.springframework.transaction.annotation.Transactional;
7 | import ru.practicum.main.category.dto.CategoryDto;
8 | import ru.practicum.main.category.mapper.CategoryMapper;
9 | import ru.practicum.main.category.model.Category;
10 | import ru.practicum.main.category.repository.CategoryMainServiceRepository;
11 | import ru.practicum.main.exception.NotFoundException;
12 |
13 | import java.util.List;
14 |
15 | import static ru.practicum.main.util.Util.createPageRequestAsc;
16 |
17 | @Service
18 | @RequiredArgsConstructor
19 | @Transactional(readOnly = true)
20 | @Slf4j
21 | public class CategoryPublicServiceImpl implements CategoryPublicService {
22 |
23 | private final CategoryMainServiceRepository repository;
24 |
25 | @Override
26 | public List readAllCategories(Integer from, Integer size) {
27 | log.info("readAllCategories - invoked");
28 | List cat = repository.findAllCategories(createPageRequestAsc(from, size));
29 | log.info("Result: categories size = {}", cat.size());
30 | return CategoryMapper.toListCategoriesDto(cat);
31 |
32 | }
33 |
34 | @Override
35 | public CategoryDto readCategoryById(Long catId) {
36 | log.info("readAllCategories - invoked");
37 | Category category = repository.findById(catId).orElseThrow(() -> {
38 | log.error("Category with id = {} not exist", catId);
39 | return new NotFoundException("Category not found");
40 | });
41 | log.info("Result: received a category - {}", category.getName());
42 | return CategoryMapper.toCategoryDto(category);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/ewm-stat-service/stat_client/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | ru.practicum
8 | explore-with-me
9 | 0.0.1-SNAPSHOT
10 | ../../pom.xml
11 |
12 |
13 | stat_client
14 | 0.0.1-SNAPSHOT
15 |
16 |
17 | 11
18 | 11
19 | UTF-8
20 |
21 |
22 |
23 |
24 | org.springframework.boot
25 | spring-boot-starter-web
26 |
27 |
28 |
29 | org.apache.httpcomponents
30 | httpclient
31 |
32 |
33 |
34 | ru.practicum
35 | stat_dto
36 | 0.0.1-SNAPSHOT
37 | compile
38 |
39 |
40 | org.projectlombok
41 | lombok
42 |
43 |
44 |
45 | org.springframework.boot
46 | spring-boot-starter-actuator
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/ewm-stat-service/stat_server/src/main/java/ru/practicum/controller/StatServiceController.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.controller;
2 |
3 | import lombok.RequiredArgsConstructor;
4 | import lombok.extern.slf4j.Slf4j;
5 | import org.springframework.format.annotation.DateTimeFormat;
6 | import org.springframework.http.HttpStatus;
7 | import org.springframework.http.ResponseEntity;
8 | import org.springframework.validation.annotation.Validated;
9 | import org.springframework.web.bind.annotation.*;
10 | import ru.practicum.dto.StatDto;
11 | import ru.practicum.dto.StatResponseDto;
12 | import ru.practicum.dto.Validator;
13 | import ru.practicum.service.StatService;
14 |
15 | import java.time.LocalDateTime;
16 | import java.util.List;
17 |
18 | import static ru.practicum.utill.Constants.DATE_FORMAT;
19 |
20 |
21 | @RestController
22 | @RequiredArgsConstructor
23 | @Validated
24 | @Slf4j
25 | public class StatServiceController {
26 |
27 | private final StatService statService;
28 |
29 | @PostMapping("/hit")
30 | public ResponseEntity addStatEvent(@RequestBody @Validated(Validator.Create.class) StatDto statDto) {
31 | log.info("Calling the POST request to /hit endpoint");
32 | StatDto statEvent = statService.createStat(statDto);
33 | return new ResponseEntity<>(statEvent, HttpStatus.CREATED);
34 | }
35 |
36 | @GetMapping("/stats")
37 | public ResponseEntity> readStatEvent(@RequestParam @DateTimeFormat(pattern = DATE_FORMAT) LocalDateTime start,
38 | @RequestParam @DateTimeFormat(pattern = DATE_FORMAT) LocalDateTime end,
39 | @RequestParam(defaultValue = "") List uris,
40 | @RequestParam(defaultValue = "false") boolean unique) {
41 | log.info("Calling the GET request to /stats endpoint");
42 | List stats = statService.readStat(start, end, uris, unique);
43 | return new ResponseEntity<>(stats, HttpStatus.OK);
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/ewm-stat-service/stat_server/src/main/java/ru/practicum/exception/ErrorHandler.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.exception;
2 |
3 | import lombok.extern.slf4j.Slf4j;
4 | import org.springframework.http.HttpStatus;
5 | import org.springframework.http.ResponseEntity;
6 | import org.springframework.web.bind.MethodArgumentNotValidException;
7 | import org.springframework.web.bind.MissingRequestHeaderException;
8 | import org.springframework.web.bind.MissingServletRequestParameterException;
9 | import org.springframework.web.bind.annotation.ExceptionHandler;
10 | import org.springframework.web.bind.annotation.RestControllerAdvice;
11 |
12 | import javax.validation.ConstraintViolationException;
13 | import java.time.LocalDateTime;
14 |
15 | import static ru.practicum.utill.Constants.FORMATTER;
16 |
17 | @Slf4j
18 | @RestControllerAdvice
19 | public class ErrorHandler {
20 |
21 | @ExceptionHandler({MethodArgumentNotValidException.class, MissingRequestHeaderException.class,
22 | ConstraintViolationException.class, MissingServletRequestParameterException.class,
23 | WrongTimeException.class})
24 | public ResponseEntity badRequest(final Exception e) {
25 | return handleException(e, HttpStatus.BAD_REQUEST);
26 | }
27 |
28 | @ExceptionHandler
29 | public ResponseEntity internalServerError(final Exception e) {
30 | return handleException(e, HttpStatus.INTERNAL_SERVER_ERROR);
31 | }
32 |
33 | private ResponseEntity handleException(final Exception e, HttpStatus status) {
34 | String errorMessage = status.is4xxClientError() ? "Incorrectly made request." : "Internal Server Error";
35 | String timestamp = LocalDateTime.now().format(FORMATTER);
36 | String errorStatus = status.name();
37 | String errorDescription = e.getMessage();
38 |
39 | log.error("{} - Status: {}, Description: {}, Timestamp: {}",
40 | errorMessage, errorStatus, errorDescription, timestamp);
41 |
42 | return new ResponseEntity<>(new ErrorResponse(errorStatus, errorDescription, errorMessage, timestamp), status);
43 | }
44 | }
45 |
46 |
--------------------------------------------------------------------------------
/ewm-stat-service/stat_client/src/main/java/ru/practicum/client/StatClient.java:
--------------------------------------------------------------------------------
1 | package ru.practicum.client;
2 |
3 | import org.springframework.beans.factory.annotation.Value;
4 | import org.springframework.boot.web.client.RestTemplateBuilder;
5 | import org.springframework.http.ResponseEntity;
6 | import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
7 | import org.springframework.lang.Nullable;
8 | import org.springframework.stereotype.Service;
9 | import org.springframework.web.util.DefaultUriBuilderFactory;
10 | import ru.practicum.dto.StatDto;
11 |
12 | import java.net.URLEncoder;
13 | import java.nio.charset.StandardCharsets;
14 | import java.util.List;
15 | import java.util.Map;
16 |
17 | @Service
18 | public class StatClient extends BaseClient {
19 |
20 |
21 | public StatClient(@Value("${stats-service.url}") String serverUrl, RestTemplateBuilder builder) {
22 | super(
23 | builder
24 | .uriTemplateHandler(new DefaultUriBuilderFactory(serverUrl))
25 | .requestFactory(HttpComponentsClientHttpRequestFactory::new)
26 | .build()
27 | );
28 | }
29 |
30 | public ResponseEntity