<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>ru.edu.penzgtu</groupId>
    <artifactId>lab</artifactId>
    <version>1.0-SNAPSHOT</version>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.6.RELEASE</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.xerial</groupId>
            <artifactId>sqlite-jdbc</artifactId>
            <version>3.30.1</version>
        </dependency>
        <dependency>
            <groupId>com.github.gwenn</groupId>
            <artifactId>sqlite-dialect</artifactId>
            <version>0.1.1</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <scope>annotationProcessor</scope>
        </dependency>    </dependencies>
</project>

application.properties
server.port=8086

spring.datasource.driver-class-name=org.sqlite.JDBC
spring.datasource.url=jdbc:sqlite:lab_db.db
spring.datasource.username=user
spring.datasource.password=pass

spring.jpa.database-platform=org.sqlite.hibernate.dialect.SQLiteDialect
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true

App.java
package ru.edu.penzgtu;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class App {
    public static void main (String[] args) {
        SpringApplication.run(App.class, args);
    }
}

Vendor.java
package ru.edu.penzgtu.entity;

import javax.persistence.*;
import java.util.List;
import java.util.Objects;

@Entity
@Table (name = "vendors")
public class Vendor {
    @Id
    @GeneratedValue
    @Column (name = "id")
    private Long id;

    @Column (name = "name")
    private String name;

    @ManyToMany
    @JoinTable(
            name = "vendors_graphic_cards",
            joinColumns = @JoinColumn (name = "vendor_id", referencedColumnName = "id"),
            inverseJoinColumns = @JoinColumn (name = "graphic_card_id", referencedColumnName = "id")
    )
    private List<GraphicCard> graphicCards;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public List<GraphicCard> getGraphicCards() {
        return graphicCards;
    }

    public void setGraphicCards(List<GraphicCard> graphicCards) {
        this.graphicCards = graphicCards;
    }

    public Vendor() {
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Vendor vendor = (Vendor) o;
        return Objects.equals(id, vendor.id) &&
                Objects.equals(name, vendor.name) &&
                Objects.equals(graphicCards, vendor.graphicCards);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, name, graphicCards);
    }
}

GraphicCard.java
package ru.edu.penzgtu.entity;

import javax.persistence.*;
import java.util.List;
import java.util.Objects;

@Entity
@Table
public class GraphicCard {
    @Id
    @GeneratedValue
    @Column(name = "id")
    private Long id;

    @Column(name = "name")
    private String name;

    @ManyToMany(mappedBy = "graphicCards")
    private List<Vendor> vendors;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public List<Vendor> getVendors() {
        return vendors;
    }

    public void setVendors(List<Vendor> vendors) {
        this.vendors = vendors;
    }

    public GraphicCard() {
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        GraphicCard graphicCard = (GraphicCard) o;
        return Objects.equals(id, graphicCard.id) &&
                Objects.equals(name, graphicCard.name) &&
                Objects.equals(vendors, graphicCard.vendors);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, name, vendors);
    }
}

VendorRepository.java
package ru.edu.penzgtu.repo;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import ru.edu.penzgtu.entity.Vendor;

@Repository
public interface VendorRepository extends JpaRepository<Vendor, Long> {
}

GraphicCardRepository.java
package ru.edu.penzgtu.repo;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import ru.edu.penzgtu.entity.GraphicCard;

@Repository
public interface GraphicCardRepository extends JpaRepository<GraphicCard, Long> {
}

VendorService.java
package ru.edu.penzgtu.service;

import org.springframework.stereotype.Service;
import ru.edu.penzgtu.entity.Vendor;
import ru.edu.penzgtu.repo.VendorRepository;

import java.util.List;

@Service
public class VendorService {
    private final VendorRepository vendorRepository;

    public VendorService(VendorRepository vendorRepository) {
        this.vendorRepository = vendorRepository;
    }

    public List<Vendor> findAllVendors() {
        return vendorRepository.findAll();
    }

    public Vendor findVendorById(Long id) {
        return vendorRepository.findById(id).orElseThrow(() -> new RuntimeException("Vendor not found"));
    }

    public void saveVendor(Vendor vendor) {
        vendorRepository.save(vendor);
    }

    public void updateVendor(Vendor newVendor) {
        Vendor oldVendor = vendorRepository.findById(newVendor.getId())
                .orElseThrow(() -> new RuntimeException("Vendor not found"));

        oldVendor.setName(newVendor.getName());

        vendorRepository.save(oldVendor);
    }

    public void deleteVendorById(Long id) {
        vendorRepository.deleteById(id);
    }
}

GraphicCardService.java
package ru.edu.penzgtu.service;

import org.springframework.stereotype.Service;
import ru.edu.penzgtu.entity.GraphicCard;
import ru.edu.penzgtu.repo.GraphicCardRepository;

import java.util.List;

@Service
public class GraphicCardService {
    private final GraphicCardRepository graphicCardRepository;

    public GraphicCardService(GraphicCardRepository graphicCardRepository) {
        this.graphicCardRepository = graphicCardRepository;
    }

    public List<GraphicCard> findAllGraphicCards() {
        return graphicCardRepository.findAll();
    }

    public GraphicCard findGraphicCardById(Long id) {
        return graphicCardRepository.findById(id).orElseThrow(() -> new RuntimeException("GraphicCard not found"));
    }

    public void saveGraphicCard(GraphicCard graphicCard) {
        graphicCardRepository.save(graphicCard);
    }

    public void updateGraphicCard(GraphicCard newGraphicCard) {
        GraphicCard oldGraphicCard = graphicCardRepository.findById(newGraphicCard.getId())
                .orElseThrow(() -> new RuntimeException("GraphicCard not found"));

        oldGraphicCard.setName(newGraphicCard.getName());

        graphicCardRepository.save(oldGraphicCard);
    }

    public void deleteGraphicCardById(Long id) {
        graphicCardRepository.deleteById(id);
    }
}

VendorController.java
package ru.edu.penzgtu.controller;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import ru.edu.penzgtu.entity.Vendor;
import ru.edu.penzgtu.service.VendorService;

import java.util.List;

@RestController
@RequestMapping("/vendors")
public class VendorController {
    private final VendorService vendorService;

    public VendorController(VendorService vendorService) {
        this.vendorService = vendorService;
    }

    @GetMapping
    public List<Vendor> findAll() {
        return vendorService.findAllVendors();
    }

    @GetMapping("/vendor/{id}")
    public Vendor getById(@PathVariable long id) {
        return vendorService.findVendorById(id);
    }

    @PostMapping
    @ResponseStatus(HttpStatus.CREATED)
    public void createVendor(@RequestBody Vendor vendor) {
        vendorService.saveVendor(vendor);
    }

    @PutMapping("/vendor/")
    public void updateVendor(@RequestBody Vendor vendor) {
        vendorService.updateVendor(vendor);
    }

    @DeleteMapping("/vendor/{id}")
    @ResponseStatus(HttpStatus.NO_CONTENT)
    public void deleteVendor(@PathVariable long id) {
        vendorService.deleteVendorById(id);
    }
}

GraphicCardController.java
package ru.edu.penzgtu.controller;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import ru.edu.penzgtu.entity.GraphicCard;
import ru.edu.penzgtu.service.GraphicCardService;

import java.util.List;

@RestController
@RequestMapping("/graphic-cards")
public class GraphicCardController {
    private final GraphicCardService graphicCardService;

    public GraphicCardController(GraphicCardService graphicCardService) {
        this.graphicCardService = graphicCardService;
    }

    @GetMapping
    public List<GraphicCard> findAll() {
        return graphicCardService.findAllGraphicCards();
    }

    @GetMapping("/graphic-card/{id}")
    public GraphicCard getById(@PathVariable long id) {
        return graphicCardService.findGraphicCardById(id);
    }

    @PostMapping
    @ResponseStatus(HttpStatus.CREATED)
    public void createGraphicCard(@RequestBody GraphicCard graphicCard) {
        graphicCardService.saveGraphicCard(graphicCard);
    }

    @PutMapping("/graphic-card/")
    public void updateGraphicCard(@RequestBody GraphicCard graphicCard) {
        graphicCardService.updateGraphicCard(graphicCard);
    }

    @DeleteMapping("/graphic-card/{id}")
    @ResponseStatus(HttpStatus.NO_CONTENT)
    public void deleteGraphicCard(@PathVariable long id) {
        graphicCardService.deleteGraphicCardById(id);
    }
}


переделай автомобили в вендоры видеокарт, пример выше
MarkaService
package ru.edu.penzgtu.servise;


import org.springframework.stereotype.Service;
import ru.edu.penzgtu.dto.MarkaDto;
import ru.edu.penzgtu.entity.Marka;
import ru.edu.penzgtu.repo.MarkaRepository;
import ru.edu.penzgtu.servise.mapper.MarkaMapper;

import java.util.List;

@Service
public class MarkaServise {
    private final MarkaRepository markaRepisitory;
    private final MarkaMapper markaMapper;

    public MarkaServise(MarkaRepository markaRepisitory, MarkaMapper markaMapper) {
        this.markaRepisitory = markaRepisitory;
        this.markaMapper = markaMapper;
    }

    public List<MarkaDto> findAllMarks() {
        return markaMapper.toListDto(markaRepisitory.findAll());
    }
    
    public MarkaDto findMarkaById(Long id) {
        Marka marka = markaRepisitory.findById(id)
                .orElseThrow(() -> new RuntimeException("Marka not found"));
        return markaMapper.toDto(marka);
    }
    
    public void saveMarka (MarkaDto markaDto) {
        Marka marka = markaMapper.toEntity(markaDto);
        markaRepisitory.save(marka);
    }
    
    public  void updateMarka (MarkaDto newMarka) {
        Marka oldMarka = markaRepisitory.findById(newMarka.getId())
            .orElseThrow(() -> new RuntimeException("Marka not found"));

        oldMarka.setName (newMarka.getName());
    
        markaRepisitory.save(oldMarka);
    }
    
    public void deleteMarkaById(Long id) {
        markaRepisitory.deleteById(id);
    }
}


CarService
package ru.edu.penzgtu.servise;


import org.springframework.stereotype.Service;
import ru.edu.penzgtu.dto.CarDto;
import ru.edu.penzgtu.entity.Car;
import ru.edu.penzgtu.repo.CarRepository;
import ru.edu.penzgtu.servise.mapper.CarMapper;

import java.util.List;

@Service
public class CarServise {
    private final CarRepository carRepisitory;
    private final CarMapper carMapper;

    public CarServise(CarRepository carRepisitory, CarMapper carMapper) {
        this.carRepisitory = carRepisitory;
        this.carMapper = carMapper;
    }

    public List<CarDto> findAllCars() {
        return carMapper.toListDto(carRepisitory.findAll());
    }

    public CarDto findCarById(Long id) {
        Car car = carRepisitory.findById(id)
                .orElseThrow(()-> new RuntimeException("Car not found"));

        return carMapper.toDto(car);
    }

    public void saveCar (CarDto carDto) {
        Car car = carMapper.toEntity(carDto);
        carRepisitory.save(car);
    }

    public  void updateCar (CarDto newCar) {
        Car oldCar = carRepisitory.findById(newCar.getId())
                .orElseThrow(() -> new RuntimeException("car not found"));

        oldCar.setName (newCar.getName());

        carRepisitory.save(oldCar);
    }

    public void deleteCarById(Long id) {
        carRepisitory.deleteById(id);
    }
}

MarkaController.java
package ru.edu.penzgtu.controller;


import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.http.HttpStatus;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import ru.edu.penzgtu.dto.MarkaDto;
import ru.edu.penzgtu.servise.MarkaServise;

import javax.validation.constraints.Min;
import java.util.List;
@Validated
@RestController
@RequestMapping("/marks")
@Tag(name = "Марки", description = "Операции над марками")
public class MarkaController {
    private final MarkaServise markaServise;

    public MarkaController(MarkaServise markaServise) {
        this.markaServise = markaServise;
    }

    @Operation(
            summary = "Получение всех марок" ,description = "Позволяет выгрузитиь все марки из БД"
    )

    @GetMapping
    public List<MarkaDto> findAll() {
        return  markaServise.findAllMarks();
    }

    @Operation(
            summary = "получение марка по ID", description = "Позволяет выгрузить одну марку по ID из БД"
    )

    @GetMapping("/marka/{id}")
    public MarkaDto getById(@PathVariable @Min(0) long id) {return  markaServise.findMarkaById(id);}

    @PostMapping
    @ResponseStatus(HttpStatus.CREATED)
    public void createMarka(@RequestBody MarkaDto marka) {markaServise.saveMarka(marka);}

    @Operation(
            summary = "Обновить данные о марке" ,description = "Позволяет обновить информаицию о марке в БД"
    )

    @PutMapping("/Marka/")
    public void  updateMarka(@RequestBody MarkaDto marka) {
        markaServise.updateMarka(marka);
    }

    @Operation(
            summary = "Удалить марку по ID", description = "Позволяет удалить марку по ID из БД"
    )

    @DeleteMapping("/marka/{id}")
    @ResponseStatus(HttpStatus.NO_CONTENT)
    public  void deleteMarka(@PathVariable @Min(0) long id) {
        markaServise.deleteMarkaById(id);
    }
}

CarController.java
package ru.edu.penzgtu.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.http.HttpStatus;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import ru.edu.penzgtu.dto.CarDto;
import ru.edu.penzgtu.servise.CarServise;

import javax.validation.Valid;
import javax.validation.constraints.Min;
import java.util.List;

@RestController
@RequestMapping("/cars")
@Validated
@Tag (name = "Модели", description = "Операции над моделями")
public class CarController {
    private final CarServise carServise;

    public CarController(CarServise carServise) {
        this.carServise = carServise;
    }

    @Operation(
            summary = "Получение всех моделей", description = "Позволяет выгрузить все модели из БД"
    )
    @GetMapping
    public List<CarDto> findAll() {
        return  carServise.findAllCars();
    }

    @Operation(
            summary = "Получение модели машины по ID", description = "Позволяет выгрузить одну марку машины по ID по БД"
    )

    @GetMapping("/car/{id}")
    public CarDto getById(@PathVariable @Min(0) long id) {
        return  carServise.findCarById(id);
    }

   @Operation(
           summary = "Создать модель", description = "Позволяет создать новую запись о модели в БД"
   )

    @PostMapping
    @ResponseStatus(HttpStatus.CREATED)
    public void createCar(@RequestBody @Valid CarDto car) {
        carServise.saveCar(car);
    }

    @Operation(
            summary = "Обновить данные о модели машины", description = "Позволяет обновить информацию о модели в БД"
    )

    @PutMapping("/Car/")
    public void  updateCar(@RequestBody @Valid CarDto car) {
        carServise.updateCar(car);
    }

    @Operation(
            summary = "Удалить модель по ID", description = "Позволяет удалить модель машины по ID в БД"
    )

    @DeleteMapping("/car/{id}")
    @ResponseStatus(HttpStatus.NO_CONTENT)
    public  void deleteCar(@PathVariable @Min(0) long id) {
        carServise.deleteCarById(id);
    }
}

CarMapper.java
package ru.edu.penzgtu.servise.mapper;


import org.springframework.stereotype.Service;
import ru.edu.penzgtu.dto.CarDto;
import ru.edu.penzgtu.entity.Car;
import ru.edu.penzgtu.entity.Marka;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class CarMapper {

    public List<CarDto> toListDto(List<Car> cars) {
        return cars.stream().map(this::toDto).collect(Collectors.toList());
    }

    public  CarDto toDto(Car car) {
        CarDto dto = new CarDto();
        dto.setId(car.getId());

        dto.setName(car.getName());

        dto.setMarks(car.getMarks().stream().map(Marka::getName)
                .collect(Collectors.toList()));

        return dto;
    }

    public Car toEntity(CarDto carDto) {
        Car car = new Car();
        car.setId(car.getId());
        car.setName(carDto.getName());
        return car;
    }
}


MarkaMapper.java
package ru.edu.penzgtu.servise.mapper;


import org.springframework.stereotype.Service;
import ru.edu.penzgtu.dto.CarDto;
import ru.edu.penzgtu.entity.Car;
import ru.edu.penzgtu.entity.Marka;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class CarMapper {

    public List<CarDto> toListDto(List<Car> cars) {
        return cars.stream().map(this::toDto).collect(Collectors.toList());
    }

    public  CarDto toDto(Car car) {
        CarDto dto = new CarDto();
        dto.setId(car.getId());

        dto.setName(car.getName());

        dto.setMarks(car.getMarks().stream().map(Marka::getName)
                .collect(Collectors.toList()));

        return dto;
    }

    public Car toEntity(CarDto carDto) {
        Car car = new Car();
        car.setId(car.getId());
        car.setName(carDto.getName());
        return car;
    }
}