вот код, запомни его
Pom.xml:
<?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>
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-annotations</artifactId>
<version>2.2.8</version>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.6.14</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</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 io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.info.Contact;
import io.swagger.v3.oas.annotations.info.Info;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;

@OpenAPIDefinition(
info = @Info(
title = “PenzGTU Java Lab API”,
description = “Api fro labs”, version = “1.0.0”,
contact = @Contact(
name = “Student PenzGTU”,
email = “<PRESIDIO_ANONYMIZED_EMAIL_ADDRESS>”
)
)
)

@SpringBootApplication
@EnableWebMvc
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 javax.validation.constraints.NotNull;
import java.util.List;
import java.util.Objects;

@Entity
@Table(name = “vendors”)
public class Vendor {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = “id”)
private Long id;

@NotNull
@Column(name = “name”)
private String name;

@ManyToMany(cascade = CascadeType.ALL)
@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 Vendor() {
}

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;
}

@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(name = “graphic_cards”)
public class GraphicCard {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = “id”)
private Long id;

@Column(name = “name”)
private String name;

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

public GraphicCard() {
}

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;
}

@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);
}
}

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> {
}

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> {
}

VendorService.java

package ru.edu.penzgtu.service;

import org.springframework.stereotype.Service;
import ru.edu.penzgtu.dto.VendorDto;
import ru.edu.penzgtu.entity.Vendor;
import ru.edu.penzgtu.repo.VendorRepository;
import ru.edu.penzgtu.service.mapper.VendorMapper;

import java.util.List;

@Service
public class VendorService {
private final VendorRepository vendorRepository;
private final VendorMapper vendorMapper;

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

public List<VendorDto> findAllVendors() {
return vendorMapper.toListDto(vendorRepository.findAll());
}

public VendorDto findVendorById(Long id) {
Vendor vendor = vendorRepository.findById(id)
.orElseThrow(() -> new RuntimeException(“Vendor not found”));
return vendorMapper.toDto(vendor);
}

public void saveVendor(VendorDto vendorDto) {
Vendor vendor = vendorMapper.toEntity(vendorDto);
vendorRepository.save(vendor);
}

public void updateVendor(VendorDto 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.dto.GraphicCardDto;
import ru.edu.penzgtu.entity.GraphicCard;
import ru.edu.penzgtu.repo.GraphicCardRepository;
import ru.edu.penzgtu.service.mapper.GraphicCardMapper;

import java.util.List;

@Service
public class GraphicCardService {
private final GraphicCardRepository graphicCardRepository;
private final GraphicCardMapper graphicCardMapper;

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

public List<GraphicCardDto> findAllGraphicCards() {
return graphicCardMapper.toListDto(graphicCardRepository.findAll());
}

public GraphicCardDto findGraphicCardById(Long id) {
GraphicCard graphicCard = graphicCardRepository.findById(id)
.orElseThrow(() -> new RuntimeException(“GraphicCard not found”));
return graphicCardMapper.toDto(graphicCard);
}

public void saveGraphicCard(GraphicCardDto graphicCardDto) {
GraphicCard graphicCard = graphicCardMapper.toEntity(graphicCardDto);
graphicCardRepository.save(graphicCard);
}

public void updateGraphicCard(GraphicCardDto 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 io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.;
import ru.edu.penzgtu.dto.VendorDto;
import ru.edu.penzgtu.service.VendorService;

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

@RestController
@RequestMapping(“/vendors”)
@Tag(name = “Vendors”, description = “Operations related to vendors”)
public class VendorController {
private final VendorService vendorService;

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

@Operation(
summary = “Get all vendors”, description = “Fetch all vendors from the database”
)
@GetMapping
public List<VendorDto> findAll() {
return vendorService.findAllVendors();
}

@Operation(
summary = “Get a vendor by ID”, description = “Fetch a single vendor by ID from the database”
)
@GetMapping(“/vendor/{id}”)
public VendorDto getById(@PathVariable @Min(0) long id) {
return vendorService.findVendorById(id);
}

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

@Operation(
summary = “Update vendor details”, description = “Update the details of a vendor in the database”
)
@PutMapping(“/vendor”)
public void updateVendor(@RequestBody @Valid VendorDto vendor) {
vendorService.updateVendor(vendor);
}

@Operation(
summary = “Delete a vendor by ID”, description = “Delete a vendor by ID from the database”
)
@DeleteMapping(“/vendor/{id}”)
@ResponseStatus(HttpStatus.NO_CONTENT)
public void deleteVendor(@PathVariable @Min(0) long id) {
vendorService.deleteVendorById(id);
}
}

GraphicCardController.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.web.bind.annotation.;
import ru.edu.penzgtu.dto.GraphicCardDto;
import ru.edu.penzgtu.service.GraphicCardService;

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

@RestController
@RequestMapping(“/graphic-cards”)
@Tag(name = “Graphic Cards”, description = “Operations related to graphic cards”)
public class GraphicCardController {
private final GraphicCardService graphicCardService;

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

@Operation(
summary = “Get all graphic cards”, description = “Fetch all graphic cards from the database”
)
@GetMapping
public List<GraphicCardDto> findAll() {
return graphicCardService.findAllGraphicCards();
}

@Operation(
summary = “Get a graphic card by ID”, description = “Fetch a single graphic card by ID from the database”
)
@GetMapping(“/graphic-card/{id}”)
public GraphicCardDto getById(@PathVariable @Min(0) long id) {
return graphicCardService.findGraphicCardById(id);
}

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

@Operation(
summary = “Update graphic card details”, description = “Update the details of a graphic card in the database”
)
@PutMapping(“/graphic-card”)
public void updateGraphicCard(@RequestBody @Valid GraphicCardDto graphicCard) {
graphicCardService.updateGraphicCard(graphicCard);
}

@Operation(
summary = “Delete a graphic card by ID”, description = “Delete a graphic card by ID from the database”
)
@DeleteMapping(“/graphic-card/{id}”)
@ResponseStatus(HttpStatus.NO_CONTENT)
public void deleteGraphicCard(@PathVariable @Min(0) long id) {
graphicCardService.deleteGraphicCardById(id);
}
}

VendorMapper.java

package ru.edu.penzgtu.service.mapper;

import org.springframework.stereotype.Service;
import ru.edu.penzgtu.dto.VendorDto;
import ru.edu.penzgtu.entity.Vendor;

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

@Service
public class VendorMapper {
public List<VendorDto> toListDto(List<Vendor> vendors) {
return vendors.stream().map(this::toDto).collect(Collectors.toList());
}

public VendorDto toDto(Vendor vendor) {
VendorDto dto = new VendorDto();
dto.setId(vendor.getId());
dto.setName(vendor.getName());
return dto;
}

public Vendor toEntity(VendorDto vendorDto) {
Vendor vendor = new Vendor();
vendor.setId(vendorDto.getId());
vendor.setName(vendorDto.getName());
return vendor;
}
}

GraphicCardMapper.java

package ru.edu.penzgtu.service.mapper;

import org.springframework.stereotype.Service;
import ru.edu.penzgtu.dto.GraphicCardDto;
import ru.edu.penzgtu.entity.GraphicCard;
import ru.edu.penzgtu.entity.Vendor;

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

@Service
public class GraphicCardMapper {

public List<GraphicCardDto> toListDto(List<GraphicCard> graphicCards) {
return graphicCards.stream().map(this::toDto).collect(Collectors.toList());
}

public GraphicCardDto toDto(GraphicCard graphicCard) {
GraphicCardDto dto = new GraphicCardDto();
dto.setId(graphicCard.getId());
dto.setName(graphicCard.getName());
dto.setVendors(graphicCard.getVendors().stream().map(Vendor::getName)
.collect(Collectors.toList()));
return dto;
}

public GraphicCard toEntity(GraphicCardDto graphicCardDto) {
GraphicCard graphicCard = new GraphicCard();
graphicCard.setId(graphicCardDto.getId());
graphicCard.setName(graphicCardDto.getName());
return graphicCard;
}
}