This commit is contained in:
dasha 2023-04-09 15:20:17 +04:00
parent 9d40b79426
commit 076bd4e61b
27 changed files with 123 additions and 3607 deletions

View File

@ -17,8 +17,6 @@ jar {
}
dependencies {
implementation(project(':front'))
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'com.h2database:h2:2.1.210'
implementation 'org.springframework.boot:spring-boot-starter-validation'

26
front/.gitignore vendored
View File

@ -1,26 +0,0 @@
# 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?
.parcel-cache

View File

@ -1,66 +0,0 @@
import com.github.gradle.node.util.PlatformHelper
import groovy.text.SimpleTemplateEngine
plugins {
id 'java'
id 'com.github.node-gradle.node' version '3.5.1'
id "de.undercouch.download" version '5.3.1'
}
//task wrapper(type: Wrapper){
// gradleVersion = '7.2'
//}
//
//task prepareKotlinBuildScriptModel {
//
//}
node {
version = '18.15.0'
download = true
}
jar.dependsOn 'npmBuild'
clean.dependsOn 'npmClean'
nodeSetup.dependsOn 'downloadNode'
jar {
from 'dist'
into 'static'
final devHost = 'http://localhost:8080'
final prodHost = ''
filesMatching('index.html') {
filter { line -> line.replaceAll(devHost, prodHost) }
}
}
task downloadNode(type: Download) {
final helper = new PlatformHelper()
final templateData = [
"url" : node.distBaseUrl.get(),
"version": node.version.get(),
"os" : helper.osName,
"arch" : helper.osArch,
"ext" : helper.windows ? 'zip' : 'tar.gz'
]
final urlTemplate = '${url}/v${version}/node-v${version}-${os}-${arch}.${ext}'
final engine = new SimpleTemplateEngine()
final url = engine.createTemplate(urlTemplate).make(templateData).toString()
final String destDir = '.gradle/'
file(destDir).mkdirs()
src url
dest destDir
overwrite false
}
tasks.register('npmBuild', NpmTask) {
dependsOn npmInstall
args = ['run-script', 'build']
}
tasks.register('npmClean', NpmTask) {
dependsOn npmInstall
args = ['run-script', 'clean']
}

Binary file not shown.

View File

@ -1,5 +0,0 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

2898
front/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,17 +0,0 @@
{
"name": "int-prog",
"version": "1.0.0",
"source": "src/index.html",
"scripts": {
"start": "parcel --port 3000",
"build": "npm run clean && parcel build",
"clean": "rimraf dist"
},
"dependencies": {
"bootstrap": "5.2.3"
},
"devDependencies": {
"parcel": "2.8.3",
"rimraf": "4.4.0"
}
}

View File

@ -1,74 +0,0 @@
<!doctype html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>REST Client Example</title>
<script type="module" src="../node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
<link href="../node_modules/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet"/>
</head>
<body>
<header class="d-flex justify-content-center py-3">
<ul class="nav nav-pills">
<li class="nav-item"><a href="./index.html" class="nav-link active" aria-current="page">Customer</a></li>
<li class="nav-item"><a href="./ticket.html" class="nav-link">Ticket</a></li>
<li class="nav-item"><a href="./order.html" class="nav-link">Order</a></li>
</ul>
</header>
<div class="container">
<form id="form" novalidate>
<div class="row mt-3">
<div class="col-sm-6">
<label for="login" class="form-label">login</label>
<input type="text" class="form-control" id="login" required>
</div>
<div class="col-sm-6">
<label for="password" class="form-label">password</label>
<input type="password" class="form-control" id="password" required>
</div>
</div>
<div class="row mt-3">
<div class="d-grid col-sm-4 mx-auto">
<button type="submit" class="btn btn-success">Add</button>
</div>
<div class="d-grid col-sm-4 mx-auto mt-3 mt-sm-0">
<button id="testError" type="button" class="btn btn-danger">Test</button>
</div>
<div class="d-grid col-sm-4 mx-auto mt-3 mt-sm-0">
<button id="testNormal" type="button" class="btn btn-secondary">Test</button>
</div>
</div>
</form>
<div class="row mt-3">
<div class="col-sm-4">
<label for="id" class="form-label">id</label>
<input type="number" class="form-control" id="id" required>
</div>
</div>
<div class="row mt-3">
<div class="d-grid col-sm-2">
<button id="editBtn" class="btn btn-primary">Edit</button>
</div>
<div class="d-grid col-sm-2">
<button id="removeBtn" class="btn btn-danger">Remove</button>
</div>
</div>
<div class="row table-responsive">
<table class="table mt-3">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Login</th>
<th scope="col">Password</th>
</tr>
</thead>
<tbody id="tbody">
</tbody>
</table>
</div>
</div>
</body>
<script src="script.js"></script>
</html>

View File

@ -1,72 +0,0 @@
<!doctype html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>REST Client Example</title>
<script type="module" src="../node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
<link href="../node_modules/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet"/>
</head>
<body>
<header class="d-flex justify-content-center py-3">
<ul class="nav nav-pills">
<li class="nav-item"><a href="./index.html" class="nav-link" aria-current="page">Customer</a></li>
<li class="nav-item"><a href="./ticket.html" class="nav-link">Ticket</a></li>
<li class="nav-item"><a href="./order.html" class="nav-link active">Order</a></li>
</ul>
</header>
<div class="container">
<form id="form" novalidate>
<div class="row mt-3">
<div class="col-sm-6">
<label for="id" class="form-label">id</label>
<input type="number" class="form-control" id="id" required>
</div>
<div class="col-sm-6">
<label for="customer" class="form-label">customer id</label>
<input type="text" class="form-control" id="customer" required>
</div>
</div>
<div class="row mt-3">
<div class="d-grid col-sm-6">
<button id="removeBtn" class="btn btn-danger">Remove</button>
</div>
<div class="d-grid col-sm-6 mx-auto">
<button type="submit" class="btn btn-success">Add order</button>
</div>
<!--<div class="d-grid col-sm-6">
<button id="relateBtn" class="btn btn-primary">Relate</button>
</div>-->
</div>
<div class="row mt-3">
<div class="col-sm-6">
<label for="ticket" class="form-label">ticket id</label>
<input type="text" class="form-control" id="ticket" required>
</div>
</div>
<div class="row mt-3">
<div class="d-grid col-sm-6">
<button id="ticketBtn" class="btn btn-danger">Add ticket</button>
</div>
</div>
</form>
<div class="row table-responsive">
<table class="table mt-3">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Customer</th>
<th scope="col">Date Of Purchase</th>
<th scope="col">Tickets</th>
</tr>
</thead>
<tbody id="tbody">
</tbody>
</table>
</div>
</div>
</body>
<script src="order.js"></script>
</html>

View File

@ -1,75 +0,0 @@
"use strict";
window.addEventListener('DOMContentLoaded', function () {
const host = "http://localhost:8080";
const table = document.getElementById("tbody");
const form = document.getElementById("form");
const customerInput = document.getElementById("customer");
const idInput = document.getElementById("id");
const removeBtn = document.getElementById("removeBtn");
const getData = async function () {
table.innerHTML = "";
const response = await fetch(host + "/order");
const data = await response.json();
data.forEach(order => {
let temp = "<select>";
order.tickets.forEach(ticket => {
temp += `<option>${ticket.name + " " + ticket.price + " " + ticket.timestamp}</option>`
})
table.innerHTML +=
`<tr>
<th scope="row">${order.id}</th>
<td>${order.customer}</td>
<td>${order.dateOfPurchase}</td>
<td>${temp}</td>
</tr>`;
})
}
async function create(customer) {
const requestParams = {
method: "POST",
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
}
};
const response = await fetch(host + `/order?customer=${customer}`, requestParams);
return await response.json();
}
async function remove(id) {
const requestParams = {
method: "DELETE",
};
const response = await fetch(host + `/order/${id}`, requestParams);
return await response.json();
}
async function editCustomer(id) {
const requestParams = {
method: "PUT",
headers: {
"Content-Type": "application/json",
}
};
const response = await fetch(host + `/order/${id}/updcustomer`, requestParams);
return await response.json();
}
form.addEventListener("submit", function (event) {
event.preventDefault();
create(customerInput.value).then(() => {
getData();
});
});
removeBtn.addEventListener("click", function (event) {
event.preventDefault();
remove(idInput.value).then((result) => {
getData();
customerInput.value = "";
idInput.value = "";
});
});
getData();
});

View File

@ -1,114 +0,0 @@
"use strict";
window.addEventListener('DOMContentLoaded', function () {
const host = "http://localhost:8080";
const table = document.getElementById("tbody");
const form = document.getElementById("form");
const passwordInput = document.getElementById("password");
const loginInput = document.getElementById("login");
const idInput = document.getElementById("id");
const removeBtn = document.getElementById("removeBtn");
const editBtn = document.getElementById("editBtn");
const testErrorBtn = document.getElementById("testError");
const testNormalBtn = document.getElementById("testNormal");
const getData = async function () {
table.innerHTML = "";
const response = await fetch(host + "/customer");
const data = await response.json();
data.forEach(customer => {
table.innerHTML +=
`<tr>
<th scope="row">${customer.id}</th>
<td>${customer.login}</td>
<td>${customer.password}</td>
</tr>`;
})
}
const create = async function (login, password) {
const requestParams = {
method: "POST",
headers: {
"Content-Type": "application/json",
}
};
const response = await fetch(host + `/customer?login=${login}&password=${password}`, requestParams);
return await response.json();
}
async function remove(id) {
const requestParams = {
method: "DELETE",
};
const response = await fetch(host + `/customer/${id}`, requestParams);
return await response.json();
}
async function edit(id, login, password) {
const requestParams = {
method: "PUT",
headers: {
"Content-Type": "application/json",
}
};
const response = await fetch(host + `/customer/${id}?login=${login}&password=${password}`, requestParams);
return await response.json();
}
const test = async function (testObject) {
const requestParams = {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(testObject),
};
const response = await fetch(host + "/test", requestParams);
if (response.status === 200) {
const data = await response.json();
alert(`TestDto=[id=${data.id}, name=${data.name}, data=${data.data}]`);
}
if (response.status === 400) {
const data = await response.text();
alert(data);
}
}
form.addEventListener("submit", function (event) {
event.preventDefault();
create(loginInput.value, passwordInput.value).then((result) => {
getData();
loginInput.value = "";
passwordInput.value = "";
alert(`Customer[id=${result.id}, login=${result.login}, password=${result.password}]`);
});
});
testErrorBtn.addEventListener("click", function () {
test({});
});
testNormalBtn.addEventListener("click", function () {
test({id: 10, name: "test"});
});
removeBtn.addEventListener("click", function (event) {
event.preventDefault();
remove(idInput.value).then((result) => {
getData();
loginInput.value = "";
passwordInput.value = "";
idInput.value = "";
});
});
editBtn.addEventListener("click", function (event) {
event.preventDefault();
edit(idInput.value, loginInput.value, passwordInput.value).then((result) => {
getData();
loginInput.value = "";
passwordInput.value = "";
idInput.value = "";
});
});
getData();
});

View File

@ -1,74 +0,0 @@
<!doctype html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>REST Client Example</title>
<script type="module" src="../node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
<link href="../node_modules/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet"/>
</head>
<body>
<header class="d-flex justify-content-center py-3">
<ul class="nav nav-pills">
<li class="nav-item"><a href="./index.html" class="nav-link" aria-current="page">Customer</a></li>
<li class="nav-item"><a href="./ticket.html" class="nav-link active">Ticket</a></li>
<li class="nav-item"><a href="./order.html" class="nav-link">Order</a></li>
</ul>
</header>
<div class="container">
<form id="form" novalidate>
<div class="row mt-3">
<div class="col-sm-4">
<label for="name" class="form-label">name</label>
<input type="text" class="form-control" id="name" required>
</div>
<div class="col-sm-4">
<label for="price" class="form-label">price</label>
<input type="number" step="0.01" class="form-control" id="price" required>
</div>
<div class="col-sm-4">
<label for="timestamp" class="form-label">timestamp</label>
<input type="datetime-local" class="form-control" id="timestamp" required>
</div>
</div>
<div class="row mt-3">
<div class="d-grid col-sm-4 mx-auto">
<button type="submit" class="btn btn-success">Add</button>
</div>
</div>
<div class="row mt-3">
<div class="col-sm-4">
<label for="id" class="form-label">id</label>
<input type="number" class="form-control" id="id" required>
</div>
</div>
<div class="row mt-3">
<div class="d-grid col-sm-2">
<button id="editBtn" class="btn btn-primary">Edit</button>
</div>
<div class="d-grid col-sm-2">
<button id="removeBtn" class="btn btn-danger">Remove</button>
</div>
</div>
</form>
<div class="row table-responsive">
<table class="table mt-3">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Name</th>
<th scope="col">Price</th>
<th scope="col">Timestamp</th>
</tr>
</thead>
<tbody id="tbody">
</tbody>
</table>
</div>
</div>
</body>
<script src="ticket.js"></script>
</html>

View File

@ -1,89 +0,0 @@
"use strict";
window.addEventListener('DOMContentLoaded', function () {
const host = "http://localhost:8080";
const table = document.getElementById("tbody");
const form = document.getElementById("form");
const priceInput = document.getElementById("price");
const nameInput = document.getElementById("name");
const idInput = document.getElementById("id");
const removeBtn = document.getElementById("removeBtn");
const editBtn = document.getElementById("editBtn");
const timestampInput = document.getElementById("timestamp");
const getData = async function () {
table.innerHTML = "";
const response = await fetch(host + "/ticket");
const data = await response.json();
data.forEach(ticket => {
table.innerHTML +=
`<tr>
<th scope="row">${ticket.id}</th>
<td>${ticket.name}</td>
<td>${ticket.price}</td>
<td>${ticket.timestamp}</td>
</tr>`;
})
}
async function create(name, price, timestamp) {
const requestParams = {
method: "POST",
headers: {
"Content-Type": "application/json",
}
};
const response = await fetch(host + `/ticket?name=${name}&price=${price}&timestamp=${timestamp}`, requestParams);
return await response.json();
}
async function remove(id) {
const requestParams = {
method: "DELETE",
};
const response = await fetch(host + `/ticket/${id}`, requestParams);
return await response.json();
}
async function edit(id, name, price) {
const requestParams = {
method: "PUT",
headers: {
"Content-Type": "application/json",
}
};
const response = await fetch(host + `/ticket/${id}?name=${name}&price=${price}`, requestParams);
return await response.json();
}
form.addEventListener("submit", function (event) {
event.preventDefault();
create(nameInput.value, priceInput.value, timestampInput.value).then((result) => {
getData();
nameInput.value = "";
priceInput.value = "";
timestampInput.value = "";
//alert(`Ticket[id=${result.id}, name=${result.name}, price=${result.price}, timestamp=${result.timetamp}]`);
});
});
removeBtn.addEventListener("click", function (event) {
event.preventDefault();
remove(idInput.value).then((result) => {
getData();
nameInput.value = "";
priceInput.value = "";
timestampInput.value = "";
idInput.value = "";
});
});
editBtn.addEventListener("click", function (event) {
event.preventDefault();
edit(idInput.value, nameInput.value, priceInput.value).then((result) => {
getData();
nameInput.value = "";
priceInput.value = "";
idInput.value = "";
});
});
getData();
});

View File

@ -1,6 +1,7 @@
package com.labwork1.app.student.controller;
import com.labwork1.app.student.service.CinemaService;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@ -27,14 +28,13 @@ public class CinemaController {
}
@PostMapping
public CinemaDto createCinema(@RequestParam("name") String name) {
return new CinemaDto(cinemaService.addCinema(name));
public CinemaDto createCinema(@RequestBody @Valid CinemaDto cinemaDto) {
return new CinemaDto(cinemaService.addCinema(cinemaDto));
}
@PutMapping("/{id}")
public CinemaDto updateCinema(@PathVariable Long id,
@RequestParam("name") String name) {
return new CinemaDto(cinemaService.updateCinema(id, name));
public CinemaDto updateCinema(@RequestBody @Valid CinemaDto cinemaDto) {
return new CinemaDto(cinemaService.updateCinema(cinemaDto));
}
@DeleteMapping("/{id}")

View File

@ -2,25 +2,31 @@ package com.labwork1.app.student.controller;
import com.labwork1.app.student.model.Cinema;
import java.util.List;
import java.nio.charset.StandardCharsets;
public class CinemaDto {
private final long id;
private final String name;
private final List<SessionDto> sessions;
private long id;
private String name;
private String image;
public CinemaDto() {
}
public CinemaDto(Cinema cinema) {
this.id = cinema.getId();
this.name = cinema.getName();
this.sessions = cinema.getSessions().stream()
.map(SessionDto::new).toList();
this.image = new String(cinema.getImage(), StandardCharsets.UTF_8);
}
public String getImage() {
return image;
}
public long getId() {
return id;
}
public String getName() {
return name;
}
public List<SessionDto> getSessions() {
return sessions;
}
}

View File

@ -2,31 +2,44 @@ package com.labwork1.app.student.controller;
import com.labwork1.app.student.model.Customer;
import com.labwork1.app.student.model.Order;
import com.labwork1.app.student.model.OrderSession;
import java.util.ArrayList;
import java.util.List;
public class CustomerDto {
private final long id;
private final String login;
private final String password;
private final List<Order> orders;
private long id;
private String login;
private String password;
private List<OrderDto> orders;
public CustomerDto() {
}
public CustomerDto(Customer customer) {
this.id = customer.getId();
this.login = customer.getLogin();
this.password = customer.getPassword();
this.orders = customer.getOrders();
this.orders = new ArrayList<>();
if (customer.getOrders() != null) {
orders = customer.getOrders().stream()
.map(OrderDto::new).toList();
}
}
public long getId() {
return id;
}
public String getLogin() {
return login;
}
public String getPassword() {
return password;
}
public List<Order> getOrders() {
public List<OrderDto> getOrders() {
return orders;
}
}

View File

@ -2,34 +2,43 @@ package com.labwork1.app.student.controller;
import com.labwork1.app.student.model.Customer;
import com.labwork1.app.student.model.Order;
import com.labwork1.app.student.model.OrderSession;
import java.sql.Date;
import java.util.List;
public class OrderDto {
private final long id;
private final Date dateOfPurchase;
private final Customer customer;
private final List<OrderSessionDto> sessions;
private long id;
private Date dateOfPurchase;
private Customer customer;
private List<OrderSessionDto> sessions;
public OrderDto() {
}
public OrderDto(Order order) {
this.id = order.getId();
this.dateOfPurchase = order.getDateOfPurchase();
this.customer = order.getCustomer();
this.sessions = order.getSessions()
.stream()
.map(x -> new OrderSessionDto(x.getId().getSessionId(),
x.getId().getOrderId(), x.getCount())).toList();
if (order.getSessions() != null && order.getSessions().size() > 0)
this.sessions = order.getSessions()
.stream()
.map(x -> new OrderSessionDto(x.getId().getSessionId(),
x.getId().getOrderId(), x.getCount())).toList();
}
public long getId() {
return id;
}
public Date getDateOfPurchase() {
return dateOfPurchase;
}
public Customer getCustomer() {
return customer;
}
public List<OrderSessionDto> getSessions() {
return sessions;
}

View File

@ -7,17 +7,21 @@ public class OrderSessionDto {
public OrderSessionDto() {
}
public OrderSessionDto(Long sessionId, Long orderId, Integer count) {
this.sessionId = sessionId;
this.orderId = orderId;
this.count = count;
}
public Long getSessionId() {
return sessionId;
}
public Long getOrderId() {
return orderId;
}
public Integer getCount() {
return count;
}

View File

@ -1,43 +1,51 @@
package com.labwork1.app.student.controller;
import com.labwork1.app.student.model.Cinema;
import com.labwork1.app.student.model.Session;
import java.sql.Timestamp;
import java.util.List;
public class SessionDto {
private final long id;
private long id;
private Double price;
private Timestamp timestamp;
private final List<OrderSessionDto> orders;
private final CinemaDto cinema;
private final int capacity;
private CinemaDto cinema;
private int capacity;
private int maxCount;
public SessionDto() {
}
public SessionDto(Session session) {
this.id = session.getId();
this.price = session.getPrice();
this.timestamp = session.getTimestamp();
this.capacity = session.getCapacity();
this.cinema = new CinemaDto(session.getCinema());
this.orders = session.getOrders()
.stream()
.map(x -> new OrderSessionDto(x.getId().getSessionId(),
x.getId().getOrderId(), x.getCount())).toList();
this.maxCount = session.getMaxCount();
if (session.getCinema() != null) this.cinema = new CinemaDto(session.getCinema());
else this.cinema = null;
}
public int getMaxCount() {
return maxCount;
}
public int getCapacity() {
return capacity;
}
public long getId() {
return id;
}
public Double getPrice() {
return price;
}
public Timestamp getTimestamp() {
return timestamp;
}
public List<OrderSessionDto> getOrders() {
return orders;
}
public CinemaDto getCinema() {
return cinema;
}

View File

@ -1,5 +1,7 @@
package com.labwork1.app.student.model;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.labwork1.app.student.controller.CinemaDto;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotBlank;
@ -15,7 +17,11 @@ public class Cinema {
@Column
private String name;
@OneToMany(fetch = FetchType.EAGER, mappedBy = "cinema", cascade = CascadeType.REMOVE)
@JsonIgnore
private List<Session> sessions;
@Lob
private byte[] image;
public Cinema() {
}
@ -24,6 +30,20 @@ public class Cinema {
this.sessions = new ArrayList<>();
}
public Cinema(CinemaDto cinemaDto) {
this.name = cinemaDto.getName();
this.image = cinemaDto.getImage().getBytes();
this.sessions = new ArrayList<>();
}
public byte[] getImage() {
return image;
}
public void setImage(byte[] image) {
this.image = image;
}
public List<Session> getSessions() {
return sessions;
}

View File

@ -1,5 +1,6 @@
package com.labwork1.app.student.model;
import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
@ -19,6 +20,7 @@ public class Order {
private Date dateOfPurchase;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "customer_fk")
@JsonIgnore
private Customer customer;
@OneToMany(mappedBy = "order", fetch = FetchType.EAGER, cascade = CascadeType.ALL)
private List<OrderSession> sessions;

View File

@ -1,19 +1,23 @@
package com.labwork1.app.student.model;
import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.*;
@Entity
@Table(name = "order_session")
public class OrderSession {
@EmbeddedId
@JsonIgnore
private OrderSessionKey id;
@ManyToOne
@MapsId("sessionId")
@JoinColumn(name = "session_id")
@JsonIgnore
private Session session;
@ManyToOne
@MapsId("orderId")
@JoinColumn(name = "order_id")
@JsonIgnore
private Order order;
@Column(name = "count")
private Integer count;

View File

@ -53,7 +53,7 @@ public class OrderRepositoryImpl implements OrderRepositoryExtension {
new OrderSessionKey(currentSession.getId(), currentOrder.getId()));
if (currentSession.getCapacity() < count ||
(orderSession != null && orderSession.getCount() + count > currentSession.getCapacity())) {
(orderSession != null && orderSession.getCount() + count > currentSession.getMaxCount())) {
throw new IllegalArgumentException("No more tickets in session. Capacity - "+currentSession.getCapacity()+". Count - "+count);
}
if (orderSession == null)

View File

@ -1,5 +1,6 @@
package com.labwork1.app.student.service;
import com.labwork1.app.student.controller.CinemaDto;
import com.labwork1.app.student.model.Cinema;
import com.labwork1.app.student.repository.CinemaRepository;
import com.labwork1.app.util.validation.ValidatorUtil;
@ -13,11 +14,19 @@ import java.util.Optional;
public class CinemaService {
private final CinemaRepository cinemaRepository;
private final ValidatorUtil validatorUtil;
public CinemaService(CinemaRepository cinemaRepository, ValidatorUtil validatorUtil) {
this.cinemaRepository = cinemaRepository;
this.validatorUtil = validatorUtil;
}
@Transactional
public Cinema addCinema(CinemaDto dto) {
final Cinema cinema = new Cinema(dto);
validatorUtil.validate(cinema);
return cinemaRepository.save(cinema);
}
@Transactional
public Cinema addCinema(String name) {
final Cinema cinema = new Cinema(name);
@ -37,9 +46,10 @@ public class CinemaService {
}
@Transactional
public Cinema updateCinema(Long id, String name) {
final Cinema currentCinema = findCinema(id);
currentCinema.setName(name);
public Cinema updateCinema(CinemaDto cinema) {
final Cinema currentCinema = findCinema(cinema.getId());
currentCinema.setName(cinema.getName());
currentCinema.setImage(cinema.getImage().getBytes());
validatorUtil.validate(currentCinema);
return cinemaRepository.save(currentCinema);
}

View File

@ -1,17 +0,0 @@
package com.labwork1.app.test.controller;
import com.labwork1.app.test.model.TestDto;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/test")
public class TestController {
@PostMapping
public TestDto testValidation(@RequestBody @Valid TestDto testDto) {
return testDto;
}
}

View File

@ -1,31 +0,0 @@
package com.labwork1.app.test.model;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
public class TestDto {
@NotNull(message = "Id can't be null")
private Long id;
@NotBlank(message = "Name can't be null or empty")
private String name;
public Long getId() {
return id;
}
public String getName() {
return name;
}
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
public String getData() {
return String.format("%s %s", id, name);
}
@JsonIgnore
public String getAnotherData() {
return "Test";
}
}

View File

@ -1,4 +1,3 @@
/*
package com.labwork1.app;
import com.labwork1.app.student.model.Customer;
@ -48,6 +47,8 @@ public class JpaCustomerTests {
.findCinema(cinema1.getId()).getSessions().size(), 2);
// 1 покупатель
final Customer customer1 = customerService.addCustomer("Родион", "Иванов");
customerService.updateCustomer(customer1.getId(), "Пчел", "Пчелов");
Assertions.assertEquals(customerService.findCustomer(customer1.getId()).getLogin(), "Пчел");
// 1 заказ, 1 копия заказа
final Order order0 = orderService.addOrder(customerService.findCustomer(customer1.getId()).getId());
final Order order1 = orderService.findOrder(order0.getId());
@ -118,4 +119,3 @@ public class JpaCustomerTests {
cinemaService.deleteCinema(cinema2.getId());
}
}
*/