-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBookingController.java
More file actions
68 lines (58 loc) · 3.37 KB
/
BookingController.java
File metadata and controls
68 lines (58 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package ru.practicum.shareit.booking;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import ru.practicum.shareit.booking.dto.BookingDTO;
import ru.practicum.shareit.booking.dto.BookingDTOToReturn;
import ru.practicum.shareit.booking.service.BookingService;
import javax.validation.Valid;
import javax.validation.constraints.PositiveOrZero;
import java.util.List;
@RestController
@RequestMapping(path = "/bookings")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@Slf4j
@Validated
public class BookingController {
private final BookingService bookingService;
@PostMapping
public BookingDTOToReturn add(@RequestHeader("X-Sharer-User-Id") Long userId,
@Valid @RequestBody BookingDTO bookingDto) {
log.info("Добавление запроса на аренду пользователем с id {}", userId);
return bookingService.add(userId, bookingDto);
}
@PatchMapping("/{bookingId}")
public BookingDTOToReturn update(@RequestHeader("X-Sharer-User-Id") Long userId,
@PathVariable Long bookingId,
@RequestParam Boolean approved) {
log.info("Обновление статуса запроса на аренду с id {}", bookingId);
return bookingService.update(userId, bookingId, approved);
}
@GetMapping("/{bookingId}")
public BookingDTOToReturn get(@RequestHeader("X-Sharer-User-Id") Long userId, @PathVariable Long bookingId) {
log.info("Просмотр запроса на пренду с id {}", bookingId);
return bookingService.get(userId, bookingId);
}
@GetMapping
public List<BookingDTOToReturn> findByBooker(@RequestHeader("X-Sharer-User-Id") Long userId,
@RequestParam(required = false, defaultValue = "ALL") String state,
@PositiveOrZero @RequestParam(name = "from", defaultValue = "0")
Integer from,
@PositiveOrZero @RequestParam(name = "size", defaultValue = "10")
Integer size) {
log.info("Получение списка бронирований пользовалеля с id {}", userId);
return bookingService.getByBooker(userId, state, from, size);
}
@GetMapping("/owner")
public List<BookingDTOToReturn> findByOwner(@RequestHeader("X-Sharer-User-Id") Long userId,
@RequestParam(defaultValue = "ALL") String state,
@PositiveOrZero @RequestParam(name = "from", defaultValue = "0")
Integer from,
@PositiveOrZero @RequestParam(name = "size", defaultValue = "10")
Integer size) {
log.info("Получение списка бронирований для всех вещей пользователя с id {}", userId);
return bookingService.getByOwner(userId, state, from, size);
}
}