Skip to content
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

Feature/aso rest controller #30

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .DS_Store
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
import com.urjc.asociationPlatform.model.User;
import com.urjc.asociationPlatform.service.AsociationService;
import com.urjc.asociationPlatform.service.UserService;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.PathVariable;
Expand Down Expand Up @@ -47,6 +54,14 @@ private User getUser(HttpServletRequest request) {
return null;
}


@Operation(summary = "Get personal Association")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Association obtained sucessfully",content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = Asociation.class))}),
@ApiResponse(responseCode = "404", description = "comment not found", content = @Content)

})
@GetMapping("/miAsociacion")
public ResponseEntity<Asociation> getMyAsso(HttpServletRequest request) {
User currentUser = checkAdminOrAsso("ASO", request);
Expand All @@ -61,6 +76,13 @@ public ResponseEntity<Asociation> getMyAsso(HttpServletRequest request) {
return new ResponseEntity<>(asso.get(), HttpStatus.OK);
}

@Operation(summary = "Get Association by id")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Association obtained sucessfully",content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = Asociation.class))}),
@ApiResponse(responseCode = "404", description = "Association not found", content = @Content)

})
@GetMapping("/{id}")
public ResponseEntity<Asociation> getById(@PathVariable long id) {
Optional<Asociation> asso = assoService.findById(id);
Expand All @@ -70,21 +92,53 @@ public ResponseEntity<Asociation> getById(@PathVariable long id) {
return new ResponseEntity<>(asso.get(), HttpStatus.OK);
}

@Operation(summary = "Get Association list")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Association list obtained sucessfully",content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = Asociation.class))})

})
@GetMapping("/asociationsList")
public ResponseEntity<List<Asociation>> ListAsso() {
return new ResponseEntity<>(assoService.findAll(), HttpStatus.OK);
}

@Operation(summary = "Edit personal association")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Association edited sucessfully",content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = Asociation.class))}),
@ApiResponse(responseCode = "401", description = "current user doesn´t have the required permissions", content = @Content),
@ApiResponse(responseCode = "403", description = "these changes can´t be made", content = @Content),
@ApiResponse(responseCode = "404", description = "Asociation not found", content = @Content)

})
@PutMapping("/miAsociacion")
public ResponseEntity<Asociation> editMyAsso(@RequestBody Asociation asso, HttpServletRequest request) {
return edditAssoAux("ASO", request, asso, null);
}

@Operation(summary = "Edit association")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Association edited sucessfully",content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = Asociation.class))}),
@ApiResponse(responseCode = "401", description = "current user doesn´t have the required permissions", content = @Content),
@ApiResponse(responseCode = "403", description = "these changes can´t be made", content = @Content),
@ApiResponse(responseCode = "404", description = "Asociation not found", content = @Content)

})
@PutMapping("/{id}")
public ResponseEntity<Asociation> editAsso(@RequestBody Asociation asso,@PathVariable long id, HttpServletRequest request) {
return edditAssoAux("ADMIN", request, asso, id);
}

@Operation(summary = "Delete Association")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Association deleted sucessfully",content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = Asociation.class))}),
@ApiResponse(responseCode = "401", description = "current user doesn´t have the required permissions", content = @Content),
@ApiResponse(responseCode = "404", description = "Association not found", content = @Content)

})
@DeleteMapping("/{id}")
public ResponseEntity<Asociation> deleteAsso(@PathVariable long id, HttpServletRequest request) {
if (checkAdminOrAsso("ADMIN", request) == null)
Expand Down