Class RoleController

java.lang.Object
com.needleandstitch.pavuk.controller.RoleController

@Controller @RequestMapping("/roles") public class RoleController extends Object
REST controller for managing Role objects.

This class provides endpoints for handling role-related operations such as retrieving roles, creating new roles, updating existing roles, and deleting roles.

Endpoints:

  • GET /roles Retrieve all roles
  • GET /roles/{id} Retrieve a role by its ID
  • GET /roles/name/{name} Retrieve a role by its name
  • POST /roles Create a new role
  • PUT /roles/{id} Update an existing role
  • DELETE /roles/{id} Delete a role
Since:
15.12.2024
Version:
1.0.0
Author:
Needle & Stitch
  • Constructor Details

    • RoleController

      public RoleController()
  • Method Details

    • getAllRoles

      @GetMapping public org.springframework.http.ResponseEntity<List<Role>> getAllRoles()
      Retrieves all roles.
      Returns:
      A ResponseEntity with a 200 OK status, a list of all roles
    • getRoleById

      @GetMapping("/{id}") public org.springframework.http.ResponseEntity<Role> getRoleById(@PathVariable Long id)
      Retrieves a role by its ID.
      Parameters:
      id - The ID of the role to retrieve
      Returns:
      A ResponseEntity with a 200 OK status with a role if successful, or a 404 Not Found status if not.
    • getRoleByName

      @GetMapping("/name/{name}") public org.springframework.http.ResponseEntity<Role> getRoleByName(@PathVariable String name)
      Retrieves a role by its name.
      Parameters:
      name - The name of the role to retrieve
      Returns:
      A ResponseEntity with a 200 OK status with a role if successful, or a 404 Not Found status if not.
    • createRole

      @PostMapping public org.springframework.http.ResponseEntity<Role> createRole(@RequestBody Role role)
      Creates a new role.
      Parameters:
      role - The role to create
      Returns:
      A ResponseEntity with a status of 201 (CREATED).
    • updateRole

      @PutMapping("/{id}") public org.springframework.http.ResponseEntity<Role> updateRole(@PathVariable Long id, @RequestBody Role role)
      Updates an existing role's name.
      Parameters:
      id - The ID of the role to update
      role - The updated role object
      Returns:
      A ResponseEntity with a 200 OK status if successful, or a 404 Not Found status if not.
    • deleteRole

      @DeleteMapping("/{id}") public org.springframework.http.ResponseEntity<Void> deleteRole(@PathVariable Long id)
      Deletes a role by its ID.
      Parameters:
      id - the ID of the role to delete
      Returns:
      A ResponseEntity with a 204 No Content status if successful, or a 404 Not Found status if not.