MVCs are done.
This commit is contained in:
parent
55c85931a4
commit
4f574dbb18
@ -0,0 +1,57 @@
|
||||
package ru.ulstu.is.sbapp.Customer.MVC;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ru.ulstu.is.sbapp.Customer.Controller.CustomerDTO;
|
||||
import ru.ulstu.is.sbapp.Customer.Service.CustomerService;
|
||||
import ru.ulstu.is.sbapp.Movie.Controller.MovieDTO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/customer")
|
||||
public class CustomerMVC {
|
||||
private final CustomerService customerService;
|
||||
|
||||
public CustomerMVC(CustomerService customerService)
|
||||
{
|
||||
this.customerService = customerService;
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public String getCustomer(@PathVariable Long id, Model model) {
|
||||
model.addAttribute("customer",new CustomerDTO(customerService.findCustomer(id)));
|
||||
return "customer-details";
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public String getCustomers(Model model) {
|
||||
model.addAttribute("customers", customerService.findAllCustomers().stream().map(CustomerDTO::new).toList());
|
||||
return "customers-list";
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public String createCustomer(@RequestParam("fullName") String fullName, @RequestParam("password") String password ) {
|
||||
return "redirect:/customer/" + new CustomerDTO(customerService.addCustomer(fullName,password)).getID();
|
||||
}
|
||||
|
||||
@PutMapping("/{id}")
|
||||
public String updateCustomer(@PathVariable Long id, @RequestParam("fullName") String fullName) {
|
||||
return "redirect:/customer/" + new CustomerDTO(customerService.updateCustomer(id,fullName)).getID();
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public String deleteCustomer(@PathVariable Long id) {
|
||||
customerService.deleteCustomer(id);
|
||||
return "redirect:/customer";
|
||||
}
|
||||
|
||||
@GetMapping("/movies/{customerId}")
|
||||
public String getCustomerMovies(@PathVariable("customerId") Long customerId, Model model) {
|
||||
model.addAttribute("movies", customerService.findCustomerMovies(customerId).stream()
|
||||
.map(MovieDTO::new)
|
||||
.toList());
|
||||
return "customer-movies";
|
||||
}
|
||||
}
|
56
src/main/java/ru/ulstu/is/sbapp/Genre/MVC/GenreMVC.java
Normal file
56
src/main/java/ru/ulstu/is/sbapp/Genre/MVC/GenreMVC.java
Normal file
@ -0,0 +1,56 @@
|
||||
package ru.ulstu.is.sbapp.Genre.MVC;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ru.ulstu.is.sbapp.Genre.Controller.GenreDTO;
|
||||
import ru.ulstu.is.sbapp.Genre.Service.GenreService;
|
||||
import java.util.List;
|
||||
@Controller
|
||||
@RequestMapping("/genre")
|
||||
public class GenreMVC {
|
||||
private final GenreService genreService;
|
||||
|
||||
public GenreMVC(GenreService genreService) {
|
||||
this.genreService = genreService;
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public String getGenre(@PathVariable Long id, Model model) {
|
||||
model.addAttribute("genre",new GenreDTO(genreService.findGenre(id)));
|
||||
return "genre-details";
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public String getGenres(Model model) {
|
||||
model.addAttribute("genres",genreService.findAllGenres().stream()
|
||||
.map(GenreDTO::new)
|
||||
.toList());
|
||||
return "genres-list";
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public String createGenre(@RequestParam("name") String name) {
|
||||
|
||||
return "redirect:/genre/" + new GenreDTO(genreService.addGenre(name)).getID();
|
||||
}
|
||||
|
||||
@PutMapping("/{id}")
|
||||
public String updateGenre(@PathVariable Long id,
|
||||
@RequestParam("name") String name) {
|
||||
return "redirect:/genre/" + new GenreDTO(genreService.updateGenre(id,name)).getID();
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public String deleteGenre(@PathVariable Long id) {
|
||||
|
||||
genreService.deleteGenre(id);
|
||||
return "redirect:/genre";
|
||||
}
|
||||
|
||||
@PostMapping("/fill")
|
||||
public String insertGenres() {
|
||||
genreService.fillRepo();
|
||||
return "redirect:/genre";
|
||||
}
|
||||
}
|
84
src/main/java/ru/ulstu/is/sbapp/Movie/MVC/MovieMVC.java
Normal file
84
src/main/java/ru/ulstu/is/sbapp/Movie/MVC/MovieMVC.java
Normal file
@ -0,0 +1,84 @@
|
||||
package ru.ulstu.is.sbapp.Movie.MVC;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ru.ulstu.is.sbapp.Movie.Controller.MovieDTO;
|
||||
import ru.ulstu.is.sbapp.Movie.Service.MovieService;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/movie")
|
||||
public class MovieMVC {
|
||||
private final MovieService movieService;
|
||||
|
||||
public MovieMVC(MovieService movieService)
|
||||
{
|
||||
this.movieService = movieService;
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public String getMovie(@PathVariable Long id, Model model) {
|
||||
model.addAttribute("movie", new MovieDTO(movieService.findMovie(id)));
|
||||
return "movie-details";
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public String getMovies(Model model) {
|
||||
model.addAttribute("movies", movieService.findAllMovies().stream()
|
||||
.map(MovieDTO::new)
|
||||
.toList());
|
||||
return "movies-list";
|
||||
}
|
||||
|
||||
@GetMapping("/movies/{genre}")
|
||||
public String getSpecificMovies(@PathVariable("genre") String genre, Model model) {
|
||||
model.addAttribute("movies", movieService.findAllSpecificMovies(genre).stream()
|
||||
.map(MovieDTO::new)
|
||||
.toList());
|
||||
return "specific-movie-list";
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public String createMovie(@RequestParam("title") String title,
|
||||
@RequestParam("length") int length,
|
||||
@RequestParam("score") double score,
|
||||
@RequestParam("genre") Long genreId) {
|
||||
movieService.addMovie(title, length, score, genreId);
|
||||
return "redirect:/movie";
|
||||
}
|
||||
|
||||
@PutMapping("/{id}")
|
||||
public String updateMovie(@PathVariable("id") Long id,
|
||||
@RequestParam("title") String title,
|
||||
@RequestParam("length") int length,
|
||||
@RequestParam("score") double score) {
|
||||
movieService.updateMovie(id, title, length, score);
|
||||
return "redirect:/movie/" + id;
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public String deleteMovie(@PathVariable("id") Long id) {
|
||||
movieService.deleteMovie(id);
|
||||
return "redirect:/movie";
|
||||
}
|
||||
|
||||
@PostMapping("/{customerId}/{id}")
|
||||
public String assignMovie(@PathVariable("customerId") Long customerId,
|
||||
@PathVariable("id") Long id) {
|
||||
movieService.assignMovie(customerId, id);
|
||||
return "redirect:/customer/" + customerId;
|
||||
}
|
||||
|
||||
@DeleteMapping("/{customerId}/{id}")
|
||||
public String deleteMovieCustomer(@PathVariable("customerId") Long customerId,
|
||||
@PathVariable("id") Long id) {
|
||||
movieService.deleteMovieCustomer(id, customerId);
|
||||
return "redirect:/customer/" + customerId;
|
||||
}
|
||||
|
||||
@PostMapping("/fill")
|
||||
public String insertMovies() {
|
||||
movieService.fillRepo();
|
||||
return "redirect:/movie";
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user