Отчёт.
This commit is contained in:
parent
e9f9075f09
commit
e3f7da3e4b
23
react_online_calculator/.gitignore
vendored
23
react_online_calculator/.gitignore
vendored
@ -1,23 +0,0 @@
|
||||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||
|
||||
# dependencies
|
||||
/node_modules
|
||||
/.pnp
|
||||
.pnp.js
|
||||
|
||||
# testing
|
||||
/coverage
|
||||
|
||||
# production
|
||||
/build
|
||||
|
||||
# misc
|
||||
.DS_Store
|
||||
.env.local
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
@ -1,11 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>React App</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
</body>
|
||||
</html>
|
@ -1,10 +0,0 @@
|
||||
import React from 'react';
|
||||
|
||||
function App() {
|
||||
return (
|
||||
<div className="App">
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default App;
|
@ -1,11 +0,0 @@
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom/client';
|
||||
import App from './App';
|
||||
|
||||
const root = ReactDOM.createRoot(document.getElementById('root'));
|
||||
root.render(
|
||||
<App />
|
||||
//document.getElementById('root'); - для работы этого надо поставит запятую после <App/>
|
||||
//и делаем import 'react-dom', вместо 'react-dom/client'
|
||||
);
|
||||
|
@ -12,6 +12,10 @@ repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
jar {
|
||||
enabled = false
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'org.springframework.boot:spring-boot-starter-web'
|
||||
|
||||
@ -20,6 +24,9 @@ dependencies {
|
||||
|
||||
implementation group: 'org.springdoc', name: 'springdoc-openapi-ui', version: '1.6.5'
|
||||
|
||||
implementation 'org.hibernate.validator:hibernate-validator'
|
||||
implementation 'org.springdoc:springdoc-openapi-ui:1.6.5'
|
||||
|
||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||
}
|
||||
|
||||
|
@ -1,100 +0,0 @@
|
||||
package premium_store.model;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Entity
|
||||
public class Client {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private Long id;
|
||||
|
||||
@Column(nullable = false, length = 255)
|
||||
private String nickName;
|
||||
|
||||
@Column(nullable = false, length = 255)
|
||||
private String email;
|
||||
|
||||
private Integer balance;
|
||||
|
||||
@OneToMany(fetch= FetchType.EAGER)
|
||||
private List<Tank> tanks = new ArrayList<>();
|
||||
|
||||
public Client(){ }
|
||||
|
||||
public Client(String nickName, String email, Integer balance){
|
||||
this.nickName = nickName;
|
||||
this.email = email;
|
||||
this.balance = balance;
|
||||
}
|
||||
|
||||
public Long getId(){
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getNickName(){
|
||||
return nickName;
|
||||
}
|
||||
|
||||
public void setNickName(String nickName){
|
||||
this.nickName = nickName;
|
||||
}
|
||||
|
||||
public String getEmail(){
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email){
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public Integer getBalance(){
|
||||
return balance;
|
||||
}
|
||||
|
||||
public void setBalance(Integer balance){
|
||||
this.balance = balance;
|
||||
}
|
||||
|
||||
public List<Tank> getTanks(){
|
||||
return tanks;
|
||||
}
|
||||
|
||||
public void setTanks(List<Tank> tanks){
|
||||
this.tanks = tanks;
|
||||
}
|
||||
|
||||
//метод для сравнения
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o)
|
||||
return true;
|
||||
|
||||
if (o == null || getClass() != o.getClass())
|
||||
return false;
|
||||
|
||||
Client client = (Client) o;
|
||||
|
||||
return Objects.equals(id, client.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(id);
|
||||
}
|
||||
|
||||
//преобразование данных по объекту в строчку
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Client{" +
|
||||
"id=" + id +
|
||||
", nickName='" + nickName + '\'' +
|
||||
", email='" + email + '\'' +
|
||||
", balance='" + balance + '\'' +
|
||||
", tanks='" + tanks.stream().map(Object::toString).collect(Collectors.joining(", ")) + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
package premium_store.model;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.Objects;
|
||||
|
||||
@Entity
|
||||
public class Level {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private Long id;
|
||||
|
||||
@Column(nullable = false)
|
||||
private int level;
|
||||
|
||||
public Level() {
|
||||
}
|
||||
|
||||
public Level(int level) {
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
//возвращает id
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
//возвращает нацию
|
||||
public int getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
public void setLevel(int level) {
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
//метод для сравнения
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o)
|
||||
return true;
|
||||
|
||||
if (o == null || getClass() != o.getClass())
|
||||
return false;
|
||||
|
||||
Level level = (Level) o;
|
||||
|
||||
return Objects.equals(id, level.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(id);
|
||||
}
|
||||
|
||||
//преобразование данных по объекту в строчку
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Level{" +
|
||||
"id=" + id +
|
||||
", level='" + level + '}';
|
||||
}
|
||||
}
|
@ -5,23 +5,23 @@ import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Entity
|
||||
@Table(name = "NATIONS")
|
||||
public class Nation {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private Long id;
|
||||
|
||||
@Column(nullable = false)
|
||||
@Column(name = "nation")
|
||||
private String nation;
|
||||
|
||||
@OneToMany(mappedBy = "nation", fetch = FetchType.EAGER, cascade = CascadeType.MERGE)
|
||||
private List<Tank> tanksOfThisNation;
|
||||
private List<Tank> tanksOfThisNation = new ArrayList<>();
|
||||
|
||||
public Nation() {
|
||||
}
|
||||
|
||||
public Nation(String nation) {
|
||||
this.nation = nation;
|
||||
tanksOfThisNation = new ArrayList<>();
|
||||
}
|
||||
|
||||
//возвращает id
|
||||
@ -42,8 +42,8 @@ public class Nation {
|
||||
return tanksOfThisNation;
|
||||
}
|
||||
|
||||
public void setTankOfThisNation(List<Tank> newTank){
|
||||
this.tanksOfThisNation = newTank;
|
||||
public void setTanksOfThisNation(Tank newTank){
|
||||
this.tanksOfThisNation.add(newTank);
|
||||
}
|
||||
|
||||
//метод для сравнения
|
||||
@ -75,3 +75,4 @@ public class Nation {
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@ import javax.persistence.*;
|
||||
import java.util.Objects;
|
||||
|
||||
@Entity
|
||||
@Table(name = "TANKS")
|
||||
public class Tank {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
@ -17,8 +18,8 @@ public class Tank {
|
||||
private Nation nation;
|
||||
|
||||
@ManyToOne(fetch = FetchType.EAGER)
|
||||
@JoinColumn(name = "level")
|
||||
private Level level;
|
||||
@JoinColumn(name = "tankLevel")
|
||||
private TankLevel tankLevel;
|
||||
|
||||
@Column(nullable = false)
|
||||
private int cost;
|
||||
@ -26,10 +27,10 @@ public class Tank {
|
||||
public Tank() {
|
||||
}
|
||||
|
||||
public Tank(String name, Nation nation, Level level, int cost) {
|
||||
public Tank(String name, Nation nation, TankLevel tankLevel, int cost) {
|
||||
this.name = name;
|
||||
this.nation = nation;
|
||||
this.level = level;
|
||||
this.tankLevel = tankLevel;
|
||||
this.cost = cost;
|
||||
}
|
||||
|
||||
@ -53,12 +54,12 @@ public class Tank {
|
||||
this.cost = cost;
|
||||
}
|
||||
|
||||
public Level getLevel() {
|
||||
return level;
|
||||
public TankLevel getLevel() {
|
||||
return tankLevel;
|
||||
}
|
||||
|
||||
public void setLevel(Level level) {
|
||||
this.level = level;
|
||||
public void setLevel(TankLevel tankLevel) {
|
||||
this.tankLevel = tankLevel;
|
||||
}
|
||||
|
||||
public Nation getNation() {
|
||||
@ -91,9 +92,10 @@ public class Tank {
|
||||
return "Tank{" +
|
||||
"id=" + id +
|
||||
", name='" + name + '\'' +
|
||||
", nation='" + nation.getId() + '\'' +
|
||||
", level='" + level + '\'' +
|
||||
", nation='" + nation.getNation() + '\'' +
|
||||
", level='" + tankLevel.getLevel() + '\'' +
|
||||
", cost='" + cost + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,88 +0,0 @@
|
||||
package premium_store.service;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
import premium_store.model.Client;
|
||||
import premium_store.model.Tank;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.EntityNotFoundException;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class ClientService {
|
||||
@PersistenceContext
|
||||
private EntityManager em;
|
||||
|
||||
@Transactional
|
||||
public Client addClient(String newNickName, String newEmail, Integer newBallance) {
|
||||
if (!StringUtils.hasText(newNickName) || !StringUtils.hasText(newEmail)) {
|
||||
throw new IllegalArgumentException("NickName or newEmail is zero or empty");
|
||||
}
|
||||
|
||||
final Client client = new Client(newNickName, newEmail, newBallance);
|
||||
em.persist(client);
|
||||
|
||||
return client;
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public Client findClient(Long id) {
|
||||
final Client Client = em.find(Client.class, id);
|
||||
|
||||
if (Client == null) {
|
||||
throw new EntityNotFoundException(String.format("Client with id [%s] is not found", id));
|
||||
}
|
||||
|
||||
return Client;
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public List<Client> findAllClients() {
|
||||
return em.createQuery("select c from Client c", Client.class)
|
||||
.getResultList();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Client updateClient(Long id, String newNickName, String newEmail, Integer newBalance, List<Tank> newTanks) {
|
||||
if (id <= 0) {
|
||||
throw new IllegalArgumentException("Invalid id");
|
||||
}
|
||||
|
||||
final Client currentClient = findClient(id);
|
||||
|
||||
if (StringUtils.hasText(newNickName)){
|
||||
currentClient.setNickName(newNickName);
|
||||
}
|
||||
|
||||
if(StringUtils.hasText(newEmail)){
|
||||
currentClient.setEmail(newEmail);
|
||||
}
|
||||
|
||||
if(newBalance != null){
|
||||
currentClient.setBalance(newBalance);
|
||||
}
|
||||
|
||||
if(newTanks != null){
|
||||
currentClient.setTanks(newTanks);
|
||||
}
|
||||
|
||||
return em.merge(currentClient);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Client deleteClient(Long id) {
|
||||
final Client currentClient = findClient(id);
|
||||
em.remove(currentClient);
|
||||
|
||||
return currentClient;
|
||||
}
|
||||
|
||||
//прямой sql-запрос на удаление всех записей в таблице
|
||||
@Transactional
|
||||
public void deleteAllClients() {
|
||||
em.createQuery("Delete from Client").executeUpdate();
|
||||
}
|
||||
}
|
@ -1,70 +0,0 @@
|
||||
package premium_store.service;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import premium_store.model.Level;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.EntityNotFoundException;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class LevelService {
|
||||
@PersistenceContext
|
||||
private EntityManager em;
|
||||
|
||||
@Transactional
|
||||
public Level addLevel(int newLevel) {
|
||||
if (newLevel <= 0) {
|
||||
throw new IllegalArgumentException("Level name is zero or less");
|
||||
}
|
||||
|
||||
final Level level = new Level(newLevel);
|
||||
em.persist(level);
|
||||
|
||||
return level;
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public Level findLevel(Long id) {
|
||||
final Level level = em.find(Level.class, id);
|
||||
|
||||
if (level == null) {
|
||||
throw new EntityNotFoundException(String.format("Level with id [%s] is not found", id));
|
||||
}
|
||||
|
||||
return level;
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public List<Level> findAllLevels() {
|
||||
return em.createQuery("select s from Level s", Level.class)
|
||||
.getResultList();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Level updateLevel(Long id, int newLevel) {
|
||||
if (newLevel <= 0) {
|
||||
throw new IllegalArgumentException("Level name is zero or less");
|
||||
}
|
||||
|
||||
final Level currentLevel = findLevel(id);
|
||||
currentLevel.setLevel(newLevel);
|
||||
|
||||
return em.merge(currentLevel);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Level deleteLevel(Long id) {
|
||||
final Level currentLevel = findLevel(id);
|
||||
em.remove(currentLevel);
|
||||
|
||||
return currentLevel;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void deleteAllLevels() {
|
||||
em.createQuery("Delete from Level").executeUpdate();
|
||||
}
|
||||
}
|
@ -5,48 +5,47 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
import premium_store.model.Nation;
|
||||
import premium_store.model.Tank;
|
||||
import premium_store.repository.NationRepository;
|
||||
import premium_store.service.exception.NationNotFoundException;
|
||||
import premium_store.util.validation.ValidatorUtil;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.EntityNotFoundException;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Service
|
||||
public class NationService {
|
||||
@PersistenceContext
|
||||
private EntityManager em;
|
||||
private final NationRepository nationRepository;
|
||||
private final ValidatorUtil validatorUtil;
|
||||
|
||||
public NationService(NationRepository nationRepository, ValidatorUtil validatorUtil){
|
||||
this.nationRepository = nationRepository;
|
||||
this.validatorUtil = validatorUtil;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Nation addNation(String nameNation){
|
||||
if(!StringUtils.hasText(nameNation)){
|
||||
throw new IllegalArgumentException("The name of the nation is null or empty");
|
||||
}
|
||||
|
||||
final Nation nation = new Nation(nameNation);
|
||||
em.persist(nation);
|
||||
|
||||
return nation;
|
||||
validatorUtil.validate(nation);
|
||||
|
||||
return nationRepository.save(nation);
|
||||
}
|
||||
|
||||
//здесь используем Optional - спец. тип данных, позволяющий определять, вернулось ли что-то при вызове метода, или вернулся null
|
||||
@Transactional(readOnly = true)
|
||||
public Nation findNation(Long id){
|
||||
final Nation nation = em.find(Nation.class, id);
|
||||
final Optional<Nation> nation = nationRepository.findById(id);
|
||||
|
||||
if(nation == null){
|
||||
throw new EntityNotFoundException(String.format("Nation with id [%s] is not found", id));
|
||||
}
|
||||
|
||||
return nation;
|
||||
//благодаря Optional можем вызвать orElseThrow, который в случае null сделает проброс кастомного исключения
|
||||
return nation.orElseThrow(() -> new NationNotFoundException(id));
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public List<Nation> findAllNations() {
|
||||
return em.createQuery("select n from Nation n", Nation.class)
|
||||
.getResultList();
|
||||
return nationRepository.findAll();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Nation updateNation(Long id, String newNation, List<Tank> newTank) {
|
||||
public Nation updateNation(Long id, String newNation, Tank newTank) {
|
||||
if(id <= 0){
|
||||
throw new IllegalArgumentException(String.format("Incorrect id: [%s]", id));
|
||||
}
|
||||
@ -57,23 +56,23 @@ public class NationService {
|
||||
currentNation.setNation(newNation);
|
||||
}
|
||||
|
||||
if(newTank.size() > 0){
|
||||
currentNation.setTankOfThisNation(newTank);
|
||||
if(newTank != null){
|
||||
currentNation.setTanksOfThisNation(newTank);
|
||||
}
|
||||
|
||||
return em.merge(currentNation);
|
||||
return nationRepository.save(currentNation);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Nation deleteNAtion(Long id) {
|
||||
public Nation deleteNation(Long id) {
|
||||
final Nation currentNation = findNation(id);
|
||||
em.remove(currentNation);
|
||||
nationRepository.delete(currentNation);
|
||||
|
||||
return currentNation;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void deleteAllNations() {
|
||||
em.createQuery("delete from Nation").executeUpdate();
|
||||
nationRepository.deleteAll();
|
||||
}
|
||||
}
|
||||
|
@ -3,52 +3,49 @@ package premium_store.service;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
import premium_store.model.Level;
|
||||
import premium_store.model.TankLevel;
|
||||
import premium_store.model.Nation;
|
||||
import premium_store.model.Tank;
|
||||
import premium_store.repository.TankRepository;
|
||||
import premium_store.service.exception.TankNotFoundException;
|
||||
import premium_store.util.validation.ValidatorUtil;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.EntityNotFoundException;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Service
|
||||
public class TankService {
|
||||
@PersistenceContext
|
||||
private EntityManager em;
|
||||
private final TankRepository tankRepository;
|
||||
private final ValidatorUtil validatorUtil;
|
||||
|
||||
public TankService(TankRepository tankRepository, ValidatorUtil validatorUtil){
|
||||
this.tankRepository = tankRepository;
|
||||
this.validatorUtil = validatorUtil;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Tank addTank(String newName, Nation newNation, Level newLevel, int newCost) {
|
||||
if (!StringUtils.hasText(newName) || newNation == null || newLevel == null || newCost <= 0) {
|
||||
throw new IllegalArgumentException("New Name, new Nation, new Level or newCost is zero or empty");
|
||||
}
|
||||
public Tank addTank(String newName, Nation newNation, TankLevel newTankLevel, int newCost) {
|
||||
final Tank tank = new Tank(newName, newNation, newTankLevel, newCost);
|
||||
validatorUtil.validate(tank);
|
||||
|
||||
final Tank tank = new Tank(newName, newNation, newLevel, newCost);
|
||||
em.persist(tank);
|
||||
|
||||
return tank;
|
||||
return tankRepository.save(tank);
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public Tank findTank(Long id) {
|
||||
final Tank Tank = em.find(Tank.class, id);
|
||||
final Optional<Tank> tank = tankRepository.findById(id);
|
||||
|
||||
if (Tank == null) {
|
||||
throw new EntityNotFoundException(String.format("Tank with id [%s] is not found", id));
|
||||
}
|
||||
|
||||
return Tank;
|
||||
return tank.orElseThrow(() -> new TankNotFoundException(id));
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public List<Tank> findAllTanks() {
|
||||
return em.createQuery("select t from Tank t", Tank.class)
|
||||
.getResultList();
|
||||
return tankRepository.findAll();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Tank updateTank(Long id, String newName, Nation newNation,
|
||||
Level newLevel, int newCost) {
|
||||
TankLevel newLevel, int newCost) {
|
||||
if (id <= 0) {
|
||||
throw new IllegalArgumentException("Invalid id");
|
||||
}
|
||||
@ -71,29 +68,26 @@ public class TankService {
|
||||
currentTank.setCost(newCost);
|
||||
}
|
||||
|
||||
return em.merge(currentTank);
|
||||
return tankRepository.save(currentTank);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Tank deleteTank(Long id) {
|
||||
final Tank currentTank = findTank(id);
|
||||
em.remove(currentTank);
|
||||
tankRepository.delete(currentTank);
|
||||
|
||||
return currentTank;
|
||||
}
|
||||
|
||||
//прямой sql-запрос на удаление всех записей в таблице
|
||||
//запрос на удаление всех записей в таблице
|
||||
@Transactional
|
||||
public void deleteAllTanks() {
|
||||
em.createQuery("Delete from Tank").executeUpdate();
|
||||
tankRepository.deleteAll();
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public List<Tank> findTank(Level level, Nation nation) {
|
||||
return em.createQuery("select t from Tank t where t.nation.nation = :Nid and t.level.level BETWEEN :Llevel AND :L2level", Tank.class)
|
||||
.setParameter("Nid", nation.getNation())
|
||||
.setParameter("Llevel", level.getLevel())
|
||||
.setParameter("L2level", level.getLevel() + 1)
|
||||
.getResultList();
|
||||
public List<Tank> findListTank(String nationName, int levelFirst, int levelSecond) {
|
||||
return tankRepository.checkNationAndLevel(nationName, levelFirst, levelSecond);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
spring.main.banner-mode=off
|
||||
#server.port=8080
|
||||
server.port=8080
|
||||
server.tomcat.relaxed-query-chars=|,{,},[,]
|
||||
spring.datasource.url=jdbc:h2:file:./data
|
||||
spring.datasource.driverClassName=org.h2.Driver
|
||||
spring.datasource.username=sa
|
||||
@ -8,4 +9,4 @@ 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
|
||||
spring.h2.console.settings.web-allow-others=false
|
||||
|
@ -1,11 +1,11 @@
|
||||
package premium_store;
|
||||
|
||||
import premium_store.model.Client;
|
||||
import premium_store.model.Level;
|
||||
import premium_store.model.GameClient;
|
||||
import premium_store.model.TankLevel;
|
||||
import premium_store.model.Nation;
|
||||
import premium_store.model.Tank;
|
||||
import premium_store.service.ClientService;
|
||||
import premium_store.service.LevelService;
|
||||
import premium_store.service.GameClientService;
|
||||
import premium_store.service.TankLevelService;
|
||||
import premium_store.service.NationService;
|
||||
import premium_store.service.TankService;
|
||||
|
||||
@ -15,56 +15,56 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import premium_store.service.exception.ClientNotFoundException;
|
||||
|
||||
import javax.persistence.EntityNotFoundException;
|
||||
import java.util.*;
|
||||
|
||||
@SpringBootTest
|
||||
class PremiumStoreApplicationTests {
|
||||
private static final Logger log = LoggerFactory.getLogger(PremiumStoreApplicationTests.class);
|
||||
private static final Logger log = LoggerFactory.getLogger(PremiumStoreApplicationTests.class);
|
||||
|
||||
@Autowired
|
||||
TankService tankService;
|
||||
|
||||
@Autowired
|
||||
ClientService clientService;
|
||||
TankService tankService;
|
||||
|
||||
@Autowired
|
||||
LevelService levelService;
|
||||
GameClientService gameClientService;
|
||||
|
||||
@Autowired
|
||||
NationService nationService;
|
||||
TankLevelService tankLevelService;
|
||||
|
||||
@Test
|
||||
void testClientRead() {
|
||||
clientService.deleteAllClients();
|
||||
@Autowired
|
||||
NationService nationService;
|
||||
|
||||
Client client = clientService.addClient("3tankista73", "fff@mail.ru", 3400);
|
||||
log.info(client.toString());
|
||||
@Test
|
||||
void testClientRead() {
|
||||
gameClientService.deleteAllClients();
|
||||
|
||||
Client findClient = clientService.findClient(client.getId());
|
||||
log.info(findClient.toString());
|
||||
GameClient client = gameClientService.addClient("3tankista73", "fff@mail.ru", 3400);
|
||||
log.info(client.toString());
|
||||
|
||||
Assertions.assertEquals(client, findClient);
|
||||
}
|
||||
GameClient findClient = gameClientService.findClient(client.getId());
|
||||
log.info(findClient.toString());
|
||||
|
||||
Assertions.assertEquals(client, findClient);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testNationRead() {
|
||||
nationService.deleteAllNations();
|
||||
tankService.deleteAllTanks();
|
||||
levelService.deleteAllLevels();
|
||||
tankLevelService.deleteAllLevels();
|
||||
|
||||
Nation nation = nationService.addNation("Германия");
|
||||
|
||||
Level firstLevel = levelService.addLevel(8);
|
||||
Level secondLevel = levelService.addLevel(9);
|
||||
TankLevel firstLevel = tankLevelService.addLevel(8);
|
||||
TankLevel secondLevel = tankLevelService.addLevel(9);
|
||||
|
||||
Tank firstTank = tankService.addTank("ИС-3", nation, firstLevel, 3700000);
|
||||
Tank secondTank = tankService.addTank("E-75", nation, secondLevel, 5600000);
|
||||
|
||||
List<Tank> tanks = new ArrayList<>(Arrays.asList(firstTank, secondTank));
|
||||
|
||||
nation = nationService.updateNation(nation.getId(), "СССР", tanks);
|
||||
nation = nationService.updateNation(nation.getId(), "СССР", null);
|
||||
|
||||
log.info(nation.toString());
|
||||
|
||||
@ -76,30 +76,30 @@ class PremiumStoreApplicationTests {
|
||||
|
||||
@Test
|
||||
void testClientReadNotFound() {
|
||||
clientService.deleteAllClients();
|
||||
Assertions.assertThrows(EntityNotFoundException.class, () -> clientService.findClient(-1L));
|
||||
gameClientService.deleteAllClients();
|
||||
Assertions.assertThrows(ClientNotFoundException.class, () -> gameClientService.findClient(-1L));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testLevelRead() {
|
||||
tankService.deleteAllTanks();
|
||||
levelService.deleteAllLevels();
|
||||
tankLevelService.deleteAllLevels();
|
||||
|
||||
Level level = levelService.addLevel(8);
|
||||
TankLevel level = tankLevelService.addLevel(8);
|
||||
log.info(level.toString());
|
||||
|
||||
Level secondLevel = levelService.addLevel(9);
|
||||
TankLevel secondLevel = tankLevelService.addLevel(9);
|
||||
log.info(secondLevel.toString());
|
||||
|
||||
Assertions.assertEquals(levelService.findAllLevels().size(), 2);
|
||||
Assertions.assertEquals(tankLevelService.findAllLevels().size(), 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testLevelReadAllEmpty() {
|
||||
tankService.deleteAllTanks();
|
||||
levelService.deleteAllLevels();
|
||||
tankLevelService.deleteAllLevels();
|
||||
|
||||
List<Level> levels = levelService.findAllLevels();
|
||||
List<TankLevel> levels = tankLevelService.findAllLevels();
|
||||
log.info(levels.toString());
|
||||
|
||||
Assertions.assertEquals(levels.size(), 0);
|
||||
@ -108,10 +108,10 @@ class PremiumStoreApplicationTests {
|
||||
@Test
|
||||
void testTankReadAll() {
|
||||
tankService.deleteAllTanks();
|
||||
levelService.deleteAllLevels();
|
||||
tankLevelService.deleteAllLevels();
|
||||
|
||||
Level firstLevel = levelService.addLevel(8);
|
||||
Level secondLevel = levelService.addLevel(9);
|
||||
TankLevel firstLevel = tankLevelService.addLevel(8);
|
||||
TankLevel secondLevel = tankLevelService.addLevel(9);
|
||||
|
||||
tankService.addTank("ИС-3", nationService.addNation("СССР"), firstLevel, 3700000);
|
||||
tankService.addTank("E-75", nationService.addNation("Германия"), secondLevel, 5600000);
|
||||
@ -124,25 +124,25 @@ class PremiumStoreApplicationTests {
|
||||
|
||||
@Test
|
||||
void testClientCreate() {
|
||||
clientService.deleteAllClients();
|
||||
gameClientService.deleteAllClients();
|
||||
|
||||
Client firstClient = clientService.addClient("Barbarian", "dsfg@gmail.com", 56000);
|
||||
GameClient firstClient = gameClientService.addClient("Barbarian", "dsfg@gmail.com", 56000);
|
||||
log.info(firstClient.toString());
|
||||
|
||||
Client secondClient = clientService.addClient("KorbenDallas", "tankoviyGeniy@mail.ru", 37000);
|
||||
GameClient secondClient = gameClientService.addClient("KorbenDallas", "tankoviyGeniy@mail.ru", 37000);
|
||||
log.info(secondClient.toString());
|
||||
|
||||
Assertions.assertEquals(clientService.findAllClients().size(), 2);
|
||||
Assertions.assertEquals(gameClientService.findAllClients().size(), 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testUpdateTank(){
|
||||
tankService.deleteAllTanks();
|
||||
levelService.deleteAllLevels();
|
||||
clientService.deleteAllClients();
|
||||
tankService.deleteAllTanks();
|
||||
tankLevelService.deleteAllLevels();
|
||||
gameClientService.deleteAllClients();
|
||||
|
||||
Level firstLevel = levelService.addLevel(8);
|
||||
Level secondLevel = levelService.addLevel(9);
|
||||
TankLevel firstLevel = tankLevelService.addLevel(8);
|
||||
TankLevel secondLevel = tankLevelService.addLevel(9);
|
||||
|
||||
Tank firstTank = tankService.addTank("ИС-3", nationService.addNation("СССР"), firstLevel, 3700000);
|
||||
Tank secondTank = tankService.addTank("E-75", nationService.addNation("Германия"), secondLevel, 5600000);
|
||||
@ -161,22 +161,22 @@ class PremiumStoreApplicationTests {
|
||||
void testNewTest() {
|
||||
nationService.deleteAllNations();
|
||||
tankService.deleteAllTanks();
|
||||
levelService.deleteAllLevels();
|
||||
tankLevelService.deleteAllLevels();
|
||||
|
||||
Nation nation = nationService.addNation("Германия");
|
||||
Nation newNation = nationService.addNation("CCCР");
|
||||
|
||||
Level firstLevel = levelService.addLevel(8);
|
||||
Level secondLevel = levelService.addLevel(9);
|
||||
TankLevel firstLevel = tankLevelService.addLevel(8);
|
||||
TankLevel secondLevel = tankLevelService.addLevel(9);
|
||||
|
||||
Tank firstTank = tankService.addTank("ИС-3", nation, firstLevel, 3700000);
|
||||
Tank secondTank = tankService.addTank("E-75", nation, secondLevel, 5600000);
|
||||
|
||||
List<Tank> tanks = new ArrayList<>(Arrays.asList(firstTank, secondTank));
|
||||
|
||||
nation = nationService.updateNation(nation.getId(), "СССР", tanks);
|
||||
nation = nationService.updateNation(nation.getId(), "СССР", null);
|
||||
|
||||
tanks = tankService.findTank(firstLevel, nation);
|
||||
//tanks = tankService.findListTank(firstLevel, nation);
|
||||
|
||||
log.info("AAAAA" + tanks.toString());
|
||||
}
|
||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user