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
Binary file modified db/shareit.mv.db
Binary file not shown.
42 changes: 42 additions & 0 deletions db/shareit.trace.db
Original file line number Diff line number Diff line change
Expand Up @@ -344,3 +344,45 @@ java.sql.SQLClientInfoException: Client info name 'ApplicationName' not supporte
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at java.base/java.lang.Thread.run(Thread.java:833)
2023-01-22 08:51:38 jdbc[3]: exception
java.sql.SQLClientInfoException: Client info name 'ApplicationName' not supported.
at org.h2.jdbc.JdbcConnection.setClientInfo(JdbcConnection.java:1573)
at com.intellij.database.remote.jdbc.impl.RemoteConnectionImpl.setClientInfo(RemoteConnectionImpl.java:470)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:360)
at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:200)
at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:197)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:712)
at java.rmi/sun.rmi.transport.Transport.serviceCall(Transport.java:196)
at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:587)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:828)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:705)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:704)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at java.base/java.lang.Thread.run(Thread.java:833)
2023-01-22 08:51:57 jdbc[3]: exception
java.sql.SQLClientInfoException: Client info name 'ApplicationName' not supported.
at org.h2.jdbc.JdbcConnection.setClientInfo(JdbcConnection.java:1573)
at com.intellij.database.remote.jdbc.impl.RemoteConnectionImpl.setClientInfo(RemoteConnectionImpl.java:470)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:360)
at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:200)
at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:197)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:712)
at java.rmi/sun.rmi.transport.Transport.serviceCall(Transport.java:196)
at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:587)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:828)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:705)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:704)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at java.base/java.lang.Thread.run(Thread.java:833)
21 changes: 15 additions & 6 deletions src/main/java/ru/practicum/shareit/booking/BookingController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import ru.practicum.shareit.pageValidator.PageValidator;

import javax.validation.Valid;
import java.util.List;
Expand All @@ -26,22 +27,30 @@ public BookingResponseDto approveBooking(@RequestHeader("X-Sharer-User-Id") Long
}

@GetMapping("/{bookingId}")
public BookingResponseDto getBooking(@RequestHeader("X-Sharer-User-Id") Long userId,
@PathVariable Long bookingId) {
public BookingResponseDto getBookingById(@RequestHeader("X-Sharer-User-Id") Long userId,
@PathVariable Long bookingId) {
return bookingService.getById(userId, bookingId);
}

@GetMapping
public List<BookingResponseDto> getAllUserBookings(@RequestHeader("X-Sharer-User-Id") Long userId,
@RequestParam(name = "state",
defaultValue = "ALL") String state) {
return bookingService.getAllUserBookings(userId, state);
defaultValue = "ALL") String state,
@RequestParam(name = "from",
defaultValue = "0") Integer from,
@RequestParam(name = "size",
defaultValue = "10") Integer size) {
return bookingService.getAllUserBookings(userId, state, PageValidator.validatePage(from, size));
}

@GetMapping("/owner")
public List<BookingResponseDto> getAllUserItemsBookings(@RequestHeader("X-Sharer-User-Id") Long userId,
@RequestParam(name = "state",
defaultValue = "ALL") String state) {
return bookingService.getAllUserItemsBookings(userId, state);
defaultValue = "ALL") String state,
@RequestParam(name = "from",
defaultValue = "0") Integer from,
@RequestParam(name = "size",
defaultValue = "10") Integer size) {
return bookingService.getAllUserItemsBookings(userId, state, PageValidator.validatePage(from, size));
}
}
33 changes: 22 additions & 11 deletions src/main/java/ru/practicum/shareit/booking/BookingRepository.java
Original file line number Diff line number Diff line change
@@ -1,43 +1,49 @@
package ru.practicum.shareit.booking;

import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import ru.practicum.shareit.exceptions.NotFoundException;


import java.time.LocalDateTime;
import java.util.List;

public interface BookingRepository extends JpaRepository<Booking, Long> {
List<Booking> findAllByBookerIdOrderByStartDesc(Long userId);
List<Booking> findAllByBookerIdOrderByStartDesc(Long userId, Pageable pageRequest);

List<Booking> findAllByBookerIdAndStartIsBeforeAndEndIsAfterOrderByStartDesc(Long userId, LocalDateTime startTime,
LocalDateTime endTime);
LocalDateTime endTime,
Pageable pageRequest);

List<Booking> findAllByBookerIdAndEndIsBeforeOrderByStartDesc(Long userId, LocalDateTime endTime);
List<Booking> findAllByBookerIdAndEndIsBeforeOrderByStartDesc(Long userId, LocalDateTime endTime,
Pageable pageRequest);

List<Booking> findAllByBookerIdAndStartIsAfterOrderByStartDesc(Long userId, LocalDateTime startTime);
List<Booking> findAllByBookerIdAndStartIsAfterOrderByStartDesc(Long userId, LocalDateTime startTime,
Pageable pageRequest);

List<Booking> findAllByBookerIdAndStatusOrderByStartDesc(Long userId, Status status);
List<Booking> findAllByBookerIdAndStatusOrderByStartDesc(Long userId, Status status, Pageable pageRequest);

@Query("select b from Booking b " +
"where b.item.owner.id = ?1 order by b.start desc")
List<Booking> findAllItemOwnerBookings(Long userId);
List<Booking> findAllItemOwnerBookings(Long userId, Pageable pageRequest);

@Query("select b from Booking b " +
"where b.item.owner.id = ?1 and b.start< ?2 and b.end> ?3 order by b.start desc")
List<Booking> findAllItemOwnerCurrentBookings(Long userId, LocalDateTime startTime,
LocalDateTime endTime);
List<Booking> findAllItemOwnerCurrentBookings(Long userId, LocalDateTime startTime, LocalDateTime endTime,
Pageable pageRequest);

@Query("select b from Booking b " +
"where b.item.owner.id = ?1 and b.end< ?2 order by b.start desc")
List<Booking> findAllItemOwnerPastBookings(Long userId, LocalDateTime endTime);
List<Booking> findAllItemOwnerPastBookings(Long userId, LocalDateTime endTime, Pageable pageRequest);

@Query("select b from Booking b " +
"where b.item.owner.id = ?1 and b.start> ?2 order by b.start desc")
List<Booking> findAllItemOwnerFutureBookings(Long userId, LocalDateTime startTime);
List<Booking> findAllItemOwnerFutureBookings(Long userId, LocalDateTime startTime, Pageable pageRequest);

@Query("select b from Booking b " +
"where b.item.owner.id = ?1 and b.status = ?2 order by b.start desc")
List<Booking> findAllItemOwnerBookingsByStatus(Long userId, Status status);
List<Booking> findAllItemOwnerBookingsByStatus(Long userId, Status status, Pageable pageRequest);

@Query("select b from Booking b " +
"where b.item.id = ?1")
Expand All @@ -46,4 +52,9 @@ List<Booking> findAllItemOwnerCurrentBookings(Long userId, LocalDateTime startTi
@Query("select b from Booking b " +
"where b.booker.id = ?1 and b.item.id = ?2 and b.end <= ?3")
List<Booking> findAllUserBookings(Long userId, Long itemId, LocalDateTime now);

default Booking getBookingById(Long bookingId) {
return findById(bookingId)
.orElseThrow(() -> new NotFoundException("Бронирование с id=" + bookingId + " не существует"));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package ru.practicum.shareit.booking;


import org.springframework.data.domain.Pageable;

import java.util.List;

public interface BookingService {
Expand All @@ -9,7 +12,7 @@ public interface BookingService {

BookingResponseDto getById(Long userId, Long bookingId);

List<BookingResponseDto> getAllUserBookings(Long userId, String state);
List<BookingResponseDto> getAllUserBookings(Long userId, String state, Pageable pageRequest);

List<BookingResponseDto> getAllUserItemsBookings(Long userId, String state);
List<BookingResponseDto> getAllUserItemsBookings(Long userId, String state, Pageable pageRequest);
}
Loading