-
Notifications
You must be signed in to change notification settings - Fork 0
10 fix/microservicio clases #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
c59e8f4
1db19f1
9639cdc
e0db3e2
5b58c8f
5d7f115
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| package com.classes.controllers; | ||
|
|
||
| import com.classes.dtos.Class.ClassRequest; | ||
| import com.classes.dtos.Class.ClassResponse; | ||
| import com.classes.services.ClassService; | ||
| import org.springframework.security.access.prepost.PreAuthorize; | ||
| import org.springframework.web.bind.annotation.PostMapping; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.http.HttpStatus; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.*; | ||
|
|
||
| import java.util.List; | ||
| import java.util.UUID; | ||
|
|
||
| @RestController | ||
| @RequestMapping("/api/classes") | ||
| @RequiredArgsConstructor | ||
| public class ClassController { | ||
|
|
||
| private final ClassService classService; | ||
|
|
||
|
|
||
|
|
||
| @PostMapping | ||
| @PreAuthorize("@authorizationServiceImpl.canAccessResource(#id, authentication)") | ||
| public ResponseEntity<ClassResponse> createClass(@RequestBody ClassRequest request) { | ||
| ClassResponse created = classService.createClass(request); | ||
| return ResponseEntity.status(HttpStatus.CREATED).body(created); | ||
| } | ||
|
|
||
| @GetMapping | ||
| @PreAuthorize("@authorizationServiceImpl.canAccessResource(#id, authentication)") | ||
| public ResponseEntity<List<ClassResponse>> findAllClasses() { | ||
| List<ClassResponse> list = classService.findAll(); | ||
| return ResponseEntity.ok(list); | ||
| } | ||
|
RogerCll06 marked this conversation as resolved.
|
||
|
|
||
|
|
||
| @PutMapping("/{id}") | ||
| @PreAuthorize("@authorizationServiceImpl.canAccessResource(#id, authentication)") | ||
| public ResponseEntity<ClassResponse> updateClass(@PathVariable UUID id, @RequestBody ClassRequest request) { | ||
| ClassResponse updated = classService.updateClass(id, request); | ||
| return ResponseEntity.ok(updated); | ||
| } | ||
|
|
||
| @DeleteMapping("/{id}") | ||
| @PreAuthorize("@authorizationServiceImpl.canAccessResource(#id, authentication)") | ||
| public ResponseEntity<String> deleteClass(@PathVariable UUID id) { | ||
| classService.deleteClass(id); | ||
| return ResponseEntity.ok("Clase eliminada correctamente"); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,15 @@ | ||
| package com.classes.controllers; | ||
|
|
||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| @RestController | ||
| @RequestMapping("/saludo") | ||
| @RequestMapping("/test") | ||
| public class HelloController { | ||
| public String saludo() { | ||
| return "Microservicio de clases activo"; | ||
| @GetMapping("saludo") | ||
| public ResponseEntity<String> saludo() { | ||
| return ResponseEntity.ok("Microservicio de clases activo"); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,16 @@ | ||
| package com.classes.controllers; | ||
|
|
||
| import com.classes.annotations.AdminOrTrainerAccess; | ||
| import com.classes.dtos.LocationDTO; | ||
| import com.classes.entities.LocationEntity; | ||
| import com.classes.dtos.Location.LocationRequest; | ||
| import com.classes.dtos.Location.LocationResponse; | ||
| import com.classes.services.LocationService; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.data.domain.Page; | ||
| import org.springframework.http.HttpStatus; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.security.access.prepost.PreAuthorize; | ||
| import org.springframework.web.bind.annotation.*; | ||
|
|
||
| import java.util.List; | ||
| import java.util.UUID; | ||
|
|
||
| @RestController | ||
|
|
@@ -21,29 +21,45 @@ public class LocationController { | |
|
|
||
| private final LocationService locationService; | ||
|
|
||
| @PreAuthorize("@authorizationServiceImpl.canAccessResource(#id,authentication)") | ||
| @PostMapping | ||
| public ResponseEntity<LocationDTO> create(@RequestBody LocationDTO dto) { | ||
| LocationDTO created = locationService.create(dto); | ||
| public ResponseEntity<LocationResponse> create(@RequestBody LocationRequest request) { | ||
| LocationResponse created = locationService.create(request); | ||
| return new ResponseEntity<>(created, HttpStatus.CREATED); | ||
| } | ||
|
|
||
| @PreAuthorize("@authorizationServiceImpl.canAccessResource(#id,authentication)") | ||
| @GetMapping | ||
| public ResponseEntity<Page<LocationDTO>> findAll( | ||
| public ResponseEntity<Page<LocationResponse>> findAll( | ||
| @RequestParam(defaultValue = "0") int page, | ||
| @RequestParam(defaultValue = "10") int size | ||
| @RequestParam(defaultValue = "10") int size, | ||
| @RequestParam(required = false) String search, | ||
| @RequestParam(required = false) Boolean active | ||
| ) { | ||
| Page<LocationDTO> locations = locationService.findAll(page, size); | ||
| Page<LocationResponse> locations = locationService.findAll(page, size, search, active); | ||
| return ResponseEntity.ok(locations); | ||
| } | ||
|
|
||
| @PreAuthorize("@authorizationServiceImpl.canAccessResource(#id,authentication)") | ||
|
Comment on lines
+24
to
+42
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Corregir expresión @PreAuthorize inválida En Line 24 y Line 31 la expresión 🤖 Prompt for AI Agents |
||
| @GetMapping("/{id}") | ||
| public ResponseEntity<LocationEntity> findById(@PathVariable UUID id) { | ||
| return ResponseEntity.ok(locationService.findById(id)); | ||
| public ResponseEntity<LocationResponse> findById(@PathVariable UUID id) { | ||
| LocationResponse location = locationService.findById(id); | ||
| return ResponseEntity.ok(location); | ||
| } | ||
|
|
||
| @PreAuthorize("@authorizationServiceImpl.canAccessResource(#id,authentication)") | ||
| @PutMapping("/{id}") | ||
| public ResponseEntity<LocationResponse> update( | ||
| @PathVariable UUID id, | ||
| @RequestBody LocationRequest request | ||
| ) { | ||
| LocationResponse updated = locationService.update(id, request); | ||
| return ResponseEntity.ok(updated); | ||
| } | ||
|
|
||
| @PreAuthorize("@authorizationServiceImpl.canAccessResource(#id,authentication)") | ||
| @DeleteMapping("/{id}") | ||
| public ResponseEntity<Void> delete(@PathVariable UUID id) { | ||
| locationService.delete(id); | ||
| locationService.delete(id); // Validación interna | ||
| return ResponseEntity.noContent().build(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| package com.classes.dtos.Class; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonFormat; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Data; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| import java.time.LocalDate; | ||
| import java.time.LocalTime; | ||
| import java.util.UUID; | ||
|
|
||
| @Data | ||
| @AllArgsConstructor | ||
| @NoArgsConstructor | ||
| public class ClassRequest { | ||
| private String className; | ||
| private UUID locationId; | ||
| private UUID trainerId; | ||
| @JsonFormat(pattern = "dd-MM-yyyy") | ||
| private LocalDate classDate; | ||
| private int duration; | ||
| private int maxCapacity; | ||
| private LocalTime startTime; | ||
| private LocalTime endTime; | ||
| private boolean active; | ||
| private String description; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package com.classes.dtos.Class; | ||
|
|
||
|
|
||
| import com.fasterxml.jackson.annotation.JsonFormat; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Data; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| import java.time.LocalDate; | ||
| import java.time.LocalTime; | ||
| import java.util.UUID; | ||
|
|
||
| @Data | ||
| @AllArgsConstructor | ||
| @NoArgsConstructor | ||
| public class ClassResponse { | ||
| private UUID id; | ||
| private String className; | ||
| private String locationName; | ||
| private String trainerName; | ||
| @JsonFormat(pattern = "dd-MM-yyyy") | ||
| private LocalDate classDate; | ||
| private int duration; | ||
| private int maxCapacity; | ||
| private String schedule; | ||
| private boolean active; | ||
| private String description; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package com.classes.dtos.Location; | ||
|
|
||
| import lombok.Data; | ||
|
|
||
| import java.util.UUID; | ||
|
|
||
| @Data | ||
| public class LocationResponse { | ||
| private UUID id; // si tienes un ID generado | ||
| private String name; | ||
| private String description; | ||
| private int ability; | ||
| private boolean active; | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.