prepared all services
~0.5h work
This commit is contained in:
parent
2f1700ebed
commit
fad46df96c
@ -0,0 +1,34 @@
|
||||
package at.nanopenguin.mtcg.application.service;
|
||||
|
||||
import at.nanopenguin.mtcg.http.HttpMethod;
|
||||
import at.nanopenguin.mtcg.http.HttpRequest;
|
||||
import at.nanopenguin.mtcg.http.HttpStatus;
|
||||
import at.nanopenguin.mtcg.http.Response;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class CardsService implements Service {
|
||||
|
||||
@Override
|
||||
public Response handleRequest(HttpRequest request) throws JsonProcessingException {
|
||||
try {
|
||||
if (request.getPath().split("/")[1].equals("cards") && request.getMethod() == HttpMethod.GET) {
|
||||
return new Response(HttpStatus.NOT_IMPLEMENTED);
|
||||
}
|
||||
|
||||
if (request.getPath().split("/")[1].equals("deck")) {
|
||||
return switch (request.getMethod()) {
|
||||
case GET -> new Response(HttpStatus.NOT_IMPLEMENTED);
|
||||
case PUT -> new Response(HttpStatus.NOT_IMPLEMENTED); // String[] array = new ObjectMapper().readValue(request.getBody(), String[].class)
|
||||
default -> new Response(HttpStatus.NOT_FOUND);
|
||||
};
|
||||
}
|
||||
|
||||
return new Response(HttpStatus.NOT_FOUND);
|
||||
} catch (ArrayIndexOutOfBoundsException e) {
|
||||
return new Response(HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
}
|
||||
31
src/at/nanopenguin/mtcg/application/service/GameService.java
Normal file
31
src/at/nanopenguin/mtcg/application/service/GameService.java
Normal file
@ -0,0 +1,31 @@
|
||||
package at.nanopenguin.mtcg.application.service;
|
||||
|
||||
import at.nanopenguin.mtcg.http.HttpMethod;
|
||||
import at.nanopenguin.mtcg.http.HttpRequest;
|
||||
import at.nanopenguin.mtcg.http.HttpStatus;
|
||||
import at.nanopenguin.mtcg.http.Response;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
|
||||
public class GameService implements Service {
|
||||
|
||||
@Override
|
||||
public Response handleRequest(HttpRequest request) throws JsonProcessingException {
|
||||
try {
|
||||
if (request.getPath().split("/")[1].equals("stats") && request.getMethod() == HttpMethod.GET) {
|
||||
return new Response(HttpStatus.NOT_IMPLEMENTED);
|
||||
}
|
||||
|
||||
if (request.getPath().split("/")[1].equals("scoreboard") && request.getMethod() == HttpMethod.GET) {
|
||||
return new Response(HttpStatus.NOT_IMPLEMENTED);
|
||||
}
|
||||
|
||||
if (request.getPath().split("/")[1].equals("battles") && request.getMethod() == HttpMethod.POST) {
|
||||
return new Response(HttpStatus.NOT_IMPLEMENTED);
|
||||
}
|
||||
|
||||
return new Response(HttpStatus.NOT_FOUND);
|
||||
} catch (ArrayIndexOutOfBoundsException e) {
|
||||
return new Response(HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,30 @@
|
||||
package at.nanopenguin.mtcg.application.service;
|
||||
|
||||
import at.nanopenguin.mtcg.http.HttpMethod;
|
||||
import at.nanopenguin.mtcg.http.HttpRequest;
|
||||
import at.nanopenguin.mtcg.http.HttpStatus;
|
||||
import at.nanopenguin.mtcg.http.Response;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class PackagesService implements Service {
|
||||
|
||||
@Override
|
||||
public Response handleRequest(HttpRequest request) throws JsonProcessingException {
|
||||
try {
|
||||
if (request.getPath().split("/")[1].equals("packages") && request.getMethod() == HttpMethod.POST) {
|
||||
return new Response(HttpStatus.NOT_IMPLEMENTED); // new ObjectMapper().readValue(request.getBody(), Card.class);
|
||||
}
|
||||
|
||||
if (String.join("/", Arrays.copyOfRange(request.getPath().split("/"), 1, 2)).equals("transactions/packages") && request.getMethod() == HttpMethod.POST) {
|
||||
return new Response(HttpStatus.NOT_IMPLEMENTED);
|
||||
}
|
||||
|
||||
return new Response(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
catch (ArrayIndexOutOfBoundsException e) {
|
||||
return new Response(HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
package at.nanopenguin.mtcg.application.service;
|
||||
|
||||
import at.nanopenguin.mtcg.http.HttpMethod;
|
||||
import at.nanopenguin.mtcg.http.HttpRequest;
|
||||
import at.nanopenguin.mtcg.http.HttpStatus;
|
||||
import at.nanopenguin.mtcg.http.Response;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
|
||||
public class TradingService implements Service {
|
||||
|
||||
@Override
|
||||
public Response handleRequest(HttpRequest request) throws JsonProcessingException {
|
||||
try {
|
||||
if (request.getPath().split("/")[1].equals("tradings")) {
|
||||
return switch (request.getMethod()) {
|
||||
case GET -> new Response(HttpStatus.NOT_IMPLEMENTED);
|
||||
case POST -> new Response(HttpStatus.NOT_IMPLEMENTED); // request.getPath().split("/").length > 2 => path variable
|
||||
case DELETE -> new Response(HttpStatus.NOT_IMPLEMENTED);
|
||||
default -> new Response(HttpStatus.NOT_FOUND);
|
||||
};
|
||||
}
|
||||
|
||||
return new Response(HttpStatus.NOT_FOUND);
|
||||
} catch (ArrayIndexOutOfBoundsException e) {
|
||||
return new Response(HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,7 @@
|
||||
package at.nanopenguin.mtcg.application.service;
|
||||
|
||||
import at.nanopenguin.mtcg.application.service.schemas.UserCredentials;
|
||||
import at.nanopenguin.mtcg.http.HttpMethod;
|
||||
import at.nanopenguin.mtcg.http.HttpRequest;
|
||||
import at.nanopenguin.mtcg.http.HttpStatus;
|
||||
import at.nanopenguin.mtcg.http.Response;
|
||||
@ -14,17 +15,22 @@ public class UserService implements Service {
|
||||
@Override
|
||||
public Response handleRequest(HttpRequest request) throws JsonProcessingException {
|
||||
try {
|
||||
if (request.getPath().split("/")[1].equals("sessions")) {
|
||||
if (request.getPath().split("/")[1].equals("sessions") && request.getMethod() == HttpMethod.POST) {
|
||||
// response = login()
|
||||
return new Response(HttpStatus.NOT_IMPLEMENTED);
|
||||
return new Response(HttpStatus.NOT_IMPLEMENTED); // new ObjectMapper().readValue(request.getBody(), UserCredentials.class);
|
||||
}
|
||||
|
||||
if (request.getPath().split("/")[1].equals("users")) {
|
||||
return switch (request.getMethod()) {
|
||||
case GET -> new Response(HttpStatus.NO_CONTENT);
|
||||
case POST -> new Response(HttpStatus.NOT_IMPLEMENTED);
|
||||
case PUT -> new Response(HttpStatus.NOT_IMPLEMENTED);
|
||||
default -> new Response(HttpStatus.INTERNAL);
|
||||
case GET -> new Response(HttpStatus.NOT_IMPLEMENTED);
|
||||
case POST -> new Response(HttpStatus.NOT_IMPLEMENTED); // new ObjectMapper().readValue(request.getBody(), UserCredentials.class);
|
||||
case PUT -> new Response(HttpStatus.NOT_IMPLEMENTED); // new ObjectMapper().readValue(request.getBody(), UserData.class);
|
||||
default -> new Response(HttpStatus.NOT_FOUND);
|
||||
};
|
||||
}
|
||||
|
||||
return new Response(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
catch (ArrayIndexOutOfBoundsException e) {
|
||||
return new Response(HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user