Formatted code
This commit is contained in:
@@ -24,16 +24,16 @@ public class DataController {
|
||||
|
||||
private final HttpRequest httpRequest;
|
||||
|
||||
public DataController(){
|
||||
public DataController() {
|
||||
httpRequest = new HttpRequest();
|
||||
}
|
||||
|
||||
public boolean login(String username, String password){
|
||||
public boolean login(String username, String password) {
|
||||
try {
|
||||
USER_ID = Long.parseLong(httpRequest.sendPostRequest(
|
||||
LOGIN_ENDPOINT,
|
||||
"login=" + username
|
||||
+ "&password=" + password
|
||||
+ "&password=" + password
|
||||
));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
@@ -42,7 +42,7 @@ public class DataController {
|
||||
return USER_ID >= 0;
|
||||
}
|
||||
|
||||
public void createEvent(Event event){
|
||||
public void createEvent(Event event) {
|
||||
try {
|
||||
System.out.println(httpRequest.sendPostRequest(ADD_EVENT_ENDPOINT, event.getAsUrlParam()));
|
||||
} catch (Exception e) {
|
||||
@@ -50,7 +50,7 @@ public class DataController {
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteEvent(int eventId){
|
||||
public void deleteEvent(int eventId) {
|
||||
try {
|
||||
System.out.println(httpRequest.sendPostRequest(DELETE_EVENT_ENDPOINT, "eventId=" + eventId));
|
||||
} catch (Exception e) {
|
||||
@@ -68,10 +68,10 @@ public class DataController {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
//String json = "{ \"color\" : \"Black\", \"type\" : \"BMW\" }";
|
||||
|
||||
for (Object obj : objectMapper.readValue(jsonResponse, Object[].class)){
|
||||
for (Object obj : objectMapper.readValue(jsonResponse, Object[].class)) {
|
||||
ArrayList<Object> list = new ArrayList<>();
|
||||
if (obj.getClass().isArray()) {
|
||||
list = (ArrayList<Object>) Arrays.asList((Object[])obj);
|
||||
list = (ArrayList<Object>) Arrays.asList((Object[]) obj);
|
||||
} else if (obj instanceof Collection) {
|
||||
list = new ArrayList<>((Collection<?>) obj);
|
||||
}
|
||||
|
@@ -66,20 +66,21 @@ public class Event {
|
||||
String end,
|
||||
LocalDateTime date,
|
||||
int ownerId
|
||||
) throws IllegalArgumentException{
|
||||
if(name.length() < 3){
|
||||
) throws IllegalArgumentException {
|
||||
if (name.length() < 3) {
|
||||
throw new IllegalArgumentException("Der Name muss eine L\u00e4nge von 3 haben.");
|
||||
}
|
||||
Pattern pattern = Pattern.compile("[A-Za-zÄÖÜäöü0-9 =!?+*/$%€.:,;_<>()-]*");
|
||||
Matcher matcher = pattern.matcher(name);
|
||||
if(!matcher.matches()){
|
||||
throw new IllegalArgumentException("Der Name Darf nur aus Zahlen, Buchstaben und folgenden Sonderzeichen bestehen: =!?+*/$%€.:,;_ <>()-");
|
||||
if (!matcher.matches()) {
|
||||
throw new IllegalArgumentException("Der Name Darf nur aus Zahlen, Buchstaben und " +
|
||||
"folgenden Sonderzeichen bestehen: =!?+*/$%€.:,;_ <>()-");
|
||||
}
|
||||
if(priority < 0){
|
||||
if (priority < 0) {
|
||||
throw new IllegalArgumentException("Bitte eine Priorit\u00e4t w\u00e4hlen.");
|
||||
}
|
||||
LocalDateTime today = LocalDateTime.now().toLocalDate().atStartOfDay();
|
||||
if(Duration.between(today, date).isNegative()){
|
||||
if (Duration.between(today, date).isNegative()) {
|
||||
throw new IllegalArgumentException("Das Datum muss in der Zukunft liegen.");
|
||||
}
|
||||
|
||||
|
@@ -9,7 +9,7 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class HttpRequest {
|
||||
public String sendPostRequest(String urlString, String urlParameters) throws Exception{
|
||||
public String sendPostRequest(String urlString, String urlParameters) throws Exception {
|
||||
byte[] postData = urlParameters.getBytes(StandardCharsets.UTF_8);
|
||||
int postDataLength = postData.length;
|
||||
|
||||
@@ -46,7 +46,7 @@ public class HttpRequest {
|
||||
}
|
||||
}
|
||||
|
||||
public String sendGetRequest(String urlString) throws Exception{
|
||||
public String sendGetRequest(String urlString) throws Exception {
|
||||
URL url = new URL(urlString);
|
||||
HttpURLConnection con = (HttpURLConnection) url.openConnection();
|
||||
con.setRequestMethod("GET");
|
||||
|
Reference in New Issue
Block a user