From 715f5d6382f0d9a7f4b0672a8ec7d78d1a14099d Mon Sep 17 00:00:00 2001 From: Nishanth Uchil Date: Wed, 17 Apr 2024 19:47:07 -0700 Subject: [PATCH 1/2] fixed /relationship requestParam to resolve error response --- .../RequestObjectMethodArgumentResolver.java | 8 ++++++++ .../server/controller/AccountController.java | 18 ++++++++++++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/server/src/main/java/edu/sjsu/moth/server/annotations/RequestObjectMethodArgumentResolver.java b/server/src/main/java/edu/sjsu/moth/server/annotations/RequestObjectMethodArgumentResolver.java index 7fc4cc42..7c7a935e 100644 --- a/server/src/main/java/edu/sjsu/moth/server/annotations/RequestObjectMethodArgumentResolver.java +++ b/server/src/main/java/edu/sjsu/moth/server/annotations/RequestObjectMethodArgumentResolver.java @@ -8,6 +8,7 @@ import org.springframework.core.ReactiveAdapterRegistry; import org.springframework.core.ResolvableType; import org.springframework.core.io.buffer.DataBufferUtils; +import org.springframework.http.HttpMethod; import org.springframework.http.MediaType; import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; import org.springframework.stereotype.Component; @@ -69,6 +70,13 @@ public boolean supportsParameter(MethodParameter parameter) { } var root = new ObjectNode(JsonNodeFactory.instance); parseParams(exchange.getRequest().getQueryParams(), root); + if (exchange.getRequest().getMethod().equals(HttpMethod.GET)) { + try { + return Mono.just(reader.readValue(root)); + } catch (IOException e) { + return Mono.error(e); + } + } return DataBufferUtils.join(exchange.getRequest().getBody()).flatMap(db -> { var formdata = db.toString(UTF_8); var exps = StringUtils.delimitedListToStringArray(formdata, "&"); diff --git a/server/src/main/java/edu/sjsu/moth/server/controller/AccountController.java b/server/src/main/java/edu/sjsu/moth/server/controller/AccountController.java index 43ac6f65..27389c06 100644 --- a/server/src/main/java/edu/sjsu/moth/server/controller/AccountController.java +++ b/server/src/main/java/edu/sjsu/moth/server/controller/AccountController.java @@ -3,6 +3,7 @@ import edu.sjsu.moth.generated.CredentialAccount; import edu.sjsu.moth.generated.Relationship; import edu.sjsu.moth.generated.Source; +import edu.sjsu.moth.server.annotations.RequestObject; import edu.sjsu.moth.server.db.Account; import edu.sjsu.moth.server.db.AccountField; import edu.sjsu.moth.server.service.AccountService; @@ -25,6 +26,7 @@ import java.security.Principal; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.regex.Pattern; @@ -126,11 +128,10 @@ public Mono> verifyCredentials(Principal user, } @GetMapping("/api/v1/accounts/relationships") - public ResponseEntity> getApiV1AccountsRelationships(Principal user, String[] id, - @RequestParam(required = false, - defaultValue = "false") boolean with_suspended) { + public ResponseEntity> getApiV1AccountsRelationships(Principal user, + @RequestObject RelationshipRequest req) { var relationships = new ArrayList(); - for (var i : id) { + for (var i : req.id) { relationships.add( new Relationship(i, false, false, false, false, false, false, false, false, false, false, false, false, "")); @@ -160,4 +161,13 @@ public Mono> getBlocks(Integer max_id, Integer since_id, Inte return Mono.just(new ArrayList()); } + private static class RelationshipRequest { + public String[] id; + public Boolean with_suspended; + + public String toString() { + return ("id=" + Arrays.toString(id) + ", with_suspended: " + with_suspended); + } + } + } From 32b54d6418535e1e5bb5513b7e0a2054da59b04a Mon Sep 17 00:00:00 2001 From: Nishanth Uchil Date: Wed, 17 Apr 2024 19:52:18 -0700 Subject: [PATCH 2/2] removed debugging toString --- .../edu/sjsu/moth/server/controller/AccountController.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/server/src/main/java/edu/sjsu/moth/server/controller/AccountController.java b/server/src/main/java/edu/sjsu/moth/server/controller/AccountController.java index 27389c06..496322ff 100644 --- a/server/src/main/java/edu/sjsu/moth/server/controller/AccountController.java +++ b/server/src/main/java/edu/sjsu/moth/server/controller/AccountController.java @@ -164,10 +164,6 @@ public Mono> getBlocks(Integer max_id, Integer since_id, Inte private static class RelationshipRequest { public String[] id; public Boolean with_suspended; - - public String toString() { - return ("id=" + Arrays.toString(id) + ", with_suspended: " + with_suspended); - } } }