Class BaseService

java.lang.Object
ch.bztf.m226blb1.Base.BaseService
Direct Known Subclasses:
InstagramService, TwitterService

@Service public abstract class BaseService extends Object
This class is the base class for all other services. It contains all the repositories and the web client.
Category:
Base
API Note:
Responses are of type ResponseHandler
Implementation Note:
This class is not intended to be used directly. The inherited classes need to have the annotation @Service
  • Field Details

    • webClient

      protected final org.springframework.web.reactive.function.client.WebClient webClient
      WebClient for requesting data from the API
      See Also:
      • WebClient
    • accountRepository

      @Autowired protected AccountRepository accountRepository
      AccountRepository for the accounts with the authentication
    • userRepository

      @Autowired protected UserRepository userRepository
      UserRepository for caching the users
    • postRepository

      @Autowired protected PostRepository postRepository
      PostRepository for saving the posts
  • Constructor Details

    • BaseService

      protected BaseService(Platform platform)
      Constructor which sets up all values
      Parameters:
      platform - The platform, for which the service is responsible
    • BaseService

      protected BaseService(Platform platform, @NonNull @NonNull org.springframework.web.reactive.function.client.WebClient webClient)
      Constructor which sets up all values
      Parameters:
      platform - The platform, for which the service is responsible
      webClient - The web client for requesting data
  • Method Details

    • getBaseWebClient

      public static org.springframework.web.reactive.function.client.WebClient.Builder getBaseWebClient()
      Returns the builder for building the web client
      Returns:
      The web client builder
    • getUser

      public ResponseHandler<User> getUser(@NotBlank @Size(min=128,max=128) @NotBlank @Size(min=128,max=128) String apiKey, @NotBlank @NotBlank String username)
      Gets the user stats from username by platform
      Parameters:
      apiKey - API key of the Account which makes the request
      username - Username of the user
      Returns:
      ResponseHandler with the user username or an error
    • getPosts

      public ResponseHandler<Set<Post>> getPosts(@NotBlank @Size(min=128,max=128) @NotBlank @Size(min=128,max=128) String apiKey, @NotBlank @NotBlank String username, @NotBlank @PositiveOrZero @javax.validation.constraints.NotBlank,@javax.validation.constraints.PositiveOrZero int limit)
      Gets the posts from the user username by platform
      Parameters:
      apiKey - API key of the Account which makes the request
      username - Username of the user
      limit - Limit of the posts
      Returns:
      ResponseHandler with the last limit posts from username or an error
    • getJsonData

      public ResponseHandler<String> getJsonData(@NonNull @NonNull String requestUri, @NotBlank @Size(min=128,max=128) @NotBlank @Size(min=128,max=128) String apiKey, @NotBlank @NotBlank String username)
      Gets the user json data from the API
      Parameters:
      requestUri - URI of the request
      apiKey - API key of the Account which makes the request
      username - username of the Instagram user
      Returns:
      ResponseHandler with the json data or an error message
      See Also:
      Implementation Note:
      This method uses the rate limiter to limit the requests.
    • mapJsonToUser

      public abstract User mapJsonToUser(@NotBlank @NotBlank String json)
      Maps the JSON data to a user object
      Parameters:
      json - the JSON data to map
      Returns:
      the created user object
      See Also:
      • ObjectMapper
    • mapJsonToPosts

      public abstract Set<Post> mapJsonToPosts(@NotBlank @NotBlank String json, @PositiveOrZero @javax.validation.constraints.PositiveOrZero int limit)
      Maps the JSON data to a set of posts
      Parameters:
      json - the JSON data to map
      limit - the limit of the posts
      Returns:
      the created set of posts limited by limit
      See Also:
      • ObjectMapper
    • getUserRequestUri

      protected abstract String getUserRequestUri(String username)
      Gets the uri for requesting the user data
      Parameters:
      username - the username of the user
      Returns:
      the uri for requesting the user data
      See Also:
      • User
    • getPostRequestUri

      protected abstract String getPostRequestUri(String username, int limit)
      Gets the uri for requesting the posts data
      Parameters:
      username - the username of the user
      limit - the limit of the posts
      Returns:
      the uri for requesting the posts data
      See Also:
      • User