| 1 | package com.tecmilenio.mapsconect.controller; |
| 2 | |
| 3 | import com.tecmilenio.mapsconect.dto.ApiResponse; |
| 4 | import com.tecmilenio.mapsconect.dto.EmpresaDTO; |
| 5 | import com.tecmilenio.mapsconect.dto.ResenaDTO; |
| 6 | import com.tecmilenio.mapsconect.dto.ResenaRequestDTO; |
| 7 | import com.tecmilenio.mapsconect.service.EmpresarialService; |
| 8 | import jakarta.validation.Valid; |
| 9 | import org.springframework.beans.factory.annotation.Autowired; |
| 10 | import org.springframework.http.HttpStatus; |
| 11 | import org.springframework.http.ResponseEntity; |
| 12 | import org.springframework.security.core.Authentication; |
| 13 | import org.springframework.web.bind.annotation.*; |
| 14 | |
| 15 | import java.util.List; |
| 16 | import java.util.Map; |
| 17 | |
| 18 | @RestController |
| 19 | @RequestMapping("/empresarial") |
| 20 | public class EmpresarialController { |
| 21 | |
| 22 | @Autowired |
| 23 | private EmpresarialService empresarialService; |
| 24 | |
| 25 | // Contrato consumido por frontend/js/pages/empresarial.js: { empresas: [...] } |
| 26 | @GetMapping |
| 27 | public ResponseEntity<Map<String, Object>> listar( |
| 28 | @RequestParam(required = false) String busqueda, |
| 29 | @RequestParam(required = false) Double calificacionMinima) { |
| 30 | List<EmpresaDTO> empresas = empresarialService.listarEmpresas(busqueda, calificacionMinima); |
| 31 | return ResponseEntity.ok(Map.of("empresas", empresas)); |
| 32 | } |
| 33 | |
| 34 | @GetMapping("/{id}/resenas") |
| 35 | public ResponseEntity<ApiResponse<List<ResenaDTO>>> listarResenas(@PathVariable Integer id) { |
| 36 | return ResponseEntity.ok(ApiResponse.success(empresarialService.listarResenasPorEmpresa(id))); |
| 37 | } |
| 38 | |
| 39 | @PostMapping("/resenas") |
| 40 | public ResponseEntity<ApiResponse<ResenaDTO>> crearResena( |
| 41 | Authentication authentication, |
| 42 | @Valid @RequestBody ResenaRequestDTO dto) { |
| 43 | ResenaDTO resena = empresarialService.crearResena(authentication.getName(), dto); |
| 44 | return ResponseEntity.status(HttpStatus.CREATED) |
| 45 | .body(ApiResponse.success(resena, "Reseña publicada correctamente")); |
| 46 | } |
| 47 | |
| 48 | } |
| 49 |