From 2d2394bce5262794381cee0ca305dd20338e4d87 Mon Sep 17 00:00:00 2001 From: dasha Date: Sat, 22 Apr 2023 11:47:42 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BF=D0=BE=D1=87=D1=82=D0=B8=20=D0=B2=D1=81?= =?UTF-8?q?=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 24 ++-- .../com/labwork1/app/WebConfiguration.java | 34 ++---- .../student/controller/CinemaController.java | 3 +- .../app/student/controller/CinemaDto.java | 12 ++ .../controller/CinemaMvcController.java | 81 +++++++++++++ .../controller/CustomerController.java | 3 +- .../app/student/controller/CustomerDto.java | 16 +++ .../controller/CustomerMvcController.java | 64 ++++++++++ .../student/controller/OrderController.java | 3 +- .../app/student/controller/OrderDto.java | 26 ++++ .../controller/OrderMvcController.java | 99 ++++++++++++++++ .../student/controller/OrderSessionDto.java | 12 ++ .../student/controller/SessionController.java | 9 +- .../app/student/controller/SessionDto.java | 46 +++++-- .../controller/SessionMvcController.java | 81 +++++++++++++ .../labwork1/app/student/model/Session.java | 11 +- .../app/student/service/SessionService.java | 3 +- src/main/resources/public/css/style.css | 112 ++++++++++++++++++ src/main/resources/public/favicon.svg | 4 + src/main/resources/public/search.jpg | Bin 0 -> 3703 bytes src/main/resources/public/vk.jpg | Bin 0 -> 2236 bytes src/main/resources/templates/cinema-edit.html | 32 +++++ src/main/resources/templates/cinema.html | 57 +++++++++ .../resources/templates/customer-edit.html | 32 +++++ src/main/resources/templates/customer.html | 51 ++++++++ src/main/resources/templates/default.html | 68 +++++++++++ src/main/resources/templates/error.html | 13 ++ src/main/resources/templates/index.html | 13 ++ src/main/resources/templates/order-edit.html | 57 +++++++++ src/main/resources/templates/order.html | 51 ++++++++ .../resources/templates/ordersession.html | 69 +++++++++++ .../resources/templates/session-edit.html | 45 +++++++ src/main/resources/templates/session.html | 57 +++++++++ 33 files changed, 1131 insertions(+), 57 deletions(-) create mode 100644 src/main/java/com/labwork1/app/student/controller/CinemaMvcController.java create mode 100644 src/main/java/com/labwork1/app/student/controller/CustomerMvcController.java create mode 100644 src/main/java/com/labwork1/app/student/controller/OrderMvcController.java create mode 100644 src/main/java/com/labwork1/app/student/controller/SessionMvcController.java create mode 100644 src/main/resources/public/css/style.css create mode 100644 src/main/resources/public/favicon.svg create mode 100644 src/main/resources/public/search.jpg create mode 100644 src/main/resources/public/vk.jpg create mode 100644 src/main/resources/templates/cinema-edit.html create mode 100644 src/main/resources/templates/cinema.html create mode 100644 src/main/resources/templates/customer-edit.html create mode 100644 src/main/resources/templates/customer.html create mode 100644 src/main/resources/templates/default.html create mode 100644 src/main/resources/templates/error.html create mode 100644 src/main/resources/templates/index.html create mode 100644 src/main/resources/templates/order-edit.html create mode 100644 src/main/resources/templates/order.html create mode 100644 src/main/resources/templates/ordersession.html create mode 100644 src/main/resources/templates/session-edit.html create mode 100644 src/main/resources/templates/session.html diff --git a/build.gradle b/build.gradle index 7e8766c..58f9b3c 100644 --- a/build.gradle +++ b/build.gradle @@ -12,22 +12,24 @@ repositories { mavenCentral() } -jar { - enabled = false -} - dependencies { - implementation(project(':front')) - implementation 'org.springframework.boot:spring-boot-starter-web' - implementation 'com.h2database:h2:2.1.210' - implementation 'org.springframework.boot:spring-boot-starter-validation' - implementation group: 'org.springdoc', name: 'springdoc-openapi-ui', version: '1.6.5' + implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' + implementation 'org.springframework.boot:spring-boot-devtools' + implementation 'nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect' + + implementation 'org.webjars:bootstrap:5.1.3' + implementation 'org.webjars:jquery:3.6.0' + implementation 'org.webjars:font-awesome:6.1.0' + implementation 'org.springframework.boot:spring-boot-starter-data-jpa' + implementation 'com.h2database:h2:2.1.210' + + implementation 'org.hibernate.validator:hibernate-validator' + + implementation 'org.springdoc:springdoc-openapi-ui:1.6.5' testImplementation 'org.springframework.boot:spring-boot-starter-test' - implementation 'org.hibernate.validator:hibernate-validator' - implementation 'org.springdoc:springdoc-openapi-ui:1.6.5' } tasks.named('test') { diff --git a/src/main/java/com/labwork1/app/WebConfiguration.java b/src/main/java/com/labwork1/app/WebConfiguration.java index 8b69823..2b87533 100644 --- a/src/main/java/com/labwork1/app/WebConfiguration.java +++ b/src/main/java/com/labwork1/app/WebConfiguration.java @@ -1,35 +1,19 @@ package com.labwork1.app; -import org.springframework.boot.web.server.ErrorPage; -import org.springframework.boot.web.server.WebServerFactoryCustomizer; -import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory; -import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.http.HttpStatus; -import org.springframework.web.servlet.config.annotation.CorsRegistry; -import org.springframework.web.servlet.config.annotation.ViewControllerRegistration; -import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +import org.springframework.web.servlet.config.annotation.*; + @Configuration public class WebConfiguration implements WebMvcConfigurer { + public static final String REST_API = "/api"; + + @Override + public void addViewControllers(ViewControllerRegistry registry) { + WebMvcConfigurer.super.addViewControllers(registry); + } + @Override public void addCorsMappings(CorsRegistry registry) { registry.addMapping("/**").allowedMethods("*"); } - @Override - public void addViewControllers(ViewControllerRegistry registry) { - ViewControllerRegistration registration = registry.addViewController("/notFound"); - registration.setViewName("forward:/index.html"); - registration.setStatusCode(HttpStatus.OK); - - // Alternative way (404 error hits the console): - // > registry.addViewController("/notFound").setViewName("forward:/index.html"); - } - - @Bean - public WebServerFactoryCustomizer containerCustomizer() { - return container -> { - container.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/notFound")); - }; - } } \ No newline at end of file diff --git a/src/main/java/com/labwork1/app/student/controller/CinemaController.java b/src/main/java/com/labwork1/app/student/controller/CinemaController.java index 767bf26..9b3720e 100644 --- a/src/main/java/com/labwork1/app/student/controller/CinemaController.java +++ b/src/main/java/com/labwork1/app/student/controller/CinemaController.java @@ -1,5 +1,6 @@ package com.labwork1.app.student.controller; +import com.labwork1.app.WebConfiguration; import com.labwork1.app.student.service.CinemaService; import jakarta.validation.Valid; import org.springframework.web.bind.annotation.*; @@ -7,7 +8,7 @@ import org.springframework.web.bind.annotation.*; import java.util.List; @RestController -@RequestMapping("/cinema") +@RequestMapping(WebConfiguration.REST_API + "/cinema") public class CinemaController { private final CinemaService cinemaService; diff --git a/src/main/java/com/labwork1/app/student/controller/CinemaDto.java b/src/main/java/com/labwork1/app/student/controller/CinemaDto.java index 115bdf7..e6baeac 100644 --- a/src/main/java/com/labwork1/app/student/controller/CinemaDto.java +++ b/src/main/java/com/labwork1/app/student/controller/CinemaDto.java @@ -18,6 +18,18 @@ public class CinemaDto { this.image = new String(cinema.getImage(), StandardCharsets.UTF_8); } + public void setId(long id) { + this.id = id; + } + + public void setName(String name) { + this.name = name; + } + + public void setImage(String image) { + this.image = image; + } + public String getImage() { return image; } diff --git a/src/main/java/com/labwork1/app/student/controller/CinemaMvcController.java b/src/main/java/com/labwork1/app/student/controller/CinemaMvcController.java new file mode 100644 index 0000000..4412914 --- /dev/null +++ b/src/main/java/com/labwork1/app/student/controller/CinemaMvcController.java @@ -0,0 +1,81 @@ +package com.labwork1.app.student.controller; + +import com.labwork1.app.student.service.CinemaService; +import jakarta.validation.Valid; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.validation.BindingResult; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +import java.io.IOException; +import java.util.Base64; +import java.util.List; + +@Controller +@RequestMapping("/cinema") +public class CinemaMvcController { + private final CinemaService cinemaService; + + public CinemaMvcController(CinemaService cinemaService) { + this.cinemaService = cinemaService; + } + + @GetMapping + public String getCinemas(Model model) { + model.addAttribute("cinemas", + cinemaService.findAllCinemas().stream() + .map(CinemaDto::new) + .toList()); + return "cinema"; + } + + @GetMapping(value = {"/edit", "/edit/{id}"}) + public String editCinema(@PathVariable(required = false) Long id, + Model model) { + if (id == null || id <= 0) { + model.addAttribute("cinemaDto", new CinemaDto()); + } else { + model.addAttribute("cinemaId", id); + model.addAttribute("cinemaDto", new CinemaDto(cinemaService.findCinema(id))); + } + return "cinema-edit"; + } + + @GetMapping (value = "/search/") + public String searchCinema(@RequestParam String request, + Model model) { + List cinemas = cinemaService.findAllCinemas(request) + .stream().map(CinemaDto::new).toList(); + model.addAttribute("cinemas", cinemas); + return "cinema"; + } + + @PostMapping(value = {"/", "/{id}"}) + public String saveCinema(@PathVariable(required = false) Long id, + @RequestParam("multipartFile") MultipartFile multipartFile, + @ModelAttribute @Valid CinemaDto cinemaDto, + BindingResult bindingResult, + Model model) throws IOException { + if (bindingResult.hasErrors()) { + model.addAttribute("errors", bindingResult.getAllErrors()); + return "cinema-edit"; + } + if (id == null || id <= 0) { + cinemaDto.setImage("data:image/jpeg;base64," + Base64.getEncoder().encodeToString(multipartFile.getBytes())); + cinemaService.addCinema(cinemaDto); + } else { + cinemaDto.setId(id); + cinemaDto.setImage("data:image/jpeg;base64," + Base64.getEncoder().encodeToString(multipartFile.getBytes())); + cinemaService.updateCinema(cinemaDto); + } + return "redirect:/cinema"; + } + + @PostMapping("/delete/{id}") + public String deleteCinema(@PathVariable Long id) { + cinemaService.deleteCinema(id); + return "redirect:/cinema"; + } + +} diff --git a/src/main/java/com/labwork1/app/student/controller/CustomerController.java b/src/main/java/com/labwork1/app/student/controller/CustomerController.java index ead463d..c2760a6 100644 --- a/src/main/java/com/labwork1/app/student/controller/CustomerController.java +++ b/src/main/java/com/labwork1/app/student/controller/CustomerController.java @@ -1,12 +1,13 @@ package com.labwork1.app.student.controller; +import com.labwork1.app.WebConfiguration; import com.labwork1.app.student.service.CustomerService; import org.springframework.web.bind.annotation.*; import java.util.List; @RestController -@RequestMapping("/customer") +@RequestMapping(WebConfiguration.REST_API + "/customer") public class CustomerController { private final CustomerService customerService; diff --git a/src/main/java/com/labwork1/app/student/controller/CustomerDto.java b/src/main/java/com/labwork1/app/student/controller/CustomerDto.java index 388d81b..812c3ce 100644 --- a/src/main/java/com/labwork1/app/student/controller/CustomerDto.java +++ b/src/main/java/com/labwork1/app/student/controller/CustomerDto.java @@ -27,6 +27,22 @@ public class CustomerDto { } } + public void setId(long id) { + this.id = id; + } + + public void setLogin(String login) { + this.login = login; + } + + public void setPassword(String password) { + this.password = password; + } + + public void setOrders(List orders) { + this.orders = orders; + } + public long getId() { return id; } diff --git a/src/main/java/com/labwork1/app/student/controller/CustomerMvcController.java b/src/main/java/com/labwork1/app/student/controller/CustomerMvcController.java new file mode 100644 index 0000000..104b787 --- /dev/null +++ b/src/main/java/com/labwork1/app/student/controller/CustomerMvcController.java @@ -0,0 +1,64 @@ +package com.labwork1.app.student.controller; + +import com.labwork1.app.student.service.CustomerService; +import jakarta.validation.Valid; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.validation.BindingResult; +import org.springframework.web.bind.annotation.*; + +@Controller +@RequestMapping("/customer") +public class CustomerMvcController { + private final CustomerService customerService; + + public CustomerMvcController(CustomerService customerService) { + this.customerService = customerService; + } + + @GetMapping + public String getCustomers(Model model) { + model.addAttribute("customers", + customerService.findAllCustomers().stream() + .map(CustomerDto::new) + .toList()); + return "customer"; + } + + @GetMapping(value = {"/edit", "/edit/{id}"}) + public String editCustomer(@PathVariable(required = false) Long id, + Model model) { + if (id == null || id <= 0) { + model.addAttribute("customerDto", new CustomerDto()); + } else { + model.addAttribute("customerId", id); + model.addAttribute("customerDto", new CustomerDto(customerService.findCustomer(id))); + } + return "customer-edit"; + } + + @PostMapping(value = {"/", "/{id}"}) + public String saveCustomer(@PathVariable(required = false) Long id, + @ModelAttribute @Valid CustomerDto customerDto, + BindingResult bindingResult, + Model model) { + if (bindingResult.hasErrors()) { + model.addAttribute("errors", bindingResult.getAllErrors()); + return "customer-edit"; + } + if (id == null || id <= 0) { + customerService.addCustomer(customerDto.getLogin(), customerDto.getPassword()); + } else { + customerDto.setId(id); + customerService.updateCustomer(id, customerDto.getLogin(), customerDto.getPassword()); + } + return "redirect:/customer"; + } + + @PostMapping("/delete/{id}") + public String deleteCustomer(@PathVariable Long id) { + customerService.deleteCustomer(id); + return "redirect:/customer"; + } + +} diff --git a/src/main/java/com/labwork1/app/student/controller/OrderController.java b/src/main/java/com/labwork1/app/student/controller/OrderController.java index a0ecc5f..f3ab633 100644 --- a/src/main/java/com/labwork1/app/student/controller/OrderController.java +++ b/src/main/java/com/labwork1/app/student/controller/OrderController.java @@ -1,12 +1,13 @@ package com.labwork1.app.student.controller; +import com.labwork1.app.WebConfiguration; import com.labwork1.app.student.service.OrderService; import org.springframework.web.bind.annotation.*; import java.util.List; @RestController -@RequestMapping("/order") +@RequestMapping(WebConfiguration.REST_API + "/order") public class OrderController { private final OrderService orderService; diff --git a/src/main/java/com/labwork1/app/student/controller/OrderDto.java b/src/main/java/com/labwork1/app/student/controller/OrderDto.java index 775fae0..7ae4e42 100644 --- a/src/main/java/com/labwork1/app/student/controller/OrderDto.java +++ b/src/main/java/com/labwork1/app/student/controller/OrderDto.java @@ -10,6 +10,7 @@ import java.util.List; public class OrderDto { private long id; private Date dateOfPurchase; + private Long customerId; private String customer; private List sessions; @@ -19,6 +20,7 @@ public class OrderDto { public OrderDto(Order order) { this.id = order.getId(); this.dateOfPurchase = order.getDateOfPurchase(); + this.customerId = order.getCustomer().getId(); this.customer = order.getCustomer().getLogin(); if (order.getSessions() != null && order.getSessions().size() > 0) this.sessions = order.getSessions() @@ -27,6 +29,30 @@ public class OrderDto { x.getId().getOrderId(), x.getCount())).toList(); } + public Long getCustomerId() { + return customerId; + } + + public void setCustomerId(Long customerId) { + this.customerId = customerId; + } + + public void setId(long id) { + this.id = id; + } + + public void setDateOfPurchase(Date dateOfPurchase) { + this.dateOfPurchase = dateOfPurchase; + } + + public void setCustomer(String customer) { + this.customer = customer; + } + + public void setSessions(List sessions) { + this.sessions = sessions; + } + public long getId() { return id; } diff --git a/src/main/java/com/labwork1/app/student/controller/OrderMvcController.java b/src/main/java/com/labwork1/app/student/controller/OrderMvcController.java new file mode 100644 index 0000000..e760793 --- /dev/null +++ b/src/main/java/com/labwork1/app/student/controller/OrderMvcController.java @@ -0,0 +1,99 @@ +package com.labwork1.app.student.controller; + +import com.labwork1.app.student.service.CustomerService; +import com.labwork1.app.student.service.OrderService; +import com.labwork1.app.student.service.SessionService; +import jakarta.validation.Valid; +import org.slf4j.event.KeyValuePair; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.validation.BindingResult; +import org.springframework.web.bind.annotation.*; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Controller +@RequestMapping("/order") +public class OrderMvcController { + private final OrderService orderService; + private final SessionService sessionService; + private final CustomerService customerService; + + public OrderMvcController(OrderService orderService, SessionService sessionService, CustomerService customerService) { + this.orderService = orderService; + this.sessionService = sessionService; + this.customerService = customerService; + } + + @GetMapping + public String getOrders(Model model) { + model.addAttribute("orders", + orderService.findAllOrders().stream() + .map(OrderDto::new) + .toList()); + return "order"; + } + + @GetMapping(value = {"/edit", "/edit/{id}"}) + public String editOrder(@PathVariable(required = false) Long id, + Model model) { + if (id == null || id <= 0) { + List customers = customerService.findAllCustomers().stream() + .map(CustomerDto::new) + .toList(); + model.addAttribute("orderDto", new OrderDto()); + model.addAttribute("customers", customers); + + return "order-edit"; + } else { + List temp = orderService.findOrder(id).getSessions() + .stream().map(x -> new OrderSessionDto(new SessionDto(x.getSession()), + x.getOrder().getId(), x.getCount())).toList(); + List sessions = sessionService.findAllSessions().stream() + .map(SessionDto::new) + .toList(); + HashMap orderSessions = new HashMap<>(); + for (var os : temp) { + orderSessions.put(os.getSession(), os.getCount()); + } + model.addAttribute("orderSessions", orderSessions); + model.addAttribute("sessions", sessions); + model.addAttribute("orderSessionDto", new OrderSessionDto()); + + return "ordersession"; + } + } + + @PostMapping(value = "/") + public String saveOrder(@ModelAttribute @Valid OrderDto orderDto, + BindingResult bindingResult, + Model model) { + if (bindingResult.hasErrors()) { + model.addAttribute("errors", bindingResult.getAllErrors()); + return "order-edit"; + } + orderService.addOrder(orderDto.getCustomerId()); + return "redirect:/order"; + } + + @PostMapping(value = {"/{id}"}) + public String editOrder(@PathVariable Long id, + @RequestParam("session") Long session, + @RequestParam(value = "count", required = false) Integer count, + Model model) { + if (count == null) + orderService.deleteSessionInOrder(id, session, Integer.MAX_VALUE); + else if (count > 0) + orderService.addSession(id, session, count); + return "redirect:/order/edit/" + id; + } + + @PostMapping("/delete/{id}") + public String deleteOrder(@PathVariable Long id) { + orderService.deleteOrder(id); + return "redirect:/order"; + } + +} diff --git a/src/main/java/com/labwork1/app/student/controller/OrderSessionDto.java b/src/main/java/com/labwork1/app/student/controller/OrderSessionDto.java index 8aa8234..b663c5e 100644 --- a/src/main/java/com/labwork1/app/student/controller/OrderSessionDto.java +++ b/src/main/java/com/labwork1/app/student/controller/OrderSessionDto.java @@ -14,6 +14,18 @@ public class OrderSessionDto { this.count = count; } + public void setSession(SessionDto session) { + this.session = session; + } + + public void setOrderId(Long orderId) { + this.orderId = orderId; + } + + public void setCount(Integer count) { + this.count = count; + } + public SessionDto getSession() { return session; } diff --git a/src/main/java/com/labwork1/app/student/controller/SessionController.java b/src/main/java/com/labwork1/app/student/controller/SessionController.java index 9d04b6e..e06dac0 100644 --- a/src/main/java/com/labwork1/app/student/controller/SessionController.java +++ b/src/main/java/com/labwork1/app/student/controller/SessionController.java @@ -1,16 +1,19 @@ package com.labwork1.app.student.controller; +import com.labwork1.app.WebConfiguration; import com.labwork1.app.student.service.SessionService; import org.springframework.web.bind.annotation.*; import java.sql.Timestamp; import java.text.ParseException; import java.text.SimpleDateFormat; +import java.time.LocalDate; +import java.time.LocalDateTime; import java.util.Date; import java.util.List; @RestController -@RequestMapping("/session") +@RequestMapping(WebConfiguration.REST_API + "/session") public class SessionController { private final SessionService sessionService; @@ -36,11 +39,11 @@ public class SessionController { @RequestParam("cinemaid") Long cinemaId, @RequestParam("capacity") Integer capacity) throws ParseException { SimpleDateFormat format = new SimpleDateFormat(); - format.applyPattern("yyyy-MM-dd-HH:ss"); + format.applyPattern("yyyy-MM-dd-HH:mm"); Date docDate = format.parse(timestamp.replace('T', '-')); return new SessionDto(sessionService.findSession( sessionService.addSession(Double.parseDouble(price), - new Timestamp(docDate.getTime()), cinemaId, capacity).getId())); + LocalDateTime.now(), cinemaId, capacity).getId())); } @PutMapping("/{id}") diff --git a/src/main/java/com/labwork1/app/student/controller/SessionDto.java b/src/main/java/com/labwork1/app/student/controller/SessionDto.java index aa91f6a..f994538 100644 --- a/src/main/java/com/labwork1/app/student/controller/SessionDto.java +++ b/src/main/java/com/labwork1/app/student/controller/SessionDto.java @@ -1,16 +1,17 @@ package com.labwork1.app.student.controller; import com.labwork1.app.student.model.Session; +import org.springframework.format.annotation.DateTimeFormat; -import java.sql.Timestamp; +import java.time.LocalDateTime; public class SessionDto { private long id; private Double price; - private Timestamp timestamp; + @DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm") + private LocalDateTime timestamp; private CinemaDto cinema; private Long capacity; - private int maxCount; public SessionDto() { @@ -22,31 +23,56 @@ public class SessionDto { this.timestamp = session.getTimestamp(); this.capacity = session.getCapacity(); this.maxCount = session.getMaxCount(); - if (session.getCinema() != null) this.cinema = new CinemaDto(session.getCinema()); - else this.cinema = null; + if (session.getCinema() != null) { + this.cinema = new CinemaDto(session.getCinema()); + } else this.cinema = null; } - public int getMaxCount() { - return maxCount; + public CinemaDto getCinema() { + return cinema; + } + + public void setCinema(CinemaDto cinema) { + this.cinema = cinema; } public long getId() { return id; } + public void setId(long id) { + this.id = id; + } + public Double getPrice() { return price; } - public Timestamp getTimestamp() { + public void setPrice(Double price) { + this.price = price; + } + + public LocalDateTime getTimestamp() { return timestamp; } + public void setTimestamp(LocalDateTime timestamp) { + this.timestamp = timestamp; + } + public Long getCapacity() { return capacity; } - public CinemaDto getCinema() { - return cinema; + public void setCapacity(Long capacity) { + this.capacity = capacity; + } + + public int getMaxCount() { + return maxCount; + } + + public void setMaxCount(int maxCount) { + this.maxCount = maxCount; } } diff --git a/src/main/java/com/labwork1/app/student/controller/SessionMvcController.java b/src/main/java/com/labwork1/app/student/controller/SessionMvcController.java new file mode 100644 index 0000000..e8ccba1 --- /dev/null +++ b/src/main/java/com/labwork1/app/student/controller/SessionMvcController.java @@ -0,0 +1,81 @@ +package com.labwork1.app.student.controller; + +import com.labwork1.app.student.service.CinemaService; +import com.labwork1.app.student.service.SessionService; +import jakarta.validation.Valid; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.validation.BindingResult; +import org.springframework.web.bind.annotation.*; + +import java.time.LocalDateTime; +import java.util.List; + +@Controller +@RequestMapping("/session") +public class SessionMvcController { + private final SessionService sessionService; + private final CinemaService cinemaService; + + public SessionMvcController(SessionService sessionService, CinemaService cinemaService) { + this.sessionService = sessionService; + this.cinemaService = cinemaService; + } + + @GetMapping + public String getSessions(Model model) { + model.addAttribute("sessions", + sessionService.findAllSessions().stream() + .map(SessionDto::new) + .toList()); + return "session"; + } + + @GetMapping(value = {"/edit", "/edit/{id}"}) + public String editSession(@PathVariable(required = false) Long id, + Model model) { + if (id == null || id <= 0) { + List cinemas = cinemaService.findAllCinemas().stream() + .map(CinemaDto::new) + .toList(); + model.addAttribute("sessionDto", new SessionDto()); + model.addAttribute("cinemas", cinemas); + } else { + model.addAttribute("sessionId", id); + model.addAttribute("sessionDto", new SessionDto(sessionService.findSession(id))); + } + return "session-edit"; + } + + @PostMapping(value = "/{id}") + public String editSession(@PathVariable Long id, + @ModelAttribute @Valid SessionDto sessionDto, + BindingResult bindingResult, + Model model) { + if (bindingResult.hasErrors()) { + model.addAttribute("errors", bindingResult.getAllErrors()); + return "session-edit"; + } + sessionService.updateSession(id, sessionDto.getPrice()); + + return "redirect:/session"; + } + + @PostMapping(value = "/") + public String saveSession(@RequestParam("price") String price, + @RequestParam("timestamp") LocalDateTime timestamp, + @RequestParam("cinemaid") Long cinemaId, + @RequestParam("maxCount") Integer capacity, + Model model) { + sessionService.addSession(Double.parseDouble(price), timestamp, + cinemaId, capacity); + return "redirect:/session"; + } + + @PostMapping("/delete/{id}") + public String deleteSession(@PathVariable Long id) { + sessionService.deleteSession(id); + return "redirect:/session"; + } + +} diff --git a/src/main/java/com/labwork1/app/student/model/Session.java b/src/main/java/com/labwork1/app/student/model/Session.java index b7986ed..1ff14c0 100644 --- a/src/main/java/com/labwork1/app/student/model/Session.java +++ b/src/main/java/com/labwork1/app/student/model/Session.java @@ -2,8 +2,10 @@ package com.labwork1.app.student.model; import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; +import org.springframework.format.annotation.DateTimeFormat; import java.sql.Timestamp; +import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; import java.util.Objects; @@ -18,7 +20,8 @@ public class Session { @NotNull(message = "timestamp can't be null or empty") @Column @Temporal(TemporalType.TIMESTAMP) - private Timestamp timestamp; + @DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm") + private LocalDateTime timestamp; @OneToMany(mappedBy = "session", fetch = FetchType.EAGER) private List orders; @ManyToOne(fetch = FetchType.EAGER) @@ -37,7 +40,7 @@ public class Session { return maxCount; } - public Session(Double price, Timestamp timestamp, Integer maxCount) { + public Session(Double price, LocalDateTime timestamp, Integer maxCount) { this.price = price; this.timestamp = timestamp; this.maxCount = maxCount; @@ -125,11 +128,11 @@ public class Session { this.price = price; } - public Timestamp getTimestamp() { + public LocalDateTime getTimestamp() { return timestamp; } - public void setTimestamp(Timestamp timestamp) { + public void setTimestamp(LocalDateTime timestamp) { this.timestamp = timestamp; } diff --git a/src/main/java/com/labwork1/app/student/service/SessionService.java b/src/main/java/com/labwork1/app/student/service/SessionService.java index 30bffbe..43967b0 100644 --- a/src/main/java/com/labwork1/app/student/service/SessionService.java +++ b/src/main/java/com/labwork1/app/student/service/SessionService.java @@ -8,6 +8,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.sql.Timestamp; +import java.time.LocalDateTime; import java.util.List; @Service @@ -23,7 +24,7 @@ public class SessionService { } @Transactional - public Session addSession(Double price, Timestamp date, Long cinemaId, Integer capacity) { + public Session addSession(Double price, LocalDateTime date, Long cinemaId, Integer capacity) { final Session session = new Session(price, date, capacity); final Cinema cinema = cinemaService.findCinema(cinemaId); session.setCinema(cinema); diff --git a/src/main/resources/public/css/style.css b/src/main/resources/public/css/style.css new file mode 100644 index 0000000..b0b24a3 --- /dev/null +++ b/src/main/resources/public/css/style.css @@ -0,0 +1,112 @@ +html, +body { + background: #2b2d33; +} +.green-mark { + background-color: #38a65d; +} +.willSee { + background-color: #38a65d; +} +.delete { + background-color: #e94049; +} +.icon { + width: 50px; + height: 50px; +} +hr { + height: 2px !important; +} +.description { + color: #8f9398; +} +.editIcon { + height: 2.5vh; +} +.posterChoiceToTaste { + width: 290px; + height: 437px; +} +.posterFilmPage{ + width: 290px; + height: 437px; +} +a { + text-decoration: none; +} +a:hover { + color: white; +} + +.current a { + color: white; +} + +/* for film-page */ +.table { + color: #8f9398; +} +/* main */ +@media screen and (max-width: 290px) { + .posterItem { + display: none !important; + } + .fs-1 { + margin-left: 1em !important; + } +} + +body { + background: #2b2d33; +} + +.content { + min-height: calc(100vh - 25.1vh); + background: #40444d; +} + +.content_header { + margin: -1.5em -1.5em 0em -1.5em; + background-color: #8f9297; +} + +.posterItem { + width: 90px; + height: 90px; + margin-top: -10px; +} + +form input { + max-width: 300px; +} + +table tbody tr td { + border: 0px !important; +} + +footer { + flex: 0 0 auto !important; + background: #1a1c20; + color: #c2c2c2; +} + +footer nav { + color: #c2c2c2; +} + +header { + background: #1a1c20; +} + +header a { + color: #c2c2c2; +} + +header a:hover { + color: #ffffff; +} + +.mainInput { + max-width: 200px; +} \ No newline at end of file diff --git a/src/main/resources/public/favicon.svg b/src/main/resources/public/favicon.svg new file mode 100644 index 0000000..c2e8ab2 --- /dev/null +++ b/src/main/resources/public/favicon.svg @@ -0,0 +1,4 @@ + + + \ No newline at end of file diff --git a/src/main/resources/public/search.jpg b/src/main/resources/public/search.jpg new file mode 100644 index 0000000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-L-qcwXFt z8~*FqF+%4As_5#oGTNNpBh{U~4J{J@h>=V(9a)aid~+#;wmaVF@bd-v`ecfF^- zcln!dW{R7dAS%uTTG>GA3uDY zPw7b)`dprSe)bDk7cX6sEpKm??6DKHpXD!Zv8uBRMxenL zSj3-~UwKXU{8;h4!NLt`Meo~}C$o$d``cM2sdi;w56TaBirp_80u`{>^P4?;uH@$* zDz!mszxY0`x^CSD88~FPC>8!Ur?y%?1As&KII{-uuJ#en$@#K&uJHL zuvjSGHdR2@@R52p!s&T@@}Y54|JH;80tIb$jEhdQRGd{=;;h5$IddiNzya-7k#=}q zbX}=G2b2tPMj!^1q)wP z3#7kqzn}3_$5QxLt?u8NP{5$DDk^Ks~sr%@MaY*FGjhk}z>{(g0 zdW{UtdP1Rko_8RLrt07$aZYn}Qox`Pu!eh#@!}YO#*Fjl&@OKX)qV#|k1vM^7Yon~txStqA z-AR^BwSb%PdTs-<6gE(n07f>?p9-Pf%BR?gAwa{@?BMv%d4r`)I=$;G@0u>7eK+S2tJL}{Z9IP|!~4aictfU?Virr>OU z?T5)*BF@;w&#_8CTlYFWJDe(aP)@SL^CqYJ%2SmB)c=DXfeKKMKn18rpaN12`5(mc VIxAk^nIc@*| literal 0 HcmV?d00001 diff --git a/src/main/resources/public/vk.jpg b/src/main/resources/public/vk.jpg new file mode 100644 index 0000000000000000000000000000000000000000..d2e40c90b9a182370315e6ab1a2f6487ef83250e GIT binary patch literal 2236 zcmV;t2t)UYP)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D2vJEyK~#8N?VRgt zTtyhh{W~=GWRp#E+gvuc&8e`4F&RK~N}EEEE)rLZMJ81cJq)s1!ph z)nK(mtF5*6Vq4pi8k=5HTly!A=Q(leoU_ll%(-QElMg={y62rU^X$w!@4Pd!Pd!~$ zC05aARk(m8F5ENa)uN)RPE^;XMO{O)Xlm^ena)1Z)iWe|a-*VeV4dh6TyKKE@qb;t zL*_GhHf7jU*QJdzQf67~9Z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wAkZ2)IDQ}7Uq7wws1g-SB%3Jbq*^U2qYX>@_E^!_yq_FCIZB2 zL5HVGVBrA7!)&W_{B^m&{y}<8CeTE{2ql~Z2>~3RD8!+Qo19}7b7v@RN$NAXpCH23DEy7z z!Ng~{Z-6~t_$?gOh{NIQuq?ur0;|FWWL3C;tO^&9RpA0rCH@7g4w=oaMhMdY0000< KMNUMnLSTYX)+0~= literal 0 HcmV?d00001 diff --git a/src/main/resources/templates/cinema-edit.html b/src/main/resources/templates/cinema-edit.html new file mode 100644 index 0000000..5f79ff4 --- /dev/null +++ b/src/main/resources/templates/cinema-edit.html @@ -0,0 +1,32 @@ + + + + + +
+

Фильм

+
+
+
+ + +
+
+ + +
+
+ + + Назад + +
+
+
+ + \ No newline at end of file diff --git a/src/main/resources/templates/cinema.html b/src/main/resources/templates/cinema.html new file mode 100644 index 0000000..327bb7c --- /dev/null +++ b/src/main/resources/templates/cinema.html @@ -0,0 +1,57 @@ + + + + + +
+

Фильмы

+
+ + + +
+
+ + +
+
+ + + + + + +
+ ${cinema.name} +
+
+

+ +

+
+
+
9.2
+ +
+
+ +
+
+
+
+
+ + \ No newline at end of file diff --git a/src/main/resources/templates/customer-edit.html b/src/main/resources/templates/customer-edit.html new file mode 100644 index 0000000..297ce31 --- /dev/null +++ b/src/main/resources/templates/customer-edit.html @@ -0,0 +1,32 @@ + + + + + +
+

Пользователь

+
+
+
+ + +
+
+ + +
+
+ + + Назад + +
+
+
+ + \ No newline at end of file diff --git a/src/main/resources/templates/customer.html b/src/main/resources/templates/customer.html new file mode 100644 index 0000000..8e99be3 --- /dev/null +++ b/src/main/resources/templates/customer.html @@ -0,0 +1,51 @@ + + + + + +
+

Пользователи

+
+ + + +
+ + + + + + + + + + + + + + +
IDЛогинПароль
+ + + + +
+ +
+
+
+ + \ No newline at end of file diff --git a/src/main/resources/templates/default.html b/src/main/resources/templates/default.html new file mode 100644 index 0000000..9af2ebb --- /dev/null +++ b/src/main/resources/templates/default.html @@ -0,0 +1,68 @@ + + + + + Киносайт + + + + + + + + + +
+ +
+
+
+

Киносайт

+
+
+
+
+ + + + +
2022 г. + +
+ \ No newline at end of file diff --git a/src/main/resources/templates/error.html b/src/main/resources/templates/error.html new file mode 100644 index 0000000..0a81607 --- /dev/null +++ b/src/main/resources/templates/error.html @@ -0,0 +1,13 @@ + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html new file mode 100644 index 0000000..a7a11f2 --- /dev/null +++ b/src/main/resources/templates/index.html @@ -0,0 +1,13 @@ + + + + + +
+
It's works!
+ ERROR +
+ + \ No newline at end of file diff --git a/src/main/resources/templates/order-edit.html b/src/main/resources/templates/order-edit.html new file mode 100644 index 0000000..eba3a8d --- /dev/null +++ b/src/main/resources/templates/order-edit.html @@ -0,0 +1,57 @@ + + + + + +
+

Создание заказа

+

Добавление сеансов в заказ

+
+
+
+ + +
+
+ + + Назад + +
+
+
+
+ + +
+
+ + +
+
+ + + Назад + +
+
+
+ + \ No newline at end of file diff --git a/src/main/resources/templates/order.html b/src/main/resources/templates/order.html new file mode 100644 index 0000000..098b315 --- /dev/null +++ b/src/main/resources/templates/order.html @@ -0,0 +1,51 @@ + + + + + +
+

Заказы

+
+ + + +
+ + + + + + + + + + + + + + +
IDCustomerDateOfPurchase
+ + + + +
+ +
+
+
+ + \ No newline at end of file diff --git a/src/main/resources/templates/ordersession.html b/src/main/resources/templates/ordersession.html new file mode 100644 index 0000000..d54f059 --- /dev/null +++ b/src/main/resources/templates/ordersession.html @@ -0,0 +1,69 @@ + + + + + +
+

+
+
+ + +
+
+ + +
+
+ + + Назад + +
+
+ + + + + + + + + + + + + + + + +
IDPriceCinemaTimestampCount
+ + + + + +
+ + + +
+
+ +
+
+
+ + \ No newline at end of file diff --git a/src/main/resources/templates/session-edit.html b/src/main/resources/templates/session-edit.html new file mode 100644 index 0000000..60be082 --- /dev/null +++ b/src/main/resources/templates/session-edit.html @@ -0,0 +1,45 @@ + + + + + +
+

Сеанс

+
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + + Назад + +
+
+
+ + \ No newline at end of file diff --git a/src/main/resources/templates/session.html b/src/main/resources/templates/session.html new file mode 100644 index 0000000..7aaa9e4 --- /dev/null +++ b/src/main/resources/templates/session.html @@ -0,0 +1,57 @@ + + + + + +
+

Сеансы

+
+ + + +
+ + + + + + + + + + + + + + + + + +
IDPriceCinemaTimestampCapacityMaxCount
+ + + + + + + +
+ +
+
+
+ + \ No newline at end of file