Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
alexwti committed Apr 19, 2023
1 parent be718bc commit 3ed7cbf
Show file tree
Hide file tree
Showing 75 changed files with 2,620 additions and 133 deletions.
15 changes: 15 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@ services:
- POSTGRES_USER=root
- POSTGRES_PASSWORD=root

ewm-main:
build: ewm-main
container_name: ewm-main
ports:
- "8080:8080"
depends_on:
- ewm-db
environment:
- DB_NAME=ewm-server
- POSTGRES_USER=root
- POSTGRES_PASSWORD=root
- DB_HOST=ewm-db
- DB_PORT=5432
- STAT_SERVER_URL=http://ewm-stat:9090

ewm-db:
image: postgres:15.1-alpine
container_name: EWM-server-db
Expand Down
38 changes: 38 additions & 0 deletions ewm-main/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/

### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr

### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/

### Mac OS ###
.DS_Store
3 changes: 3 additions & 0 deletions ewm-main/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM amazoncorretto:17-alpine-jdk
COPY target/*.jar app.jar
ENTRYPOINT ["java","-jar","/app.jar"]
114 changes: 114 additions & 0 deletions ewm-main/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>ru.practicum</groupId>
<artifactId>explore-with-me</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>

<artifactId>ewm-main</artifactId>

<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>1.5.3.Final</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>ru.practicum</groupId>
<artifactId>stats-client</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>11</source>
<target>11</target>
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>1.5.3.Final</version>
</path>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.24</version>
</path>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-mapstruct-binding</artifactId>
<version>0.2.0</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
</project>
12 changes: 12 additions & 0 deletions ewm-main/src/main/java/ru/practicum/EwmMainApp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package ru.practicum;


import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class EwmMainApp {
public static void main(String[] args) {
SpringApplication.run(EwmMainApp.class, args);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package ru.practicum.category.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import ru.practicum.category.dto.CategoryDto;
import ru.practicum.category.service.CategoryService;

import javax.validation.Valid;

@RestController
@RequestMapping(path = "/admin/categories")
@RequiredArgsConstructor
@Validated
public class AdminCategoryController {
private final CategoryService categoryService;

@PostMapping
@ResponseStatus(HttpStatus.CREATED)
public CategoryDto createCategory(@Valid @RequestBody CategoryDto categoryDto) {
return categoryService.createCategory(categoryDto);
}

@DeleteMapping("/{catId}")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void deleteCategory(@PathVariable Long catId) {
categoryService.deleteCategory(catId);
}

@PatchMapping("/{catId}")
public CategoryDto updateCategory(@PathVariable Long catId, @Valid @RequestBody CategoryDto categoryDto) {
return categoryService.updateCategory(catId, categoryDto);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package ru.practicum.category.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import ru.practicum.category.dto.CategoryDto;
import ru.practicum.category.service.CategoryService;

import java.util.List;

@RestController
@RequestMapping(path = "/categories")
@RequiredArgsConstructor
public class PublicCategoryController {
private final CategoryService categoryService;

@GetMapping
public List<CategoryDto> getCategories(@RequestParam(required = false, defaultValue = "0") Integer from,
@RequestParam(required = false, defaultValue = "10") Integer size) {
return categoryService.getCategories(from, size);
}

@GetMapping("/{catId}")
public CategoryDto getCategory(@PathVariable Long catId) {
return categoryService.getCategory(catId);
}
}
20 changes: 20 additions & 0 deletions ewm-main/src/main/java/ru/practicum/category/dto/CategoryDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package ru.practicum.category.dto;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class CategoryDto {
private Long id;
@NotBlank
@NotNull
private String name;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package ru.practicum.category.mapper;

import org.mapstruct.Mapper;
import org.springframework.stereotype.Component;
import ru.practicum.category.dto.CategoryDto;
import ru.practicum.category.model.Category;

@Mapper(componentModel = "spring")
@Component
public interface CategoryMapper {
Category toCategory(CategoryDto categoryDto);

CategoryDto toCategoryDto(Category category);
}
21 changes: 21 additions & 0 deletions ewm-main/src/main/java/ru/practicum/category/model/Category.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package ru.practicum.category.model;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import javax.persistence.*;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Table(name = "categories", schema = "public")
public class Category {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package ru.practicum.category.repository;


import org.springframework.data.jpa.repository.JpaRepository;
import ru.practicum.category.model.Category;

public interface CategoryRepository extends JpaRepository<Category, Long> {
Boolean existsByName(String name);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package ru.practicum.category.service;


import ru.practicum.category.dto.CategoryDto;

import java.util.List;

public interface CategoryService {
CategoryDto createCategory(CategoryDto categoryDto);

List<CategoryDto> getCategories(Integer from, Integer size);

CategoryDto getCategory(Long catId);

void deleteCategory(Long catId);

CategoryDto updateCategory(Long catId, CategoryDto categoryDto);

}
Loading

0 comments on commit 3ed7cbf

Please sign in to comment.