-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package telraam.api; | ||
|
||
import telraam.database.daos.BatonDAO; | ||
import telraam.database.models.Baton; | ||
|
||
import javax.ws.rs.*; | ||
import javax.ws.rs.core.MediaType; | ||
import javax.ws.rs.core.Response; | ||
import java.util.Optional; | ||
|
||
@Path("/baton") | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public class BatonResource { | ||
|
||
private BatonDAO batonDAO; | ||
|
||
public BatonResource(BatonDAO batonDAO) { | ||
this.batonDAO = batonDAO; | ||
} | ||
|
||
@GET | ||
public Baton sayHello(@QueryParam("id") Optional<Integer> id) { | ||
if(id.isPresent()){ | ||
Optional<Baton> optionalBaton = batonDAO.findBatonById(id.get()); | ||
if(optionalBaton.isPresent()){ | ||
return optionalBaton.get(); | ||
} else { | ||
throw new WebApplicationException(String.format("Baton with id: %d not found", id.get()), Response.Status.NOT_FOUND); | ||
} | ||
} else { | ||
throw new WebApplicationException("You did not pass an id", Response.Status.BAD_REQUEST); | ||
} | ||
} | ||
|
||
} |