main #8

Closed
student-18211 wants to merge 22 commits from student-18211/NTO-2025-Backend-TeamTask:main into main
3 changed files with 11 additions and 6 deletions
Showing only changes of commit 0cf5cfdf59 - Show all commits

View File

@@ -52,10 +52,16 @@ public class BookingController {
@PostMapping("/{code}/book") @PostMapping("/{code}/book")
public ResponseEntity<?> createBooking( public ResponseEntity<?> createBooking(
@PathVariable String code, @PathVariable String code,
@RequestBody Long placeId, @RequestBody Map<String, Object> body
@RequestBody String date
) { ) {
try { try {
Long placeId = body.get("placeId") != null
? Long.valueOf(body.get("placeId").toString())
: null;
String date = body.get("date") != null
? body.get("date").toString()
: null;
if (placeId == null || date == null || date.isEmpty()) { if (placeId == null || date == null || date.isEmpty()) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST) return ResponseEntity.status(HttpStatus.BAD_REQUEST)
.body("Place ID and date must be provided"); .body("Place ID and date must be provided");
@@ -85,7 +91,7 @@ public class BookingController {
.body("Place already booked for this date"); .body("Place already booked for this date");
} }
Booking booking = new Booking(); Booking booking = new Booking();
booking.setEmployee((Map<String, Object>) employee); booking.setEmployee(employee);
booking.setPlace(place); booking.setPlace(place);
booking.setDate(bookingDate); booking.setDate(bookingDate);
bookingRepository.save(booking); bookingRepository.save(booking);

View File

@@ -7,7 +7,6 @@ import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.Map;
/** /**
@@ -58,7 +57,7 @@ public class Booking {
this.place = place; this.place = place;
} }
public void setEmployee(Map<String, Object> employee) { public void setEmployee(Employee employee) {
this.employee = (Employee) employee; this.employee = (Employee) employee;
} }
} }

View File

@@ -89,7 +89,7 @@ public class BookingServiceImpl implements BookingService {
throw new IllegalArgumentException("Place already booked for this date"); throw new IllegalArgumentException("Place already booked for this date");
} }
Booking booking = new Booking(); Booking booking = new Booking();
booking.setEmployee((Map<String, Object>) employee); booking.setEmployee((Employee) employee);
booking.setPlace(place); booking.setPlace(place);
booking.setDate(bookingDate); booking.setDate(bookingDate);
bookingRepository.save(booking); bookingRepository.save(booking);