Skip to content

Instantly share code, notes, and snippets.

@karol-lotkowski
Created October 18, 2015 21:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karol-lotkowski/4963f52a418b0a7c35eb to your computer and use it in GitHub Desktop.
Save karol-lotkowski/4963f52a418b0a7c35eb to your computer and use it in GitHub Desktop.
Dropwizard resource class which return clean code rule.
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