I’ve
public type Posts = {
author : Text;
title : Text;
content : Text;
category : Text;
categoryId : Nat;
likes : Nat;
published : Bool;
};
var map1 = HashMap.HashMap<Principal, List.List<Posts>>(1, Principal.equal, Principal.hash);
var map2 = HashMap.HashMap<categoryId, List.List<Principal>>(1, Nat.equal, Hash.hash);
public shared (msg) func fetchPosts(categoryId : Nat) : async [Posts] {
var users : List.List<Principal> = switch (map2.get(categoryId)) {
case null List.nil<Principal>();
case (?result) result;
};
for (x in Iter.fromList(users)) {
};
}
If user selects a category i want to get all the posts unique to that category by using categoryId
I want to filter the posts by likes in descending specific to the category how can i do it?