Commit ddd46401 authored by Grzegorz Pietrusza's avatar Grzegorz Pietrusza

throw exception when team not found

parent acdbd32a
package com.telephoners.krakyournet.ctf.exceptions;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;
public class TeamNotFoundException extends WebApplicationException
{
public TeamNotFoundException() {
super(Response.status(Response.Status.NOT_FOUND)
.entity("Team not found.").type("text/plain").build());
}
}
......@@ -2,6 +2,7 @@ package com.telephoners.krakyournet.ctf.repositories;
import com.telephoners.krakyournet.ctf.beans.Team;
import com.telephoners.krakyournet.ctf.beans.User;
import com.telephoners.krakyournet.ctf.exceptions.TeamNotFoundException;
import org.mongodb.morphia.Datastore;
import javax.inject.Inject;
......@@ -27,7 +28,8 @@ public class TeamsRepository extends Repository<Team>
{
return datastore.createQuery(Team.class).asList().stream()
.filter(team -> team.getMembers().contains(user))
.findFirst().get();
.findFirst()
.orElseThrow(TeamNotFoundException::new);
}
public Team getTeamByUserName(String username)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment