Class ApiController

java.lang.Object
edu.ucsb.cs156.gauchoride.controllers.ApiController
Direct Known Subclasses:
ChatMessageController, DriverAvailabilityController, DriversController, RideController, RiderApplicationController, ShiftController, SystemInfoController, UserInfoController, UserProfileController, UsersController

public abstract class ApiController extends Object
Base class for all API controllers. Provides a method to get the current user as well as common methods for error handling.
  • Constructor Details

    • ApiController

      public ApiController()
  • Method Details

    • getCurrentUser

      protected CurrentUser getCurrentUser()
      Get the current user
      Returns:
      the current user
    • genericMessage

      protected Object genericMessage(String message)
      This creates a plain old java object that can be returned as a JSON response
      Returns:
      a Map object with a single key/value pair: "message" => message
    • handleGenericException

      @ExceptionHandler(EntityNotFoundException.class) @ResponseStatus(NOT_FOUND) public Object handleGenericException(Throwable e)
      This catches any EntityNotFoundExceptions and returns a 404 (NOT_FOUND) response
      Returns:
      a Map object that can be returned as a JSON response