@Service
@Slf4j
@RequiredArgsConstructor
public class VendorService {
private final VendorRepository vendorRepository;
private final VendorMapper vendorMapper;
private final CountryRepository countryRepository;
public List<VendorDto> findAllVendors() {
log.info(“Найдены все существующие вендоры в БД”);
return vendorMapper.toListDto(vendorRepository.findAll());
}
public VendorDto findVendorById(Long id) throws PenzGtuException {
log.info("Найден вендор по id: " + id);
Vendor vendor = vendorRepository.findById(id)
.orElseThrow(() -> new PenzGtuException(ErrorType.NOT_FOUND, “Вендор " + id + " не найден”));
return vendorMapper.toDto(vendor);
}
public void saveVendor(VendorDto vendorDto) {
log.info(“Вендор сохранен”);
Vendor vendor = vendorMapper.toEntity(vendorDto);
vendor.setCountry(countryRepository.findByName(vendorDto.getCountryName()));
vendorRepository.save(vendor);
}
public void updateVendor(Vendor newVendor) {
log.info(“Данные о вендоре были обновлены”);
Vendor oldVendor = vendorRepository.findById(newVendor.getId())
.orElseThrow(() -> new PenzGtuException(ErrorType.NOT_FOUND, “Вендор не найден “));
oldVendor.setName(newVendor.getName());
oldVendorRepository.save(oldVendor);
}
public void deleteVendorById(Long id) {
log.info(“Удален вендор с id: " + id);
vendorRepository.deleteById(id);
}
}
CarService.java (Эту часть заменим на GraphicCardService и другие связанные компоненты)
package ru.edu.penzgtu.lab.service;
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
@Service
@Slf4j
@RequiredArgsConstructor
public class GraphicCardService {
private final GraphicCardRepository graphicCardRepository;
private final GraphicCardMapper graphicCardMapper;
private final VendorRepository vendorRepository;
public List<GraphicCardDto> findAllGraphicCards() {
log.info(“Найдены все существующие видеокарты в БД”);
return graphicCardMapper.toListDto(graphicCardRepository.findAll());
}
public GraphicCardDto findGraphicCardById(Long id) throws PenzGtuException {
log.info(“Найдена видеокарта по id: " + id);
GraphicCard graphicCard = graphicCardRepository.findById(id)
.orElseThrow(() -> new PenzGtuException(ErrorType.NOT_FOUND, “Видеокарта " + id + " не найдена”));
return graphicCardMapper.toDto(graphicCard);
}
public void saveGraphicCard(GraphicCardDto graphicCardDto) {
log.info(“Видеокарта сохранена”);
GraphicCard graphicCard = graphicCardMapper.toEntity(graphicCardDto);
graphicCard.setLocalDateTime(LocalDateTime.now());
graphicCard.setVendors(vendorRepository.findByName(graphicCardDto.getVendorName()));
graphicCardRepository.save(graphicCard);
}
public void updateGraphicCard(GraphicCard newGraphicCard) {
log.info(“Данные о видеокарте были обновлены”);
GraphicCard oldGraphicCard = graphicCardRepository.findById(newGraphicCard.getId())
.orElseThrow(() -> new PenzGtuException(ErrorType.NOT_FOUND, “Видеокарта не найдена “));
oldGraphicCard.setName(newGraphicCard.getName());
graphicCardRepository.save(oldGraphicCard);
}
public void deleteGraphicCardById(Long id) {
log.info(“Удалена видеокарта с id: " + id);
graphicCardRepository.deleteById(id);
}
@Service
@Slf4j
@RequiredArgsConstructor
public class CountryService {
private final CountryRepository countryRepository;
private final CountryMapper countryMapper;
@Transactional
public List<CountryDto> findAllCountries() {
log.info(“Найдены все существующие страны в БД”);
return countryMapper.toListDto(countryRepository.findAll());
}
public CountryDto findCountryById(Long id) {
Country country = countryRepository.findById(id)
.orElseThrow(() -> new PenzGtuException(ErrorType.NOT_FOUND, “Страна с id " + id + " не найдена”));
return countryMapper.toDto(country);
}
public void saveCountry(CountryDto countryDto) {
log.info(“Страна сохранена”);
Country country = countryMapper.toEntity(countryDto);
country.setLocalDateTime(LocalDateTime.now());
countryRepository.save(country);
}
public void updateCountry(CountryDto newCountry) {
log.info(“Данные о стране были обновлены”);
Country oldCountry = countryRepository.findById(newCountry.getId())
.orElseThrow(() -> new PenzGtuException(ErrorType.NOT_FOUND, “Страна не найдена “));
oldCountry.setName(newCountry.getName());
oldCountry.setCapital(newCountry.getCapital());
oldCountry.setLanguage(newCountry.getLanguage());
countryRepository.save(oldCountry);
}
public void deleteCountryById(Long id) {
log.info(“Удалена страна с id: " + id);
countryRepository.deleteById(id);
}
}
DriverService.java (Эту часть заменим на VendorService и другие связанные компоненты)
@Service
@Slf4j
@RequiredArgsConstructor
public class VendorService {
private final VendorRepository vendorRepository;
private final VendorMapper vendorMapper;
private final GraphicCardRepository graphicCardRepository;
public List<VendorDto> findAllVendors() {
log.info(“Найдены все существующие вендоры в БД”);
return vendorMapper.toListDto(vendorRepository.findAll());
}
public VendorDto findVendorById(Long id) throws PenzGtuException {
log.info(“Найден вендор по id: " + id);
Vendor vendor = vendorRepository.findById(id)
.orElseThrow(() -> new PenzGtuException(ErrorType.NOT_FOUND, “Вендор " + id + " не найден”));
return vendorMapper.toDto(vendor);
}
public void saveVendor(VendorDto vendorDto) {
log.info(“Вендор сохранен”);
Vendor vendor = vendorMapper.toEntity(vendorDto);
vendor.setLocalDateTime(LocalDateTime.now());
vendorRepository.save(vendor);
}
public void updateVendor(Vendor newVendor) {
log.info(“Данные о вендоре были обновлены”);
Vendor oldVendor = vendorRepository.findById(newVendor.getId())
.orElseThrow(() -> new PenzGtuException(ErrorType.NOT_FOUND, “Вендор не найден “));
oldVendor.setName(newVendor.getName());
oldVendorRepository.save(oldVendor);
}
public void deleteVendorById(Long id) {
log.info(“Удален вендор с id: " + id);
vendorRepository.deleteById(id);
}
}
MarkaController.java (Эту часть заменим на VendorController и другие связанные компоненты)
@Validated
@RestController
@RequestMapping(“/vendors”)
@RequiredArgsConstructor
@Tag(name = “Вендоры”,description = “Операции над вендорами”)
public class VendorController {
private final VendorService vendorService;
private final BaseResponseService baseResponseService;
@Operation(
summary = “Получение всех вендоров”, description = “Позволяет выгрузить всех вендоров из БД”
)
@GetMapping
public ResponseWrapper<List<VendorDto>> findAllVendors() {
return baseResponseService.wrapSuccessResponse(vendorService.findAllVendors());
}
@Operation(
summary = “Получение вендора по ID”, description = “Позволяет выгрузить одного вендора по ID из БД”
)
@GetMapping(“/vendor/{id}”)
public ResponseWrapper<VendorDto> getVendorById(@PathVariable @Min(0) Long id) throws PenzGtuException {
return baseResponseService.wrapSuccessResponse(vendorService.findVendorById(id));
}
@Operation(
summary = “Создать вендора”, description = “Позволяет создать новую запись о вендоре в БД”
)
@PostMapping
@ResponseStatus(HttpStatus.CREATED)
public void createVendor(@RequestBody @Valid VendorDto vendor){
vendorService.saveVendor(vendor);
}
@Operation(
summary = “Обновить данные о вендоре”, description = “Позволяет обновить информацию о вендоре в БД”
)
@PutMapping(“/vendor”)
public void updateVendor(@RequestBody @Valid Vendor vendor) {
vendorService.updateVendor(vendor);
}
@Operation(
summary = “Удалить вендора по ID”, description = “Позволяет удалить вендора по ID из БД”
)
@DeleteMapping(“/vendor/{id}”)
@ResponseStatus(HttpStatus.NO_CONTENT)
public void deleteVendor(@PathVariable @Min(0) Long id) {
vendorService.deleteVendorById(id);
}
}
CarController.java (Эту часть заменим на GraphicCardController и другие связанные компоненты)
@Validated
@RestController
@RequestMapping(”/graphic-cards”)
@RequiredArgsConstructor
@Tag(name = “Видеокарты”,description = “Операции над видеокартами”)
public class GraphicCardController {
private final GraphicCardService graphicCardService;
private final BaseResponseService baseResponseService;
@Operation(
summary = “Получение всех видеокарт”, description = “Позволяет выгрузить все видеокарты из БД”
)
@GetMapping
public ResponseWrapper<List<GraphicCardDto>> findAllGraphicCards() {
return baseResponseService.wrapSuccessResponse(graphicCardService.findAllGraphicCards());
}
@Operation(
summary = “Получение видеокарты по ID”, description = “Позволяет выгрузить одну видеокарту по ID из БД”
)
@GetMapping(”/graphic-card/{id}”)
public ResponseWrapper<GraphicCardDto> getGraphicCardById(@PathVariable @Min(0) Long id) throws PenzGtuException {
return baseResponseService.wrapSuccessResponse(graphicCardService.findGraphicCardById(id));
}
@Operation(
summary = “Создать видеокарту”, description = “Позволяет создать новую запись о видеокарте в БД”
)
@PostMapping
@ResponseStatus(HttpStatus.CREATED)
public void createGraphicCard(@RequestBody @Valid GraphicCardDto graphicCard){
graphicCardService.saveGraphicCard(graphicCard);
}
@Operation(
summary = “Обновить данные о видеокарте”, description = “Позволяет обновить информацию о видеокарте в БД”
)
@PutMapping(”/graphic-card”)
public void updateGraphicCard(@RequestBody @Valid GraphicCard graphicCard) {
graphicCardService.updateGraphicCard(graphicCard);
}
@Operation(
summary = “Удалить видеокарту по ID”, description = “Позволяет удалить видеокарту по ID из БД”
)
@DeleteMapping(”/graphic-card/{id}”)
@ResponseStatus(HttpStatus.NO_CONTENT)
public void deleteGraphicCard(@PathVariable @Min(0) Long id) {
graphicCardService.deleteGraphicCardById(id);
}
@Validated
@RestController
@RequestMapping(”/countries”)
@RequiredArgsConstructor
@Tag(name = “Страны производителей”,description = “Операции над странами производителей”)
public class CountryController {
private final CountryService countryService;
private final BaseResponseService baseResponseService;
private final CountryRepository countryRepository;
@Operation(
summary = “Получение всех стран производителей”, description = “Позволяет выгрузить все страны производителей из БД”
)
@GetMapping
public ResponseWrapper<List<CountryDto>> findAllCountries() {
return baseResponseService.wrapSuccessResponse(countryService.findAllCountries());
}
@Operation(
summary = “Получение страны производителя по ID”, description = “Позволяет выгрузить одну страну производителя по ID из БД”
)
@GetMapping(”/country/{id}”)
public ResponseWrapper<CountryDto> getCountryById(@PathVariable @Min(0) Long id) throws PenzGtuException {
return baseResponseService.wrapSuccessResponse(countryService.findCountryById(id));
}
@Operation(
summary = “Создать страну производителя”, description = “Позволяет создать новую запись о стране производителя в БД”
)
@PostMapping
@ResponseStatus(HttpStatus.CREATED)
public void createCountry(@RequestBody @Valid CountryDto country){
countryService.saveCountry(country);
}
@Operation(
summary = “Обновить данные о стране производителя”, description = “Позволяет обновить информацию о стране производителя в БД”
)
@PutMapping(”/country”)
public void updateCountry(@RequestBody @Valid CountryDto country) {
countryService.updateCountry(country);
}
@Operation(
summary = “Удалить страну производителя по ID”, description
Конечно, продолжу с места, на котором остановился.
CountryController.java (продолжение)
description = “Позволяет удалить страну производителя по ID из БД”
)
@DeleteMapping(“/country/{id}”)
@ResponseStatus(HttpStatus.NO_CONTENT)
public void deleteCountry(@PathVariable @Min(0) Long id) {
countryService.deleteCountryById(id);
}
}
CountryRepository.java
package ru.edu.penzgtu.lab.repo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import ru.edu.penzgtu.lab.entity.Country;
@Repository
public interface CountryRepository extends JpaRepository<Country, Long> {
Country findByName(String name);
}
package ru.edu.penzgtu.lab.service;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import ru.edu.penzgtu.lab.dto.VendorDto;
import ru.edu.penzgtu.lab.exception.ErrorType;
import ru.edu.penzgtu.lab.exception.PenzGtuException;
import ru.edu.penzgtu.lab.repo.VendorRepository;
import ru.edu.penzgtu.lab.entity.Vendor;
import ru.edu.penzgtu.lab.repo.CountryRepository;
import ru.edu.penzgtu.lab.service.mapper.VendorMapper;
import java.util.List;
@Service
@Slf4j
@RequiredArgsConstructor
public class VendorService {
private final VendorRepository vendorRepository;
private final VendorMapper vendorMapper;
private final CountryRepository countryRepository;
public List<VendorDto> findAllVendors() {
log.info("Найдены все существующие вендоры в БД");
return vendorMapper.toListDto(vendorRepository.findAll());
}
public VendorDto findVendorById(Long id) throws PenzGtuException {
log.info("Найден вендор по id: " + id);
Vendor vendor = vendorRepository.findById(id)
.orElseThrow(() -> new PenzGtuException(ErrorType.NOT_FOUND, "Вендор " + id + " не найден"));
return vendorMapper.toDto(vendor);
}
public void saveVendor(VendorDto vendorDto) {
log.info("Вендор сохранен");
Vendor vendor = vendorMapper.toEntity(vendorDto);
vendor.setCountry(countryRepository.findByName(vendorDto.getCountryName()));
vendorRepository.save(vendor);
}
public void updateVendor(Vendor newVendor) {
log.info("Данные о вендоре были обновлены");
Vendor oldVendor = vendorRepository.findById(newVendor.getId())
.orElseThrow(() -> new PenzGtuException(ErrorType.NOT_FOUND, "Вендор не найден"));
oldVendor.setName(newVendor.getName());
vendorRepository.save(oldVendor);
}
public void deleteVendorById(Long id) {
log.info("Удален вендор с id: " + id);
vendorRepository.deleteById(id);
}
}
GraphicCardService.java
package ru.edu.penzgtu.lab.service;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import ru.edu.penzgtu.lab.dto.GraphicCardDto;
import ru.edu.penzgtu.lab.entity.GraphicCard;
import ru.edu.penzgtu.lab.exception.ErrorType;
import ru.edu.penzgtu.lab.exception.PenzGtuException;
import ru.edu.penzgtu.lab.repo.GraphicCardRepository;
import ru.edu.penzgtu.lab.repo.VendorRepository;
import ru.edu.penzgtu.lab.service.mapper.GraphicCardMapper;
import java.time.LocalDateTime;
import java.util.List;
@Service
@Slf4j
@RequiredArgsConstructor
public class GraphicCardService {
private final GraphicCardRepository graphicCardRepository;
private final GraphicCardMapper graphicCardMapper;
private final VendorRepository vendorRepository;
public List<GraphicCardDto> findAllGraphicCards() {
log.info("Найдены все существующие видеокарты в БД");
return graphicCardMapper.toListDto(graphicCardRepository.findAll());
}
public GraphicCardDto findGraphicCardById(Long id) throws PenzGtuException {
log.info("Найдена видеокарта по id: " + id);
GraphicCard graphicCard = graphicCardRepository.findById(id)
.orElseThrow(() -> new PenzGtuException(ErrorType.NOT_FOUND, "Видеокарта " + id + " не найдена"));
return graphicCardMapper.toDto(graphicCard);
}
public void saveGraphicCard(GraphicCardDto graphicCardDto) {
log.info("Видеокарта сохранена");
GraphicCard graphicCard = graphicCardMapper.toEntity(graphicCardDto);
graphicCard.setLocalDateTime(LocalDateTime.now());
graphicCard.setVendors(vendorRepository.findByName(graphicCardDto.getVendorName()));
graphicCardRepository.save(graphicCard);
}
public void updateGraphicCard(GraphicCard newGraphicCard) {
log.info("Данные о видеокарте были обновлены");
GraphicCard oldGraphicCard = graphicCardRepository.findById(newGraphicCard.getId())
.orElseThrow(() -> new PenzGtuException(ErrorType.NOT_FOUND, "Видеокарта не найдена"));
oldGraphicCard.setName(newGraphicCard.getName());
graphicCardRepository.save(oldGraphicCard);
}
public void deleteGraphicCardById(Long id) {
log.info("Удалена видеокарта с id: " + id);
graphicCardRepository.deleteById(id);
}
}
CountryService.java
package ru.edu.penzgtu.lab.service;
import jakarta.transaction.Transactional;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import ru.edu.penzgtu.lab.dto.CountryDto;
import ru.edu.penzgtu.lab.entity.Country;
import ru.edu.penzgtu.lab.exception.ErrorType;
import ru.edu.penzgtu.lab.exception.PenzGtuException;
import ru.edu.penzgtu.lab.repo.CountryRepository;
import ru.edu.penzgtu.lab.service.mapper.CountryMapper;
import java.time.LocalDateTime;
import java.util.List;
@Service
@Slf4j
@RequiredArgsConstructor
public class CountryService {
private final CountryRepository countryRepository;
private final CountryMapper countryMapper;
@Transactional
public List<CountryDto> findAllCountries() {
log.info("Найдены все существующие страны в БД");
return countryMapper.toListDto(countryRepository.findAll());
}
public CountryDto findCountryById(Long id) {
Country country = countryRepository.findById(id)
.orElseThrow(() -> new PenzGtuException(ErrorType.NOT_FOUND, "Страна с id " + id + " не найдена"));
return countryMapper.toDto(country);
}
public void saveCountry(CountryDto countryDto) {
log.info("Страна сохранена");
Country country = countryMapper.toEntity(countryDto);
country.setLocalDateTime(LocalDateTime.now());
countryRepository.save(country);
}
public void updateCountry(CountryDto newCountry) {
log.info("Данные о стране были обновлены");
Country oldCountry = countryRepository.findById(newCountry.getId())
.orElseThrow(() -> new PenzGtuException(ErrorType.NOT_FOUND, "Страна не найдена"));
oldCountry.setName(newCountry.getName());
oldCountry.setCapital(newCountry.getCapital());
oldCountry.setLanguage(newCountry.getLanguage());
countryRepository.save(oldCountry);
}
public void deleteCountryById(Long id) {
log.info("Удалена страна с id: " + id);
countryRepository.deleteById(id);
}
}
VendorController.java
package ru.edu.penzgtu.lab.controller;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import jakarta.validation.constraints.Min;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import ru.edu.penzgtu.lab.baseresponce.BaseResponseService;
import ru.edu.penzgtu.lab.baseresponce.ResponseWrapper;
import ru.edu.penzgtu.lab.dto.VendorDto;
import ru.edu.penzgtu.lab.entity.Vendor;
import ru.edu.penzgtu.lab.exception.PenzGtuException;
import ru.edu.penzgtu.lab.service.VendorService;
import java.util.List;
@Validated
@RestController
@RequestMapping("/vendors")
@RequiredArgsConstructor
@Tag(name = "Вендоры", description = "Операции над вендорами")
public class VendorController {
private final VendorService vendorService;
private final BaseResponseService baseResponseService;
@Operation(
summary = "Получение всех вендоров", description = "Позволяет выгрузить всех вендоров из БД"
)
@GetMapping
public ResponseWrapper<List<VendorDto>> findAllVendors() {
return baseResponseService.wrapSuccessResponse(vendorService.findAllVendors());
}
@Operation(
summary = "Получение вендора по ID", description = "Позволяет выгрузить одного вендора по ID из БД"
)
@GetMapping("/vendor/{id}")
public ResponseWrapper<VendorDto> getVendorById(@PathVariable @Min(0) Long id) throws PenzGtuException {
return baseResponseService.wrapSuccessResponse(vendorService.findVendorById(id));
}
@Operation(
summary = "Создать вендора", description = "Позволяет создать новую запись о вендоре в БД"
)
@PostMapping
@ResponseStatus(HttpStatus.CREATED)
public void createVendor(@RequestBody @Valid VendorDto vendor) {
vendorService.saveVendor(vendor);
}
@Operation(
summary = "Обновить данные о вендоре", description = "Позволяет обновить информацию о вендоре в БД"
)
@PutMapping("/vendor")
public void updateVendor(@RequestBody @Valid Vendor vendor) {
vendorService.updateVendor(vendor);
}
@Operation(
summary = "Удалить вендора по ID", description = "Позволяет удалить вендора по ID из БД"
)
@DeleteMapping("/vendor/{id}")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void deleteVendor(@PathVariable @Min(0) Long id) {
vendorService.deleteVendorById(id);
}
}
GraphicCardController.java
package ru.edu.penzgtu.lab.controller;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import jakarta.validation.constraints.Min;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import ru.edu.penzgtu.lab.baseresponce.BaseResponseService;
import ru.edu.penzgtu.lab.baseresponce.ResponseWrapper;
import ru.edu.penzgtu.lab.dto.GraphicCardDto;
import ru.edu.penzgtu.lab.entity.GraphicCard;
import ru.edu.penzgtu.lab.exception.PenzGtuException;
import ru.edu.penzgtu.lab.service.GraphicCardService;
import java.util.List;
@Validated
@RestController
@RequestMapping("/graphic-cards")
@RequiredArgsConstructor
@Tag(name = "Видеокарты", description = "Операции над видеокартами")
public class GraphicCardController {
private final GraphicCardService graphicCardService;
private final BaseResponseService baseResponseService;
@Operation(
summary = "Получение всех видеокарт", description = "Позволяет выгрузить все видеокарты из БД"
)
@GetMapping
public ResponseWrapper<List<GraphicCardDto>> findAllGraphicCards() {
return baseResponseService.wrapSuccessResponse(graphicCardService.findAllGraphicCards());
}
@Operation(
summary = "Получение видеокарты по ID", description = "Позволяет выгрузить одну видеокарту по ID из БД"
)
@GetMapping("/graphic-card/{id}")
public ResponseWrapper<GraphicCardDto> getGraphicCardById(@PathVariable @Min(0) Long id) throws PenzGtuException {
return baseResponseService.wrapSuccessResponse(graphicCardService.findGraphicCardById(id));
}
@Operation(
summary = "Создать видеокарту", description = "Позволяет создать новую запись о видеокарте в БД"
)
@PostMapping
@ResponseStatus(HttpStatus.CREATED)
public void createGraphicCard(@RequestBody @Valid GraphicCardDto graphicCard) {
graphicCardService.saveGraphicCard(graphicCard);
}
@Operation(
summary = "Обновить данные о видеокарте", description = "Позволяет обновить информацию о видеокарте в БД"
)
@PutMapping("/graphic-card")
public void updateGraphicCard(@RequestBody @Valid GraphicCard graphicCard) {
graphicCardService.updateGraphicCard(graphicCard);
}
@Operation(
summary = "Удалить видеокарту по ID", description = "Позволяет удалить видеокарту по ID из БД"
)
@DeleteMapping("/graphic-card/{id}")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void deleteGraphicCard(@PathVariable @Min(0) Long id) {
graphicCardService.deleteGraphicCardById(id);
}
}
CountryController.java
package ru.edu.penzgtu.lab.controller;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import jakarta.validation.constraints.Min;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import ru.edu.penzgtu.lab.baseresponce.BaseResponseService;
import ru.edu.penzgtu.lab.baseresponce.ResponseWrapper;
import ru.edu.penzgtu.lab.dto.CountryDto;
import ru.edu.penzgtu.lab.entity.Country;
import ru.edu.penzgtu.lab.exception.PenzGtuException;
import ru.edu.penzgtu.lab.service.CountryService;
import java.util.List;
@Validated
@RestController
@RequestMapping("/countries")
@RequiredArgsConstructor
@Tag(name = "Страны производителей", description = "Операции над странами производителей")
public class CountryController {
private final CountryService countryService;
private final BaseResponseService baseResponseService;
@Operation(
summary = "Получение всех стран производителей", description = "Позволяет выгрузить все страны производителей из БД"
)
@GetMapping
public ResponseWrapper<List<CountryDto>> findAllCountries() {
return baseResponseService.wrapSuccessResponse(countryService.findAllCountries());
}
@Operation(
summary = "Получение страны производителя по ID", description = "Позволяет выгрузить одну страну производителя по ID из БД"
)
@GetMapping("/country/{id}")
public ResponseWrapper<CountryDto> getCountryById(@PathVariable @Min(0) Long id) throws PenzGtuException {
return baseResponseService.wrapSuccessResponse(countryService.findCountryById(id));
}
@Operation(
summary = "Создать страну производителя", description = "Позволяет создать новую запись о стране производителя в БД"
)
@PostMapping
@ResponseStatus(HttpStatus.CREATED)
public void createCountry(@RequestBody @Valid CountryDto country) {
countryService.saveCountry(country);
}
@Operation(
summary = "Обновить данные о стране производителя", description = "Позволяет обновить информацию о стране производителя в БД"
)
@PutMapping("/country")
public void updateCountry(@RequestBody @Valid CountryDto country) {
countryService.updateCountry(country);
}
@Operation(
summary = "Удалить страну производителя по ID", description = "Позволяет удалить страну производителя по ID из БД"
)
@DeleteMapping("/country/{id}")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void deleteCountry(@PathVariable @Min(0) Long id) {
countryService.deleteCountryById(id);
}
}
Теперь все файлы связаны с новой доменной областью: подсистема, работающая с вендорами, странами производителей и видеокартами.