generated from yandex-praktikum/java-explore-with-me
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
75 changed files
with
2,620 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
FROM amazoncorretto:17-alpine-jdk | ||
COPY target/*.jar app.jar | ||
ENTRYPOINT ["java","-jar","/app.jar"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
ewm-main/src/main/java/ru/practicum/category/controller/AdminCategoryController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package ru.practicum.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); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
ewm-main/src/main/java/ru/practicum/category/controller/PublicCategoryController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package ru.practicum.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
20
ewm-main/src/main/java/ru/practicum/category/dto/CategoryDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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; | ||
} |
14 changes: 14 additions & 0 deletions
14
ewm-main/src/main/java/ru/practicum/category/mapper/CategoryMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package ru.practicum.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
21
ewm-main/src/main/java/ru/practicum/category/model/Category.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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; | ||
} |
9 changes: 9 additions & 0 deletions
9
ewm-main/src/main/java/ru/practicum/category/repository/CategoryRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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); | ||
} |
19 changes: 19 additions & 0 deletions
19
ewm-main/src/main/java/ru/practicum/category/service/CategoryService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package ru.practicum.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); | ||
|
||
} |
Oops, something went wrong.