-
-
Save karol-lotkowski/4963f52a418b0a7c35eb to your computer and use it in GitHub Desktop.
Dropwizard resource class which return clean code rule.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.karollotkowski.cleancode.resources; | |
import com.codahale.metrics.annotation.Timed; | |
import com.karollotkowski.cleancode.core.Rule; | |
import com.karollotkowski.cleancode.repositories.RulesRepository; | |
import javax.ws.rs.GET; | |
import javax.ws.rs.Path; | |
import javax.ws.rs.Produces; | |
import javax.ws.rs.core.MediaType; | |
@Path("/rules") | |
@Produces(MediaType.APPLICATION_JSON) | |
public class RulesResource { | |
private final RulesRepository rulesRepository; | |
private final Rule notDefinedRule; | |
public RulesResource(final RulesRepository rulesRepository) { | |
this.rulesRepository = rulesRepository; | |
this.notDefinedRule = new Rule("No title", "No description"); | |
} | |
@GET | |
@Timed | |
public Rule presentRandomRule() { | |
return rulesRepository.random().orElse(notDefinedRule); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment