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

small fix for public statuses #148

Merged
merged 1 commit into from
Oct 21, 2024
Merged
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 @@ -14,6 +14,7 @@
import edu.sjsu.moth.server.service.AccountService;
import edu.sjsu.moth.server.service.ActorService;
import edu.sjsu.moth.server.service.StatusService;
import edu.sjsu.moth.server.util.MothConfiguration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
Expand All @@ -29,6 +30,7 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@RestController
Expand Down Expand Up @@ -169,17 +171,37 @@ public Mono<String> usersInbox(@PathVariable String id, @RequestBody JsonNode in
@GetMapping("/users/{id}/following")
public Mono<UsersFollowResponse> usersFollowing(
@PathVariable String id,
@RequestParam(required = false) Integer page, @RequestParam(required = false) Integer limit) {
@RequestParam(required = false, defaultValue = "1") Integer page,
@RequestParam(required = false, defaultValue = "10") Integer limit) {
return accountService.usersFollow(id, page, limit, "following");
}

@GetMapping("/users/{id}/followers")
public Mono<UsersFollowResponse> usersFollowers(
@PathVariable String id,
@RequestParam(required = false) Integer page, @RequestParam(required = false) Integer limit) {
@RequestParam(required = false, defaultValue = "1") Integer page,
@RequestParam(required = false, defaultValue = "10") Integer limit) {
return accountService.usersFollow(id, page, limit, "followers");
}

@GetMapping("/users/{id}/collections/featured")
public Mono<ResponseEntity<OrderedCollection>> getFeaturedCollection(@PathVariable String id) {
String collectionId =
MothConfiguration.mothConfiguration.getServerName() + "/users/" + id + "/collections/featured";
OrderedCollection featuredCollection = new OrderedCollection(collectionId, 0, Collections.emptyList());

return Mono.just(ResponseEntity.ok(featuredCollection));
}

@GetMapping("/users/{id}/collections/tags")
public Mono<ResponseEntity<OrderedCollection>> getTagsCollection(@PathVariable String id) {
String collectionId =
MothConfiguration.mothConfiguration.getServerName() + "/users/" + id + "/collections/tags";
OrderedCollection tagsCollection = new OrderedCollection(collectionId, 0, Collections.emptyList());

return Mono.just(ResponseEntity.ok(tagsCollection));
}

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({ "@context", "id", "type", "totalItems", "first", "next", "partOf", "orderedItems" })
public record UsersFollowResponse(String id, String type, int totalItems, String first, String next, String partOf,
Expand All @@ -189,4 +211,13 @@ public String getContext() {
return "https://www.w3.org/ns/activitystreams";
}
}

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({ "@context", "id", "type", "totalItems", "orderedItems" })
public record OrderedCollection(@JsonProperty("@context") String context, String id, String type, int totalItems,
List<Object> orderedItems) {
public OrderedCollection(String id, int totalItems, List<Object> orderedItems) {
this("https://www.w3.org/ns/activitystreams", id, "OrderedCollection", totalItems, orderedItems);
}
}
}
Loading