Compare commits
No commits in common. "master" and "Lab3" have entirely different histories.
2
.gitignore
vendored
2
.gitignore
vendored
@ -35,3 +35,5 @@ out/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
*.db
|
13
build.gradle
13
build.gradle
@ -1,10 +1,10 @@
|
||||
plugins {
|
||||
id 'org.springframework.boot' version '2.6.3'
|
||||
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
|
||||
id 'java'
|
||||
id 'org.springframework.boot' version '3.0.2'
|
||||
id 'io.spring.dependency-management' version '1.1.0'
|
||||
}
|
||||
|
||||
group = 'com.example'
|
||||
group = 'ru.ulstu.is'
|
||||
version = '0.0.1-SNAPSHOT'
|
||||
sourceCompatibility = '17'
|
||||
|
||||
@ -14,7 +14,12 @@ repositories {
|
||||
|
||||
dependencies {
|
||||
implementation 'org.springframework.boot:spring-boot-starter-web'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
|
||||
|
||||
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
|
||||
implementation 'com.h2database:h2:2.1.210'
|
||||
|
||||
implementation group: 'org.springdoc', name: 'springdoc-openapi-ui', version: '1.6.5'
|
||||
|
||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||
}
|
||||
|
||||
|
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Binary file not shown.
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@ -1,5 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
6
gradlew
vendored
6
gradlew
vendored
@ -205,12 +205,6 @@ set -- \
|
||||
org.gradle.wrapper.GradleWrapperMain \
|
||||
"$@"
|
||||
|
||||
# Stop when "xargs" is not available.
|
||||
if ! command -v xargs >/dev/null 2>&1
|
||||
then
|
||||
die "xargs is not available"
|
||||
fi
|
||||
|
||||
# Use "xargs" to parse quoted args.
|
||||
#
|
||||
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||
|
14
gradlew.bat
vendored
14
gradlew.bat
vendored
@ -14,7 +14,7 @@
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%"=="" @echo off
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@ -25,7 +25,7 @@
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%"=="" set DIRNAME=.
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@ -40,7 +40,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if %ERRORLEVEL% equ 0 goto execute
|
||||
if "%ERRORLEVEL%" == "0" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
@ -75,15 +75,13 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if %ERRORLEVEL% equ 0 goto mainEnd
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
set EXIT_CODE=%ERRORLEVEL%
|
||||
if %EXIT_CODE% equ 0 set EXIT_CODE=1
|
||||
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
|
||||
exit /b %EXIT_CODE%
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
@ -1 +1 @@
|
||||
rootProject.name = 'demo'
|
||||
rootProject.name = 'sbapp'
|
||||
|
@ -1,38 +0,0 @@
|
||||
package com.example.demo.Controllers;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
@Controller
|
||||
class GController {
|
||||
|
||||
@GetMapping("/")
|
||||
public String home(@RequestParam(name="name", required=false, defaultValue="World") String name, Model model) {
|
||||
model.addAttribute("name", name);
|
||||
return "home";
|
||||
}
|
||||
@GetMapping("/hello")
|
||||
public String hello(@RequestParam(value = "name", defaultValue = "World") String name, Model model) {
|
||||
model.addAttribute("name", String.format("Hello %s!", name));
|
||||
return "home";
|
||||
}
|
||||
@GetMapping("/sum")
|
||||
public String doSum(@RequestParam int val1, @RequestParam int val2, Model model){
|
||||
model.addAttribute("name", String.format("%s", val1+val2));
|
||||
return "home";
|
||||
}
|
||||
@GetMapping("/sub")
|
||||
public String doSub(@RequestParam int val1, @RequestParam int val2, Model model){
|
||||
model.addAttribute("name", String.format("%s", val1-val2));
|
||||
return "home";
|
||||
}
|
||||
@GetMapping("/hello2")
|
||||
public String hello2(@RequestParam(value = "name", defaultValue = "World") String name,
|
||||
@RequestParam(value = "day", defaultValue = "1") Integer day,
|
||||
@RequestParam(value = "month", defaultValue = "January") String month, Model model) {
|
||||
model.addAttribute("name", String.format("Hello %s!Your birthday is %s %s", name,day,month));
|
||||
return "home";
|
||||
}
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
package com.example.demo;
|
||||
|
||||
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
|
||||
@RestController
|
||||
public class DemoApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(DemoApplication.class, args);
|
||||
}
|
||||
|
||||
/*@GetMapping("/hello")
|
||||
public String hello(@RequestParam(value = "name", defaultValue = "World") String name) {
|
||||
return String.format("Hello %s!", name);
|
||||
}
|
||||
@GetMapping("/sum")
|
||||
public Integer doSum(@RequestParam int val1, @RequestParam int val2){
|
||||
return val1+val2;
|
||||
}
|
||||
@GetMapping("/sub")
|
||||
public Integer doSub(@RequestParam int val1, @RequestParam int val2){
|
||||
return val1-val2;
|
||||
}
|
||||
@GetMapping("/hello2")
|
||||
public String hello2(@RequestParam(value = "name", defaultValue = "World") String name,
|
||||
@RequestParam(value = "day", defaultValue = "1") Integer day,
|
||||
@RequestParam(value = "month", defaultValue = "January") String month) {
|
||||
return String.format("Hello %s!Your birthday is %s %s", name,day,month);
|
||||
}*/
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
package com.example.demo;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@Configuration
|
||||
public class WebConfiguration implements WebMvcConfigurer {
|
||||
@Override
|
||||
public void addCorsMappings(CorsRegistry registry){
|
||||
registry.addMapping("/**").allowedMethods("*");
|
||||
}
|
||||
|
||||
}
|
11
src/main/java/ru/ulstu/is/sbapp/SbappApplication.java
Normal file
11
src/main/java/ru/ulstu/is/sbapp/SbappApplication.java
Normal file
@ -0,0 +1,11 @@
|
||||
package ru.ulstu.is.sbapp;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class SbappApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(SbappApplication.class, args);
|
||||
}
|
||||
}
|
101
src/main/java/ru/ulstu/is/sbapp/cinema/model/Cinema.java
Normal file
101
src/main/java/ru/ulstu/is/sbapp/cinema/model/Cinema.java
Normal file
@ -0,0 +1,101 @@
|
||||
package ru.ulstu.is.sbapp.cinema.model;
|
||||
|
||||
import org.hibernate.annotations.OnDelete;
|
||||
import org.hibernate.annotations.OnDeleteAction;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@Entity
|
||||
@OnDelete(action = OnDeleteAction.CASCADE)
|
||||
public class Cinema {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private Long id;
|
||||
@Column(nullable = false)
|
||||
private String name;
|
||||
@Column(nullable = false)
|
||||
private String address;
|
||||
|
||||
@OneToMany(targetEntity =Timetable.class, mappedBy = "cinema", fetch = FetchType.EAGER, cascade= CascadeType.ALL)
|
||||
@OnDelete(action = OnDeleteAction.CASCADE)
|
||||
private List<Timetable> timetables;
|
||||
|
||||
public Cinema(){
|
||||
}
|
||||
public Cinema(String name, String address){
|
||||
this.name=name;
|
||||
this.address=address;
|
||||
}
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public String getAddress() {
|
||||
return this.address;
|
||||
}
|
||||
public void setAddress(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
public void addTimetable(Timetable timetable) {
|
||||
if (timetables == null){
|
||||
timetables = new ArrayList<>();
|
||||
}
|
||||
this.timetables.add(timetable);
|
||||
}
|
||||
public void removeTimetable(Timetable timetable){
|
||||
if(timetables != null){
|
||||
timetables.remove(timetable);
|
||||
}
|
||||
}
|
||||
public List<Timetable> getTimetables(){
|
||||
if (timetables ==null){
|
||||
timetables =new ArrayList<>();
|
||||
}
|
||||
return this.timetables;
|
||||
}
|
||||
public String[] getTimetablesName(){
|
||||
String[] result;
|
||||
if (timetables !=null) {
|
||||
result = new String[timetables.size()];
|
||||
for (int i = 0; i < timetables.size(); ++i) {
|
||||
result[i] = timetables.get(i).toString();
|
||||
}
|
||||
}
|
||||
else {
|
||||
result = new String[0];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
} else if (o != null && this.getClass() == o.getClass()) {
|
||||
Cinema cinema = (Cinema) o;
|
||||
return Objects.equals(this.id, cinema.id);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(new Object[]{this.id});
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Cinema{" +
|
||||
"id=" + id +
|
||||
", name='" + name + '\'' +
|
||||
", address='" + address + '\'' +
|
||||
", films='" + String.join(", ",getTimetablesName()) + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
102
src/main/java/ru/ulstu/is/sbapp/cinema/model/Film.java
Normal file
102
src/main/java/ru/ulstu/is/sbapp/cinema/model/Film.java
Normal file
@ -0,0 +1,102 @@
|
||||
package ru.ulstu.is.sbapp.cinema.model;
|
||||
|
||||
import org.hibernate.annotations.OnDelete;
|
||||
import org.hibernate.annotations.OnDeleteAction;
|
||||
import ru.ulstu.is.sbapp.cinema.model.enums.AgeRestriction;
|
||||
import ru.ulstu.is.sbapp.cinema.model.enums.Genre;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@Entity
|
||||
@OnDelete(action = OnDeleteAction.CASCADE)
|
||||
public class Film {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private Long id;
|
||||
@Column(nullable = false)
|
||||
private String name;
|
||||
@Column(nullable = false)
|
||||
private int duration;
|
||||
@Column(name = "genre", nullable = false)
|
||||
@Enumerated(EnumType.STRING)
|
||||
private Genre genre;
|
||||
@Column(name = "ageRestriction", nullable = false)
|
||||
@Enumerated(EnumType.STRING)
|
||||
private AgeRestriction ageRestriction;
|
||||
|
||||
public Film() {
|
||||
}
|
||||
|
||||
public Film(String name, int duration, Genre genre, AgeRestriction ageRestriction) {
|
||||
this.name = name;
|
||||
this.duration = duration;
|
||||
this.genre = genre;
|
||||
this.ageRestriction = ageRestriction;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getDuration() {
|
||||
return this.duration;
|
||||
}
|
||||
|
||||
public void setDuration(int duration) {
|
||||
this.duration = duration;
|
||||
}
|
||||
|
||||
public Genre getGenre() {
|
||||
return this.genre;
|
||||
}
|
||||
|
||||
public void setGenre(Genre genre) {
|
||||
this.genre = genre;
|
||||
}
|
||||
|
||||
public AgeRestriction getAgeRestriction() {
|
||||
return this.ageRestriction;
|
||||
}
|
||||
|
||||
public void setAgeRestriction(AgeRestriction ageRestriction) {
|
||||
this.ageRestriction = ageRestriction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
} else if (o != null && this.getClass() == o.getClass()) {
|
||||
Film film = (Film) o;
|
||||
return Objects.equals(this.id, film.id);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(new Object[]{this.id});
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
Long var10000 = this.id;
|
||||
return "Film{id=" + var10000 +
|
||||
", name ='" + this.name +
|
||||
"', duration ='" + String.valueOf(this.duration) +
|
||||
"', genre ='" + this.genre +
|
||||
"', ageRestriction ='" + this.ageRestriction +
|
||||
"'}";
|
||||
}
|
||||
}
|
77
src/main/java/ru/ulstu/is/sbapp/cinema/model/Ticket.java
Normal file
77
src/main/java/ru/ulstu/is/sbapp/cinema/model/Ticket.java
Normal file
@ -0,0 +1,77 @@
|
||||
package ru.ulstu.is.sbapp.cinema.model;
|
||||
|
||||
import org.hibernate.annotations.OnDelete;
|
||||
import org.hibernate.annotations.OnDeleteAction;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.time.LocalDate;
|
||||
import java.util.Objects;
|
||||
|
||||
@Entity
|
||||
@OnDelete(action = OnDeleteAction.CASCADE)
|
||||
public class Ticket {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private Long id;
|
||||
@ManyToOne(fetch = FetchType.EAGER,cascade = CascadeType.MERGE)
|
||||
@JoinColumn(name = "film_id", nullable = false)
|
||||
private Film film;
|
||||
@ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.MERGE)
|
||||
@JoinColumn(name = "cinema_id", nullable = false)
|
||||
private Cinema cinema;
|
||||
@Column(nullable = false)
|
||||
private LocalDate date;
|
||||
|
||||
public Ticket(){
|
||||
}
|
||||
public Ticket(Film film,Cinema cinema,LocalDate date){
|
||||
this.film=film;
|
||||
this.cinema=cinema;
|
||||
this.date=date;
|
||||
}
|
||||
public Long getId(){
|
||||
return this.id;
|
||||
}
|
||||
public void setFilm(Film film) {
|
||||
this.film=film;
|
||||
}
|
||||
public Film getFilm() {
|
||||
return this.film;
|
||||
}
|
||||
public void setCinema(Cinema cinema) {
|
||||
this.cinema=cinema;
|
||||
}
|
||||
public Cinema getСinema() {
|
||||
return this.cinema;
|
||||
}
|
||||
public void setDate(LocalDate date) {
|
||||
this.date=date;
|
||||
}
|
||||
public LocalDate getDate() {
|
||||
return this.date;
|
||||
}
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
} else if (o != null && this.getClass() == o.getClass()) {
|
||||
Ticket ticket = (Ticket) o;
|
||||
return Objects.equals(this.id, ticket.id);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(new Object[]{this.id});
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Ticket{" +
|
||||
"id=" + id +
|
||||
", cinema='" + cinema.getName() + '\'' +
|
||||
", film='" + film.getName() + '\'' +
|
||||
", date='" + date.toString() + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
125
src/main/java/ru/ulstu/is/sbapp/cinema/model/Timetable.java
Normal file
125
src/main/java/ru/ulstu/is/sbapp/cinema/model/Timetable.java
Normal file
@ -0,0 +1,125 @@
|
||||
package ru.ulstu.is.sbapp.cinema.model;
|
||||
|
||||
import org.hibernate.annotations.OnDelete;
|
||||
import org.hibernate.annotations.OnDeleteAction;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@Entity
|
||||
@Table(uniqueConstraints = {
|
||||
@UniqueConstraint(columnNames = {"filmId", "cinemaId"})
|
||||
})
|
||||
@OnDelete(action = OnDeleteAction.CASCADE)
|
||||
public class Timetable {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private Long id;
|
||||
@ManyToOne(fetch = FetchType.EAGER)
|
||||
@OnDelete(action = OnDeleteAction.CASCADE)
|
||||
@JoinColumn(name = "filmId", nullable = false)
|
||||
private Film film;
|
||||
@ManyToOne(fetch = FetchType.EAGER,cascade = CascadeType.ALL)
|
||||
@OnDelete(action = OnDeleteAction.CASCADE)
|
||||
@JoinColumn(name = "cinemaId", nullable = false)
|
||||
private Cinema cinema;
|
||||
|
||||
@ElementCollection
|
||||
@Column(nullable = true)
|
||||
private List<LocalDate> dates;
|
||||
public Timetable(){
|
||||
}
|
||||
public Timetable(Cinema cinema, Film film){
|
||||
this.cinema=cinema;
|
||||
this.film=film;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
public Cinema getCinema() {
|
||||
return this.cinema;
|
||||
}
|
||||
public void setCinema(Cinema cinema) {
|
||||
this.cinema = cinema;
|
||||
}
|
||||
public Film getFilm(){return this.film;}
|
||||
public void setFilm(Film film){this.film=film;}
|
||||
|
||||
public void setDate(LocalDate date) {
|
||||
if (dates == null){
|
||||
dates = new ArrayList<>();
|
||||
}
|
||||
this.dates.add(date);
|
||||
}
|
||||
public void setDates(List<LocalDate> dates) {
|
||||
if (this.dates == null){
|
||||
this.dates = dates;
|
||||
}
|
||||
for (var date: dates) {
|
||||
dates.add(date);
|
||||
}
|
||||
}
|
||||
public void removeDate(LocalDate date){
|
||||
if(dates != null){
|
||||
dates.remove(date);
|
||||
}
|
||||
}
|
||||
public List<LocalDate> getDates(){
|
||||
if (dates ==null){
|
||||
dates =new ArrayList<>();
|
||||
}
|
||||
return this.dates;
|
||||
}
|
||||
public boolean containsDate(LocalDate date){
|
||||
if (dates != null){
|
||||
if (dates.contains(date)) return true;
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public String[] getDatesString(){
|
||||
String[] result;
|
||||
if (dates !=null) {
|
||||
if (dates.size()>0) {
|
||||
result = new String[dates.size()];
|
||||
for (int i = 0; i < dates.size(); ++i) {
|
||||
result[i] = dates.get(i).toString();
|
||||
}
|
||||
}
|
||||
else {result=new String[0];}
|
||||
}
|
||||
else {
|
||||
result = new String[0];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
} else if (o != null && this.getClass() == o.getClass()) {
|
||||
Timetable timetable = (Timetable) o;
|
||||
return Objects.equals(this.id, timetable.id);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(new Object[]{this.id});
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Timetable{" +
|
||||
"id=" + id +
|
||||
", cinema='" + cinema.getName() + '\'' +
|
||||
", film='" + film.getName() + '\'' +
|
||||
", dates='" + String.join(", ",getDatesString()) + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package ru.ulstu.is.sbapp.cinema.model.enums;
|
||||
|
||||
public enum AgeRestriction {
|
||||
Zero("0+") ,
|
||||
Six("6+") ,
|
||||
Fourteen("14+") ,
|
||||
Sixteen("16+") ,
|
||||
Eighteen("18+") ;
|
||||
|
||||
private final String name;
|
||||
AgeRestriction(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package ru.ulstu.is.sbapp.cinema.model.enums;
|
||||
|
||||
public enum Genre {
|
||||
Drama("Драма"),
|
||||
Animation("Анимация"),
|
||||
Comedy("Комедия"),
|
||||
HistoricalFilm("Исторический фильм"),
|
||||
Adventure("Приключение"),
|
||||
Horror("Ужастик");
|
||||
private final String name;
|
||||
Genre(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
package ru.ulstu.is.sbapp.cinema.service;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
import ru.ulstu.is.sbapp.cinema.model.Cinema;
|
||||
import ru.ulstu.is.sbapp.cinema.model.Film;
|
||||
import ru.ulstu.is.sbapp.cinema.model.Timetable;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.EntityNotFoundException;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class CinemaService {
|
||||
@PersistenceContext
|
||||
private EntityManager em;
|
||||
|
||||
@Transactional
|
||||
public Cinema addCinema(String name, String address) {
|
||||
if (!StringUtils.hasText(name) || !StringUtils.hasText(address)) {
|
||||
throw new IllegalArgumentException("Some information about the cinema is null");
|
||||
}
|
||||
final Cinema cinema = new Cinema(name,address);
|
||||
em.persist(cinema);
|
||||
return cinema;
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
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(readOnly = true)
|
||||
public List<Cinema> findAllCinemas() {
|
||||
return em.createQuery("select c from Cinema c", Cinema.class)
|
||||
.getResultList();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Cinema updateCinema(Long id, String name, String address) {
|
||||
if (!StringUtils.hasText(name) || !StringUtils.hasText(address)) {
|
||||
throw new IllegalArgumentException("Some information about the cinema is null");
|
||||
}
|
||||
final Cinema currentCinema = findCinema(id);
|
||||
currentCinema.setName(name);
|
||||
currentCinema.setAddress(address);
|
||||
return em.merge(currentCinema);
|
||||
}
|
||||
@Transactional
|
||||
public Cinema addTimetableToCinema(Long id, Timetable timetable){
|
||||
if(timetable == null){
|
||||
throw new IllegalArgumentException("Some information is null");
|
||||
}
|
||||
final Cinema currentCinema = findCinema(id);
|
||||
currentCinema.addTimetable(timetable);
|
||||
return em.merge(currentCinema);
|
||||
}
|
||||
@Transactional
|
||||
public List<Timetable> getFilmsOnCinema(Long id){
|
||||
final Cinema currentCinema = findCinema(id);
|
||||
return currentCinema.getTimetables();
|
||||
}
|
||||
@Transactional
|
||||
public Cinema removeFilmFromCinema(Long id, Timetable timetable){
|
||||
if(timetable == null){
|
||||
throw new IllegalArgumentException("Some information is null");
|
||||
}
|
||||
final Cinema currentCinema = findCinema(id);
|
||||
currentCinema.removeTimetable(timetable);
|
||||
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();
|
||||
}
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
package ru.ulstu.is.sbapp.cinema.service;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
import ru.ulstu.is.sbapp.cinema.model.Film;
|
||||
import ru.ulstu.is.sbapp.cinema.model.enums.AgeRestriction;
|
||||
import ru.ulstu.is.sbapp.cinema.model.enums.Genre;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.EntityNotFoundException;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class FilmService {
|
||||
@PersistenceContext
|
||||
private EntityManager em;
|
||||
|
||||
@Transactional
|
||||
public Film addFilm(String name, int duration, Genre genre, AgeRestriction ageRestriction) {
|
||||
if (!StringUtils.hasText(name) || !StringUtils.hasText(genre.toString()) || duration<=0 || !StringUtils.hasText(ageRestriction.toString())) {
|
||||
throw new IllegalArgumentException("Some information about the film is null");
|
||||
}
|
||||
final Film film = new Film(name,duration,genre,ageRestriction);
|
||||
em.persist(film);
|
||||
return film;
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public Film findFilm(Long id) {
|
||||
final Film film = em.find(Film.class, id);
|
||||
if (film == null) {
|
||||
throw new EntityNotFoundException(String.format("Film with id [%s] is not found", id));
|
||||
}
|
||||
return film;
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public List<Film> findAllFilms() {
|
||||
return em.createQuery("select f from Film f", Film.class)
|
||||
.getResultList();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Film updateFilm(Long id, String name, int duration, Genre genre, AgeRestriction ageRestriction) {
|
||||
if (!StringUtils.hasText(name) || !StringUtils.hasText(genre.toString()) || duration<=0 || !StringUtils.hasText(ageRestriction.toString())) {
|
||||
throw new IllegalArgumentException("Some information about the film is null");
|
||||
}
|
||||
final Film currentFilm = findFilm(id);
|
||||
currentFilm.setName(name);
|
||||
currentFilm.setDuration(duration);
|
||||
currentFilm.setGenre(genre);
|
||||
currentFilm.setAgeRestriction(ageRestriction);
|
||||
return em.merge(currentFilm);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Film deleteFilm(Long id) {
|
||||
final Film currentFilm = findFilm(id);
|
||||
em.remove(currentFilm);
|
||||
return currentFilm;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void deleteAllFilms() {
|
||||
em.createQuery("delete from Film").executeUpdate();
|
||||
}
|
||||
}
|
@ -0,0 +1,91 @@
|
||||
package ru.ulstu.is.sbapp.cinema.service;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import ru.ulstu.is.sbapp.cinema.model.Cinema;
|
||||
import ru.ulstu.is.sbapp.cinema.model.Film;
|
||||
import ru.ulstu.is.sbapp.cinema.model.Ticket;
|
||||
import ru.ulstu.is.sbapp.cinema.model.Timetable;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.EntityNotFoundException;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
@Service
|
||||
public class TicketService {
|
||||
@PersistenceContext
|
||||
private EntityManager em;
|
||||
|
||||
@Transactional
|
||||
public Ticket addTicket(Film film, Cinema cinema,LocalDate date) {
|
||||
if (film == null || cinema == null || date == null) {
|
||||
throw new IllegalArgumentException("Some information is null");
|
||||
}
|
||||
List<Timetable> lt = em.createQuery("SELECT t FROM Timetable t WHERE :film = t.film.id AND :cinema= t.cinema.id and :date MEMBER OF t.dates", Timetable.class)
|
||||
.setParameter("date", date)
|
||||
.setParameter("film", film.getId())
|
||||
.setParameter("cinema", cinema.getId())
|
||||
.getResultList();
|
||||
if(lt.size()==0){
|
||||
throw new IllegalArgumentException("Кинотеатр не показывает в эту дату этот фильм");
|
||||
}
|
||||
Ticket ticket = new Ticket(film, cinema, date);
|
||||
em.merge(film);
|
||||
em.merge(cinema);
|
||||
em.persist(ticket);
|
||||
return ticket;
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public Ticket findTicket(Long id) {
|
||||
final Ticket ticket = em.find(Ticket.class, id);
|
||||
if (ticket == null) {
|
||||
throw new EntityNotFoundException(String.format("Ticket with id [%s] is not found", id));
|
||||
}
|
||||
return ticket;
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public List<Ticket> findAllTickets() {
|
||||
return em.createQuery("select t from Ticket t", Ticket.class)
|
||||
.getResultList();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Ticket updateTicket(Long id, Film film, Cinema cinema, LocalDate date) {
|
||||
if (film==null || cinema==null || date==null) {
|
||||
throw new IllegalArgumentException("Some information is null");
|
||||
}
|
||||
boolean contain = false;
|
||||
List<Timetable> lt = em.createQuery("select t from Timetable t", Timetable.class).getResultList();
|
||||
for(int i=0; i<lt.size();i++){
|
||||
if((lt.get(i)).getFilm() == film && (lt.get(i)).containsDate(date)){
|
||||
contain=true;
|
||||
}
|
||||
}
|
||||
if (!contain) {
|
||||
throw new IllegalArgumentException("Cinema does not show this film");
|
||||
}
|
||||
final Ticket currentTicket = findTicket(id);
|
||||
currentTicket.setCinema(cinema);
|
||||
currentTicket.setFilm(film);
|
||||
currentTicket.setDate(date);
|
||||
return em.merge(currentTicket);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Ticket deleteTicket(Long id) {
|
||||
final Ticket currentTicket = findTicket(id);
|
||||
em.remove(currentTicket);
|
||||
return currentTicket;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void deleteAllTickets() {
|
||||
em.createQuery("delete from Ticket").executeUpdate();
|
||||
}
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
package ru.ulstu.is.sbapp.cinema.service;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
import ru.ulstu.is.sbapp.cinema.model.Cinema;
|
||||
import ru.ulstu.is.sbapp.cinema.model.Film;
|
||||
import ru.ulstu.is.sbapp.cinema.model.Timetable;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.EntityNotFoundException;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class TimetableService {
|
||||
@PersistenceContext
|
||||
private EntityManager em;
|
||||
|
||||
@Transactional
|
||||
public Timetable addTimeTable(Cinema cinema,Film film) {
|
||||
if (cinema==null || film==null) {
|
||||
throw new IllegalArgumentException("Some information about the cinema is null");
|
||||
}
|
||||
final Timetable timetable = new Timetable(cinema,film);
|
||||
|
||||
return em.merge(timetable);
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public Timetable findTimetable(Long id) {
|
||||
final Timetable timetable = em.find(Timetable.class, id);
|
||||
if (timetable == null) {
|
||||
throw new EntityNotFoundException(String.format("Timetable with id [%s] is not found", id));
|
||||
}
|
||||
return timetable;
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public List<Timetable> findAllTimetables() {
|
||||
return em.createQuery("select t from Timetable t", Timetable.class).getResultList();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Timetable updateTimetable(Long id, Cinema cinema, Film film) {
|
||||
if (cinema==null || film==null) {
|
||||
throw new IllegalArgumentException("Some information about the cinema is null");
|
||||
}
|
||||
final Timetable currenttimetable = findTimetable(id);
|
||||
currenttimetable.setCinema(cinema);
|
||||
currenttimetable.setFilm(film);
|
||||
return em.merge(currenttimetable);
|
||||
}
|
||||
@Transactional
|
||||
public Timetable addDateToTimetable(Long id, LocalDate date){
|
||||
if(date == null){
|
||||
throw new IllegalArgumentException("Some information is null");
|
||||
}
|
||||
final Timetable currenttimetable = findTimetable(id);
|
||||
currenttimetable.setDate(date);
|
||||
return em.merge(currenttimetable);
|
||||
}
|
||||
@Transactional
|
||||
public List<LocalDate> getDateOnTimetable(Long id){
|
||||
final Timetable currenttimetable = findTimetable(id);
|
||||
return currenttimetable.getDates();
|
||||
}
|
||||
@Transactional
|
||||
public Timetable removeDateOnTimetable(Long id, LocalDate date){
|
||||
if(date == null){
|
||||
throw new IllegalArgumentException("Some information is null");
|
||||
}
|
||||
final Timetable currenttimetable = findTimetable(id);
|
||||
currenttimetable.removeDate(date);
|
||||
return em.merge(currenttimetable);
|
||||
}
|
||||
@Transactional
|
||||
public Timetable deleteTimetable(Long id) {
|
||||
final Timetable currenttimetable = findTimetable(id);
|
||||
em.remove(currenttimetable);
|
||||
return currenttimetable;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void deleteAllTimetables() {
|
||||
em.createQuery("delete from Timetable").executeUpdate();
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
spring.main.banner-mode=off
|
||||
#server.port=8080
|
||||
spring.datasource.url=jdbc:h2:file:./data
|
||||
spring.datasource.driverClassName=org.h2.Driver
|
||||
spring.datasource.username=sa
|
||||
spring.datasource.password=password
|
||||
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
|
||||
spring.jpa.hibernate.ddl-auto=validate
|
||||
spring.h2.console.enabled=true
|
||||
spring.h2.console.settings.trace=false
|
||||
spring.h2.console.settings.web-allow-others=false
|
@ -1,14 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns:th="http://www.thymeleaf.org">
|
||||
<head>
|
||||
<title>Sarafan</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<p class="badge text-bg-primary " style="margin-top: 10%; margin-left: 10%; font-size: 64px" th:text="${name}"/>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
@ -1,12 +0,0 @@
|
||||
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
|
||||
pageEncoding="ISO-8859-1"%>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="ISO-8859-1">
|
||||
<title>InsertTitleHere</title>
|
||||
</head>
|
||||
<body>
|
||||
<h2>Hello ${name}!</h2>
|
||||
</body>
|
||||
</html>
|
@ -1,13 +0,0 @@
|
||||
package com.example.demo;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class DemoApplicationTests {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
78
src/test/java/ru/ulstu/is/sbapp/JpaCinemaTests.java
Normal file
78
src/test/java/ru/ulstu/is/sbapp/JpaCinemaTests.java
Normal file
@ -0,0 +1,78 @@
|
||||
package ru.ulstu.is.sbapp;
|
||||
|
||||
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 ru.ulstu.is.sbapp.cinema.model.*;
|
||||
import ru.ulstu.is.sbapp.cinema.model.enums.AgeRestriction;
|
||||
import ru.ulstu.is.sbapp.cinema.model.enums.Genre;
|
||||
import ru.ulstu.is.sbapp.cinema.service.CinemaService;
|
||||
import ru.ulstu.is.sbapp.cinema.service.FilmService;
|
||||
import ru.ulstu.is.sbapp.cinema.service.TimetableService;
|
||||
|
||||
import javax.persistence.EntityNotFoundException;
|
||||
import java.util.List;
|
||||
|
||||
@SpringBootTest
|
||||
public class JpaCinemaTests {
|
||||
private static final Logger log = LoggerFactory.getLogger(JpaCinemaTests.class);
|
||||
|
||||
@Autowired
|
||||
private CinemaService cinemaService;
|
||||
@Autowired
|
||||
private FilmService filmService;
|
||||
@Autowired
|
||||
private TimetableService timetableService;
|
||||
|
||||
@Test
|
||||
void testCinemaCreate() {
|
||||
|
||||
final Cinema cinema = cinemaService.addCinema("Окко", "город Ульяновск");
|
||||
log.info(cinema.toString());
|
||||
Assertions.assertNotNull(cinema.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCinemaRead() {
|
||||
final Cinema cinema = cinemaService.addCinema("Окко", "город Ульяновск");
|
||||
log.info(cinema.toString());
|
||||
final Cinema findCinema = cinemaService.findCinema(cinema.getId());
|
||||
log.info(findCinema.toString());
|
||||
Assertions.assertEquals(cinema, findCinema);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCinemaReadNotFound() {
|
||||
Assertions.assertThrows(EntityNotFoundException.class, () -> cinemaService.findCinema(-1L));
|
||||
}
|
||||
@Test
|
||||
void testCinemaReadAllEmpty() {
|
||||
cinemaService.deleteAllCinemas();
|
||||
final List<Cinema> cinemas = cinemaService.findAllCinemas();
|
||||
log.info(cinemas.toString());
|
||||
Assertions.assertEquals(cinemas.size(), 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCinemaReadAll() {
|
||||
cinemaService.deleteAllCinemas();
|
||||
cinemaService.addCinema("Окко", "город Ульяновск");
|
||||
cinemaService.addCinema("Матрица", "город Самара");
|
||||
final List<Cinema> cinemas = cinemaService.findAllCinemas();
|
||||
Assertions.assertEquals(cinemas.size(), 2);
|
||||
}
|
||||
@Test
|
||||
void testTimetablesAtCinema() {
|
||||
cinemaService.deleteAllCinemas();
|
||||
filmService.deleteAllFilms();
|
||||
timetableService.deleteAllTimetables();
|
||||
Film film = filmService.addFilm("Одна",102,Genre.Drama,AgeRestriction.Sixteen);
|
||||
Cinema cinema = cinemaService.addCinema("Окко", "Ульяновск");
|
||||
timetableService.addTimeTable(cinemaService.findCinema(cinema.getId()),filmService.findFilm(film.getId()));
|
||||
List<Timetable> lt = cinemaService.getFilmsOnCinema(cinema.getId());
|
||||
Assertions.assertEquals(lt.size(), 1);
|
||||
}
|
||||
}
|
65
src/test/java/ru/ulstu/is/sbapp/JpaFilmTests.java
Normal file
65
src/test/java/ru/ulstu/is/sbapp/JpaFilmTests.java
Normal file
@ -0,0 +1,65 @@
|
||||
package ru.ulstu.is.sbapp;
|
||||
|
||||
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 ru.ulstu.is.sbapp.cinema.model.enums.AgeRestriction;
|
||||
import ru.ulstu.is.sbapp.cinema.model.Film;
|
||||
import ru.ulstu.is.sbapp.cinema.model.enums.Genre;
|
||||
import ru.ulstu.is.sbapp.cinema.service.FilmService;
|
||||
|
||||
import javax.persistence.EntityNotFoundException;
|
||||
import java.util.List;
|
||||
|
||||
@SpringBootTest
|
||||
public class JpaFilmTests {
|
||||
private static final Logger log = LoggerFactory.getLogger(JpaFilmTests.class);
|
||||
|
||||
@Autowired
|
||||
private FilmService filmService;
|
||||
|
||||
@Test
|
||||
void testFilmCreate() {
|
||||
filmService.deleteAllFilms();
|
||||
final Film film = filmService.addFilm("После", 102, Genre.Drama, AgeRestriction.Sixteen);
|
||||
log.info(film.toString());
|
||||
Assertions.assertNotNull(film.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFilmRead() {
|
||||
filmService.deleteAllFilms();
|
||||
final Film film = filmService.addFilm("После", 102, Genre.Drama, AgeRestriction.Sixteen);
|
||||
log.info(film.toString());
|
||||
final Film findFilm = filmService.findFilm(film.getId());
|
||||
log.info(findFilm.toString());
|
||||
Assertions.assertEquals(film, findFilm);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFilmReadNotFound() {
|
||||
filmService.deleteAllFilms();
|
||||
Assertions.assertThrows(EntityNotFoundException.class, () -> filmService.findFilm(-1L));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFilmReadAll() {
|
||||
filmService.deleteAllFilms();
|
||||
filmService.addFilm("После", 102, Genre.Drama, AgeRestriction.Sixteen);
|
||||
filmService.addFilm("Барбоскины", 85, Genre.Animation,AgeRestriction.Zero);
|
||||
final List<Film> films = filmService.findAllFilms();
|
||||
log.info(films.toString());
|
||||
Assertions.assertEquals(films.size(), 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFilmReadAllEmpty() {
|
||||
filmService.deleteAllFilms();
|
||||
final List<Film> films = filmService.findAllFilms();
|
||||
log.info(films.toString());
|
||||
Assertions.assertEquals(films.size(), 0);
|
||||
}
|
||||
}
|
101
src/test/java/ru/ulstu/is/sbapp/JpaTicketTests.java
Normal file
101
src/test/java/ru/ulstu/is/sbapp/JpaTicketTests.java
Normal file
@ -0,0 +1,101 @@
|
||||
package ru.ulstu.is.sbapp;
|
||||
|
||||
import org.assertj.core.internal.bytebuddy.asm.Advice;
|
||||
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 ru.ulstu.is.sbapp.cinema.model.*;
|
||||
import ru.ulstu.is.sbapp.cinema.model.enums.AgeRestriction;
|
||||
import ru.ulstu.is.sbapp.cinema.model.enums.Genre;
|
||||
import ru.ulstu.is.sbapp.cinema.service.CinemaService;
|
||||
import ru.ulstu.is.sbapp.cinema.service.FilmService;
|
||||
import ru.ulstu.is.sbapp.cinema.service.TicketService;
|
||||
import ru.ulstu.is.sbapp.cinema.service.TimetableService;
|
||||
|
||||
import javax.persistence.EntityNotFoundException;
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
@SpringBootTest
|
||||
public class JpaTicketTests {
|
||||
private static final Logger log = LoggerFactory.getLogger(JpaTicketTests.class);
|
||||
@Autowired
|
||||
private TicketService ticketService;
|
||||
@Autowired
|
||||
private CinemaService cinemaService;
|
||||
@Autowired
|
||||
private FilmService filmService;
|
||||
@Autowired
|
||||
private TimetableService timetableService;
|
||||
|
||||
@Test
|
||||
void testTicketCreate() {
|
||||
|
||||
Film film = filmService.addFilm("Одна",102,Genre.Drama,AgeRestriction.Sixteen);
|
||||
Cinema cinema =cinemaService.addCinema("Окко","Ульяновск");
|
||||
Timetable timetable= timetableService.addTimeTable(cinemaService.findCinema(cinema.getId()),filmService.findFilm(film.getId()));
|
||||
timetableService.addDateToTimetable(timetable.getId(),LocalDate.of(2023, 4, 9));
|
||||
final Ticket ticket = ticketService.addTicket(filmService.findFilm(film.getId()),cinemaService.findCinema(cinema.getId()),LocalDate.of(2023, 4, 9));
|
||||
log.info(ticket.toString());
|
||||
Assertions.assertNotNull(ticket.getId());
|
||||
}
|
||||
@Test
|
||||
void testTicketNotCreate() {
|
||||
|
||||
Film film = filmService.addFilm("Одна",102,Genre.Drama,AgeRestriction.Sixteen);
|
||||
Cinema cinema =cinemaService.addCinema("Окко","Ульяновск");
|
||||
Timetable timetable= timetableService.addTimeTable(cinemaService.findCinema(cinema.getId()),filmService.findFilm(film.getId()));
|
||||
timetableService.addDateToTimetable(timetable.getId(),LocalDate.of(2023, 4, 9));
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () ->
|
||||
ticketService.addTicket(filmService.findFilm(film.getId()),cinemaService.findCinema(cinema.getId()),LocalDate.of(2020, 1, 1)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testTicketRead() {
|
||||
|
||||
Film film = filmService.addFilm("Одна",102,Genre.Drama,AgeRestriction.Sixteen);
|
||||
Cinema cinema =cinemaService.addCinema("Окко","Ульяновск");
|
||||
Timetable timetable= timetableService.addTimeTable(cinemaService.findCinema(cinema.getId()),filmService.findFilm(film.getId()));
|
||||
timetableService.addDateToTimetable(timetable.getId(),LocalDate.of(2023, 4, 9));
|
||||
final Ticket ticket = ticketService.addTicket(filmService.findFilm(film.getId()),cinemaService.findCinema(cinema.getId()),LocalDate.of(2023, 4, 9));
|
||||
log.info(ticket.toString());
|
||||
final Ticket findTicket = ticketService.findTicket(ticket.getId());
|
||||
log.info(findTicket.toString());
|
||||
Assertions.assertEquals(ticket, findTicket);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testTicketReadNotFound() {
|
||||
ticketService.deleteAllTickets();
|
||||
Assertions.assertThrows(EntityNotFoundException.class, () -> ticketService.findTicket(-1L));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testTicketReadAll() {
|
||||
timetableService.deleteAllTimetables();
|
||||
cinemaService.deleteAllCinemas();
|
||||
filmService.deleteAllFilms();
|
||||
ticketService.findAllTickets();
|
||||
Film film = filmService.addFilm("Одна",102,Genre.Drama,AgeRestriction.Sixteen);
|
||||
Cinema cinema =cinemaService.addCinema("Окко","Ульяновск");
|
||||
Timetable timetable= timetableService.addTimeTable(cinemaService.findCinema(cinema.getId()),filmService.findFilm(film.getId()));
|
||||
timetableService.addDateToTimetable(timetable.getId(),LocalDate.of(2023, 4, 9));
|
||||
ticketService.addTicket(filmService.findFilm(film.getId()),cinemaService.findCinema(cinema.getId()),LocalDate.of(2023, 4, 9));
|
||||
ticketService.addTicket(filmService.findFilm(film.getId()),cinemaService.findCinema(cinema.getId()),LocalDate.of(2023, 4, 9));
|
||||
final List<Ticket> tickets = ticketService.findAllTickets();
|
||||
log.info(tickets.toString());
|
||||
Assertions.assertEquals(tickets.size(), 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testTicketReadAllEmpty() {
|
||||
ticketService.deleteAllTickets();
|
||||
ticketService.findAllTickets();
|
||||
final List<Ticket> tickets = ticketService.findAllTickets();
|
||||
log.info(tickets.toString());
|
||||
Assertions.assertEquals(tickets.size(), 0);
|
||||
}
|
||||
}
|
98
src/test/java/ru/ulstu/is/sbapp/JpaTimetableTests.java
Normal file
98
src/test/java/ru/ulstu/is/sbapp/JpaTimetableTests.java
Normal file
@ -0,0 +1,98 @@
|
||||
package ru.ulstu.is.sbapp;
|
||||
|
||||
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 ru.ulstu.is.sbapp.cinema.model.Film;
|
||||
import ru.ulstu.is.sbapp.cinema.model.enums.AgeRestriction;
|
||||
import ru.ulstu.is.sbapp.cinema.model.Cinema;
|
||||
import ru.ulstu.is.sbapp.cinema.model.enums.Genre;
|
||||
import ru.ulstu.is.sbapp.cinema.model.Timetable;
|
||||
import ru.ulstu.is.sbapp.cinema.service.CinemaService;
|
||||
import ru.ulstu.is.sbapp.cinema.service.FilmService;
|
||||
import ru.ulstu.is.sbapp.cinema.service.TimetableService;
|
||||
|
||||
import javax.persistence.EntityNotFoundException;
|
||||
import java.util.List;
|
||||
|
||||
@SpringBootTest
|
||||
public class JpaTimetableTests {
|
||||
private static final Logger log = LoggerFactory.getLogger(JpaTimetableTests.class);
|
||||
|
||||
@Autowired
|
||||
private CinemaService cinemaService;
|
||||
@Autowired
|
||||
private FilmService filmService;
|
||||
@Autowired
|
||||
private TimetableService timetableService;
|
||||
|
||||
@Test
|
||||
void testTimetableCreate() {
|
||||
timetableService.deleteAllTimetables();
|
||||
cinemaService.deleteAllCinemas();
|
||||
filmService.deleteAllFilms();
|
||||
Film film = filmService.addFilm("Одна",102,Genre.Drama,AgeRestriction.Sixteen);
|
||||
Cinema cinema =cinemaService.addCinema("Окко","Ульяновск");
|
||||
Timetable timetable = timetableService.addTimeTable(cinemaService.findCinema(cinema.getId()),filmService.findFilm(film.getId()));
|
||||
log.info(timetable.toString());
|
||||
Assertions.assertNotNull(timetable.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testTimetableRead() {
|
||||
timetableService.deleteAllTimetables();
|
||||
cinemaService.deleteAllCinemas();
|
||||
filmService.deleteAllFilms();
|
||||
Film film = filmService.addFilm("Одна",102,Genre.Drama,AgeRestriction.Sixteen);
|
||||
Cinema cinema =cinemaService.addCinema("Окко","Ульяновск");
|
||||
Timetable timetable = timetableService.addTimeTable(cinemaService.findCinema(cinema.getId()),filmService.findFilm(film.getId()));
|
||||
Timetable findCTimetable = timetableService.findTimetable(timetable.getId());
|
||||
Assertions.assertEquals(timetable, findCTimetable);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testTimetableReadNotFound() {
|
||||
timetableService.deleteAllTimetables();
|
||||
Assertions.assertThrows(EntityNotFoundException.class, () -> timetableService.findTimetable(-1L));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCinemaAddNotUnique() {
|
||||
timetableService.deleteAllTimetables();
|
||||
cinemaService.deleteAllCinemas();
|
||||
filmService.deleteAllFilms();
|
||||
Film film = filmService.addFilm("Одна",102,Genre.Drama,AgeRestriction.Sixteen);
|
||||
Cinema cinema =cinemaService.addCinema("Окко","Ульяновск");
|
||||
timetableService.addTimeTable(cinemaService.findCinema(cinema.getId()),filmService.findFilm(film.getId()));
|
||||
try {
|
||||
timetableService.addTimeTable(cinemaService.findCinema(cinema.getId()), filmService.findFilm(film.getId()));
|
||||
}catch (Exception NotUnique){
|
||||
}
|
||||
final List<Timetable> timetables = timetableService.findAllTimetables();
|
||||
Assertions.assertEquals(timetables.size(), 1);
|
||||
}
|
||||
@Test
|
||||
void testCinemaReadAll() {
|
||||
timetableService.deleteAllTimetables();
|
||||
cinemaService.deleteAllCinemas();
|
||||
filmService.deleteAllFilms();
|
||||
Film film = filmService.addFilm("Одна",102,Genre.Drama,AgeRestriction.Sixteen);
|
||||
Cinema cinema =cinemaService.addCinema("Окко","Ульяновск");
|
||||
timetableService.addTimeTable(cinemaService.findCinema(cinema.getId()),filmService.findFilm(film.getId()));
|
||||
Film film2 = filmService.addFilm("Одна",102,Genre.Drama,AgeRestriction.Sixteen);
|
||||
timetableService.addTimeTable(cinemaService.findCinema(cinema.getId()), filmService.findFilm(film2.getId()));
|
||||
final List<Timetable> timetables = timetableService.findAllTimetables();
|
||||
Assertions.assertEquals(timetables.size(), 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testTimetableReadAllEmpty() {
|
||||
timetableService.deleteAllTimetables();
|
||||
final List<Timetable> timetables = timetableService.findAllTimetables();
|
||||
log.info(timetables.toString());
|
||||
Assertions.assertEquals(timetables.size(), 0);
|
||||
}
|
||||
}
|
6
src/test/resources/application.properties
Normal file
6
src/test/resources/application.properties
Normal file
@ -0,0 +1,6 @@
|
||||
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
|
Loading…
Reference in New Issue
Block a user