generated from yandex-praktikum/java-explore-with-me
-
Notifications
You must be signed in to change notification settings - Fork 0
main work #2
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
Merged
main work #2
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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,5 +1,3 @@ | ||
| FROM eclipse-temurin:21-jre-jammy | ||
| VOLUME /tmp | ||
| ARG JAR_FILE=target/*.jar | ||
| COPY ${JAR_FILE} app.jar | ||
| ENTRYPOINT ["sh", "-c", "java ${JAVA_OPTS} -jar /app.jar"] | ||
| COPY ./target/*.jar main-service.jar | ||
| ENTRYPOINT ["java","-jar","/main-service.jar"] |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| package ewm; | ||
|
|
||
| import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer; | ||
| import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer; | ||
| import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer; | ||
| import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer; | ||
| import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
|
|
||
| import java.time.format.DateTimeFormatter; | ||
|
|
||
| @Configuration | ||
| public class DateFormatConfig { | ||
|
|
||
| @Bean | ||
| public Jackson2ObjectMapperBuilderCustomizer jackson2ObjectMapperBuilderCustomizer() { | ||
|
|
||
| return builder -> { | ||
|
|
||
| // formatter | ||
| DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); | ||
| DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); | ||
|
|
||
| // deserializers | ||
| builder.deserializers(new LocalDateDeserializer(dateFormatter)); | ||
| builder.deserializers(new LocalDateTimeDeserializer(dateTimeFormatter)); | ||
|
|
||
| // serializers | ||
| builder.serializers(new LocalDateSerializer(dateFormatter)); | ||
| builder.serializers(new LocalDateTimeSerializer(dateTimeFormatter)); | ||
| }; | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package ewm.categories; | ||
|
|
||
| import jakarta.persistence.*; | ||
| import lombok.*; | ||
|
|
||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
| @Builder | ||
| @Getter | ||
| @Setter | ||
| @ToString | ||
| @Entity | ||
| @Table(name = "categories") | ||
| public class Category { | ||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| private long id; | ||
|
|
||
| @Column(nullable = false, unique = true) | ||
| private String name; | ||
| } |
24 changes: 24 additions & 0 deletions
24
main-service/src/main/java/ewm/categories/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,24 @@ | ||
| package ewm.categories; | ||
|
|
||
| import ewm.categories.dto.CategoryCreateDto; | ||
| import ewm.categories.dto.CategoryDto; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| @Component | ||
| public class CategoryMapper { | ||
|
|
||
| public Category categoryCreateDtoToModel(CategoryCreateDto dto) { | ||
| return Category.builder() | ||
| .name(dto.getName()) | ||
| .build(); | ||
| } | ||
|
|
||
| public CategoryDto modelToDto(Category category) { | ||
| return CategoryDto.builder() | ||
| .id(category.getId()) | ||
| .name(category.getName()) | ||
| .build(); | ||
| } | ||
|
|
||
|
|
||
| } |
6 changes: 6 additions & 0 deletions
6
main-service/src/main/java/ewm/categories/CategoryRepository.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,6 @@ | ||
| package ewm.categories; | ||
|
|
||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| public interface CategoryRepository extends JpaRepository<Category, Long> { | ||
| } |
37 changes: 37 additions & 0 deletions
37
main-service/src/main/java/ewm/categories/controller/CategoriesAdminController.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 ewm.categories.controller; | ||
|
|
||
| import ewm.categories.dto.CategoryCreateDto; | ||
| import ewm.categories.dto.CategoryDto; | ||
| import ewm.categories.service.CategoryService; | ||
| import jakarta.validation.Valid; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.http.HttpStatus; | ||
| import org.springframework.validation.annotation.Validated; | ||
| import org.springframework.web.bind.annotation.*; | ||
|
|
||
| @Validated | ||
| @RestController | ||
| @RequiredArgsConstructor | ||
| @RequestMapping("/admin/categories") | ||
| public class CategoriesAdminController { | ||
| private final CategoryService service; | ||
|
|
||
| @PostMapping | ||
| @ResponseStatus(value = HttpStatus.CREATED) | ||
| public CategoryDto create(@RequestBody @Valid CategoryCreateDto createDto) { | ||
| return service.create(createDto); | ||
| } | ||
|
|
||
| @PatchMapping("/{catId}") | ||
| public CategoryDto update(@PathVariable Long catId, | ||
| @RequestBody @Valid CategoryCreateDto createDto) { | ||
| return service.update(catId, createDto); | ||
| } | ||
|
|
||
| @DeleteMapping("/{catId}") | ||
| @ResponseStatus(value = HttpStatus.NO_CONTENT) | ||
| public void deleteById(@PathVariable Long catId) { | ||
| service.deleteById(catId); | ||
| } | ||
|
|
||
| } |
30 changes: 30 additions & 0 deletions
30
main-service/src/main/java/ewm/categories/controller/CategoriesPublicController.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,30 @@ | ||
| package ewm.categories.controller; | ||
|
|
||
| import ewm.categories.dto.CategoryDto; | ||
| import ewm.categories.service.CategoryService; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.validation.annotation.Validated; | ||
| import org.springframework.web.bind.annotation.*; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @Validated | ||
| @RestController | ||
| @RequiredArgsConstructor | ||
| @RequestMapping("/categories") | ||
| public class CategoriesPublicController { | ||
| private final CategoryService service; | ||
|
|
||
| @GetMapping | ||
| public List<CategoryDto> getCategories( | ||
| @RequestParam(value = "from", defaultValue = "0") Integer from, | ||
| @RequestParam(value = "size", defaultValue = "10") Integer size) { | ||
| return service.getCategories(from, size); | ||
| } | ||
|
|
||
| @GetMapping("/{catId}") | ||
| public CategoryDto getById(@PathVariable Long catId) { | ||
| return service.getById(catId); | ||
| } | ||
|
|
||
| } |
14 changes: 14 additions & 0 deletions
14
main-service/src/main/java/ewm/categories/dto/CategoryCreateDto.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,14 @@ | ||
| package ewm.categories.dto; | ||
|
|
||
| import jakarta.validation.constraints.NotBlank; | ||
| import jakarta.validation.constraints.NotNull; | ||
| import jakarta.validation.constraints.Size; | ||
| import lombok.Data; | ||
|
|
||
| @Data | ||
| public class CategoryCreateDto { | ||
| @NotNull | ||
| @NotBlank | ||
| @Size(min = 1, max = 50) | ||
| private String name; | ||
| } |
15 changes: 15 additions & 0 deletions
15
main-service/src/main/java/ewm/categories/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,15 @@ | ||
| package ewm.categories.dto; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import lombok.Data; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @AllArgsConstructor | ||
| @NoArgsConstructor | ||
| @Data | ||
| @Builder | ||
| public class CategoryDto { | ||
| private long id; | ||
| private String name; | ||
| } |
21 changes: 21 additions & 0 deletions
21
main-service/src/main/java/ewm/categories/service/CategoryService.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,21 @@ | ||
| package ewm.categories.service; | ||
|
|
||
| import ewm.categories.Category; | ||
| import ewm.categories.dto.CategoryCreateDto; | ||
| import ewm.categories.dto.CategoryDto; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public interface CategoryService { | ||
| CategoryDto create(CategoryCreateDto createDto); | ||
|
|
||
| CategoryDto update(long categoryId, CategoryCreateDto createDto); | ||
|
|
||
| void deleteById(long categoryId); | ||
|
|
||
| List<CategoryDto> getCategories(Integer from, Integer size); | ||
|
|
||
| CategoryDto getById(long categoryId); | ||
|
|
||
| Category checkAndReturnCategory(long id); | ||
| } |
62 changes: 62 additions & 0 deletions
62
main-service/src/main/java/ewm/categories/service/CategoryServiceImpl.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,62 @@ | ||
| package ewm.categories.service; | ||
|
|
||
| import ewm.categories.Category; | ||
| import ewm.categories.CategoryMapper; | ||
| import ewm.categories.CategoryRepository; | ||
| import ewm.categories.dto.CategoryCreateDto; | ||
| import ewm.categories.dto.CategoryDto; | ||
| import ewm.exception.NotFoundException; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.data.domain.PageRequest; | ||
| import org.springframework.data.domain.Pageable; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @Transactional | ||
| @Service | ||
| @RequiredArgsConstructor | ||
| public class CategoryServiceImpl implements CategoryService { | ||
| private final CategoryRepository repository; | ||
| private final CategoryMapper mapper; | ||
|
|
||
| @Override | ||
| public CategoryDto create(CategoryCreateDto createDto) { | ||
| Category category = mapper.categoryCreateDtoToModel(createDto); | ||
| return mapper.modelToDto(repository.save(category)); | ||
| } | ||
|
|
||
| @Override | ||
| public CategoryDto update(long categoryId, CategoryCreateDto createDto) { | ||
| Category savedCategory = checkAndReturnCategory(categoryId); | ||
| savedCategory.setName(createDto.getName()); | ||
| return mapper.modelToDto(repository.save(savedCategory)); | ||
| } | ||
|
|
||
| @Override | ||
| public void deleteById(long categoryId) { | ||
| checkAndReturnCategory(categoryId); | ||
| repository.deleteById(categoryId); | ||
| } | ||
|
|
||
| @Override | ||
| @Transactional(readOnly = true) | ||
| public List<CategoryDto> getCategories(Integer from, Integer size) { | ||
| Pageable pageable = PageRequest.of(from / size, size); | ||
| return repository.findAll(pageable).map(mapper::modelToDto).toList(); | ||
| } | ||
|
|
||
| @Override | ||
| @Transactional(readOnly = true) | ||
| public CategoryDto getById(long categoryId) { | ||
| Category category = checkAndReturnCategory(categoryId); | ||
| return mapper.modelToDto(category); | ||
| } | ||
|
|
||
| public Category checkAndReturnCategory(long id) { | ||
| return repository.findById(id).orElseThrow(() -> | ||
| new NotFoundException("Category with id=" + id + " was not found")); | ||
| } | ||
|
|
||
| } | ||
39 changes: 39 additions & 0 deletions
39
main-service/src/main/java/ewm/compilations/Compilation.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,39 @@ | ||
| package ewm.compilations; | ||
|
|
||
| import ewm.events.Event; | ||
| import jakarta.persistence.*; | ||
| import lombok.*; | ||
|
|
||
| import java.util.Set; | ||
|
|
||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
| @Builder | ||
| @Getter | ||
| @Setter | ||
| @ToString | ||
| @Entity | ||
| @Table(name = "compilations") | ||
| public class Compilation { | ||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| private long id; | ||
|
|
||
| @Column(name = "title", nullable = false) | ||
| private String title; | ||
|
|
||
| @Column(name = "pinned", nullable = false) | ||
| private Boolean pinned; | ||
|
|
||
| @ManyToMany | ||
| @JoinTable(name = "compilation_event", | ||
| joinColumns = @JoinColumn(name = "compilation_id"), | ||
| inverseJoinColumns = @JoinColumn(name = "event_id")) | ||
| private Set<Event> events; | ||
|
|
||
| public Compilation(String title, Boolean pinned) { | ||
| this.title = title; | ||
| this.pinned = pinned; | ||
| } | ||
|
|
||
| } |
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.