-
Notifications
You must be signed in to change notification settings - Fork 0
Sprint 17 Stage 2 solution #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
1bfbbb4
Update application properties for environment variables and enhance l…
Naz1anmak 168bbfb
Update application properties for environment variables and enhance l…
Naz1anmak 942ffcd
Add implementation Dto
Naz1anmak a65d3f7
Merge pull request #6 from Naz1anmak/main_svc_dto
Naz1anmak 8e8aef6
Merge remote-tracking branch 'origin/main_svc' into main_svc
6b86d3d
The sections of the final task 17 of the second part have been comple…
8c27b64
Edits made after the review
dd57998
Enhance logging, refactor exception handling, and update application …
Naz1anmak da4726b
Merge pull request #7 from Naz1anmak/main_svc_ivan
Naz1anmak 39a8e98
Implement category management: add create, update, delete, and retrie…
Mult1k33 c5d91a5
Merge pull request #8 from Naz1anmak/main_svc_categories
Naz1anmak 22be17e
Refactor controllers to enhance validation and logging; update applic…
Naz1anmak a9fbde9
Merge pull request #10 from Naz1anmak/main_svc_requests
internet-prodashi cb31116
Refactor error handling and validation messages; update DTOs for impr…
Naz1anmak 432589b
The assembly module has been completed, statistics have been corrected
7771179
The assembly module has been completed, statistics have been corrected
1a1bfb6
Merge remote-tracking branch 'origin/main_svc_compilations' into main…
b5395fa
Edits have been made based on the review
b66cec6
Refactor controller methods for improved readability; update paramete…
Naz1anmak 78e5c8f
Merge pull request #11 from Naz1anmak/main_svc_compilations
Naz1anmak 2918d57
Refactor compilation-related methods for improved clarity; update log…
Naz1anmak 283cb7f
Refactor date-time handling by introducing a centralized DateTimeCons…
Naz1anmak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Комментарии в Pull Request обязательно должны быть на русском языке! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,3 +20,4 @@ target/ | |
| *.iws | ||
| *.iml | ||
| *.ipr | ||
| /.run/ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| <component name="ProjectRunConfigurationManager"> | ||
| <configuration default="false" name="Deployment compose-local" type="docker-deploy" factoryName="docker-compose.yml" server-name="Docker"> | ||
| <deployment type="docker-compose.yml"> | ||
| <settings> | ||
| <option name="envFilePath" value="" /> | ||
| <option name="sourceFilePath" value="compose-local.yaml" /> | ||
| </settings> | ||
| </deployment> | ||
| <method v="2" /> | ||
| </configuration> | ||
| </component> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| <component name="ProjectRunConfigurationManager"> | ||
| <configuration default="false" name="MainApplication (local)" type="Application" factoryName="Application"> | ||
| <option name="ALTERNATIVE_JRE_PATH" value="21"/> | ||
| <option name="MAIN_CLASS_NAME" value="ru.practicum.MainApplication"/> | ||
| <module name="main-service"/> | ||
| <option name="VM_PARAMETERS" value="-Dspring.profiles.active=local"/> | ||
| <method v="2"> | ||
| <option name="Make" enabled="true"/> | ||
| </method> | ||
| </configuration> | ||
| </component> |
5 changes: 2 additions & 3 deletions
5
.run/MainApplication (docker).run.xml → .run/MainApplication.run.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| <component name="ProjectRunConfigurationManager"> | ||
| <configuration default="false" name="StatApplication (local)" type="Application" factoryName="Application"> | ||
| <option name="ALTERNATIVE_JRE_PATH" value="21"/> | ||
| <option name="MAIN_CLASS_NAME" value="ru.practicum.StatApplication"/> | ||
| <module name="stats-server"/> | ||
| <option name="VM_PARAMETERS" value="-Dspring.profiles.active=local"/> | ||
| <method v="2"> | ||
| <option name="Make" enabled="true"/> | ||
| </method> | ||
| </configuration> | ||
| </component> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,11 @@ | ||
| <component name="ProjectRunConfigurationManager"> | ||
| <configuration default="false" name="StatApplication" type="Application" factoryName="Application"> | ||
| <option name="ALTERNATIVE_JRE_PATH" value="23" /> | ||
| <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="true" /> | ||
| <option name="MAIN_CLASS_NAME" value="ru.practicum.StatApplication" /> | ||
| <module name="stats-server" /> | ||
| <option name="VM_PARAMETERS" value="-Dspring.profiles.active=test" /> | ||
| <method v="2"> | ||
| <option name="Make" enabled="true" /> | ||
| </method> | ||
| </configuration> | ||
| <configuration default="false" name="StatApplication" type="Application" factoryName="Application"> | ||
| <option name="ALTERNATIVE_JRE_PATH" value="21"/> | ||
| <option name="MAIN_CLASS_NAME" value="ru.practicum.StatApplication"/> | ||
| <module name="stats-server"/> | ||
| <option name="VM_PARAMETERS" value="-Dspring.profiles.active=test"/> | ||
| <method v="2"> | ||
| <option name="Make" enabled="true"/> | ||
| </method> | ||
| </configuration> | ||
| </component> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| name: java-explore-with-me-local | ||
| services: | ||
| stats-db-local: | ||
| image: postgres:16.1 | ||
| container_name: stats_db_local | ||
| ports: | ||
| - "6542:5432" | ||
| environment: | ||
| - POSTGRES_DB=statDB_local | ||
| - POSTGRES_USER=localuser | ||
| - POSTGRES_PASSWORD=localpass | ||
| healthcheck: | ||
| test: pg_isready -q -d $$POSTGRES_DB -U $$POSTGRES_USER | ||
| timeout: 5s | ||
| interval: 5s | ||
| retries: 10 | ||
|
|
||
| main-db-local: | ||
| image: postgres:16.1 | ||
| container_name: main_db_local | ||
| ports: | ||
| - "6543:5432" | ||
| environment: | ||
| - POSTGRES_DB=mainDB_local | ||
| - POSTGRES_USER=localuser | ||
| - POSTGRES_PASSWORD=localpass | ||
| healthcheck: | ||
| test: pg_isready -q -d $$POSTGRES_DB -U $$POSTGRES_USER | ||
| timeout: 5s | ||
| interval: 5s | ||
| retries: 10 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
main-service/src/main/java/ru/practicum/category/controller/AdminCategoryController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| package ru.practicum.category.controller; | ||
|
|
||
| import jakarta.validation.Valid; | ||
| import jakarta.validation.constraints.Positive; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.http.HttpStatus; | ||
| import org.springframework.web.bind.annotation.*; | ||
| import ru.practicum.category.dto.CategoryDto; | ||
| import ru.practicum.category.dto.NewCategoryDto; | ||
| import ru.practicum.category.service.CategoryService; | ||
|
|
||
| @Slf4j | ||
| @RestController | ||
| @RequestMapping("/admin/categories") | ||
| @RequiredArgsConstructor | ||
| public class AdminCategoryController { | ||
| private final CategoryService categoryService; | ||
|
|
||
| @PostMapping | ||
| @ResponseStatus(HttpStatus.CREATED) | ||
| public CategoryDto createCategory(@RequestBody @Valid NewCategoryDto newCategoryDto) { | ||
| log.debug("Controller: createCategory data {}", newCategoryDto); | ||
| return categoryService.createCategory(newCategoryDto); | ||
| } | ||
|
|
||
| @DeleteMapping("/{categoryId}") | ||
| @ResponseStatus(HttpStatus.NO_CONTENT) | ||
| public void deleteCategory(@PathVariable @Positive Long categoryId) { | ||
| log.debug("Controller: deleteCategory id={}", categoryId); | ||
| categoryService.deleteCategory(categoryId); | ||
| } | ||
|
|
||
| @PatchMapping("/{categoryId}") | ||
| public CategoryDto updateCategory(@PathVariable @Positive Long categoryId, | ||
| @RequestBody @Valid NewCategoryDto newCategoryDto) { | ||
| log.debug("Controller: updateCategory id={}, data={}", categoryId, newCategoryDto); | ||
| return categoryService.updateCategory(categoryId, newCategoryDto); | ||
| } | ||
| } |
37 changes: 37 additions & 0 deletions
37
main-service/src/main/java/ru/practicum/category/controller/PublicCategoryController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| package ru.practicum.category.controller; | ||
|
|
||
| import jakarta.validation.constraints.Positive; | ||
| import jakarta.validation.constraints.PositiveOrZero; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.data.domain.PageRequest; | ||
| import org.springframework.data.domain.Pageable; | ||
| import org.springframework.web.bind.annotation.*; | ||
| import ru.practicum.category.dto.CategoryDto; | ||
| import ru.practicum.category.service.CategoryService; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @Slf4j | ||
| @RestController | ||
| @RequestMapping("/categories") | ||
| @RequiredArgsConstructor | ||
| public class PublicCategoryController { | ||
| private final CategoryService categoryService; | ||
|
|
||
| @GetMapping | ||
| public List<CategoryDto> getCategories( | ||
| @RequestParam(defaultValue = "0") @PositiveOrZero Integer from, | ||
| @RequestParam(defaultValue = "10") @Positive Integer size) { | ||
| int page = from / size; | ||
| Pageable pageable = PageRequest.of(page, size); | ||
| log.debug("Controller: getCategories with from={}, size={}", from, size); | ||
| return categoryService.getCategories(pageable); | ||
| } | ||
|
|
||
| @GetMapping("/{categoryId}") | ||
| public CategoryDto getCategoryById(@PathVariable @Positive Long categoryId) { | ||
| log.debug("Controller: getCategoryById with id={}", categoryId); | ||
| return categoryService.getCategoryById(categoryId); | ||
| } | ||
| } |
13 changes: 13 additions & 0 deletions
13
main-service/src/main/java/ru/practicum/category/dto/CategoryDto.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package ru.practicum.category.dto; | ||
|
|
||
| import jakarta.validation.constraints.NotBlank; | ||
| import jakarta.validation.constraints.Size; | ||
|
|
||
| public record CategoryDto( | ||
| Long id, | ||
|
|
||
| @NotBlank(message = "Название категории не может быть пустым") | ||
| @Size(min = 1, max = 50, message = "Название категории должно содержать от {min} до {max} символов") | ||
| String name | ||
| ) { | ||
| } |
11 changes: 11 additions & 0 deletions
11
main-service/src/main/java/ru/practicum/category/dto/NewCategoryDto.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package ru.practicum.category.dto; | ||
|
|
||
| import jakarta.validation.constraints.NotBlank; | ||
| import jakarta.validation.constraints.Size; | ||
|
|
||
| public record NewCategoryDto( | ||
| @NotBlank(message = "Название категории не может быть пустым") | ||
| @Size(min = 1, max = 50, message = "Название категории должно содержать от {min} до {max} символов") | ||
| String name | ||
| ) { | ||
| } |
22 changes: 22 additions & 0 deletions
22
main-service/src/main/java/ru/practicum/category/mapper/CategoryMapper.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| package ru.practicum.category.mapper; | ||
|
|
||
| import org.mapstruct.Mapper; | ||
| import org.mapstruct.Mapping; | ||
| import org.mapstruct.MappingTarget; | ||
| import ru.practicum.category.dto.CategoryDto; | ||
| import ru.practicum.category.dto.NewCategoryDto; | ||
| import ru.practicum.category.model.Category; | ||
|
|
||
| @Mapper(componentModel = "spring") | ||
| public interface CategoryMapper { | ||
|
|
||
| @Mapping(target = "id", ignore = true) | ||
| Category toEntity(NewCategoryDto newCategoryDto); | ||
|
|
||
| CategoryDto toDto(Category category); | ||
|
|
||
| @Mapping(target = "id", ignore = true) | ||
| void updateCategoryFromDto(NewCategoryDto dto, @MappingTarget Category category); | ||
|
|
||
| Category toEntityFromDto(CategoryDto dto); | ||
| } |
23 changes: 23 additions & 0 deletions
23
main-service/src/main/java/ru/practicum/category/model/Category.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| package ru.practicum.category.model; | ||
|
|
||
| import jakarta.persistence.*; | ||
| import lombok.EqualsAndHashCode; | ||
| import lombok.Getter; | ||
| import lombok.Setter; | ||
| import lombok.ToString; | ||
|
|
||
| @Entity | ||
| @Table(name = "categories") | ||
| @Getter | ||
| @Setter | ||
| @ToString | ||
| @EqualsAndHashCode(onlyExplicitlyIncluded = true) | ||
| public class Category { | ||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| @EqualsAndHashCode.Include | ||
| private Long id; | ||
|
|
||
| @Column(name = "name", unique = true, nullable = false, length = 50) | ||
| private String name; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.