Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions .run/Deployment compose-local.run.xml

This file was deleted.

11 changes: 0 additions & 11 deletions .run/MainApplication (local).run.xml

This file was deleted.

10 changes: 0 additions & 10 deletions .run/MainApplication.run.xml

This file was deleted.

11 changes: 0 additions & 11 deletions .run/StatApplication (local).run.xml

This file was deleted.

11 changes: 0 additions & 11 deletions .run/StatApplication.run.xml

This file was deleted.

7 changes: 0 additions & 7 deletions core/comment-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,6 @@
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>ru.yandex.practicum</groupId>
<artifactId>stats-dto</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
Expand Down Expand Up @@ -95,7 +89,6 @@
<dependency>
<groupId>org.springframework.retry</groupId>
<artifactId>spring-retry</artifactId>
<version>2.0.5</version>
</dependency>

<dependency>
Expand Down
7 changes: 0 additions & 7 deletions core/event-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,6 @@
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>ru.yandex.practicum</groupId>
<artifactId>stats-dto</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
Expand Down Expand Up @@ -95,7 +89,6 @@
<dependency>
<groupId>org.springframework.retry</groupId>
<artifactId>spring-retry</artifactId>
<version>2.0.5</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.HttpStatus;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import ru.practicum.ewm.stats.proto.RecommendedEventProto;
import ru.yandex.practicum.dto.event.*;
import ru.yandex.practicum.service.EventService;

import java.util.List;
import java.util.stream.Stream;

@Slf4j
@Validated
Expand All @@ -34,8 +37,28 @@ public List<EventShortDto> getEventsPublic(@ModelAttribute @Valid SearchEventPub

@GetMapping("/{id}")
public EventFullDto getEventByIdPublic(@PathVariable("id") @Positive Long eventId,
HttpServletRequest httpRequest) {
HttpServletRequest httpRequest,
@RequestHeader("X-EWM-USER-ID") Long userId) {
log.debug("Controller: getEventByIdPublic eventId={}", eventId);
return eventService.getEventByIdPublic(eventId, httpRequest.getRemoteAddr());
return eventService.getEventByIdPublic(eventId, httpRequest.getRemoteAddr(), userId);
}

@GetMapping("/recommendations")
public Stream<RecommendedEventProto> getRecommendations(
@RequestHeader("X-EWM-USER-ID") Long userId,
@RequestParam(defaultValue = "10") int maxResults) {

log.debug("Controller: getRecommendations userId={}, maxResults={}", userId, maxResults);
return eventService.getRecommendationsForUser(userId, maxResults);
}

@PutMapping("/{eventId}/like")
@ResponseStatus(HttpStatus.OK)
public void likeEvent(
@PathVariable Long eventId,
@RequestHeader("X-EWM-USER-ID") Long userId) {

log.debug("Controller: likeEvent eventId={}, userId={}", eventId, userId);
eventService.likeEvent(userId, eventId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public interface EventMapper {
@Mapping(target = "createdOn", ignore = true)
@Mapping(target = "publishedOn", ignore = true)
@Mapping(target = "confirmedRequests", ignore = true)
@Mapping(target = "views", ignore = true)
@Mapping(target = "rating", ignore = true)
Event toEntity(NewEventDto dto, Long initiatorId, Category category);

@Mapping(target = "initiator", ignore = true)
Expand All @@ -32,7 +32,7 @@ public interface EventMapper {
@Mapping(target = "publishedOn", ignore = true)
@Mapping(target = "state", ignore = true)
@Mapping(target = "category", ignore = true)
@Mapping(target = "views", ignore = true)
@Mapping(target = "rating", ignore = true)
@Mapping(target = "confirmedRequests", ignore = true)
@BeanMapping(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE)
void updateEventFromUserRequest(UpdateEventUserRequest request, @MappingTarget Event event, Category category);
Expand All @@ -43,7 +43,7 @@ public interface EventMapper {
@Mapping(target = "createdOn", ignore = true)
@Mapping(target = "publishedOn", ignore = true)
@Mapping(target = "state", ignore = true)
@Mapping(target = "views", ignore = true)
@Mapping(target = "rating", ignore = true)
@Mapping(target = "confirmedRequests", ignore = true)
@BeanMapping(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE)
void updateEventFromAdminRequest(UpdateEventAdminRequest request, @MappingTarget Event event, Category category);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public class Event {
private Location location;

@Column(nullable = false)
@Builder.Default
private Boolean paid = false;

@Column(name = "participant_limit", nullable = false)
Expand All @@ -71,9 +72,9 @@ public class Event {
@Builder.Default
private Integer confirmedRequests = 0;

@Column(name = "views", nullable = false)
@Column(name = "rating", nullable = false)
@Builder.Default
private Long views = 0L;
private Double rating = 0.0;

public void pending() {
this.state = EventState.PENDING;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package ru.yandex.practicum.service;

import org.springframework.data.domain.Pageable;
import ru.practicum.ewm.stats.proto.RecommendedEventProto;
import ru.yandex.practicum.dto.event.*;
import ru.yandex.practicum.model.Event;

import java.util.List;
import java.util.stream.Stream;

public interface EventService {
List<EventShortDto> getEvents(Long userId, Pageable pageable);
Expand All @@ -23,5 +25,9 @@ public interface EventService {

List<EventShortDto> getEventsPublic(SearchEventPublicRequest requestParams, Pageable pageable, String ip);

EventFullDto getEventByIdPublic(Long eventId, String ip);
EventFullDto getEventByIdPublic(Long eventId, String ip, Long userId);

Stream<RecommendedEventProto> getRecommendationsForUser(Long userId, int maxResults);

void likeEvent(Long userId, Long eventId);
}
Loading