-
Notifications
You must be signed in to change notification settings - Fork 0
Main svc events #9
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
Changes from all commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
9cffcc0
feat: add jpa eventRepo
LightInTheFire 2bba240
feat: add EventMapper
LightInTheFire c3c5595
feat: add Event sort options enum
LightInTheFire d35a389
feat: add event requests for services
LightInTheFire 78c81a4
feat: add event controllers
LightInTheFire bfbb961
feat: add eventService and implementation
LightInTheFire 26ce235
feat: add querydsl
LightInTheFire 562d77a
fix: add logging to public controller
LightInTheFire 1c18b61
fix: add logging to admin controller
LightInTheFire f29732a
feat: update event private controller
LightInTheFire 1c9e128
feat: add EventsPrivateGetRequest
LightInTheFire 0e95767
feat: add methods to event service interface
LightInTheFire 16ef3ed
feat: add validation exception
LightInTheFire 0efb5ff
feat: add location mapper
LightInTheFire 52ff7fe
fix: increase limit in event model
LightInTheFire 5dca3fa
fix: update querydsl
LightInTheFire 0c91cc6
feat: add constraint to newEventDto eventdate to be in future
LightInTheFire 5b6d828
feat: separate state actions to two enums
LightInTheFire 61a2340
feat: add updatableevent interface and mapper methods
LightInTheFire 7e695b8
fix: method names
LightInTheFire b64669e
feat: add datetime properties, correct LDT requestparam mapping and c…
LightInTheFire fd3d167
feat: add boolean predicate as static methods
LightInTheFire dc0b62e
chore: move methods
LightInTheFire 03aa2d9
feat: add IllegalEventUpdateException
LightInTheFire 3f95437
fix: typo in Enum
LightInTheFire db07b1a
feat: add check to eventstate
LightInTheFire cccadff
feat: add httprequest param
LightInTheFire 8f1374b
feat: add @Future constraint
LightInTheFire b2b0711
feat: implement interface methods
LightInTheFire ebfb955
feat: update tests to containt events
LightInTheFire 8db8049
feat: add client method to accept ip and uri strings
LightInTheFire f553d4f
fix: send actual uri to service
LightInTheFire 4d87b98
fix: change transactional to readonly
LightInTheFire c7d5623
feat: add sql params logging
LightInTheFire 525a482
fix: update pagerequest to work correctly
LightInTheFire bdfbe31
feat: add ForbiddenAccessException
LightInTheFire d72064d
fix: add check to private api methods
LightInTheFire 7f5312b
fix: add call to parent constructor in FAE
LightInTheFire 3e4a447
Revert "feat: add client method to accept ip and uri strings"
LightInTheFire 10e0c8f
feat: update stats server tests
LightInTheFire 0adbb62
fix: save /events endpoint when request multiple events and send null…
LightInTheFire 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
13 changes: 13 additions & 0 deletions
13
main-service/src/main/java/ru/practicum/config/DateTimeProperties.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.config; | ||
|
|
||
| import org.springframework.boot.context.properties.ConfigurationProperties; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| import lombok.Getter; | ||
| import lombok.Setter; | ||
|
|
||
| @Component | ||
| @ConfigurationProperties(prefix = "app") | ||
| public class DateTimeProperties { | ||
| @Getter @Setter private String dateTimeFormat = "yyyy-MM-dd HH:mm:ss"; | ||
| } |
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
38 changes: 38 additions & 0 deletions
38
main-service/src/main/java/ru/practicum/config/WebConfig.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,38 @@ | ||
| package ru.practicum.config; | ||
|
|
||
| import java.text.ParseException; | ||
| import java.time.LocalDateTime; | ||
| import java.time.format.DateTimeFormatter; | ||
| import java.util.Locale; | ||
|
|
||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.format.Formatter; | ||
| import org.springframework.format.FormatterRegistry; | ||
| import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @Configuration | ||
| @RequiredArgsConstructor | ||
| public class WebConfig implements WebMvcConfigurer { | ||
| private final DateTimeProperties properties; | ||
|
|
||
| @Override | ||
| public void addFormatters(FormatterRegistry registry) { | ||
| registry.addFormatter( | ||
| new Formatter<LocalDateTime>() { | ||
|
|
||
| @Override | ||
| public String print(LocalDateTime object, Locale locale) { | ||
| return object.format( | ||
| DateTimeFormatter.ofPattern(properties.getDateTimeFormat())); | ||
| } | ||
|
|
||
| @Override | ||
| public LocalDateTime parse(String text, Locale locale) throws ParseException { | ||
| return LocalDateTime.parse( | ||
| text, DateTimeFormatter.ofPattern(properties.getDateTimeFormat())); | ||
| } | ||
| }); | ||
| } | ||
| } |
49 changes: 49 additions & 0 deletions
49
main-service/src/main/java/ru/practicum/event/controller/EventAdminController.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,49 @@ | ||
| package ru.practicum.event.controller; | ||
|
|
||
| import java.time.LocalDateTime; | ||
| import java.util.Collection; | ||
| import java.util.List; | ||
|
|
||
| import jakarta.validation.Valid; | ||
|
|
||
| import ru.practicum.event.dto.EventFullDto; | ||
| import ru.practicum.event.dto.UpdateEventAdminRequest; | ||
| import ru.practicum.event.model.EventState; | ||
| import ru.practicum.event.service.EventService; | ||
| import ru.practicum.event.service.EventsAdminGetRequest; | ||
|
|
||
| import org.springframework.web.bind.annotation.*; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
|
|
||
| @Slf4j | ||
| @RestController | ||
| @RequiredArgsConstructor | ||
| @RequestMapping("/admin/events") | ||
| public class EventAdminController { | ||
| private final EventService eventService; | ||
|
|
||
| @GetMapping | ||
| public Collection<EventFullDto> getEventsFiltered( | ||
| @RequestParam(required = false) List<Long> users, | ||
| @RequestParam(required = false) List<EventState> states, | ||
| @RequestParam(required = false) List<Long> categories, | ||
| @RequestParam(required = false) LocalDateTime rangeStart, | ||
| @RequestParam(required = false) LocalDateTime rangeEnd, | ||
| @RequestParam(defaultValue = "0") int from, | ||
| @RequestParam(defaultValue = "10") int size) { | ||
| EventsAdminGetRequest getRequest = | ||
| new EventsAdminGetRequest( | ||
| users, states, categories, rangeStart, rangeEnd, from, size); | ||
| log.info("Admin get events requested with params= {}", getRequest); | ||
| return eventService.getEvents(getRequest); | ||
| } | ||
|
|
||
| @PatchMapping("/{eventId}") | ||
| public EventFullDto updateEvent( | ||
| @PathVariable Long eventId, @RequestBody @Valid UpdateEventAdminRequest updateRequest) { | ||
| log.info("Admin update event requested with body= {}", updateRequest); | ||
| return eventService.updateEvent(eventId, updateRequest); | ||
| } | ||
| } |
63 changes: 63 additions & 0 deletions
63
main-service/src/main/java/ru/practicum/event/controller/EventPrivateController.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,63 @@ | ||
| package ru.practicum.event.controller; | ||
|
|
||
| import java.util.Collection; | ||
|
|
||
| import jakarta.validation.Valid; | ||
|
|
||
| import ru.practicum.event.dto.EventFullDto; | ||
| import ru.practicum.event.dto.EventShortDto; | ||
| import ru.practicum.event.dto.NewEventDto; | ||
| import ru.practicum.event.dto.UpdateEventUserRequest; | ||
| import ru.practicum.event.service.EventService; | ||
| import ru.practicum.event.service.EventsPrivateGetRequest; | ||
|
|
||
| import org.springframework.http.HttpStatus; | ||
| import org.springframework.web.bind.annotation.*; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
|
|
||
| @Slf4j | ||
| @RestController | ||
| @RequiredArgsConstructor | ||
| @RequestMapping("/users/{userId}/events") | ||
| public class EventPrivateController { | ||
| private final EventService eventService; | ||
|
|
||
| @GetMapping() | ||
| public Collection<EventShortDto> getEventsOfUserPaged( | ||
| @PathVariable Long userId, | ||
| @RequestParam(defaultValue = "0") int from, | ||
| @RequestParam(defaultValue = "10") int size) { | ||
| EventsPrivateGetRequest getRequest = new EventsPrivateGetRequest(userId, from, size); | ||
| log.info("Private get events requested with params= {}", getRequest); | ||
| return eventService.getEvents(getRequest); | ||
| } | ||
|
|
||
| @PostMapping() | ||
| @ResponseStatus(HttpStatus.CREATED) | ||
| public EventFullDto createEvent( | ||
| @PathVariable Long userId, @RequestBody @Valid NewEventDto newEventDto) { | ||
| log.info("Create event requested with body= {}", newEventDto); | ||
| return eventService.createEvent(userId, newEventDto); | ||
| } | ||
|
|
||
| @GetMapping("/{eventId}") | ||
| public EventFullDto getEvent(@PathVariable Long userId, @PathVariable Long eventId) { | ||
| log.info("Private get event requested with userId= {}, eventId= {}", userId, eventId); | ||
| return eventService.getByUserById(userId, eventId); | ||
| } | ||
|
|
||
| @PatchMapping("/{eventId}") | ||
| public EventFullDto updateEvent( | ||
| @PathVariable Long userId, | ||
| @PathVariable Long eventId, | ||
| @RequestBody @Valid UpdateEventUserRequest updateRequest) { | ||
| log.info( | ||
| "Private update event requested with userId= {}, eventId= {}, body = {}", | ||
| userId, | ||
| eventId, | ||
| updateRequest); | ||
| return eventService.updateEventByUser(userId, eventId, updateRequest); | ||
| } | ||
| } |
65 changes: 65 additions & 0 deletions
65
main-service/src/main/java/ru/practicum/event/controller/EventPublicController.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,65 @@ | ||
| package ru.practicum.event.controller; | ||
|
|
||
| import java.time.LocalDateTime; | ||
| import java.util.Collection; | ||
| import java.util.List; | ||
|
|
||
| import jakarta.servlet.http.HttpServletRequest; | ||
|
|
||
| import ru.practicum.event.dto.EventFullDto; | ||
| import ru.practicum.event.dto.EventShortDto; | ||
| import ru.practicum.event.service.EventService; | ||
| import ru.practicum.event.service.EventsPublicGetRequest; | ||
| import ru.practicum.exception.ValidationException; | ||
|
|
||
| import org.springframework.web.bind.annotation.*; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
|
|
||
| @Slf4j | ||
| @RestController | ||
| @RequiredArgsConstructor | ||
| @RequestMapping("/events") | ||
| public class EventPublicController { | ||
| private final EventService eventService; | ||
|
|
||
| @GetMapping() | ||
| public Collection<EventShortDto> getEventsFiltered( | ||
| @RequestParam(required = false) String text, | ||
| @RequestParam(required = false) List<Long> categories, | ||
| @RequestParam(required = false) Boolean paid, | ||
| @RequestParam(required = false) LocalDateTime rangeStart, | ||
| @RequestParam(required = false) LocalDateTime rangeEnd, | ||
| @RequestParam(defaultValue = "false") boolean onlyAvailable, | ||
| @RequestParam(required = false) EventSortBy sort, | ||
| @RequestParam(defaultValue = "0") int from, | ||
| @RequestParam(defaultValue = "10") int size, | ||
| HttpServletRequest request) { | ||
| EventsPublicGetRequest getRequest = | ||
| new EventsPublicGetRequest( | ||
| text, | ||
| categories, | ||
| paid, | ||
| rangeStart, | ||
| rangeEnd, | ||
| onlyAvailable, | ||
| sort, | ||
| from, | ||
| size, | ||
| request); | ||
| if (getRequest.hasRangeStart() && getRequest.hasRangeEnd()) { | ||
| if (getRequest.rangeEnd().isBefore(getRequest.rangeStart())) { | ||
| throw new ValidationException("End date must be before start date"); | ||
| } | ||
| } | ||
| log.info("Public get events requested with params= {}", getRequest); | ||
| return eventService.getEvents(getRequest); | ||
| } | ||
|
|
||
| @GetMapping("/{eventId}") | ||
| public EventFullDto getEventById(@PathVariable Long eventId, HttpServletRequest request) { | ||
| log.info("Public get event with eventId={} requested", eventId); | ||
| return eventService.getById(eventId, request); | ||
| } | ||
| } | ||
6 changes: 6 additions & 0 deletions
6
main-service/src/main/java/ru/practicum/event/controller/EventSortBy.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 ru.practicum.event.controller; | ||
|
|
||
| public enum EventSortBy { | ||
| EVENT_DATE, | ||
| VIEWS | ||
| } |
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
39 changes: 39 additions & 0 deletions
39
main-service/src/main/java/ru/practicum/event/dto/UpdatableEvent.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 ru.practicum.event.dto; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| public interface UpdatableEvent { | ||
| boolean hasAnnotation(); | ||
|
|
||
| String annotation(); | ||
|
|
||
| boolean hasEventDate(); | ||
|
|
||
| LocalDateTime eventDate(); | ||
|
|
||
| boolean hasCategory(); | ||
|
|
||
| boolean hasLocation(); | ||
|
|
||
| LocationDto location(); | ||
|
|
||
| boolean hasParticipantLimit(); | ||
|
|
||
| Integer participantLimit(); | ||
|
|
||
| boolean hasPaid(); | ||
|
|
||
| Boolean paid(); | ||
|
|
||
| boolean hasRequestModeration(); | ||
|
|
||
| Boolean requestModeration(); | ||
|
|
||
| boolean hasTitle(); | ||
|
|
||
| String title(); | ||
|
|
||
| boolean hasDescription(); | ||
|
|
||
| String description(); | ||
| } |
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
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.