forked from Olympic/NTO-2025-Backend-TeamTask
init
This commit is contained in:
@@ -1,10 +1,60 @@
|
||||
package com.example.nto.controller;
|
||||
|
||||
import com.example.nto.entity.Booking;
|
||||
import com.example.nto.entity.Employee;
|
||||
import com.example.nto.entity.Place;
|
||||
import com.example.nto.service.BookingService;
|
||||
import com.example.nto.service.EmployeeService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
/**
|
||||
* TODO: ДОРАБОТАТЬ в рамках задания
|
||||
* =================================
|
||||
* МОЖНО: Добавлять методы, аннотации, зависимости
|
||||
* НЕЛЬЗЯ: Изменять название класса и пакета
|
||||
*/
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/{code}")
|
||||
@RequiredArgsConstructor
|
||||
public class EmployeeController {
|
||||
private final EmployeeService employeeService;
|
||||
|
||||
@GetMapping("/auth")
|
||||
public ResponseEntity<Void> auth(@PathVariable String code) {
|
||||
employeeService.findByCode(code);
|
||||
return ResponseEntity.ok().build();
|
||||
}
|
||||
|
||||
@GetMapping("/info")
|
||||
public ResponseEntity<?> getInfo(@PathVariable String code) {
|
||||
Employee employee = employeeService.findByCode(code);
|
||||
|
||||
// Формирование booking map (дата -> booking details)
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("name", employee.getName());
|
||||
response.put("photoUrl", employee.getPhotoUrl());
|
||||
|
||||
Map<String, Map<String, Object>> bookingMap = new HashMap<>();
|
||||
if (employee.getBookingList() != null) {
|
||||
for (Booking bk : employee.getBookingList()) {
|
||||
Map<String, Object> bookingDetails = new HashMap<>();
|
||||
bookingDetails.put("id", bk.getId());
|
||||
bookingDetails.put("place", bk.getPlaceId()); // можно заменить на placeName, если нужно join
|
||||
bookingMap.put(bk.getDate().toString(), bookingDetails);
|
||||
}
|
||||
}
|
||||
response.put("booking", bookingMap);
|
||||
|
||||
return ResponseEntity.ok(response);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user