Skip to content

Commit

Permalink
Fix: PR comments, update to dfx-0.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Stanley Jones committed Feb 6, 2020
1 parent 81371eb commit a793faa
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 48 deletions.
3 changes: 1 addition & 2 deletions dfx.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,5 @@
"address": "127.0.0.1",
"port": 8000
}
},
"dfx": "0.4.12"
}
}
19 changes: 9 additions & 10 deletions src/graph/database.mo
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import Array "mo:stdlib/array.mo";
import Blob "mo:stdlib/blob.mo";
import HashMap "mo:stdlib/hashMap.mo";
import Hash "mo:stdlib/hash.mo";
import Iter "mo:stdlib/iter.mo";
import List "mo:stdlib/list.mo";
import Nat "mo:stdlib/nat.mo";
import Option "mo:stdlib/option.mo";
import Array "mo:stdlib/array";
import HashMap "mo:stdlib/hashMap";
import Hash "mo:stdlib/hash";
import Iter "mo:stdlib/iter";
import List "mo:stdlib/list";
import Nat "mo:stdlib/nat";
import Option "mo:stdlib/option";

import Types "./types.mo";
import Types "./types";

module {
type Entry = Types.Entry;
Expand All @@ -19,7 +18,7 @@ module {
func hashEntryId (x : EntryId) : Hash.Hash { Nat.toWord32(Nat.fromNat32(x)) };
let hashMap = HashMap.HashMap<EntryId, Entry>(1, natEq, hashEntryId);

public func addConnection (fromUser : EntryId, toUser : EntryId) : () {
public func addConnection (fromUser : EntryId, toUser : EntryId) {
let entry = getEntry(fromUser);
let updated : Entry = {
id = entry.id;
Expand Down
4 changes: 2 additions & 2 deletions src/graph/main.mo
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Database "./database.mo";
import Types "./types.mo";
import Database "./database";
import Types "./types";

type Entry = Types.Entry;
type EntryId = Types.EntryId;
Expand Down
2 changes: 1 addition & 1 deletion src/graph/types.mo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Hash "mo:stdlib/hash.mo";
import Hash "mo:stdlib/hash";

module {
public type EntryId = Nat32;
Expand Down
20 changes: 10 additions & 10 deletions src/profile/database.mo
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import Array "mo:stdlib/array.mo";
import HashMap "mo:stdlib/hashMap.mo";
import Hash "mo:stdlib/hash.mo";
import Iter "mo:stdlib/iter.mo";
import Nat "mo:stdlib/nat.mo";
import Option "mo:stdlib/option.mo";
import Array "mo:stdlib/array";
import HashMap "mo:stdlib/hashMap";
import Hash "mo:stdlib/hash";
import Iter "mo:stdlib/iter";
import Nat "mo:stdlib/nat";
import Option "mo:stdlib/option";

import Types "./types.mo";
import Types "./types";

module {
type NewProfile = Types.NewProfile;
Expand All @@ -17,11 +17,11 @@ module {
let hashMap : HashMap.HashMap<PrincipalId, Profile> = init();
var seeded = false;

public func createOne (userId : PrincipalId, _profile : NewProfile) : () {
public func createOne (userId : PrincipalId, _profile : NewProfile) {
ignore hashMap.set(userId, makeProfile(userId, _profile));
};

public func updateOne (userId : PrincipalId, profile : Profile) : () {
public func updateOne (userId : PrincipalId, profile : Profile) {
ignore hashMap.set(userId, profile);
};

Expand Down Expand Up @@ -82,7 +82,7 @@ module {
false
};

public func seed () : () {
public func seed () {
if (seeded) { return; };

let realPeople : [[Text]] = [
Expand Down
30 changes: 15 additions & 15 deletions src/profile/main.mo
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Make the Graph app's public methods available locally
import Graph "canister:graph";

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

type NewProfile = Types.NewProfile;
type Profile = Types.Profile;
Expand All @@ -17,20 +17,20 @@ actor Profile {

// Profiles

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

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

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

public query func get (userId : PrincipalId) : async Profile {
Expand All @@ -43,14 +43,14 @@ actor Profile {

// Connections

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

public shared { caller } func getOwnConnections () : async [Profile] {
let callerId : PrincipalId = Utils.getUserId(caller);
public shared(msg) func getOwnConnections () : async [Profile] {
let callerId : PrincipalId = Utils.getUserId(msg.caller);
let entryIds = await Graph.getConnections(Utils.toEntryId(callerId));
Utils.getConnectionProfiles(directory, entryIds)
};
Expand All @@ -60,8 +60,8 @@ actor Profile {
Utils.getConnectionProfiles(directory, entryIds)
};

public shared { caller } func isConnected (userId : PrincipalId) : async Bool {
let callerId : PrincipalId = Utils.getUserId(caller);
public shared(msg) func isConnected (userId : PrincipalId) : async Bool {
let callerId : PrincipalId = Utils.getUserId(msg.caller);
let entryIds = await Graph.getConnections(Utils.toEntryId(callerId));
Utils.includes(Utils.toEntryId(userId), entryIds)
};
Expand Down
2 changes: 1 addition & 1 deletion src/profile/types.mo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Hash "mo:stdlib/hash.mo";
import Hash "mo:stdlib/hash";

module {
public type PrincipalId = Hash.Hash;
Expand Down
14 changes: 7 additions & 7 deletions src/profile/utils.mo
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import Array "mo:stdlib/array.mo";
import Blob "mo:stdlib/blob.mo";
import Nat "mo:stdlib/nat.mo";
import Option "mo:stdlib/option.mo";
import Array "mo:stdlib/array";
import Principal "mo:stdlib/principalId";
import Nat "mo:stdlib/nat";
import Option "mo:stdlib/option";

import Database "./database.mo";
import Types "./types.mo";
import Database "./database";
import Types "./types";

module {
type NewProfile = Types.NewProfile;
Expand Down Expand Up @@ -53,7 +53,7 @@ module {

let adminIds : [PrincipalId] = [];

public func getUserId (caller : Blob) : PrincipalId { Blob.hash(caller) };
public func getUserId (caller : Principal) : PrincipalId { Principal.hash(caller) };

public func isAdmin (userId : PrincipalId) : Bool {
func identity (x : PrincipalId) : Bool { x == userId };
Expand Down

0 comments on commit a793faa

Please sign in to comment.