Skip to content
This repository was archived by the owner on Feb 1, 2025. It is now read-only.

Commit 57b4cfa

Browse files
committed
Removed body from GET requests
1 parent f91292c commit 57b4cfa

File tree

4 files changed

+27
-58
lines changed

4 files changed

+27
-58
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ plugins {
44
}
55

66
group = "diruptio"
7-
version = "2.0.2"
7+
version = "2.0.3"
88

99
repositories {
1010
mavenCentral()

src/main/java/diruptio/dynamite/endpoint/ProjectEndpoint.java

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import static diruptio.dynamite.util.JsonUtil.*;
44

5-
import com.google.gson.JsonSyntaxException;
65
import diruptio.dynamite.Dynamite;
76
import diruptio.dynamite.Project;
87
import diruptio.spikedog.Endpoint;
@@ -11,12 +10,10 @@
1110
import io.netty.handler.codec.http.HttpHeaderNames;
1211
import io.netty.handler.codec.http.HttpHeaderValues;
1312
import io.netty.handler.codec.http.HttpResponseStatus;
14-
import java.util.Objects;
1513
import java.util.Optional;
1614
import java.util.Set;
1715
import java.util.function.Predicate;
1816
import org.jetbrains.annotations.NotNull;
19-
import org.jetbrains.annotations.Nullable;
2017

2118
public class ProjectEndpoint {
2219
@Endpoint(
@@ -25,20 +22,17 @@ public class ProjectEndpoint {
2522
public void handle(final @NotNull HttpRequest request, final @NotNull HttpResponse response) {
2623
response.header(HttpHeaderNames.CONTENT_TYPE, HttpHeaderValues.APPLICATION_JSON);
2724

28-
ProjectRequest projectRequest;
29-
try {
30-
projectRequest = Objects.requireNonNull(GSON.fromJson(request.contentAsString(), ProjectRequest.class));
31-
} catch (JsonSyntaxException | NullPointerException e) {
25+
// Get the project name
26+
String projectName = request.parameter("project");
27+
if (projectName == null) {
3228
response.status(HttpResponseStatus.BAD_REQUEST);
33-
response.content(
34-
jsonError(
35-
"Please check json structure: {\"project\": string, \"filter\": {\"tags\": string[] | null} | null}"));
29+
response.content(jsonError("Parameter \"project\" is missing"));
3630
return;
3731
}
3832

3933
// Check if the project exists
4034
Optional<Project> project = Dynamite.getProjects().stream()
41-
.filter(project2 -> project2.name().equals(projectRequest.project))
35+
.filter(project2 -> project2.name().equals(projectName))
4236
.findFirst();
4337
if (project.isEmpty()) {
4438
response.status(HttpResponseStatus.NOT_FOUND);
@@ -48,22 +42,16 @@ public void handle(final @NotNull HttpRequest request, final @NotNull HttpRespon
4842

4943
// Create filter
5044
Predicate<Project.Version> filter = version -> true;
51-
if (projectRequest.filter != null) {
52-
if (projectRequest.filter.tags != null) {
53-
filter = filter.and(version -> version.tags().containsAll(projectRequest.filter.tags));
54-
}
45+
46+
// Get the project name
47+
String tagsParam = request.parameter("tags");
48+
if (tagsParam != null) {
49+
Set<String> tags = Set.of(tagsParam.split(";"));
50+
filter = filter.and(version -> version.tags().containsAll(tags));
5551
}
5652

5753
// Success
5854
response.status(HttpResponseStatus.OK);
5955
response.content(GSON.toJson(project.get().filterVersions(filter)));
6056
}
61-
62-
private record ProjectRequestFilter(@Nullable Set<String> tags) {}
63-
64-
private record ProjectRequest(@NotNull String project, @Nullable ProjectRequestFilter filter) {
65-
ProjectRequest {
66-
Objects.requireNonNull(project);
67-
}
68-
}
6957
}

src/main/java/diruptio/dynamite/endpoint/project/ProjectCreateEndpoint.java

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import static diruptio.dynamite.util.JsonUtil.*;
44

5-
import com.google.gson.JsonSyntaxException;
65
import diruptio.dynamite.Dynamite;
76
import diruptio.dynamite.Project;
87
import diruptio.spikedog.Endpoint;
@@ -12,9 +11,7 @@
1211
import io.netty.handler.codec.http.HttpHeaderValues;
1312
import io.netty.handler.codec.http.HttpResponseStatus;
1413
import java.util.ArrayList;
15-
import java.util.Objects;
1614
import org.jetbrains.annotations.NotNull;
17-
import org.jetbrains.annotations.Nullable;
1815

1916
public class ProjectCreateEndpoint {
2017
@Endpoint(
@@ -27,36 +24,29 @@ public void handle(@NotNull HttpRequest request, @NotNull HttpResponse response)
2724

2825
response.header(HttpHeaderNames.CONTENT_TYPE, HttpHeaderValues.APPLICATION_JSON);
2926

30-
ProjectCreateRequest createRequest;
31-
try {
32-
createRequest =
33-
Objects.requireNonNull(GSON.fromJson(request.contentAsString(), ProjectCreateRequest.class));
34-
} catch (JsonSyntaxException | NullPointerException e) {
27+
// Get the project name
28+
String projectName = request.parameter("name");
29+
if (projectName == null) {
3530
response.status(HttpResponseStatus.BAD_REQUEST);
36-
response.content(jsonError("Please check json structure: {\"name\": string, \"gitUrl\": string | null}"));
31+
response.content(jsonError("Parameter \"name\" is missing"));
3732
return;
3833
}
3934

4035
// Check if the project already exists
41-
if (Dynamite.getProjects().stream().anyMatch(project2 -> project2.name().equals(createRequest.name))) {
36+
if (Dynamite.getProjects().stream().anyMatch(project2 -> project2.name().equals(projectName))) {
4237
response.status(HttpResponseStatus.BAD_REQUEST);
4338
response.content(jsonError("Project already exists"));
4439
return;
4540
}
4641

47-
Dynamite.getProjects()
48-
.add(new Project(
49-
createRequest.name, System.currentTimeMillis(), createRequest.gitUrl, new ArrayList<>()));
42+
// Get the git url
43+
String gitUrl = request.parameter("git_url");
44+
45+
Dynamite.getProjects().add(new Project(projectName, System.currentTimeMillis(), gitUrl, new ArrayList<>()));
5046
Dynamite.save();
51-
Dynamite.getLogger().info("Created project %s (Git: %s)".formatted(createRequest.name, createRequest.gitUrl));
47+
Dynamite.getLogger().info("Created project %s (Git: %s)".formatted(projectName, gitUrl));
5248

5349
// Success
5450
response.status(HttpResponseStatus.CREATED);
5551
}
56-
57-
private record ProjectCreateRequest(@NotNull String name, @Nullable String gitUrl) {
58-
ProjectCreateRequest {
59-
Objects.requireNonNull(name);
60-
}
61-
}
6252
}

src/main/java/diruptio/dynamite/endpoint/project/ProjectTagsEndpoint.java

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import static diruptio.dynamite.util.JsonUtil.*;
44

5-
import com.google.gson.JsonSyntaxException;
65
import diruptio.dynamite.Dynamite;
76
import diruptio.dynamite.Project;
87
import diruptio.spikedog.Endpoint;
@@ -12,7 +11,6 @@
1211
import io.netty.handler.codec.http.HttpHeaderValues;
1312
import io.netty.handler.codec.http.HttpResponseStatus;
1413
import java.util.HashSet;
15-
import java.util.Objects;
1614
import java.util.Optional;
1715
import java.util.Set;
1816
import org.jetbrains.annotations.NotNull;
@@ -24,18 +22,17 @@ public class ProjectTagsEndpoint {
2422
public void handle(@NotNull HttpRequest request, @NotNull HttpResponse response) {
2523
response.header(HttpHeaderNames.CONTENT_TYPE, HttpHeaderValues.APPLICATION_JSON);
2624

27-
ProjectTagsRequest tagsRequest;
28-
try {
29-
tagsRequest = Objects.requireNonNull(GSON.fromJson(request.contentAsString(), ProjectTagsRequest.class));
30-
} catch (JsonSyntaxException | NullPointerException e) {
25+
// Get the project name
26+
String projectName = request.parameter("project");
27+
if (projectName == null) {
3128
response.status(HttpResponseStatus.BAD_REQUEST);
32-
response.content(jsonError("Please check json structure: {\"project\": string}"));
29+
response.content(jsonError("Parameter \"project\" is missing"));
3330
return;
3431
}
3532

3633
// Check if the project exists
3734
Optional<Project> project = Dynamite.getProjects().stream()
38-
.filter(project2 -> project2.name().equals(tagsRequest.project))
35+
.filter(project2 -> project2.name().equals(projectName))
3936
.findFirst();
4037
if (project.isEmpty()) {
4138
response.status(HttpResponseStatus.NOT_FOUND);
@@ -49,10 +46,4 @@ public void handle(@NotNull HttpRequest request, @NotNull HttpResponse response)
4946
response.status(HttpResponseStatus.OK);
5047
response.content(GSON.toJson(tags));
5148
}
52-
53-
private record ProjectTagsRequest(@NotNull String project) {
54-
ProjectTagsRequest {
55-
Objects.requireNonNull(project);
56-
}
57-
}
5849
}

0 commit comments

Comments
 (0)