Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed /relationship requestParam to resolve error response #138

Merged
merged 2 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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, "&");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -126,11 +128,10 @@ public Mono<ResponseEntity<CredentialAccount>> verifyCredentials(Principal user,
}

@GetMapping("/api/v1/accounts/relationships")
public ResponseEntity<List<Relationship>> getApiV1AccountsRelationships(Principal user, String[] id,
@RequestParam(required = false,
defaultValue = "false") boolean with_suspended) {
public ResponseEntity<List<Relationship>> getApiV1AccountsRelationships(Principal user,
@RequestObject RelationshipRequest req) {
var relationships = new ArrayList<Relationship>();
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, ""));
Expand Down Expand Up @@ -160,4 +161,9 @@ public Mono<ArrayList<Account>> getBlocks(Integer max_id, Integer since_id, Inte
return Mono.just(new ArrayList<Account>());
}

private static class RelationshipRequest {
public String[] id;
public Boolean with_suspended;
}

}
Loading