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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@ target/
!**/src/main/**/target/
!**/src/test/**/target/

tester-0.0.1.jar
/tester.bat
tester.txt

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
/execution-report.txt
26 changes: 13 additions & 13 deletions API-event-service-specification.json
Original file line number Diff line number Diff line change
Expand Up @@ -1571,7 +1571,7 @@
},
"paid": true,
"title": "Знаменитое шоу 'Летающая кукуруза'",
"views": 999
"rating": 6.6
},
{
"annotation": "За почти три десятилетия группа 'Java Core' закрепились на сцене как группа, объединяющая поколения.",
Expand All @@ -1588,7 +1588,7 @@
},
"paid": true,
"title": "Концерт рок-группы 'Java Core'",
"views": 991
"rating": 3.7
}
],
"items": {
Expand Down Expand Up @@ -1705,11 +1705,11 @@
"description": "Заголовок",
"example": "Знаменитое шоу 'Летающая кукуруза'"
},
"views": {
"type": "integer",
"description": "Количество просмотрев события",
"format": "int64",
"example": 999
"rating": {
"type": "number",
"description": "Рейтинг события",
"format": "float8",
"example": 4.8
}
}
},
Expand Down Expand Up @@ -1762,11 +1762,11 @@
"description": "Заголовок",
"example": "Знаменитое шоу 'Летающая кукуруза'"
},
"views": {
"type": "integer",
"rating": {
"type": "number",
"description": "Количество просмотрев события",
"format": "int64",
"example": 999
"format": "float8",
"example": 5.4
}
},
"description": "Краткая информация о событии",
Expand All @@ -1786,7 +1786,7 @@
},
"paid": true,
"title": "Знаменитое шоу 'Летающая кукуруза'",
"views": 999
"rating": 9.8
},
{
"annotation": "За почти три десятилетия группа 'Java Core' закрепились на сцене как группа, объединяющая поколения.",
Expand All @@ -1803,7 +1803,7 @@
},
"paid": true,
"title": "Концерт рок-группы 'Java Core'",
"views": 991
"rating": 6.8
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ public static void main(String[] args) {
SpringApplication.run(CommentServiceApplication.class, args);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

@FeignClient(name = "user-service")
public interface UserClient extends UserApi {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,4 @@ public CommentDto getCommentByEventAndCommentId(Long eventId, Long comId) {

return CommentMapper.toCommentDto(comment, userDto, eventCommentDto);
}

}
2 changes: 1 addition & 1 deletion core/comment-service/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ eureka:
instance:
instance-id: ${spring.application.name}${random.int}
preferIpAddress: false
hostname: localhost
hostname: localhost
2 changes: 1 addition & 1 deletion core/comment-service/src/main/resources/schema.sql
Original file line number Diff line number Diff line change
@@ -1 +1 @@
CREATE SCHEMA IF NOT EXISTS comment_service;
CREATE SCHEMA IF NOT EXISTS comment_service;
53 changes: 0 additions & 53 deletions core/core-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@

<dependencies>

<!-- INTERNAL DEPS -->

<!-- <dependency>-->
<!-- <groupId>ru.practicum</groupId>-->
<!-- <artifactId>stats-client</artifactId>-->
<!-- </dependency>-->

<!-- SYSTEM TOOL DEPS -->

<dependency>
Expand All @@ -34,11 +27,6 @@
<artifactId>lombok</artifactId>
</dependency>

<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-actuator</artifactId>-->
<!-- </dependency>-->

<!-- REST DEPS -->

<dependency>
Expand All @@ -57,24 +45,6 @@
<version>2.0.1.Final</version>
</dependency>

<!-- DATABASE DEPS -->

<!-- <dependency>-->
<!-- <groupId>org.postgresql</groupId>-->
<!-- <artifactId>postgresql</artifactId>-->
<!-- </dependency>-->

<!-- <dependency>-->
<!-- <groupId>com.h2database</groupId>-->
<!-- <artifactId>h2</artifactId>-->
<!-- <scope>test</scope>-->
<!-- </dependency>-->

<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-data-jpa</artifactId>-->
<!-- </dependency>-->

<!-- FEIGN DEPS -->

<dependency>
Expand All @@ -87,29 +57,6 @@
<artifactId>spring-cloud-starter-circuitbreaker-resilience4j</artifactId>
</dependency>

<!-- <dependency>-->
<!-- <groupId>org.springframework.cloud</groupId>-->
<!-- <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>-->
<!-- </dependency>-->

<!-- <dependency>-->
<!-- <groupId>org.springframework.cloud</groupId>-->
<!-- <artifactId>spring-cloud-starter-config</artifactId>-->
<!-- </dependency>-->

<!-- <dependency>-->
<!-- <groupId>org.springframework.retry</groupId>-->
<!-- <artifactId>spring-retry</artifactId>-->
<!-- </dependency>-->

<!-- TEST DEPS -->

<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-test</artifactId>-->
<!-- <scope>test</scope>-->
<!-- </dependency>-->

</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ CompilationDto getCompilationById(
@PathVariable Long compId
);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ EventFullDto updateEventByAdmin(
@RequestBody @Valid UpdateEventDto updateEventDto
);

}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ru.practicum.api.event;

public interface EventAllApi extends EventPublicApi, EventPrivateApi, EventAdminApi {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ EventFullDto updateEventByUserIdAndEventId(
@Valid @RequestBody UpdateEventDto updateEventDto
);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,32 +30,48 @@ List<EventShortDto> getAllEventsByParams(
);

// Получение подробной информации об опубликованном событии по его идентификатору
@GetMapping("/events/{id}")
@GetMapping("/events/{eventId}")
@ResponseStatus(HttpStatus.OK)
EventFullDto getInformationAboutEventByEventId(
@PathVariable @Positive Long id,
@RequestHeader("X-EWM-USER-ID") @Positive Long userId,
@PathVariable @Positive Long eventId,
HttpServletRequest request
);

// Получение информации о событии для сервиса комментариев
@GetMapping("/events/{id}/dto/comment")
@GetMapping("/events/{eventId}/dto/comment")
@ResponseStatus(HttpStatus.OK)
EventCommentDto getEventCommentDto(
@PathVariable @Positive Long id
@PathVariable @Positive Long eventId
);

// Получение информации о списке событий для сервиса комментариев
@PostMapping("/events/dto/list/comment")
@ResponseStatus(HttpStatus.OK)
Collection<EventCommentDto> getEventCommentDtoList(
@RequestBody Collection<Long> ids
@RequestBody Collection<Long> eventIds
);

// Получение информации о событии для сервиса заявок
@GetMapping("/events/{id}/dto/interaction")
@GetMapping("/events/{eventId}/dto/interaction")
@ResponseStatus(HttpStatus.OK)
EventInteractionDto getEventInteractionDto(
@PathVariable @Positive Long id
@PathVariable @Positive Long eventId
);

// рекомендации мероприятий для пользователя
@GetMapping("/events/recommendations")
@ResponseStatus(HttpStatus.OK)
Collection<EventShortDto> getRecommendations(
@RequestHeader("X-EWM-USER-ID") @Positive Long userId,
@RequestParam(defaultValue = "10") Integer size
);

@PutMapping("/events/{eventId}/like")
@ResponseStatus(HttpStatus.OK)
String sendLike(
@RequestHeader("X-EWM-USER-ID") @Positive Long userId,
@PathVariable @Positive Long eventId
);

}
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,12 @@ Map<Long, Long> getConfirmedRequestsByEventIds(
@RequestBody Collection<Long> eventIds
);

// Проверка участия пользователя в конкретном событии перед лайком
@GetMapping("/users/{userId}/events/{eventId}/check/participation")
@ResponseStatus(HttpStatus.OK)
String checkParticipation(
@PathVariable @Positive(message = "User Id not valid") Long userId,
@PathVariable @Positive(message = "Event Id not valid") Long eventId
);

}
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,4 @@ private boolean isNotFoundCode(RuntimeException e) {
return false;
}

}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package ru.practicum.client;

import feign.FeignException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import ru.practicum.api.request.RequestApi;
import ru.practicum.exception.ServiceInteractionException;

import java.util.Collection;
import java.util.Map;
Expand All @@ -24,4 +26,25 @@ public Map<Long, Long> retrieveConfirmedRequestsMapByEventIdList(Collection<Long
}
}

// Participation Check

public boolean passedParticipationCheck(Long userId, Long eventId) {
try {
requestApiClient.checkParticipation(userId, eventId);
return true;
} catch (RuntimeException e) {
if (isNotFoundCode(e)) return false;
log.warn("Service Interaction Error: caught " + e.getClass().getSimpleName() + " - " + e.getMessage());
throw new ServiceInteractionException("Unable to confirm participation of user " + userId + " in event " + eventId);
}
}

// PRIVATE METHODS

private boolean isNotFoundCode(RuntimeException e) {
if (e instanceof FeignException.NotFound) return true;
if (e.getCause() != null && e.getCause() instanceof FeignException.NotFound) return true;
return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ public class EventAdminParams {

private Integer size;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ public static EventCommentDto makeDummy(Long id) {
return dto;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public class EventFullDto {
private LocalDateTime createdOn;

private Long confirmedRequests;
private Long views;
private Double rating;

private List<CommentShortDto> comments;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@ public static EventInteractionDto makeDummy(Long id) {
return dto;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ public class EventParams {

private Integer size;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ public class EventRequestStatusUpdateRequest {

private State state;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ public class EventRequestStatusUpdateResult {

private List<ParticipationRequestDto> rejectedRequests;

}
}
Loading