forked from Olympic/NTO-2025-Backend-TeamTask
третья попытка((((
This commit is contained in:
@@ -37,19 +37,17 @@ public class BookingController {
|
||||
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build();
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/info")
|
||||
public ResponseEntity<Map<String, Object>> info(@PathVariable String code) {
|
||||
Optional<Employee> employeeOpt = employeeService.findByCode(code);
|
||||
if (employeeOpt.isEmpty()) return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build();
|
||||
|
||||
Employee employee = employeeOpt.get();
|
||||
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("name", employee.getName());
|
||||
response.put("photoUrl", employee.getPhotoUrl());
|
||||
|
||||
Map<String, Map<String, Object>> bookingsMap = new HashMap<>();
|
||||
Map<String, List<Map<String, Object>>> bookingsMap = new HashMap<>();
|
||||
List<Booking> bookingList = bookingService.getBookingsByEmployee(employee);
|
||||
|
||||
for (Booking b : bookingList) {
|
||||
@@ -58,11 +56,10 @@ public class BookingController {
|
||||
bookingData.put("id", b.getId());
|
||||
bookingData.put("place", b.getPlace().getPlace());
|
||||
|
||||
bookingsMap.put(dateKey, bookingData);
|
||||
bookingsMap.computeIfAbsent(dateKey, k -> new ArrayList<>()).add(bookingData);
|
||||
}
|
||||
|
||||
response.put("booking", bookingsMap);
|
||||
|
||||
return ResponseEntity.ok(response);
|
||||
}
|
||||
|
||||
@@ -107,8 +104,6 @@ public class BookingController {
|
||||
|
||||
try {
|
||||
String dateStr = body.get("date");
|
||||
|
||||
// поддерживаем все варианты ключей
|
||||
String placeIdStr = body.getOrDefault("placeID",
|
||||
body.getOrDefault("placeId",
|
||||
body.getOrDefault("place", null)));
|
||||
|
||||
@@ -21,7 +21,10 @@ public class EmployeeController {
|
||||
@GetMapping("/{code}")
|
||||
public ResponseEntity<Employee> getEmployeeByCode(@PathVariable String code) {
|
||||
Optional<Employee> employeeOpt = employeeService.findByCode(code);
|
||||
return employeeOpt.map(ResponseEntity::ok)
|
||||
.orElseGet(() -> ResponseEntity.status(HttpStatus.NOT_FOUND).build());
|
||||
if (employeeOpt.isPresent()) {
|
||||
return ResponseEntity.ok(employeeOpt.get());
|
||||
} else {
|
||||
return ResponseEntity.status(HttpStatus.NOT_FOUND).build();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package com.example.nto.entity;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import jakarta.persistence.*;
|
||||
import java.time.LocalDate;
|
||||
|
||||
@Entity
|
||||
@Table(name = "booking")
|
||||
@JsonIgnoreProperties({"hibernateLazyInitializer"})
|
||||
public class Booking {
|
||||
|
||||
@Id
|
||||
@@ -13,11 +15,11 @@ public class Booking {
|
||||
|
||||
private LocalDate date;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@ManyToOne(fetch = FetchType.EAGER)
|
||||
@JoinColumn(name = "place_id")
|
||||
private Place place;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@ManyToOne(fetch = FetchType.EAGER)
|
||||
@JoinColumn(name = "employee_id")
|
||||
private Employee employee;
|
||||
|
||||
@@ -31,13 +33,10 @@ public class Booking {
|
||||
|
||||
public long getId() { return id; }
|
||||
public void setId(long id) { this.id = id; }
|
||||
|
||||
public LocalDate getDate() { return date; }
|
||||
public void setDate(LocalDate date) { this.date = date; }
|
||||
|
||||
public Place getPlace() { return place; }
|
||||
public void setPlace(Place place) { this.place = place; }
|
||||
|
||||
public Employee getEmployee() { return employee; }
|
||||
public void setEmployee(Employee employee) { this.employee = employee; }
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.example.nto.entity;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import jakarta.persistence.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -20,6 +21,7 @@ public class Employee {
|
||||
private String photoUrl;
|
||||
|
||||
@OneToMany(mappedBy = "employee", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||
@JsonIgnore
|
||||
private List<Booking> bookingList = new ArrayList<>();
|
||||
|
||||
public Employee() {}
|
||||
@@ -32,16 +34,12 @@ public class Employee {
|
||||
|
||||
public long getId() { return id; }
|
||||
public void setId(long id) { this.id = id; }
|
||||
|
||||
public String getName() { return name; }
|
||||
public void setName(String name) { this.name = name; }
|
||||
|
||||
public String getCode() { return code; }
|
||||
public void setCode(String code) { this.code = code; }
|
||||
|
||||
public String getPhotoUrl() { return photoUrl; }
|
||||
public void setPhotoUrl(String photoUrl) { this.photoUrl = photoUrl; }
|
||||
|
||||
public List<Booking> getBookingList() { return bookingList; }
|
||||
public void setBookingList(List<Booking> bookingList) { this.bookingList = bookingList; }
|
||||
}
|
||||
|
||||
@@ -13,34 +13,11 @@ public class Place {
|
||||
@Column(name = "place_name", nullable = false, unique = true)
|
||||
private String place;
|
||||
|
||||
public Place() {
|
||||
}
|
||||
public Place() {}
|
||||
public Place(String place) { this.place = place; }
|
||||
|
||||
public Place(String place) {
|
||||
this.place = place;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getPlace() {
|
||||
return place;
|
||||
}
|
||||
|
||||
public void setPlace(String place) {
|
||||
this.place = place;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Place{" +
|
||||
"id=" + id +
|
||||
", place='" + place + '\'' +
|
||||
'}';
|
||||
}
|
||||
public Long getId() { return id; }
|
||||
public void setId(Long id) { this.id = id; }
|
||||
public String getPlace() { return place; }
|
||||
public void setPlace(String place) { this.place = place; }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user