Добавлены сущности, не полностью

This commit is contained in:
ArtemEmelyanov 2023-03-20 16:04:15 +04:00
parent 63c115f8be
commit 4b71c89826
15 changed files with 117 additions and 22 deletions

View File

@ -13,6 +13,9 @@ repositories {
} }
dependencies { dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'com.h2database:h2:2.1.210'
implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'org.springframework.boot:spring-boot-starter-test'
} }

View File

@ -1,11 +1,11 @@
package ru.IP_LabWorks.IP.configuration; package ru.IP_LabWorks.IP.TypeCalculator.configuration;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import ru.IP_LabWorks.IP.domain.TypeArray; import ru.IP_LabWorks.IP.TypeCalculator.domain.TypeInt;
import ru.IP_LabWorks.IP.domain.TypeDouble; import ru.IP_LabWorks.IP.TypeCalculator.domain.TypeArray;
import ru.IP_LabWorks.IP.domain.TypeInt; import ru.IP_LabWorks.IP.TypeCalculator.domain.TypeDouble;
import ru.IP_LabWorks.IP.domain.TypeString; import ru.IP_LabWorks.IP.TypeCalculator.domain.TypeString;
@Configuration @Configuration
public class TypeConfiguration { public class TypeConfiguration {

View File

@ -1,11 +1,9 @@
package ru.IP_LabWorks.IP.controllers; package ru.IP_LabWorks.IP.TypeCalculator.controllers;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import ru.IP_LabWorks.IP.domain.ITypeInterface; import ru.IP_LabWorks.IP.TypeCalculator.service.TypeService;
import ru.IP_LabWorks.IP.service.TypeService;
@RestController @RestController
public class MainController { public class MainController {

View File

@ -1,4 +1,4 @@
package ru.IP_LabWorks.IP.domain; package ru.IP_LabWorks.IP.TypeCalculator.domain;
public interface ITypeInterface<T> { public interface ITypeInterface<T> {
T Method1(T value1, T value2); T Method1(T value1, T value2);

View File

@ -1,6 +1,5 @@
package ru.IP_LabWorks.IP.domain; package ru.IP_LabWorks.IP.TypeCalculator.domain;
import java.lang.reflect.Array;
import java.util.ArrayList; import java.util.ArrayList;
public class TypeArray implements ITypeInterface<ArrayList<Integer>> { public class TypeArray implements ITypeInterface<ArrayList<Integer>> {

View File

@ -1,4 +1,4 @@
package ru.IP_LabWorks.IP.domain; package ru.IP_LabWorks.IP.TypeCalculator.domain;
public class TypeDouble implements ITypeInterface<Double> { public class TypeDouble implements ITypeInterface<Double> {

View File

@ -1,4 +1,4 @@
package ru.IP_LabWorks.IP.domain; package ru.IP_LabWorks.IP.TypeCalculator.domain;
public class TypeInt implements ITypeInterface<Integer> { public class TypeInt implements ITypeInterface<Integer> {

View File

@ -1,4 +1,4 @@
package ru.IP_LabWorks.IP.domain; package ru.IP_LabWorks.IP.TypeCalculator.domain;
public class TypeString implements ITypeInterface<String> { public class TypeString implements ITypeInterface<String> {

View File

@ -1,13 +1,10 @@
package ru.IP_LabWorks.IP.service; package ru.IP_LabWorks.IP.TypeCalculator.service;
import ru.IP_LabWorks.IP.domain.ITypeInterface; import ru.IP_LabWorks.IP.TypeCalculator.domain.ITypeInterface;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Service @Service

View File

@ -0,0 +1,12 @@
package ru.IP_LabWorks.IP.University.Model;
import jakarta.persistence.*;
@Entity
@Table(name = "groups")
public class Group {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;
}

View File

@ -0,0 +1,39 @@
package ru.IP_LabWorks.IP.University.Model;
import jakarta.persistence.*;
import java.util.List;
import java.util.Objects;
@Entity
@Table(name = "students")
public class Student {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;
private Integer age;
@ManyToMany(cascade = CascadeType.ALL)
@JoinTable(name = "student_subject",
joinColumns = @JoinColumn(name = "student_id"),
inverseJoinColumns = @JoinColumn(name = "subject_id"))
private List<Subject> subjects;
public Student(String name, Integer age) {
this.name = name;
this.age = age;
}
public Long getId() { return id; }
public String getName() { return name; }
public void setName(String name) { this.name = name; }
public Integer getAge() { return age;}
public void setAge(Integer age) { this.age = age; }
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Student student = (Student) o;
return Objects.equals(id, student.id);
}
}

View File

@ -0,0 +1,33 @@
package ru.IP_LabWorks.IP.University.Model;
import jakarta.persistence.*;
import java.util.List;
import java.util.Objects;
@Entity
@Table(name = "subjects")
public class Subject {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;
@ManyToMany(mappedBy = "subjects")
private List<Student> students;
public Subject(String name) {
this.name = name;
}
public Long getId() { return id; }
public String getName() { return name; }
public void setName(String name) { this.name = name; }
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Subject subject = (Subject) o;
return Objects.equals(id, subject.id);
}
}

View File

@ -0,0 +1,4 @@
package ru.IP_LabWorks.IP.University.Service;
public class StudentService {
}

View File

@ -1 +1,11 @@
spring.main.banner-mode=off
#server.port=8080
spring.datasource.url=jdbc:h2:file:./data
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=password
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.jpa.hibernate.ddl-auto=update
spring.h2.console.enabled=true
spring.h2.console.settings.trace=false
spring.h2.console.settings.web-allow-others=false

View File

@ -4,7 +4,7 @@ import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import ru.IP_LabWorks.IP.service.TypeService; import ru.IP_LabWorks.IP.TypeCalculator.service.TypeService;
@SpringBootTest @SpringBootTest
class IpApplicationTests { class IpApplicationTests {