Compare commits

..

1 Commits
LW03 ... master

Author SHA1 Message Date
27ec055c62 отчеты 2023-06-15 13:35:28 +04:00
26 changed files with 56 additions and 1248 deletions

View File

@ -14,11 +14,6 @@ repositories {
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'com.h2database:h2:2.1.210'
implementation 'org.springframework.boot:spring-boot-starter-validation'
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'
}

Binary file not shown.

View File

@ -1,250 +0,0 @@
2023-03-27 18:22:19 database: wrong user or password; user: "USER"
org.h2.message.DbException: Неверное имя пользователя или пароль
Wrong user name or password [28000-210]
at org.h2.message.DbException.get(DbException.java:227)
at org.h2.message.DbException.get(DbException.java:203)
at org.h2.message.DbException.get(DbException.java:192)
at org.h2.engine.Engine.openSession(Engine.java:154)
at org.h2.engine.Engine.openSession(Engine.java:222)
at org.h2.engine.Engine.createSession(Engine.java:201)
at org.h2.engine.SessionRemote.connectEmbeddedOrServer(SessionRemote.java:338)
at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:122)
at org.h2.util.JdbcUtils.getConnection(JdbcUtils.java:288)
at org.h2.server.web.WebServer.getConnection(WebServer.java:807)
at org.h2.server.web.WebApp.login(WebApp.java:1033)
at org.h2.server.web.WebApp.process(WebApp.java:226)
at org.h2.server.web.WebApp.processRequest(WebApp.java:176)
at org.h2.server.web.JakartaWebServlet.doGet(JakartaWebServlet.java:129)
at org.h2.server.web.JakartaWebServlet.doPost(JakartaWebServlet.java:166)
at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:731)
at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:814)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:223)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:158)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:185)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:158)
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:185)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:158)
at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:185)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:158)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:185)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:158)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:177)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:542)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:119)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:357)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:400)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:859)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1734)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:52)
at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: org.h2.jdbc.JdbcSQLInvalidAuthorizationSpecException: Неверное имя пользователя или пароль
Wrong user name or password [28000-210]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:529)
at org.h2.message.DbException.getJdbcSQLException(DbException.java:496)
... 50 more
2023-03-27 18:22:22 database: wrong user or password; user: "USER"
org.h2.message.DbException: Неверное имя пользователя или пароль
Wrong user name or password [28000-210]
at org.h2.message.DbException.get(DbException.java:227)
at org.h2.message.DbException.get(DbException.java:203)
at org.h2.message.DbException.get(DbException.java:192)
at org.h2.engine.Engine.openSession(Engine.java:154)
at org.h2.engine.Engine.openSession(Engine.java:222)
at org.h2.engine.Engine.createSession(Engine.java:201)
at org.h2.engine.SessionRemote.connectEmbeddedOrServer(SessionRemote.java:338)
at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:122)
at org.h2.util.JdbcUtils.getConnection(JdbcUtils.java:288)
at org.h2.server.web.WebServer.getConnection(WebServer.java:807)
at org.h2.server.web.WebApp.login(WebApp.java:1033)
at org.h2.server.web.WebApp.process(WebApp.java:226)
at org.h2.server.web.WebApp.processRequest(WebApp.java:176)
at org.h2.server.web.JakartaWebServlet.doGet(JakartaWebServlet.java:129)
at org.h2.server.web.JakartaWebServlet.doPost(JakartaWebServlet.java:166)
at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:731)
at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:814)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:223)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:158)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:185)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:158)
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:185)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:158)
at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:185)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:158)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:185)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:158)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:177)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:542)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:119)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:357)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:400)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:859)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1734)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:52)
at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: org.h2.jdbc.JdbcSQLInvalidAuthorizationSpecException: Неверное имя пользователя или пароль
Wrong user name or password [28000-210]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:529)
at org.h2.message.DbException.getJdbcSQLException(DbException.java:496)
... 50 more
2023-03-27 18:38:34 jdbc[13]: exception
org.h2.jdbc.JdbcSQLSyntaxErrorException: Синтаксическая ошибка в выражении SQL "INSERT INTO customer (id, login, password) VALUES (1, 'USA, 'USA');\000d\000a\000d\000aINSERT INTO tab_order (id, date_of_purchase, customer_fk) VALUES (1, '2023-01-01', 1);\000d\000a\000d\000aINSERT INTO TICKET (id, name, price, timestamp) VALUES (1, 'fdfdf', 100, '2023-01-01[*]');"
Syntax error in SQL statement "INSERT INTO customer (id, login, password) VALUES (1, 'USA, 'USA');\000d\000a\000d\000aINSERT INTO tab_order (id, date_of_purchase, customer_fk) VALUES (1, '2023-01-01', 1);\000d\000a\000d\000aINSERT INTO TICKET (id, name, price, timestamp) VALUES (1, 'fdfdf', 100, '2023-01-01[*]');"; SQL statement:
INSERT INTO customer (id, login, password) VALUES (1, 'USA, 'USA');
INSERT INTO tab_order (id, date_of_purchase, customer_fk) VALUES (1, '2023-01-01', 1);
INSERT INTO TICKET (id, name, price, timestamp) VALUES (1, 'fdfdf', 100, '2023-01-01'); [42000-210]
2023-03-27 18:38:54 jdbc[13]: exception
org.h2.jdbc.JdbcSQLSyntaxErrorException: Синтаксическая ошибка в выражении SQL "INSERT INTO customer (id, login, password) VALUES (1, 'USA, 'USA[*]');"
Syntax error in SQL statement "INSERT INTO customer (id, login, password) VALUES (1, 'USA, 'USA[*]');"; SQL statement:
INSERT INTO customer (id, login, password) VALUES (1, 'USA, 'USA'); [42000-210]
2023-03-27 18:39:51 jdbc[13]: exception
org.h2.jdbc.JdbcSQLSyntaxErrorException: Невозможно удалить "TICKET", пока существует зависимый объект "FKSRNEYS4QS7OF1B6DOT6W1MFDE"
Cannot drop "TICKET" because "FKSRNEYS4QS7OF1B6DOT6W1MFDE" depends on it; SQL statement:
drop table ticket [90107-210]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:651)
at org.h2.message.DbException.getJdbcSQLException(DbException.java:496)
at org.h2.message.DbException.get(DbException.java:227)
at org.h2.command.ddl.DropTable.prepareDrop(DropTable.java:97)
at org.h2.command.ddl.DropTable.update(DropTable.java:121)
at org.h2.command.CommandContainer.update(CommandContainer.java:174)
at org.h2.command.Command.executeUpdate(Command.java:252)
at org.h2.jdbc.JdbcStatement.executeInternal(JdbcStatement.java:252)
at org.h2.jdbc.JdbcStatement.execute(JdbcStatement.java:223)
at org.h2.server.web.WebApp.getResult(WebApp.java:1339)
at org.h2.server.web.WebApp.query(WebApp.java:1137)
at org.h2.server.web.WebApp.query(WebApp.java:1113)
at org.h2.server.web.WebApp.process(WebApp.java:244)
at org.h2.server.web.WebApp.processRequest(WebApp.java:176)
at org.h2.server.web.JakartaWebServlet.doGet(JakartaWebServlet.java:129)
at org.h2.server.web.JakartaWebServlet.doPost(JakartaWebServlet.java:166)
at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:731)
at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:814)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:223)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:158)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:185)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:158)
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:185)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:158)
at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:185)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:158)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:185)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:158)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:177)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:542)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:119)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:357)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:400)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:859)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1734)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:52)
at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.base/java.lang.Thread.run(Thread.java:833)
2023-03-27 18:40:39 jdbc[13]: exception
org.h2.jdbc.JdbcSQLSyntaxErrorException: Столбец "NAME" не найден
Column "NAME" not found; SQL statement:
INSERT INTO session (id, name, price, timestamp) VALUES (1, 'fdfdf', 100, '2023-01-01') [42122-210]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:521)
at org.h2.message.DbException.getJdbcSQLException(DbException.java:496)
at org.h2.message.DbException.get(DbException.java:227)
at org.h2.message.DbException.get(DbException.java:203)
at org.h2.table.Table.getColumn(Table.java:754)
at org.h2.command.Parser.parseColumn(Parser.java:1247)
at org.h2.command.Parser.parseColumnList(Parser.java:1232)
at org.h2.command.Parser.parseInsert(Parser.java:1633)
at org.h2.command.Parser.parsePrepared(Parser.java:797)
at org.h2.command.Parser.parse(Parser.java:674)
at org.h2.command.Parser.parse(Parser.java:644)
at org.h2.command.Parser.prepareCommand(Parser.java:551)
at org.h2.engine.SessionLocal.prepareLocal(SessionLocal.java:615)
at org.h2.engine.SessionLocal.prepareCommand(SessionLocal.java:553)
at org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:1116)
at org.h2.jdbc.JdbcStatement.executeInternal(JdbcStatement.java:237)
at org.h2.jdbc.JdbcStatement.execute(JdbcStatement.java:223)
at org.h2.server.web.WebApp.getResult(WebApp.java:1339)
at org.h2.server.web.WebApp.query(WebApp.java:1137)
at org.h2.server.web.WebApp.query(WebApp.java:1113)
at org.h2.server.web.WebApp.process(WebApp.java:244)
at org.h2.server.web.WebApp.processRequest(WebApp.java:176)
at org.h2.server.web.JakartaWebServlet.doGet(JakartaWebServlet.java:129)
at org.h2.server.web.JakartaWebServlet.doPost(JakartaWebServlet.java:166)
at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:731)
at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:814)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:223)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:158)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:185)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:158)
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:185)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:158)
at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:185)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:158)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:185)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:158)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:177)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:542)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:119)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:357)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:400)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:859)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1734)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:52)
at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.base/java.lang.Thread.run(Thread.java:833)
2023-03-27 18:45:24 jdbc[13]: exception
org.h2.jdbc.JdbcSQLSyntaxErrorException: Синтаксическая ошибка в выражении SQL "delete customer where id = 1 [*]on delete cascade"
Syntax error in SQL statement "delete customer where id = 1 [*]on delete cascade"; SQL statement:
delete customer where id = 1 on delete cascade [42000-210]

View File

@ -30,10 +30,7 @@
<input id="second" class="form-control" type='number' value='0' />
</div>
<div>
<button type="button" class="btn btn-primary my-2" id="calculate">Числа</button>
</div>
<div>
<button type="button" class="btn btn-primary mb-2" id="calculateStr">Строки</button>
<button type="button" class="btn btn-primary" id="calculate">Тык</button>
</div>
<div>
Результат:

View File

@ -1,30 +1,26 @@
const calculateButton = document.getElementById("calculate");
const calculateStrButton = document.getElementById("calculateStr");
const first = document.getElementById("first");
const second = document.getElementById("second");
const select = document.getElementById("operation");
const result = document.getElementById("result");
calculateButton.onclick = function() {
calculate("num");
};
calculateStrButton.onclick = function() {
calculate("str");
calculate();
};
function calculate(parametr) {
function calculate() {
switch (parseInt(select.value)) {
case 1:
doSmth("plus", parametr)
doSmth("plus")
break;
case 2:
doSmth("minus", parametr)
doSmth("minus")
break;
case 3:
doSmth("mult", parametr)
doSmth("mult")
break;
case 4:
doSmth("div", parametr)
doSmth("div")
break;
};
}
@ -36,9 +32,8 @@ function checkNum(res) {
return res
}
function doSmth(address, type) {
console.log("Тип " + type)
fetch(`http://localhost:8080/${address}?first=${first.value}&second=${second.value}&type=${type}`)
function doSmth(address) {
fetch(`http://localhost:8080/${address}?first=${first.value}&second=${second.value}`)
.then(response => response.text())
.then(res => result.innerHTML = checkNum(res));
}

View File

@ -2,6 +2,8 @@ package com.labwork1.app;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
@ -10,4 +12,32 @@ public class AppApplication {
public static void main(String[] args) {
SpringApplication.run(AppApplication.class, args);
}
@GetMapping("/hello")
public String hello(@RequestParam(value = "name", defaultValue = "World") String name) {
return String.format("Hello %s!", name);
}
@GetMapping("/plus")
public String plus(@RequestParam(required = false, defaultValue = "0") double first,
@RequestParam(required = false, defaultValue = "0") double second) {
return Double.toString(first + second);
}
@GetMapping("/minus")
public String minus(@RequestParam(required = false, defaultValue = "0") double first,
@RequestParam(required = false, defaultValue = "0") double second) {
return Double.toString(first - second);
}
@GetMapping("/mult")
public String mult(@RequestParam(required = false, defaultValue = "1") double first,
@RequestParam(required = false, defaultValue = "1") double second) {
return Double.toString(first * second);
}
@GetMapping("/div")
public String div(@RequestParam(required = false, defaultValue = "1") double first,
@RequestParam(required = false, defaultValue = "1") double second) {
if(second == 0)
{
return null;
}
return Double.toString(first/second);
}
}

View File

@ -1,50 +0,0 @@
package com.labwork1.app.student.model;
import jakarta.persistence.*;
import java.util.ArrayList;
import java.util.List;
@Entity
public class Cinema {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column
private String name;
@OneToMany(fetch = FetchType.EAGER, mappedBy = "cinema", cascade = CascadeType.REMOVE)
private List<Session> sessions;
public Cinema() {
}
public Cinema(String name) {
this.name = name;
this.sessions = new ArrayList<>();
}
public List<Session> getSessions() {
return sessions;
}
public void setSession(Session session) {
if (session.getCinema().equals(this)) {
this.sessions.add(session);
}
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

View File

@ -1,81 +0,0 @@
package com.labwork1.app.student.model;
import jakarta.persistence.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
@Entity
public class Customer {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column
private String login;
@Column
private String password;
@OneToMany(fetch = FetchType.EAGER, mappedBy = "customer", cascade = CascadeType.REMOVE)
private List<Order> orders;
public Customer() {
}
public Customer(String login, String password) {
this.login = login;
this.password = password;
this.orders = new ArrayList<>();
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Customer customer = (Customer) o;
return Objects.equals(id, customer.id);
}
@Override
public int hashCode() {
return Objects.hash(id);
}
@Override
public String toString() {
return "Customer {" +
"id=" + id +
", login='" + login + '\'' +
", password='" + password + '\'' +
'}';
}
public Long getId() {
return id;
}
public String getLogin() {
return login;
}
public void setLogin(String login) {
this.login = login;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public List<Order> getOrders() {
return orders;
}
public void setOrder(Order order) {
if (order.getCustomer().equals(this)) {
this.orders.add(order);
}
}
}

View File

@ -1,96 +0,0 @@
package com.labwork1.app.student.model;
import jakarta.persistence.*;
import java.sql.Date;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
@Entity
@Table(name = "tab_order")
public class Order {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column
@Temporal(TemporalType.DATE)
private Date dateOfPurchase;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "customer_fk")
private Customer customer;
@OneToMany(mappedBy = "order", fetch = FetchType.EAGER, cascade = CascadeType.ALL)
private List<OrderSession> sessions;
public Order() {
}
public Order(Date dateOfPurchase) {
this.dateOfPurchase = dateOfPurchase;
}
public void addSession(OrderSession orderSession) {
if (sessions == null) {
sessions = new ArrayList<>();
}
if (!sessions.contains(orderSession))
this.sessions.add(orderSession);
}
public void removeSession(OrderSession orderSession){
if (sessions.contains(orderSession))
this.sessions.remove(orderSession);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Order order = (Order) o;
return Objects.equals(id, order.id);
}
@Override
public int hashCode() {
return Objects.hash(id);
}
@Override
public String toString() {
return "Order {" +
"id=" + id +
", date='" + dateOfPurchase.toString() + '\'' +
", customer='" + customer.toString() + '\'';
}
public Long getId() {
return id;
}
public Date getDateOfPurchase() {
return dateOfPurchase;
}
public void setDateOfPurchase(Date dateOfPurchase) {
this.dateOfPurchase = dateOfPurchase;
}
public Customer getCustomer() {
return customer;
}
public void setCustomer(Customer customer) {
this.customer = customer;
if (!customer.getOrders().contains(this)) {
customer.setOrder(this);
}
}
public List<OrderSession> getSessions() {
return sessions;
}
public void setSessions(List<OrderSession> sessions) {
this.sessions = sessions;
}
}

View File

@ -1,64 +0,0 @@
package com.labwork1.app.student.model;
import jakarta.persistence.*;
@Entity
@Table(name = "order_session")
public class OrderSession {
@EmbeddedId
private OrderSessionKey id;
@ManyToOne
@MapsId("sessionId")
@JoinColumn(name = "session_id")
private Session session;
@ManyToOne
@MapsId("orderId")
@JoinColumn(name = "order_id")
private Order order;
@Column(name = "count")
private Integer count;
public OrderSession() {
}
public OrderSession(Order order, Session session, Integer count) {
this.order = order;
this.id = new OrderSessionKey(session.getId(), order.getId());
this.id.setOrderId(order.getId());
this.id.setSessionId(session.getId());
this.session = session;
this.count = count;
}
public OrderSessionKey getId() {
return id;
}
public void setId(OrderSessionKey id) {
this.id = id;
}
public Order getOrder() {
return order;
}
public void setOrder(Order order) {
this.order = order;
}
public Session getSession() {
return session;
}
public void setSession(Session session) {
this.session = session;
}
public Integer getCount() {
return count;
}
public void setCount(Integer count) {
this.count = count;
}
}

View File

@ -1,48 +0,0 @@
package com.labwork1.app.student.model;
import jakarta.persistence.Embeddable;
import java.io.Serializable;
import java.util.Objects;
@Embeddable
public class OrderSessionKey implements Serializable {
private Long sessionId;
private Long orderId;
public OrderSessionKey() {
}
public OrderSessionKey(Long sessionId, Long orderId) {
this.sessionId = sessionId;
this.orderId = orderId;
}
public Long getSessionId() {
return sessionId;
}
public void setSessionId(Long sessionId) {
this.sessionId = sessionId;
}
public Long getOrderId() {
return orderId;
}
public void setOrderId(Long orderId) {
this.orderId = orderId;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof OrderSessionKey that)) return false;
return Objects.equals(getSessionId(), that.getSessionId()) && Objects.equals(getOrderId(), that.getOrderId());
}
@Override
public int hashCode() {
return Objects.hash(getSessionId(), getOrderId());
}
}

View File

@ -1,112 +0,0 @@
package com.labwork1.app.student.model;
import jakarta.persistence.*;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
@Entity
public class Session {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column
private Double price;
@Column
@Temporal(TemporalType.TIMESTAMP)
private Timestamp timestamp;
@OneToMany(mappedBy = "session", fetch = FetchType.EAGER, cascade = CascadeType.ALL)
private List<OrderSession> orders;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "cinema_fk")
private Cinema cinema;
@Column
private Integer capacity;
public Session() {
}
public Session(Double price, Timestamp timestamp, Integer capacity) {
this.price = price;
this.timestamp = timestamp;
this.capacity = capacity;
}
public Cinema getCinema() {
return cinema;
}
public void setCinema(Cinema cinema) {
this.cinema = cinema;
if (!cinema.getSessions().contains(this)) {
cinema.setSession(this);
}
}
public void addOrder(OrderSession orderSession){
if (orders == null){
orders = new ArrayList<>();
}
if (!orders.contains(orderSession)) {
this.orders.add(orderSession);
}
}
public void removeOrder(OrderSession orderSession){
if (orders.contains(orderSession))
this.orders.remove(orderSession);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Session session = (Session) o;
return Objects.equals(id, session.id);
}
@Override
public int hashCode() {
return Objects.hash(id);
}
@Override
public String toString() {
return "Session {" +
"id=" + id +
", price='" + price + '\'' +
", timestamp='" + timestamp.toString() + '\'' +
'}';
}
public Long getId() {
return id;
}
public Double getPrice() {
return price;
}
public void setPrice(Double price) {
this.price = price;
}
public Timestamp getTimestamp() {
return timestamp;
}
public void setTimestamp(Timestamp timestamp) {
this.timestamp = timestamp;
}
public List<OrderSession> getOrders() {
return orders;
}
public Integer getCapacity() {
return capacity;
}
public void setCapacity(Integer capacity) {
this.capacity = capacity;
}
}

View File

@ -1,64 +0,0 @@
package com.labwork1.app.student.service;
import com.labwork1.app.student.model.Cinema;
import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityNotFoundException;
import jakarta.persistence.PersistenceContext;
import jakarta.transaction.Transactional;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.util.List;
@Service
public class CinemaService {
@PersistenceContext
private EntityManager em;
@Transactional
public Cinema addCinema(String name) {
if (!StringUtils.hasText(name)) {
throw new IllegalArgumentException("Cinema name is null or empty");
}
final Cinema cinema = new Cinema(name);
em.persist(cinema);
return cinema;
}
@Transactional
public Cinema findCinema(Long id) {
final Cinema cinema = em.find(Cinema.class, id);
if (cinema == null) {
throw new EntityNotFoundException(String.format("Cinema with id [%s] is not found", id));
}
return cinema;
}
@Transactional
public List<Cinema> findAllCinemas() {
return em.createQuery("select c from Cinema c", Cinema.class)
.getResultList();
}
@Transactional
public Cinema updateCinema(Long id, String name) {
if (!StringUtils.hasText(name)) {
throw new IllegalArgumentException("Cinema name is null or empty");
}
final Cinema currentCinema = findCinema(id);
currentCinema.setName(name);
return em.merge(currentCinema);
}
@Transactional
public Cinema deleteCinema(Long id) {
final Cinema currentCinema = findCinema(id);
em.remove(currentCinema);
return currentCinema;
}
@Transactional
public void deleteAllCinemas() {
em.createQuery("delete from Cinema").executeUpdate();
}
}

View File

@ -1,85 +0,0 @@
package com.labwork1.app.student.service;
import com.labwork1.app.student.model.Customer;
import com.labwork1.app.student.model.Order;
import com.labwork1.app.student.model.OrderSession;
import com.labwork1.app.student.model.Session;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityNotFoundException;
import jakarta.persistence.PersistenceContext;
import java.util.List;
@Service
public class CustomerService {
@PersistenceContext
private EntityManager em;
@Transactional
public Customer addCustomer(String login, String password) {
if (!StringUtils.hasText(login) || !StringUtils.hasText(password)) {
throw new IllegalArgumentException("Customer login/password is null or empty");
}
final Customer customer = new Customer(login, password);
em.persist(customer);
return customer;
}
@Transactional(readOnly = true)
public Customer findCustomer(Long id) {
final Customer customer = em.find(Customer.class, id);
if (customer == null) {
throw new EntityNotFoundException(String.format("Customer with id [%s] is not found", id));
}
return customer;
}
@Transactional(readOnly = true)
public List<Customer> findAllCustomers() {
return em.createQuery("select c from Customer c", Customer.class)
.getResultList();
}
@Transactional
public Customer updateCustomer(Long id, String login, String password) {
if (!StringUtils.hasText(login) || !StringUtils.hasText(password)) {
throw new IllegalArgumentException("Customer login/password is null or empty");
}
final Customer currentCustomer = findCustomer(id);
currentCustomer.setLogin(login);
currentCustomer.setPassword(password);
return em.merge(currentCustomer);
}
@Transactional
public Customer deleteCustomer(Long id) {
final Customer currentCustomer = findCustomer(id);
final List<Order> currentCustomerOrders = currentCustomer.getOrders();
for (int i = 0; i < currentCustomerOrders.size(); i++) {
final Order currentOrder = em.find(Order.class, currentCustomerOrders.get(i).getId());
List<OrderSession> orderSessionList = em
.createQuery("select p from OrderSession p where p.id.orderId = " + id, OrderSession.class)
.getResultList();
for (int j = 0; j < orderSessionList.size(); j++) {
final Session currentSession = orderSessionList.get(j).getSession();
currentOrder.getSessions().remove(orderSessionList.get(j));
currentSession.getOrders().remove(orderSessionList.get(j));
em.remove(orderSessionList.get(j));
em.merge(currentSession);
}
em.merge(currentOrder);
}
em.remove(currentCustomer);
return currentCustomer;
}
@Transactional
public void deleteAllCustomers() {
em.createQuery("delete from Customer").executeUpdate();
}
}

View File

@ -1,96 +0,0 @@
package com.labwork1.app.student.service;
import com.labwork1.app.student.model.Customer;
import com.labwork1.app.student.model.Order;
import com.labwork1.app.student.model.OrderSession;
import com.labwork1.app.student.model.Session;
import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityNotFoundException;
import jakarta.persistence.PersistenceContext;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.sql.Date;
import java.util.List;
@Service
public class OrderService {
@PersistenceContext
private EntityManager em;
@Transactional
public Order addOrder(Customer customer_id) {
if (customer_id == null || em.find(Customer.class, customer_id.getId()) == null) {
throw new IllegalArgumentException("addOrder empty fields");
}
final Order order = new Order(new Date(System.currentTimeMillis()));
order.setCustomer(customer_id);
em.persist(order);
em.merge(customer_id);
return order;
}
@Transactional
public Order addSession(Long id, Long session, Integer count) {
if (session <= 0 || count <= 0) {
throw new IllegalArgumentException("addOrder empty fields");
}
final Order currentOrder = findOrder(id);
final Session currentSession = em.find(Session.class, session);
if (currentSession.getCapacity() < count) {
throw new IllegalArgumentException("No more tickets in session. Capacity - "+currentSession.getCapacity()+". Count - "+count);
}
final OrderSession orderSession = new OrderSession(currentOrder, currentSession, count);
currentOrder.addSession(orderSession);
currentSession.addOrder(orderSession);
currentSession.setCapacity(currentSession.getCapacity() - count);
em.merge(currentSession);
return em.merge(currentOrder);
}
@Transactional(readOnly = true)
public Order findOrder(Long id) {
final Order order = em.find(Order.class, id);
if (order == null) {
throw new EntityNotFoundException(String.format("Order with id [%s] is not found", id));
}
return order;
}
@Transactional(readOnly = true)
public List<Order> findAllOrders() {
return em.createQuery("select o from Order o", Order.class)
.getResultList();
}
@Transactional
public Order deleteOrder(Long id) {
final Order currentOrder = findOrder(id);
em.remove(currentOrder);
return currentOrder;
}
@Transactional
public Order deleteSessionInOrder(Long id, Long session) {
final Order currentOrder = findOrder(id);
final Session currentSession = em.find(Session.class, session);
List<OrderSession> orderSessionList = em
.createQuery("select p from OrderSession p where p.id.orderId = " + id + " and p.id.sessionId = " + session, OrderSession.class)
.getResultList();
for (int i = 0; i < orderSessionList.size(); i++) {
currentOrder.getSessions().remove(orderSessionList.get(i));
currentSession.getOrders().remove(orderSessionList.get(i));
currentSession.setCapacity(currentSession.getCapacity() + orderSessionList.get(i).getCount());
em.remove(orderSessionList.get(i));
}
em.merge(currentSession);
return em.merge(currentOrder);
}
@Transactional
public void deleteAllOrders() {
em.createQuery("delete from Order").executeUpdate();
}
}

View File

@ -1,81 +0,0 @@
package com.labwork1.app.student.service;
import com.labwork1.app.student.model.Cinema;
import com.labwork1.app.student.model.OrderSession;
import com.labwork1.app.student.model.Session;
import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityNotFoundException;
import jakarta.persistence.PersistenceContext;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.sql.Timestamp;
import java.util.List;
@Service
public class SessionService {
@PersistenceContext
private EntityManager em;
@Transactional
public Session addSession(Double price, Timestamp date, Long cinema_id, Integer capacity) {
if (price <= 0 || date == null) {
throw new IllegalArgumentException("addSession empty fields");
}
final Session session = new Session(price, date, capacity);
final Cinema cinema = em.find(Cinema.class, cinema_id);
session.setCinema(cinema);
em.persist(session);
return session;
}
@Transactional(readOnly = true)
public Session findSession(Long id) {
final Session session = em.find(Session.class, id);
if (session == null) {
throw new EntityNotFoundException(String.format("Session with id [%s] is not found", id));
}
return session;
}
@Transactional(readOnly = true)
public List<Session> findAllSessions() {
return em.createQuery("select t from Session t", Session.class)
.getResultList();
}
@Transactional
public Session updateSession(Long id, Double price) {
if (price <= 0) {
throw new IllegalArgumentException("updateSession empty fields");
}
final Session currentSession = findSession(id);
currentSession.setPrice(price);
return em.merge(currentSession);
}
@Transactional
public Session deleteSession(Long id) {
final Session currentSession = findSession(id);
int size = currentSession.getOrders().size();
for (int i = 0; i < size; i++) {
OrderSession temp = currentSession.getOrders().get(0);
temp.getSession().removeOrder(temp);
temp.getOrder().removeSession(temp);
em.remove(temp);
}
em.remove(currentSession);
return currentSession;
}
@Transactional
public void deleteAllSessions() {
em.createQuery("delete from Session ").executeUpdate();
}
@Transactional
public List<Session> findAllSessionsWithCapacity() {
return em.createQuery("select t from Session t where capacity > 0", Session.class)
.getResultList();
}
}

View File

@ -1,10 +1 @@
spring.main.banner-mode=off
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,13 @@
package com.labwork1.app;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class AppApplicationTests {
@Test
void contextLoads() {
}
}

View File

@ -1,180 +0,0 @@
package com.labwork1.app;
import com.labwork1.app.student.model.Cinema;
import com.labwork1.app.student.model.Customer;
import com.labwork1.app.student.model.Order;
import com.labwork1.app.student.model.Session;
import com.labwork1.app.student.service.CinemaService;
import com.labwork1.app.student.service.CustomerService;
import com.labwork1.app.student.service.OrderService;
import com.labwork1.app.student.service.SessionService;
import jakarta.persistence.EntityNotFoundException;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import java.sql.Timestamp;
import java.util.List;
@SpringBootTest
public class JpaCustomerTests {
private static final Logger log = LoggerFactory.getLogger(JpaCustomerTests.class);
@Autowired
private CustomerService customerService;
@Autowired
private SessionService sessionService;
@Autowired
private OrderService orderService;
@Autowired
private CinemaService cinemaService;
@Test
void testOrder() {
sessionService.deleteAllSessions();
cinemaService.deleteAllCinemas();
orderService.deleteAllOrders();
customerService.deleteAllCustomers();
// 2 кино
final Cinema cinema1 = cinemaService.addCinema("Меню");
final Cinema cinema2 = cinemaService.addCinema("Аватар");
// 2 сеанса
final Session session1 = sessionService.addSession(300.0,
new Timestamp(System.currentTimeMillis()), cinema1.getId(), 10);
final Session session2 = sessionService.addSession( 200.0,
new Timestamp(System.currentTimeMillis()), cinema1.getId(), 10);
// проверка 2 сеанса у 1 кино
Assertions.assertEquals(cinemaService
.findCinema(cinema1.getId()).getSessions().size(), 2);
// 1 покупатель
final Customer customer1 = customerService.addCustomer("Родион", "Иванов");
// 1 заказ, 1 копия заказа
final Order order0 = orderService.addOrder(customerService.findCustomer(customer1.getId()));
final Order order1 = orderService.findOrder(order0.getId());
Assertions.assertEquals(order0, order1);
// у клиента точно есть заказ?
Assertions.assertEquals(customerService
.findCustomer(customer1.getId()).getOrders().size(), 1);
// 0 заказов
orderService.deleteAllOrders();
Assertions.assertThrows(EntityNotFoundException.class, () -> orderService.findOrder(-1L));
// 2 покупателя
final Customer customer2 = customerService.addCustomer("Иннокентий", "Иванов");
// 1 заказ
final Order order2 = orderService
.addOrder(customerService.findCustomer(customer2.getId()));
// у заказа 2 сеанса
orderService.addSession(order2.getId(), session1.getId(), 2);
Assertions.assertEquals(sessionService.findSession(session1.getId()).getCapacity(), 8);
orderService.addSession(order2.getId(), session2.getId(), 5);
Assertions.assertEquals(sessionService.findSession(session2.getId()).getCapacity(), 5);
Assertions.assertThrows(IllegalArgumentException.class, () ->
orderService.addSession(order2.getId(), session2.getId(), 6));
// у заказа 1 сеанс
orderService.deleteSessionInOrder(order2.getId(), session2.getId());
Assertions.assertEquals(sessionService.findSession(session2.getId()).getCapacity(), 10);
// заполнили всю 2 сессию
orderService.addSession(order2.getId(), session2.getId(), 10);
Assertions.assertEquals(sessionService.findAllSessions().size(), 2);
Assertions.assertEquals(sessionService.findAllSessionsWithCapacity().size(), 1);
Assertions.assertEquals(sessionService.findAllSessionsWithCapacity().get(0), session1);
orderService.deleteSessionInOrder(order2.getId(), session2.getId());
Assertions.assertEquals(sessionService.findAllSessionsWithCapacity().size(), 2);
// у заказа 0 сеансов
// 3 сеанса
final Session session3 = sessionService.addSession(300.0,
new Timestamp(System.currentTimeMillis()), cinema2.getId(), 10);
// осталось 2 сеанса
sessionService.deleteSession(session1.getId());
Assertions.assertEquals(sessionService.findAllSessions().size(), 2);
Assertions.assertEquals(orderService
.findOrder(order2.getId()).getSessions().size(), 0);
// 2-ой покупатель удален
// 0 заказов после его удаления
Assertions.assertEquals(orderService.findAllOrders().size(), 1);
customerService.deleteCustomer(customer2.getId());
Assertions.assertThrows(EntityNotFoundException.class, () -> customerService.findCustomer(customer2.getId()));
Assertions.assertThrows(EntityNotFoundException.class, () -> orderService.findOrder(order2.getId()));
Assertions.assertEquals(orderService.findAllOrders().size(), 0);
Assertions.assertEquals(sessionService.findSession(session3.getId()), session3);
cinemaService.deleteCinema(cinema2.getId());
}
/* @Test()
void testCustomer() {
customerService.deleteAllCustomers();
final Customer customer = customerService.addCustomer("Иван", "Иванов");
log.info(customer.toString() + "testCustomerCreate");
Assertions.assertNotNull(customer.getId());
customerService.deleteAllCustomers();
final Customer customer1 = customerService.addCustomer("Иван", "Иванов");
log.info(customer1.toString() + "testCustomerRead1");
final Customer findCustomer = customerService.findCustomer(customer1.getId());
log.info(findCustomer.toString() + "testCustomerRead2");
Assertions.assertEquals(customer1, findCustomer);
customerService.deleteAllCustomers();
Assertions.assertThrows(EntityNotFoundException.class, () -> customerService.findCustomer(-1L));
log.info("testCustomerReadNotFound");
customerService.deleteAllCustomers();
customerService.addCustomer("Иван", "Иванов");
customerService.addCustomer("Петр", "Петров");
final List<Customer> customers1 = customerService.findAllCustomers();
log.info(customers1.toString() + "testCustomerReadAll");
Assertions.assertEquals(customers1.size(), 2);
customerService.deleteAllCustomers();
final List<Customer> customers2 = customerService.findAllCustomers();
log.info(customers2.toString() + "testCustomerReadAllEmpty");
Assertions.assertEquals(customers2.size(), 0);
}
@Test
void testSession() {
sessionService.deleteAllSessions();
cinemaService.deleteAllCinemas();
final Cinema cinema1 = cinemaService.addCinema("Ледниковый период");
final Session session1 = sessionService.addSession(100.0,
new Timestamp(System.currentTimeMillis()), cinema1.getId());
log.info(session1.toString() + "testSessionCreate");
Assertions.assertNotNull(session1.getId());
sessionService.deleteAllSessions();
final Session session2 = sessionService.addSession(100.0,
new Timestamp(System.currentTimeMillis()), cinema1.getId());
log.info(session2.toString() + "testSessionRead1");
final Session findSession = sessionService.findSession(session2.getId());
log.info(findSession.toString() + "testSessionRead2");
Assertions.assertEquals(session2, findSession);
sessionService.deleteAllSessions();
Assertions.assertThrows(EntityNotFoundException.class, () -> sessionService.findSession(-1L));
log.info("testSessionReadNotFound");
sessionService.deleteAllSessions();
sessionService.addSession(100.0, new Timestamp(System.currentTimeMillis()), cinema1.getId());
sessionService.addSession(100.0, new Timestamp(System.currentTimeMillis()), cinema1.getId());
final List<Session> sessions1 = sessionService.findAllSessions();
log.info(sessions1.toString() + "testSessionReadAll");
Assertions.assertEquals(sessions1.size(), 2);
sessionService.deleteAllSessions();
final List<Session> sessions2 = sessionService.findAllSessions();
log.info(sessions2.toString() + "testSessionReadAllEmpty");
Assertions.assertEquals(sessions2.size(), 0);
}*/
}

View File

@ -1,6 +0,0 @@
spring.datasource.url=jdbc:h2:mem:testdb
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=create-drop