|
|
@ -10,9 +10,10 @@ import jakarta.ws.rs.Path;
|
|
|
|
import jakarta.ws.rs.PathParam;
|
|
|
|
import jakarta.ws.rs.PathParam;
|
|
|
|
import jakarta.ws.rs.Produces;
|
|
|
|
import jakarta.ws.rs.Produces;
|
|
|
|
import jakarta.ws.rs.core.MediaType;
|
|
|
|
import jakarta.ws.rs.core.MediaType;
|
|
|
|
|
|
|
|
import jakarta.ws.rs.core.Response;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.time.LocalDate;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Path("/pokemong")
|
|
|
|
@Path("/pokemong")
|
|
|
|
@Produces(MediaType.APPLICATION_JSON)
|
|
|
|
@Produces(MediaType.APPLICATION_JSON)
|
|
|
@ -26,22 +27,36 @@ public class PokemongController extends GenericController<Pokemong> {
|
|
|
|
setService(pokemongService);
|
|
|
|
setService(pokemongService);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* REST endpoint to fetch Pokemong entities by nickname.
|
|
|
|
|
|
|
|
* The match is case-insensitive, ignores leading and trailing spaces, and can be a partial nickname.
|
|
|
|
|
|
|
|
* If the nickname is null or blank, an empty list is returned.
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param nickname the nickname to search for in the database. Can be a partial nickname.
|
|
|
|
|
|
|
|
* @return List of Pokemong entities with a nickname matching the provided nickname. If no match is found, an empty list is returned.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
@GET
|
|
|
|
@GET
|
|
|
|
@Path("/nickname/{nickname}")
|
|
|
|
@Path("/nickname/{nickname}")
|
|
|
|
public List<Pokemong> findByName(@PathParam("nickname") String nickname) {
|
|
|
|
public Response findByName(@PathParam("nickname") String nickname) {
|
|
|
|
return StringUtils.isBlankStringOrNull(nickname)
|
|
|
|
if (StringUtils.isBlankStringOrNull(nickname)) {
|
|
|
|
? new ArrayList<>()
|
|
|
|
return Response.ok(new ArrayList<>())
|
|
|
|
: pokemongService.findByNickname(nickname.trim());
|
|
|
|
.build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return Response.ok(pokemongService.findByNickname(nickname.trim()))
|
|
|
|
|
|
|
|
.build();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@GET
|
|
|
|
|
|
|
|
@Path("/dob/{startDate}/{endDate}")
|
|
|
|
|
|
|
|
public Response findByDateOfBirthInterval(
|
|
|
|
|
|
|
|
@PathParam("startDate") String startDate,
|
|
|
|
|
|
|
|
@PathParam("endDate") String endDate
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
if (StringUtils.isBlankStringOrNull(startDate) || StringUtils.isBlankStringOrNull(endDate)) {
|
|
|
|
|
|
|
|
return Response.ok(new ArrayList<>())
|
|
|
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
return Response
|
|
|
|
|
|
|
|
.ok(pokemongService.findByDateOfBirthInterval(LocalDate.parse(startDate), LocalDate.parse(endDate)))
|
|
|
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
return Response.status(Response.Status.BAD_REQUEST)
|
|
|
|
|
|
|
|
.entity(e.getMessage())
|
|
|
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|