Compare commits

...

14 Commits

Author SHA1 Message Date
maxnes3
f7ad06d262 Сдал 2023-04-18 11:31:48 +04:00
maxnes3
29b448f959 Доп задания сделаны 2023-04-16 18:18:56 +04:00
maxnes3
10ba7def55 сущности готовы 2023-03-20 15:09:57 +04:00
maxnes3
402b25c5cc улучшил 2023-03-20 13:38:43 +04:00
maxnes3
2855793c7b big-ass tests final 2023-03-20 00:40:30 +04:00
maxnes3
3dee9b728b big-ass tests2 2023-03-20 00:39:31 +04:00
maxnes3
0b8348bdbc big-ass tests 2023-03-20 00:05:11 +04:00
maxnes3
309e915e7b big-ass changes 2023-03-18 22:56:06 +04:00
maxnes3
f3f31c1a03 tests complete 2023-02-21 12:42:12 +04:00
maxnes3
51b4b1b53e need to add tests 2023-02-20 16:38:27 +04:00
maxnes3
04f358067f done 2023-02-19 23:51:57 +04:00
maxnes3
4fb650e3d1 add frontend 2023-02-19 21:44:05 +04:00
Макс Бондаренко
673233ea88 labwork done 2023-02-06 21:36:17 +04:00
Макс Бондаренко
02eae37b14 4 fetch 2023-02-06 15:07:27 +04:00
39 changed files with 7834 additions and 2 deletions

View File

@ -15,6 +15,10 @@ repositories {
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
implementation 'com.h2database:h2:2.1.210'
implementation 'org.hibernate.validator:hibernate-validator:7.0.1.Final'
implementation group: 'org.springdoc', name: 'springdoc-openapi-ui', version: '1.6.5'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

BIN
data.mv.db Normal file

Binary file not shown.

1290
data.trace.db Normal file

File diff suppressed because it is too large Load Diff

View File

@ -2,8 +2,10 @@ package ru.ip.labworks.labworks;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
@RestController
public class LabworksApplication {
public static void main(String[] args) {

View File

@ -0,0 +1,4 @@
package ru.ip.labworks.labworks.bookshop.controller;
public class AuthorController {
}

View File

@ -0,0 +1,4 @@
package ru.ip.labworks.labworks.bookshop.controller;
public class BookController {
}

View File

@ -0,0 +1,4 @@
package ru.ip.labworks.labworks.bookshop.controller;
public class GenreController {
}

View File

@ -0,0 +1,70 @@
package ru.ip.labworks.labworks.bookshop.model;
import javax.persistence.*;
import java.util.*;
@Entity
public class Author {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String firstname;
private String lastname;
@Lob
private byte[] photo;
@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(name = "authors_books",
joinColumns = @JoinColumn(name = "author_fk"),
inverseJoinColumns = @JoinColumn(name = "book_fk"))
private List<Book> books;
public Author(){}
public Author(String firstname, String lastname, byte[] photo){
this.firstname = firstname;
this.lastname = lastname;
this.photo = photo;
}
public Long getId(){return id;}
public String getFirstnameName(){return firstname;}
public void setFirstnameName(String firstname){this.firstname = firstname;}
public String getLastName(){return lastname;}
public void setLastName(String lastname){this.lastname = lastname;}
public byte[] getPhoto(){return photo;}
public void setPhoto(byte[] photo){this.photo = photo;}
public List<Book> getBooks(){return books;}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Author author = (Author) o;
return Objects.equals(id, author.id);
}
@Override
public int hashCode() {
return Objects.hash(id);
}
@Override
public String toString() {
return "Author{" +
"id=" + id +
", firstname='" + firstname + '\'' +
", lastname='" + lastname + '\'' +
'}';
}
public void addBook(Book book) {
books.add(book);
}
public void removeBook(Book book) {
books.remove(book);
}
}

View File

@ -0,0 +1,77 @@
package ru.ip.labworks.labworks.bookshop.model;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
import javax.persistence.*;
import java.util.*;
@Entity
public class Book {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String name;
private Date release;
@Lob
private byte[] cover;
@ManyToMany
@LazyCollection(LazyCollectionOption.FALSE)
@JoinTable(name = "books_genres",
joinColumns = @JoinColumn(name = "book_fk"),
inverseJoinColumns = @JoinColumn(name = "genre_fk"))
private List<Genre> genres;
@ManyToMany(fetch = FetchType.EAGER, mappedBy = "books")
private List<Author> authors;
public Book(){}
public Book(String name,Date release, byte[] cover){
this.name = name;
this.release = release;
this.cover = cover;
}
public Long getId(){return id;}
public String getName(){return name;}
public void setName(String name){this.name = name;}
public Date getRelease(){return release;}
public void setRelease(Date release){this.release = release;}
public byte[] getCover(){return cover;}
public void setCover(byte[] cover){this.cover = cover;}
public List<Genre> getGenres(){return genres;}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Book book = (Book) o;
return Objects.equals(id, book.id);
}
@Override
public int hashCode() {
return Objects.hash(id);
}
@Override
public String toString() {
return "Book{" +
"id=" + id +
", name='" + name + '\'' +
", release='" + release + '\'' +
'}';
}
public void addGenre(Genre genre) {
genres.add(genre);
}
public void removeGenre(Genre genre) {
genres.remove(genre);
}
}

View File

@ -0,0 +1,43 @@
package ru.ip.labworks.labworks.bookshop.model;
import javax.persistence.*;
import java.util.*;
@Entity
public class Genre {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String name;
public Genre(){}
public Genre(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;
Genre genre = (Genre) o;
return Objects.equals(id, genre.id);
}
@Override
public int hashCode() {
return Objects.hash(id);
}
@Override
public String toString() {
return "Genre{" +
"id=" + id +
", name='" + name + '\'' +
'}';
}
}

View File

@ -0,0 +1,105 @@
package ru.ip.labworks.labworks.bookshop.service;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import ru.ip.labworks.labworks.bookshop.model.*;
import org.hibernate.query.Query;
import javax.persistence.EntityManager;
import javax.persistence.EntityNotFoundException;
import javax.persistence.PersistenceContext;
import javax.persistence.Tuple;
import java.io.File;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Service
public class AuthorService {
@PersistenceContext
private EntityManager entityManager;
@Transactional
public Author addAuthor(String firstname, String lastname, File photo){
if (!StringUtils.hasText(firstname) || !StringUtils.hasText(lastname)) {
throw new IllegalArgumentException("Author firstname and lastname is null or empty");
}
final Author author = new Author(firstname, lastname, ImageHelper.ImageToByte(photo));
entityManager.persist(author);
return author;
}
@Transactional(readOnly = true)
public Author findAuthor(Long id) {
final Author author = entityManager.find(Author.class, id);
if (author == null) {
throw new EntityNotFoundException(String.format("Author with id [%s] is not found", id));
}
return author;
}
@Transactional(readOnly = true)
public List<Author> findAllAuthors() {
return entityManager.createQuery("select s from Author s", Author.class).getResultList();
}
@Transactional
public Author updateAuthor(Long id, String firstname, String lastname, File photo){
if (!StringUtils.hasText(firstname) || !StringUtils.hasText(lastname)) {
throw new IllegalArgumentException("Author firstname and lastname is null or empty");
}
final Author currentAuthor = findAuthor(id);
currentAuthor.setFirstnameName(firstname);
currentAuthor.setLastName(lastname);
currentAuthor.setPhoto(ImageHelper.ImageToByte(photo));
return entityManager.merge(currentAuthor);
}
@Transactional
public Author deleteAuthor(Long id) {
final Author currentAuthor = findAuthor(id);
entityManager.remove(currentAuthor);
return currentAuthor;
}
@Transactional
public void deleteAllAuthors() {
entityManager.createQuery("delete from Author").executeUpdate();
}
@Transactional
public void addBookToAuthor(Long id, Book book){
final Author author = findAuthor(id);
if(author == null){
throw new IllegalArgumentException("Author with id " + id + " not found");
}
author.addBook(entityManager.find(book.getClass(), book.getId()));
entityManager.merge(author);
}
@Transactional
public void removeBookFromAuthor(Long id, Book book){
final Author author = findAuthor(id);
if(author == null){
throw new IllegalArgumentException("Author with id " + id + " not found");
}
author.removeBook(entityManager.find(book.getClass(), book.getId()));
entityManager.merge(author);
}
@Transactional
public Map<String, List<String>> AllAuthorsAndBooks(){
List<Object[]> temp = entityManager.createQuery("select a.lastname as author, b.name as book " +
"from Author a " +
"join a.books b " +
"group by a.id").getResultList();
return temp.stream()
.collect(
Collectors.groupingBy(
o -> (String) o[0],
Collectors.mapping( o -> (String) o[1], Collectors.toList() )
)
);
}
}

View File

@ -0,0 +1,101 @@
package ru.ip.labworks.labworks.bookshop.service;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import ru.ip.labworks.labworks.bookshop.model.Book;
import ru.ip.labworks.labworks.bookshop.model.Genre;
import javax.persistence.EntityManager;
import javax.persistence.EntityNotFoundException;
import javax.persistence.PersistenceContext;
import java.io.File;
import java.text.SimpleDateFormat;
import java.text.ParseException;
import java.util.*;
@Service
public class BookService {
@PersistenceContext
private EntityManager entityManager;
private Date ParseToDate(String s){
Date release;
try {
release = new SimpleDateFormat("dd.MM.yyyy").parse(s);
}
catch (ParseException ex){
return null;
}
return release;
}
@Transactional
public Book addBook(String name, String release, File cover){
if (!StringUtils.hasText(name) || !StringUtils.hasText(release)) {
throw new IllegalArgumentException("Book name and release is null or empty");
}
final Book book = new Book(name, ParseToDate(release), ImageHelper.ImageToByte(cover));
entityManager.persist(book);
return book;
}
@Transactional(readOnly = true)
public Book findBook(Long id) {
final Book book = entityManager.find(Book.class, id);
if (book == null) {
throw new EntityNotFoundException(String.format("Book with id [%s] is not found", id));
}
return book;
}
@Transactional(readOnly = true)
public List<Book> findAllBooks() {
return entityManager.createQuery("select s from Book s", Book.class).getResultList();
}
@Transactional
public Book updateBook(Long id, String name, String release, File cover) {
if (!StringUtils.hasText(name) || !StringUtils.hasText(release)) {
throw new IllegalArgumentException("Book name and release is null or empty");
}
final Book currentBook = findBook(id);
currentBook.setName(name);
currentBook.setRelease(ParseToDate(release));
currentBook.setCover(ImageHelper.ImageToByte(cover));
return entityManager.merge(currentBook);
}
@Transactional
public Book deleteBook(Long id) {
final Book currentBook = findBook(id);
entityManager.remove(currentBook);
return currentBook;
}
@Transactional
public void deleteAllBooks() {
entityManager.createQuery("delete from Book").executeUpdate();
}
@Transactional
public void addGenreToBook(Long id, Genre genre){
final Book book = findBook(id);
if(book == null){
throw new IllegalArgumentException("Book with id " + id + " not found");
}
book.addGenre(entityManager.find(genre.getClass(), genre.getId()));
entityManager.merge(book);
}
@Transactional
public void removeGenreFromBook(Long id, Genre genre){
final Book book = findBook(id);
if(book == null){
throw new IllegalArgumentException("Book with id " + id + " not found");
}
book.removeGenre(entityManager.find(genre.getClass(), genre.getId()));
entityManager.merge(book);
}
}

View File

@ -0,0 +1,63 @@
package ru.ip.labworks.labworks.bookshop.service;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import ru.ip.labworks.labworks.bookshop.model.Genre;
import javax.persistence.EntityManager;
import javax.persistence.EntityNotFoundException;
import javax.persistence.PersistenceContext;
import java.util.List;
@Service
public class GenreService {
@PersistenceContext
private EntityManager entityManager;
@Transactional
public Genre addGenre(String name){
if (!StringUtils.hasText(name)) {
throw new IllegalArgumentException("Genre name is null or empty");
}
final Genre genre = new Genre(name);
entityManager.persist(genre);
return genre;
}
@Transactional(readOnly = true)
public Genre findGenre(Long id) {
final Genre genre = entityManager.find(Genre.class, id);
if (genre == null) {
throw new EntityNotFoundException(String.format("Genre with id [%s] is not found", id));
}
return genre;
}
@Transactional(readOnly = true)
public List<Genre> findAllGenres() {
return entityManager.createQuery("select s from Genre s", Genre.class).getResultList();
}
@Transactional
public Genre updateGenre(Long id, String name) {
if (!StringUtils.hasText(name)) {
throw new IllegalArgumentException("Genre name is null or empty");
}
final Genre currentGenre = findGenre(id);
currentGenre.setName(name);
return entityManager.merge(currentGenre);
}
@Transactional
public Genre deleteGenre(Long id) {
final Genre currentGenre = findGenre(id);
entityManager.remove(currentGenre);
return currentGenre;
}
@Transactional
public void deleteAllGenres() {
entityManager.createQuery("delete from Genre").executeUpdate();
}
}

View File

@ -0,0 +1,20 @@
package ru.ip.labworks.labworks.bookshop.service;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.File;
public class ImageHelper {
public static byte[] ImageToByte(File image){
try {
BufferedImage bufferedImage = ImageIO.read(image);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
ImageIO.write(bufferedImage, "jpg", byteArrayOutputStream);
return byteArrayOutputStream.toByteArray();
}
catch (Exception ex) {
return null;
}
}
}

View File

@ -0,0 +1,35 @@
package ru.ip.labworks.labworks.calculator.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import ru.ip.labworks.labworks.calculator.service.CalculatorService;
@RestController
public class UserController {
private CalculatorService calculatorService;
public UserController(CalculatorService calculatorService){
this.calculatorService = calculatorService;
}
@GetMapping("/+")
public String workPlus(@RequestParam String type, @RequestParam Object arg1, @RequestParam Object arg2){
return (String) calculatorService.Plus(type, arg1, arg2);
}
@GetMapping("/-")
public String workMinus(@RequestParam String type, @RequestParam Object arg1, @RequestParam Object arg2){
return (String) calculatorService.Minus(type, arg1, arg2);
}
@GetMapping("/*")
public String workMulti(@RequestParam String type, @RequestParam Object arg1, @RequestParam Object arg2){
return (String) calculatorService.Multi(type, arg1, arg2);
}
@GetMapping("/:")
public String workDiv(@RequestParam String type, @RequestParam Object arg1, @RequestParam Object arg2){
return (String) calculatorService.Div(type, arg1, arg2);
}
}

View File

@ -0,0 +1,48 @@
package ru.ip.labworks.labworks.calculator.domain;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
@Component(value = "array")
public class ArrayCalculator implements ITypeCalculator<ArrayList<String>> {
@Override
public ArrayList<String> Plus(ArrayList<String> arg1, ArrayList<String> arg2) {
ArrayList<String> result = new ArrayList<>();
for (int i = 0; i < Math.min(arg1.size(), arg2.size()); ++i){
result.add(arg1.get(i) + arg2.get(i));
}
return result;
}
@Override
public ArrayList<String> Minus(ArrayList<String> arg1, ArrayList<String> arg2) {
ArrayList<String> result = new ArrayList<>();
for (int i = 0; i < Math.min(arg1.size(), arg2.size()); ++i){
result.add(arg1.get(i).replace(arg2.get(i), ""));
}
return result;
}
@Override
public ArrayList<String> Multi(ArrayList<String> arg1, ArrayList<String> arg2) {
ArrayList<String> result = new ArrayList<>();
for (int i = 0; i < Math.min(arg1.size(), arg2.size()); ++i){
String temp = "";
for (int j = 0; j < Integer.parseInt(arg2.get(i)); ++j){
temp += arg1.get(i);
}
result.add(temp);
}
return result;
}
@Override
public ArrayList<String> Div(ArrayList<String> arg1, ArrayList<String> arg2) {
ArrayList<String> result = new ArrayList<>();
for (int i = 0; i < Math.min(arg1.size(), arg2.size()); ++i){
result.add(arg1.get(i).substring(0, Integer.parseInt(arg2.get(i))));
}
return result;
}
}

View File

@ -0,0 +1,9 @@
package ru.ip.labworks.labworks.calculator.domain;
public interface ITypeCalculator<T> {
T Plus(T arg1, T arg2);
T Minus(T arg1, T arg2);
T Multi(T arg1, T arg2);
T Div(T arg1, T arg2);
}

View File

@ -0,0 +1,26 @@
package ru.ip.labworks.labworks.calculator.domain;
import org.springframework.stereotype.Component;
@Component(value = "int")
public class IntCalculator implements ITypeCalculator<Integer>{
@Override
public Integer Plus(Integer arg1, Integer arg2) {
return arg1 + arg2;
}
@Override
public Integer Minus(Integer arg1, Integer arg2) {
return arg1 - arg2;
}
@Override
public Integer Multi(Integer arg1, Integer arg2) {
return arg1 * arg2;
}
@Override
public Integer Div(Integer arg1, Integer arg2) {
return arg1 / arg2;
}
}

View File

@ -0,0 +1,31 @@
package ru.ip.labworks.labworks.calculator.domain;
import org.springframework.stereotype.Component;
@Component(value = "string")
public class StringCalculator implements ITypeCalculator<String>{
@Override
public String Plus(String arg1, String arg2) {
return arg1 + arg2;
}
@Override
public String Minus(String arg1, String arg2) {
return arg1.replaceAll(arg2, "");
}
@Override
public String Multi(String arg1, String arg2) {
String result = "";
for (int i = 0; i < Integer.parseInt(arg2); ++i){
result += arg1;
}
return result;
}
@Override
public String Div(String arg1, String arg2) {
String result = arg1.substring(0, arg1.length() / Integer.parseInt(arg2));
return result;
}
}

View File

@ -0,0 +1,66 @@
package ru.ip.labworks.labworks.calculator.service;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;
import ru.ip.labworks.labworks.calculator.domain.ITypeCalculator;
import java.util.ArrayList;
import java.util.Arrays;
@Service
public class CalculatorService {
private final ApplicationContext applicationContext;
private ITypeCalculator typeCalculator;
private Object arg1;
private Object arg2;
public CalculatorService(ApplicationContext applicationContext){
this.applicationContext = applicationContext;
}
private boolean ValidateParams(Object value1, Object value2, String type){
typeCalculator = (ITypeCalculator)applicationContext.getBean(type);
try {
switch (type) {
case "int" -> {
arg1 = Integer.valueOf(value1.toString());
arg2 = Integer.valueOf(value2.toString());
}
case "array" -> {
arg1 = new ArrayList<>(Arrays.asList(value1.toString().split(",")));
arg2 = new ArrayList<>(Arrays.asList(value2.toString().split(",")));
}
case "string" -> {
arg1 = value1.toString();
arg2 = value2.toString();
}
}
}
catch (Exception ex){
return false;
}
return true;
}
public Object Plus(String type, Object arg1, Object arg2){
if(!ValidateParams(arg1,arg2,type)) return String.format("Неверные данные");
return String.format("%s", typeCalculator.Plus(this.arg1, this.arg2));
}
public Object Minus(String type, Object arg1, Object arg2){
if(!ValidateParams(arg1,arg2,type)) return String.format("Неверные данные");
return String.format("%s", typeCalculator.Minus(this.arg1, this.arg2));
}
public Object Multi(String type, Object arg1, Object arg2){
if(!ValidateParams(arg1,arg2,type)) return String.format("Неверные данные");
return String.format("%s", typeCalculator.Multi(this.arg1, this.arg2));
}
public Object Div(String type, Object arg1, Object arg2){
if(!ValidateParams(arg1,arg2,type)) return String.format("Неверные данные");
return String.format("%s", typeCalculator.Div(this.arg1, this.arg2));
}
}

View File

@ -0,0 +1,13 @@
package ru.ip.labworks.labworks.configuration;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class WebConfiguration implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**").allowedMethods("*");
}
}

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

@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
node_modules
dist
dist-ssr
*.local
# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

View File

@ -0,0 +1,7 @@
# Vue 3 + Vite
This template should help get you started developing with Vue 3 in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.
## Recommended IDE Setup
- [VS Code](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur) + [TypeScript Vue Plugin (Volar)](https://marketplace.visualstudio.com/items?itemName=Vue.vscode-typescript-vue-plugin).

View File

@ -0,0 +1,19 @@
{
"posts": [
{
"id": 1,
"title": "json-server",
"author": "typicode"
}
],
"comments": [
{
"id": 1,
"body": "some comment",
"postId": 1
}
],
"profile": {
"name": "typicode"
}
}

View File

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
<title>Data Type Calculator</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js" integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN" crossorigin="anonymous"></script>
</body>
</html>

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,26 @@
{
"name": "spa-vue",
"private": true,
"version": "1.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"fake-server": "json-server --watch data.json -p 8079",
"start": "npm-run-all --parallel dev fake-server",
"build": "vite build",
"preview": "vite preview"
},
"dependencies": {
"vue": "^3.2.41",
"vue-router": "^4.1.6",
"axios": "^1.1.3",
"bootstrap": "^5.2.2",
"@fortawesome/fontawesome-free": "^6.2.1"
},
"devDependencies": {
"vite": "^3.2.3",
"@vitejs/plugin-vue": "^3.2.0",
"npm-run-all": "^4.1.5",
"json-server": "^0.17.1"
}
}

View File

@ -0,0 +1,9 @@
<script setup>
</script>
<template>
<router-view>
</router-view>
</template>

View File

@ -0,0 +1,17 @@
<template>
<footer class="container pt-4 my-md-5 pt-md-5 text-center fixed-bottom border-top">
<div class="row">
<div class="col-12 col-md">
<h5 class=""><strong>End</strong></h5>
</div>
</div>
</footer>
</template>
<script>
export default {
}
</script>
<style scoped>
</style>

View File

@ -0,0 +1,11 @@
<template>
<header class="fixed-top">
<nav class="navbar navbar-expand-lg bg-primary" data-bs-theme="dark">
<div class="container">
<a class="navbar-brand" href="#">
<strong>{ DTC } Data Type Calculator</strong>
</a>
</div>
</nav>
</header>
</template>

View File

@ -0,0 +1,7 @@
import { createApp } from 'vue'
import App from './App.vue'
import router from "./router/router.js"
const app = createApp(App)
app.use(router).mount("#app");

View File

@ -0,0 +1,75 @@
<script>
import Header from '../components/Header.vue'
import Footer from '../components/Footer.vue'
export default{
components:{
Header,
Footer
},
data(){
return {
action: "",
type: "",
str_1: "",
str_2: "",
result: ""
}
},
methods:{
GetRepuest(){
if (this.action.length == 0 || this.str_1.length == 0 || this.str_2.length == 0){
console.warn("Invalid input to fetch!");
}
console.log("http://localhost:8080/" + this.action + "?type=" + this.type + "&arg1=" + this.str_1 + "&arg2=" + this.str_2)
fetch("http://localhost:8080/" + this.action + "?type=" + this.type + "&arg1=" + this.str_1 + "&arg2=" + this.str_2)
.then(res => res.text())
.then(res => {
this.result = res;
})
}
}
}
</script>
<template>
<Header></Header>
<main class="container" style="margin-top: 50pt;">
<div class="input-group mb-2 my-5">
<span class="input-group-text bg-primary text-white" id="basic-addon1"><strong>Действие:</strong></span>
<select class="form-select" aria-label="Default select example" v-model="action">
<option value="+">Plus(+)</option>
<option value="-">Minus(-)</option>
<option value="*">Multi(*)</option>
<option value=":">Div(\)</option>
</select>
</div>
<div class="input-group mb-2">
<span class="input-group-text bg-primary text-white" id="basic-addon1"><strong>Тип данных:</strong></span>
<select class="form-select" aria-label="Default select example" v-model="type">
<option value="int">Integer{}</option>
<option value="string">String"_"</option>
<option value="array">Array[]</option>
</select>
</div>
<div class="input-group mb-2">
<span class="input-group-text bg-primary text-white" id="basic-addon1"><strong>Аргумент1:</strong></span>
<input type="text" class="form-control" placeholder="Введите превую строку" v-model="str_1">
</div>
<div class="input-group mb-2">
<span class="input-group-text bg-primary text-white" id="basic-addon1"><strong>Аргумент2:</strong></span>
<input type="text" class="form-control" placeholder="Введите вторую строку" v-model="str_2">
</div>
<div class="input-group mb-2">
<span class="input-group-text bg-success text-white" id="basic-addon1"><strong>Вывод:</strong></span>
<input type="text" class="form-control" placeholder="Выводит рузультат здесь" v-model="result" readonly>
</div>
<div class="mb-2 d-flex justify-content-center">
<button type="submit" class="btn btn-success" @click.prevent="GetRepuest"><strong>GET</strong></button>
</div>
</main>
<Footer></Footer>
</template>
<style scoped>
</style>

View File

@ -0,0 +1,14 @@
import {createRouter, createWebHistory} from "vue-router"
import Index from '../pages/Index.vue'
const routes = [
{path: '/', component: Index},
]
const router = createRouter({
history: createWebHistory(),
linkActiveClass: 'active',
routes
})
export default router;

View File

@ -0,0 +1,7 @@
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [vue()],
})

View File

@ -0,0 +1,116 @@
package ru.ip.labworks.labworks;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import ru.ip.labworks.labworks.bookshop.model.Author;
import ru.ip.labworks.labworks.bookshop.model.Book;
import ru.ip.labworks.labworks.bookshop.service.AuthorService;
import ru.ip.labworks.labworks.bookshop.service.BookService;
import javax.persistence.EntityNotFoundException;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@SpringBootTest
public class JpaAuthorTests {
@Autowired
AuthorService authorService;
@Autowired
BookService bookService;
@Test
void TestAddAuthor(){
authorService.deleteAllAuthors();
final Author author = authorService.addAuthor("test", "test", new File("D:\\Учёба\\Интернет программирование\\PIbd-22_Bondarenko_M.S._IP\\src\\main\\resources\\SK.jpg"));
Assertions.assertNotNull(author.getId());
}
@Test
void TestFindAuthor(){
authorService.deleteAllAuthors();
final Author author = authorService.addAuthor("test", "test", new File("D:\\Учёба\\Интернет программирование\\PIbd-22_Bondarenko_M.S._IP\\src\\main\\resources\\SK.jpg"));
final Author findAuthor = authorService.findAuthor(author.getId());
Assertions.assertEquals(author, findAuthor);
}
@Test
void TestAuthorReadNotFound(){
authorService.deleteAllAuthors();
Assertions.assertThrows(EntityNotFoundException.class, () -> authorService.findAuthor(-1L));
}
@Test
void TestFindAllAuthor(){
authorService.deleteAllAuthors();
final Author author1 = authorService.addAuthor("Test1","Test1", new File("D:\\Учёба\\Интернет программирование\\PIbd-22_Bondarenko_M.S._IP\\src\\main\\resources\\SK.jpg"));
final Author author2 = authorService.addAuthor("Test2","Test2", new File("D:\\Учёба\\Интернет программирование\\PIbd-22_Bondarenko_M.S._IP\\src\\main\\resources\\SK.jpg"));
final List<Author> authors = authorService.findAllAuthors();
Assertions.assertEquals(authors.size(), 2);
}
@Test
void TestAuthorReadAllEmpty() {
authorService.deleteAllAuthors();
final List<Author> authors = authorService.findAllAuthors();
Assertions.assertEquals(authors.size(), 0);
}
@Test
void TestAuthorUpdate(){
authorService.deleteAllAuthors();
Author author = authorService.addAuthor("Test1","Test1", new File("D:\\Учёба\\Интернет программирование\\PIbd-22_Bondarenko_M.S._IP\\src\\main\\resources\\SK.jpg"));
author = authorService.updateAuthor(author.getId(), "Test2", "Test2", new File("D:\\Учёба\\Интернет программирование\\PIbd-22_Bondarenko_M.S._IP\\src\\main\\resources\\SK.jpg"));
Assertions.assertEquals(author.getFirstnameName(), "Test2");
Assertions.assertEquals(author.getLastName(), "Test2");
Assertions.assertNotNull(author.getPhoto());
}
@Test
void TestDeleteAuthor(){
authorService.deleteAllAuthors();
final Author author = authorService.addAuthor("Test","Test", new File("D:\\Учёба\\Интернет программирование\\PIbd-22_Bondarenko_M.S._IP\\src\\main\\resources\\SK.jpg"));
authorService.deleteAuthor(author.getId());
Assertions.assertThrows(EntityNotFoundException.class, () -> authorService.findAuthor(1L));
}
@Test
void TestAddBookToAuthor(){
authorService.deleteAllAuthors();
Author author = authorService.addAuthor("Test", "Test", new File("D:\\Учёба\\Интернет программирование\\PIbd-22_Bondarenko_M.S._IP\\src\\main\\resources\\SK.jpg"));
final Book book = bookService.addBook("Test2", "03.04.2023", new File("D:\\Учёба\\Интернет программирование\\PIbd-22_Bondarenko_M.S._IP\\src\\main\\resources\\glow.png"));
authorService.addBookToAuthor(author.getId(), book);
author = authorService.findAuthor(author.getId());
Assertions.assertEquals(author.getBooks().size(), 1);
bookService.deleteAllBooks();
}
@Test
void TestRemoveBookFromAuthor(){
authorService.deleteAllAuthors();
bookService.deleteAllBooks();
Author author = authorService.addAuthor("Test", "Test", new File("D:\\Учёба\\Интернет программирование\\PIbd-22_Bondarenko_M.S._IP\\src\\main\\resources\\SK.jpg"));
final Book book = bookService.addBook("Test2", "03.04.2023", new File("D:\\Учёба\\Интернет программирование\\PIbd-22_Bondarenko_M.S._IP\\src\\main\\resources\\glow.png"));
authorService.addBookToAuthor(author.getId(), book);
authorService.removeBookFromAuthor(author.getId(), book);
author = authorService.findAuthor(author.getId());
Assertions.assertEquals(author.getBooks().size(), 0);
}
@Test
void TestAllAB(){
authorService.deleteAllAuthors();
bookService.deleteAllBooks();
Author author = authorService.addAuthor("Test", "Test", new File("D:\\Учёба\\Интернет программирование\\PIbd-22_Bondarenko_M.S._IP\\src\\main\\resources\\SK.jpg"));
final Book book = bookService.addBook("Test2", "03.04.2023", new File("D:\\Учёба\\Интернет программирование\\PIbd-22_Bondarenko_M.S._IP\\src\\main\\resources\\glow.png"));
authorService.addBookToAuthor(author.getId(), book);
Map<String, List<String>> result = new HashMap<>();
List<String> temp = new ArrayList<>();
temp.add(book.getName());
result.put(author.getLastName(), temp);
Assertions.assertEquals(authorService.AllAuthorsAndBooks(), result);
Assertions.assertNotNull(authorService.AllAuthorsAndBooks());
}
}

View File

@ -0,0 +1,102 @@
package ru.ip.labworks.labworks;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import ru.ip.labworks.labworks.bookshop.model.Book;
import ru.ip.labworks.labworks.bookshop.model.Genre;
import ru.ip.labworks.labworks.bookshop.service.BookService;
import ru.ip.labworks.labworks.bookshop.service.GenreService;
import javax.imageio.ImageIO;
import javax.persistence.EntityNotFoundException;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.util.List;
@SpringBootTest
public class JpaBookTests {
@Autowired
BookService bookService;
@Autowired
GenreService genreService;
@Test
void TestAddBook(){
bookService.deleteAllBooks();
final Book book = bookService.addBook("test", "03.04.2023", new File("D:\\Учёба\\Интернет программирование\\PIbd-22_Bondarenko_M.S._IP\\src\\main\\resources\\glow.png"));
Assertions.assertNotNull(book.getId());
}
@Test
void TestFindBook(){
bookService.deleteAllBooks();
final Book book = bookService.addBook("Test","03.04.2023", new File("D:\\Учёба\\Интернет программирование\\PIbd-22_Bondarenko_M.S._IP\\src\\main\\resources\\glow.png"));
final Book findBook = bookService.findBook(book.getId());
Assertions.assertEquals(book, findBook);
}
@Test
void TestBookReadNotFound(){
bookService.deleteAllBooks();
Assertions.assertThrows(EntityNotFoundException.class, () -> bookService.findBook(-1L));
}
@Test
void TestFindAllBook(){
bookService.deleteAllBooks();
final Book book1 = bookService.addBook("Test1","03.04.2023", new File("D:\\Учёба\\Интернет программирование\\PIbd-22_Bondarenko_M.S._IP\\src\\main\\resources\\glow.png"));
final Book book2 = bookService.addBook("Test2","03.04.2023", new File("D:\\Учёба\\Интернет программирование\\PIbd-22_Bondarenko_M.S._IP\\src\\main\\resources\\glow.png"));
final List<Book> books = bookService.findAllBooks();
Assertions.assertEquals(books.size(), 2);
}
@Test
void TestBookReadAllEmpty() {
bookService.deleteAllBooks();
final List<Book> books = bookService.findAllBooks();
Assertions.assertEquals(books.size(), 0);
}
@Test
void TestBookUpdate(){
bookService.deleteAllBooks();
Book book = bookService.addBook("Test1","03.04.2023", new File("D:\\Учёба\\Интернет программирование\\PIbd-22_Bondarenko_M.S._IP\\src\\main\\resources\\glow.png"));
book = bookService.updateBook(book.getId(), "Test2", "02.03.2023", new File("D:\\Учёба\\Интернет программирование\\PIbd-22_Bondarenko_M.S._IP\\src\\main\\resources\\glow.png"));
Assertions.assertEquals(book.getName(), "Test2");
Assertions.assertEquals(book.getRelease().toString(), "Thu Mar 02 00:00:00 GMT+04:00 2023");
Assertions.assertNotNull(book.getCover());
}
@Test
void TestDeleteBook(){
bookService.deleteAllBooks();
final Book book = bookService.addBook("Test","03.04.2023", new File("D:\\Учёба\\Интернет программирование\\PIbd-22_Bondarenko_M.S._IP\\src\\main\\resources\\glow.png"));
bookService.deleteBook(book.getId());
Assertions.assertThrows(EntityNotFoundException.class, () -> bookService.findBook(1L));
}
@Test
void TestAddGenreToBook(){
bookService.deleteAllBooks();
genreService.deleteAllGenres();
Book book = bookService.addBook("Test", "03.04.2023", new File("D:\\Учёба\\Интернет программирование\\PIbd-22_Bondarenko_M.S._IP\\src\\main\\resources\\glow.png"));
final Genre genre = genreService.addGenre("Test2");
bookService.addGenreToBook(book.getId(), genre);
book = bookService.findBook(book.getId());
Assertions.assertEquals(book.getGenres().size(), 1);
}
@Test
void TestRemoveGenreFromBook(){
bookService.deleteAllBooks();
genreService.deleteAllGenres();
Book book = bookService.addBook("Test", "03.04.2023", new File("D:\\Учёба\\Интернет программирование\\PIbd-22_Bondarenko_M.S._IP\\src\\main\\resources\\glow.png"));
final Genre genre = genreService.addGenre("Test2");
bookService.addGenreToBook(book.getId(), genre);
bookService.removeGenreFromBook(book.getId(), genre);
book = bookService.findBook(book.getId());
Assertions.assertEquals(book.getGenres().size(), 0);
}
}

View File

@ -0,0 +1,69 @@
package ru.ip.labworks.labworks;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import ru.ip.labworks.labworks.bookshop.model.Genre;
import ru.ip.labworks.labworks.bookshop.service.GenreService;
import javax.persistence.EntityNotFoundException;
import java.util.List;
@SpringBootTest
public class JpaGenreTests {
@Autowired
GenreService genreService;
@Test
void TestAddGenre(){
genreService.deleteAllGenres();
final Genre genre = genreService.addGenre("test");
Assertions.assertNotNull(genre.getId());
}
@Test
void TestFindGenre(){
genreService.deleteAllGenres();
final Genre genre = genreService.addGenre("Test");
final Genre findGenre = genreService.findGenre(genre.getId());
Assertions.assertEquals(genre, findGenre);
}
@Test
void TestGenreReadNotFound(){
genreService.deleteAllGenres();
Assertions.assertThrows(EntityNotFoundException.class, () -> genreService.findGenre(-1L));
}
@Test
void TestFindAllGenre(){
genreService.deleteAllGenres();
final Genre genre1 = genreService.addGenre("Test1");
final Genre genre2 = genreService.addGenre("Test2");
final List<Genre> genres = genreService.findAllGenres();
Assertions.assertEquals(genres.size(), 2);
}
@Test
void TestGenreReadAllEmpty() {
genreService.deleteAllGenres();
final List<Genre> genres = genreService.findAllGenres();
Assertions.assertEquals(genres.size(), 0);
}
@Test
void TestGenreUpdate(){
genreService.deleteAllGenres();
Genre genre = genreService.addGenre("Test1");
genre = genreService.updateGenre(genre.getId(), "Test2");
Assertions.assertEquals(genre.getName(), "Test2");
}
@Test
void TestDeleteGenre(){
genreService.deleteAllGenres();
final Genre genre = genreService.addGenre("Test");
genreService.deleteGenre(genre.getId());
Assertions.assertThrows(EntityNotFoundException.class, () -> genreService.findGenre(1L));
}
}

View File

@ -1,13 +1,91 @@
package ru.ip.labworks.labworks;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import ru.ip.labworks.labworks.calculator.service.CalculatorService;
@SpringBootTest
class LabworksApplicationTests {
@Autowired
CalculatorService calculatorService;
@Test
void contextLoads() {
void IntPlus() {
final String res = calculatorService.Plus("int", 10, 2).toString();
Assertions.assertEquals("12", res);
}
@Test
void IntMinus() {
final String res = calculatorService.Minus("int", 10, 2).toString();
Assertions.assertEquals("8", res);
}
@Test
void IntMulti() {
final String res = calculatorService.Multi("int", 10, 2).toString();
Assertions.assertEquals("20", res);
}
@Test
void IntDiv() {
final String res = calculatorService.Div("int", 10, 2).toString();
Assertions.assertEquals("5", res);
}
@Test
void StrPlus() {
final String res = calculatorService.Plus("string", "10", "2").toString();
Assertions.assertEquals("102", res);
}
@Test
void StrMinus() {
final String res = calculatorService.Minus("string", "10", "0").toString();
Assertions.assertEquals("1", res);
}
@Test
void StrMulti() {
final String res = calculatorService.Multi("string", "10", "2").toString();
Assertions.assertEquals("1010", res);
}
@Test
void StrDiv() {
final String res = calculatorService.Div("string", "1010", "2").toString();
Assertions.assertEquals("10", res);
}
@Test
void ArrayPlus() {
final String res = calculatorService.Plus("array", "2,2", "3,3").toString();
Assertions.assertEquals("[23, 23]", res);
}
@Test
void ArrayMinus() {
final String res = calculatorService.Minus("array", "24,23", "4,3").toString();
Assertions.assertEquals("[2, 2]", res);
}
@Test
void ArrayMulti() {
final String res = calculatorService.Multi("array", "23,24", "2,2").toString();
Assertions.assertEquals("[2323, 2424]", res);
}
@Test
void ArrayDiv() {
final String res = calculatorService.Div("array", "23,24", "1,1").toString();
Assertions.assertEquals("[2, 2]", res);
}
@Test
void testErrorErrorWired() {
Assertions.assertThrows(NoSuchBeanDefinitionException.class, () -> calculatorService.Plus("date", 1, 2));
}
}