| 1 | package com.tecmilenio.mapsconect.controller; |
| 2 | |
| 3 | import com.tecmilenio.mapsconect.dto.ApiResponse; |
| 4 | import com.tecmilenio.mapsconect.dto.MateriaDTO; |
| 5 | import com.tecmilenio.mapsconect.service.MateriaService; |
| 6 | import org.springframework.beans.factory.annotation.Autowired; |
| 7 | import org.springframework.http.ResponseEntity; |
| 8 | import org.springframework.web.bind.annotation.*; |
| 9 | |
| 10 | import java.util.List; |
| 11 | |
| 12 | @RestController |
| 13 | @RequestMapping("/materias") |
| 14 | public class MateriaController { |
| 15 | |
| 16 | @Autowired |
| 17 | private MateriaService materiaService; |
| 18 | |
| 19 | @GetMapping |
| 20 | public ResponseEntity<ApiResponse<List<MateriaDTO>>> listar( |
| 21 | @RequestParam(required = false) String tipo) { |
| 22 | List<MateriaDTO> materias = materiaService.listar(tipo); |
| 23 | return ResponseEntity.ok(ApiResponse.success(materias)); |
| 24 | } |
| 25 | |
| 26 | @GetMapping("/{id}") |
| 27 | public ResponseEntity<ApiResponse<MateriaDTO>> obtenerPorId(@PathVariable Integer id) { |
| 28 | MateriaDTO materia = materiaService.obtenerPorId(id); |
| 29 | return ResponseEntity.ok(ApiResponse.success(materia)); |
| 30 | } |
| 31 | |
| 32 | } |
| 33 |