контроллеры
This commit is contained in:
parent
465dcc3fae
commit
9d40b79426
@ -0,0 +1,45 @@
|
||||
package com.labwork1.app.student.controller;
|
||||
|
||||
import com.labwork1.app.student.service.CinemaService;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/cinema")
|
||||
public class CinemaController {
|
||||
private final CinemaService cinemaService;
|
||||
|
||||
public CinemaController(CinemaService cinemaService) {
|
||||
this.cinemaService = cinemaService;
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public CinemaDto getCinema(@PathVariable Long id) {
|
||||
return new CinemaDto(cinemaService.findCinema(id));
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public List<CinemaDto> getCinemas() {
|
||||
return cinemaService.findAllCinemas().stream()
|
||||
.map(CinemaDto::new)
|
||||
.toList();
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public CinemaDto createCinema(@RequestParam("name") String name) {
|
||||
return new CinemaDto(cinemaService.addCinema(name));
|
||||
}
|
||||
|
||||
@PutMapping("/{id}")
|
||||
public CinemaDto updateCinema(@PathVariable Long id,
|
||||
@RequestParam("name") String name) {
|
||||
return new CinemaDto(cinemaService.updateCinema(id, name));
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public CinemaDto deleteCinema(@PathVariable Long id) {
|
||||
return new CinemaDto(cinemaService.deleteCinema(id));
|
||||
}
|
||||
|
||||
}
|
@ -35,7 +35,9 @@ public class OrderController {
|
||||
public OrderDto updateOrder(@PathVariable Long id,
|
||||
@RequestParam("session") Long session,
|
||||
@RequestParam("count") Integer count) {
|
||||
return new OrderDto(orderService.addSession(id, session, count));
|
||||
if (count > 0)
|
||||
return new OrderDto(orderService.addSession(id, session, count));
|
||||
return new OrderDto(orderService.deleteSessionInOrder(id, session, -count));
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
|
@ -0,0 +1,56 @@
|
||||
package com.labwork1.app.student.controller;
|
||||
|
||||
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.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/session")
|
||||
public class SessionController {
|
||||
private final SessionService sessionService;
|
||||
|
||||
public SessionController(SessionService sessionService) {
|
||||
this.sessionService = sessionService;
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public SessionDto getSession(@PathVariable Long id) {
|
||||
return new SessionDto(sessionService.findSession(id));
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public List<SessionDto> getSessions() {
|
||||
return sessionService.findAllSessions().stream()
|
||||
.map(SessionDto::new)
|
||||
.toList();
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public SessionDto createSession(@RequestParam("price") String price,
|
||||
@RequestParam("timestamp") String timestamp,
|
||||
@RequestParam("cinemaid") Long cinemaId,
|
||||
@RequestParam("capacity") Integer capacity) throws ParseException {
|
||||
SimpleDateFormat format = new SimpleDateFormat();
|
||||
format.applyPattern("yyyy-MM-dd-HH:ss");
|
||||
Date docDate = format.parse(timestamp.replace('T', '-'));
|
||||
return new SessionDto(sessionService.addSession(Double.parseDouble(price),
|
||||
new Timestamp(docDate.getTime()), cinemaId, capacity));
|
||||
}
|
||||
|
||||
@PutMapping("/{id}")
|
||||
public SessionDto updateSession(@PathVariable Long id,
|
||||
@RequestParam("price") String price) {
|
||||
return new SessionDto(sessionService.updateSession(id, Double.parseDouble(price)));
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public SessionDto deleteSession(@PathVariable Long id) {
|
||||
return new SessionDto(sessionService.deleteSession(id));
|
||||
}
|
||||
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
/*
|
||||
package com.labwork1.app;
|
||||
|
||||
import com.labwork1.app.student.model.Customer;
|
||||
@ -117,3 +118,4 @@ public class JpaCustomerTests {
|
||||
cinemaService.deleteCinema(cinema2.getId());
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user