Some checks failed
Android Test / validate-and-test (pull_request) Has been cancelled
49 lines
1.5 KiB
Java
49 lines
1.5 KiB
Java
package com.example.nto.service.impl;
|
|
|
|
import com.example.nto.entity.Booking;
|
|
import com.example.nto.entity.Employee;
|
|
import com.example.nto.entity.Place;
|
|
import com.example.nto.repository.BookingRepository;
|
|
import com.example.nto.service.BookingService;
|
|
import io.micrometer.common.lang.Nullable;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import java.time.LocalDate;
|
|
import java.util.List;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.StreamSupport;
|
|
|
|
/**
|
|
* TODO: ДОРАБОТАТЬ в рамках задания
|
|
* =================================
|
|
* МОЖНО: Добавлять методы, аннотации, зависимости
|
|
* НЕЛЬЗЯ: Изменять название класса и пакета
|
|
*/
|
|
@Service
|
|
public class BookingServiceImpl implements BookingService {
|
|
@Autowired
|
|
private BookingRepository bookingRepository;
|
|
|
|
@Override
|
|
@Nullable
|
|
public Booking getById(Long id) {
|
|
return bookingRepository.findById(id).orElseGet(() -> null);
|
|
}
|
|
|
|
@Override
|
|
public List<Booking> getAll() {
|
|
return StreamSupport.stream(bookingRepository.findAll().spliterator(), false).collect(Collectors.toList());
|
|
}
|
|
|
|
@Override
|
|
public void save(LocalDate date, Place place, Employee employee) {
|
|
var booking = Booking.builder()
|
|
.date(date)
|
|
.place(place)
|
|
.employee(employee)
|
|
.build();
|
|
bookingRepository.save(booking);
|
|
}
|
|
}
|