Complete backend functionality

This commit is contained in:
2025-12-11 20:15:53 +07:00
parent 83b3202ea2
commit cebc033f0f
17 changed files with 327 additions and 14 deletions

View File

@@ -1,5 +1,12 @@
package com.example.nto.service;
import com.example.nto.entity.Booking;
import com.example.nto.entity.Employee;
import com.example.nto.entity.Place;
import java.time.LocalDate;
import java.util.List;
/**
* TODO: ДОРАБОТАТЬ в рамках задания
* =================================
@@ -7,4 +14,7 @@ package com.example.nto.service;
* НЕЛЬЗЯ: Изменять название класса и пакета
*/
public interface BookingService {
Booking getById(Long id);
List<Booking> getAll();
void save(LocalDate date, Place place, Employee employee);
}

View File

@@ -1,5 +1,9 @@
package com.example.nto.service;
import com.example.nto.entity.Employee;
import java.util.List;
/**
* TODO: ДОРАБОТАТЬ в рамках задания
* =================================
@@ -7,4 +11,8 @@ package com.example.nto.service;
* НЕЛЬЗЯ: Изменять название класса и пакета
*/
public interface EmployeeService {
Employee getById(Long id);
Employee getByName(String name);
Employee getByCode(String code);
List<Employee> getAll();
}

View File

@@ -0,0 +1,10 @@
package com.example.nto.service;
import com.example.nto.entity.Place;
import java.util.List;
public interface PlaceService {
Place getById(Long id);
List<Place> getAll();
}

View File

@@ -1,6 +1,18 @@
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: ДОРАБОТАТЬ в рамках задания
@@ -8,5 +20,29 @@ import com.example.nto.service.BookingService;
* МОЖНО: Добавлять методы, аннотации, зависимости
* НЕЛЬЗЯ: Изменять название класса и пакета
*/
@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);
}
}

View File

@@ -1,6 +1,16 @@
package com.example.nto.service.impl;
import com.example.nto.entity.Booking;
import com.example.nto.entity.Employee;
import com.example.nto.repository.EmployeeRepository;
import com.example.nto.service.EmployeeService;
import io.micrometer.common.lang.Nullable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
/**
* TODO: ДОРАБОТАТЬ в рамках задания
@@ -8,5 +18,31 @@ import com.example.nto.service.EmployeeService;
* МОЖНО: Добавлять методы, аннотации, зависимости
* НЕЛЬЗЯ: Изменять название класса и пакета
*/
@Service
public class EmployeeServiceImpl implements EmployeeService {
@Autowired
private EmployeeRepository employeeRepository;
@Override
@Nullable
public Employee getById(Long id) {
return employeeRepository.findById(id).orElseGet(() -> null);
}
@Override
@Nullable
public Employee getByName(String name) {
return employeeRepository.findByName(name).orElseGet(() -> null);
}
@Override
@Nullable
public Employee getByCode(String code) {
return employeeRepository.findByCode(code).orElseGet(() -> null);
}
@Override
public List<Employee> getAll() {
return StreamSupport.stream(employeeRepository.findAll().spliterator(), false).collect(Collectors.toList());
}
}

View File

@@ -0,0 +1,29 @@
package com.example.nto.service.impl;
import com.example.nto.entity.Place;
import com.example.nto.repository.PlaceRepository;
import com.example.nto.service.PlaceService;
import io.micrometer.common.lang.Nullable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
@Service
public class PlaceServiceImpl implements PlaceService {
@Autowired
private PlaceRepository placeRepository;
@Override
@Nullable
public Place getById(Long id) {
return placeRepository.findById(id).orElseGet(() -> null);
}
@Override
public List<Place> getAll() {
return StreamSupport.stream(placeRepository.findAll().spliterator(), false).collect(Collectors.toList());
}
}