Skip to content
This repository has been archived by the owner on Mar 17, 2021. It is now read-only.

Commit

Permalink
Added apiee
Browse files Browse the repository at this point in the history
Signed-off-by:Phillip Kruger <phillip.kruger@gmail.com>
  • Loading branch information
phillip-kruger committed Sep 26, 2019
1 parent 6a93247 commit 239c05c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
9 changes: 8 additions & 1 deletion jello-cards/pom.xml
Expand Up @@ -67,7 +67,14 @@
<version>3.12.2</version>
<scope>runtime</scope>
</dependency>


<!-- Apiee -->
<dependency>
<groupId>com.github.phillip-kruger</groupId>
<artifactId>apiee-core</artifactId>
<version>1.0.8</version>
</dependency>

<!-- Testing -->
<dependency>
<groupId>org.jboss.arquillian.testng</groupId>
Expand Down
@@ -1,5 +1,8 @@
package com.github.phillipkruger.jello.api;

import io.swagger.annotations.Contact;
import io.swagger.annotations.Info;
import io.swagger.annotations.SwaggerDefinition;
import javax.annotation.security.DeclareRoles;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
Expand All @@ -10,6 +13,17 @@
* @author Phillip Kruger (phillip.kruger@redhat.com)
*/
@ApplicationPath("/api")
@SwaggerDefinition (info = @Info (
title = "Jello Service",
description = "A simple REST API for Jello",
version = "1.0.0",
contact = @Contact (
name = "Phillip Kruger",
email = "apiee@phillip-kruger.com",
url = "http://phillip-kruger.com"
)
)
)
@DeclareRoles({ "user", "admin" })
public class ApplicationConfig extends Application {

Expand Down
Expand Up @@ -2,6 +2,8 @@

import com.github.phillipkruger.jello.Card;
import com.github.phillipkruger.jello.service.CardService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.net.URI;
import java.util.List;
import javax.inject.Inject;
Expand All @@ -27,6 +29,7 @@
@Path("/card")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@Api(value = "Card service")
@Log
public class CardRestApi {

Expand All @@ -37,12 +40,14 @@ public class CardRestApi {
private UriInfo uriInfo;

@POST
@ApiOperation(value = "Create a new Card", notes = "Create a card using json")
public Response createCard(Card card){
card = cardService.createCard(card);
return Response.created(getGetUri(card)).build();
}

@PUT
@ApiOperation(value = "Update a new Card", notes = "Update a card using json")
public Response updateCard(Card card){
if(card.getId()==null)return createCard(card);
card = cardService.updateCard(card);
Expand All @@ -51,6 +56,7 @@ public Response updateCard(Card card){

@GET
@Path("/{id}")
@ApiOperation(value = "Get a Card", notes = "Get a card using an Id", response = Card.class)
public Response getCard(@PathParam("id") Long id){
Card card = cardService.getCard(id);
if(card==null)return Response.noContent().build();
Expand All @@ -59,13 +65,15 @@ public Response getCard(@PathParam("id") Long id){

@DELETE
@Path("/{id}")
@ApiOperation(value = "Delete a Card", notes = "Delete a card with an Id")
public Response removeCard(@PathParam("id") Long id){
Card card = cardService.getCard(id);
if(card!=null)cardService.removeCard(card);
return Response.noContent().build();
}

@GET
@ApiOperation(value = "Get all cards", notes = "Get all cards in json")
public Response getCards(){
List<Card> cards = cardService.getAllCards();
if(cards==null || cards.isEmpty())return Response.noContent().build();
Expand Down

0 comments on commit 239c05c

Please sign in to comment.