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

Update: Use PrincipalIds between canisters #22

Merged
4 commits merged into from
Apr 10, 2020
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
12 changes: 6 additions & 6 deletions src/connectd/digraph.mo
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ module {

public class Digraph() {

var vertexList : [Vertex] = [];
var edgeList : [(Vertex, Vertex)] = [];
var vertexList: [Vertex] = [];
var edgeList: [(Vertex, Vertex)] = [];

public func addVertex(vertex : Vertex) {
public func addVertex(vertex: Vertex) {
vertexList := Array.append<Vertex>(vertexList, [vertex]);
};

public func addEdge(fromVertex : Vertex, toVertex : Vertex) {
public func addEdge(fromVertex: Vertex, toVertex: Vertex) {
edgeList := Array.append<(Vertex, Vertex)>(edgeList, [(fromVertex, toVertex)]);
};

public func getAdjacent(vertex : Vertex) : [Vertex] {
var adjacencyList : [Vertex] = [];
public func getAdjacent(vertex: Vertex): [Vertex] {
var adjacencyList: [Vertex] = [];
for ((fromVertex, toVertex) in Iter.fromArray<(Vertex, Vertex)>(edgeList)) {
if (fromVertex == vertex) {
adjacencyList := Array.append<Vertex>(adjacencyList, [toVertex]);
Expand Down
8 changes: 4 additions & 4 deletions src/connectd/main.mo
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import Types "./types";
type Vertex = Types.Vertex;

actor Connectd {
var graph : Digraph.Digraph = Digraph.Digraph();
var graph: Digraph.Digraph = Digraph.Digraph();

public func healthcheck() : async Bool { true };
public func healthcheck(): async Bool { true };

public func connect(userA : Vertex, userB : Vertex) : async () {
public func connect(userA: Vertex, userB: Vertex): async () {
graph.addEdge(userA, userB);
};

public func getConnections(user : Vertex) : async [Vertex] {
public func getConnections(user: Vertex): async [Vertex] {
graph.getAdjacent(user)
};

Expand Down
4 changes: 2 additions & 2 deletions src/connectd/types.mo
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Hash "mo:stdlib/hash";
import Principal "mo:stdlib/principalId";

module {
public type Vertex = Nat32;
public type Vertex = Principal;
};
225 changes: 15 additions & 210 deletions src/linkedup/database.mo

Large diffs are not rendered by default.

54 changes: 22 additions & 32 deletions src/linkedup/main.mo
Original file line number Diff line number Diff line change
@@ -1,69 +1,59 @@
// Make the Connectd app's public methods available locally
import Connectd "canister:connectd";

import Database "./database";
import Types "./types";
import Utils "./utils";

type NewProfile = Types.NewProfile;
type Profile = Types.Profile;
type PrincipalId = Types.PrincipalId;
type UserId = Types.UserId;

actor LinkedUp {
var directory : Database.Directory = Database.Directory();
directory.seed();
var directory: Database.Directory = Database.Directory();

// Healthcheck

public func healthcheck () : async Bool { true };
public func healthcheck(): async Bool { true };

// Profiles

public shared(msg) func create (profile : NewProfile) : async PrincipalId {
let newUserId = Utils.getUserId(msg.caller);
directory.createOne(newUserId, profile);
newUserId
public shared(msg) func create(profile: NewProfile): async () {
directory.createOne(msg.caller, profile);
};

public shared(msg) func update (profile : Profile) : async () {
if (Utils.hasAccess(Utils.getUserId(msg.caller), profile)) {
public shared(msg) func update(profile: Profile): async () {
if(Utils.hasAccess(msg.caller, profile)) {
directory.updateOne(profile.id, profile);
};
};

public shared query(msg) func getOwn () : async Profile {
Utils.getProfile(directory, Utils.getUserId(msg.caller))
};

public query func get (userId : PrincipalId) : async Profile {
public query func get(userId: UserId): async Profile {
Utils.getProfile(directory, userId)
};

public query func search (term : Text) : async [Profile] {
public query func search(term: Text): async [Profile] {
directory.findBy(term)
};

// Connections

public shared(msg) func connect (userId : PrincipalId) : async () {
let callerId : PrincipalId = Utils.getUserId(msg.caller);
public shared(msg) func connect(userId: UserId): async () {
// Call Connectd's public methods without an API
await Connectd.connect(Utils.toEntryId(callerId), Utils.toEntryId(userId));
await Connectd.connect(msg.caller, userId);
};

public shared(msg) func getOwnConnections () : async [Profile] {
let callerId : PrincipalId = Utils.getUserId(msg.caller);
let entryIds = await Connectd.getConnections(Utils.toEntryId(callerId));
Utils.getConnectionProfiles(directory, entryIds)
public func getConnections(userId: UserId): async [Profile] {
let userIds = await Connectd.getConnections(userId);
directory.findMany(userIds)
};

public func getConnections (userId : PrincipalId) : async [Profile] {
let entryIds = await Connectd.getConnections(Utils.toEntryId(userId));
Utils.getConnectionProfiles(directory, entryIds)
public shared(msg) func isConnected(userId: UserId): async Bool {
let userIds = await Connectd.getConnections(msg.caller);
Utils.includes(userId, userIds)
};

public shared(msg) func isConnected (userId : PrincipalId) : async Bool {
let callerId : PrincipalId = Utils.getUserId(msg.caller);
let entryIds = await Connectd.getConnections(Utils.toEntryId(callerId));
Utils.includes(Utils.toEntryId(userId), entryIds)
};
// User Auth

public shared query(msg) func getOwnId(): async UserId { msg.caller }

};
Loading