diff --git a/greataped/README.md b/greataped/README.md index 2db95bd..32a6749 100644 --- a/greataped/README.md +++ b/greataped/README.md @@ -17,6 +17,7 @@ 10. [FollowActor](#follow-actor) 11. [AuthorizeInteraction](#authorize-interaction) 12. [GetFollowers](#get-followers) +13. [GetFollowing](#get-following) --- @@ -180,3 +181,18 @@ Result: string first ``` [Back to List](#apis) + +## Get Following +``` +Request: + string username + +Result: + string @context + string id + string type + int32 totalItems + repeated string orderedItems + string first +``` +[Back to List](#apis) diff --git a/greataped/app/commands/spi/get_following.go b/greataped/app/commands/spi/get_following.go new file mode 100644 index 0000000..9c984eb --- /dev/null +++ b/greataped/app/commands/spi/get_following.go @@ -0,0 +1,27 @@ +package spi + +import ( + . "rail.town/infrastructure/components/constants" + . "rail.town/infrastructure/components/contracts" +) + +func GetFollowing(x IDispatcher, username string) (IGetFollowingResult, error) { + identities := x.FilterIdentities(func(identity IIdentity) bool { + return identity.Username() == username + }) + + x.Assert(identities.HasExactlyOneItem()).Or(ERROR_USER_NOT_FOUND) + identity := identities.First() + + actor := x.Format("%s/u/%s", x.PublicUrl(), identity.Username()) + + var orderedItems []string = []string{} + return x.NewGetFollowingResult( + ACTIVITY_STREAMS, // context + x.Format("%s/following", actor), // id + ACTIVITY_PUB_ORDERED_COLLECTION, // type + int32(len(orderedItems)), // totalItems + orderedItems, // orderedItems + "", // first + ), nil +}