From a793faa306858e27b6654c41ecfa843552e8c2fe Mon Sep 17 00:00:00 2001 From: Stanley Jones Date: Thu, 6 Feb 2020 13:42:59 -0800 Subject: [PATCH] Fix: PR comments, update to dfx-0.5.0 --- dfx.json | 3 +-- src/graph/database.mo | 19 +++++++++---------- src/graph/main.mo | 4 ++-- src/graph/types.mo | 2 +- src/profile/database.mo | 20 ++++++++++---------- src/profile/main.mo | 30 +++++++++++++++--------------- src/profile/types.mo | 2 +- src/profile/utils.mo | 14 +++++++------- 8 files changed, 46 insertions(+), 48 deletions(-) diff --git a/dfx.json b/dfx.json index d808517..c44b091 100644 --- a/dfx.json +++ b/dfx.json @@ -22,6 +22,5 @@ "address": "127.0.0.1", "port": 8000 } - }, - "dfx": "0.4.12" + } } diff --git a/src/graph/database.mo b/src/graph/database.mo index 2a4abb7..489fd51 100644 --- a/src/graph/database.mo +++ b/src/graph/database.mo @@ -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; @@ -19,7 +18,7 @@ module { func hashEntryId (x : EntryId) : Hash.Hash { Nat.toWord32(Nat.fromNat32(x)) }; let hashMap = HashMap.HashMap(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; diff --git a/src/graph/main.mo b/src/graph/main.mo index 43930bd..155b861 100644 --- a/src/graph/main.mo +++ b/src/graph/main.mo @@ -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; diff --git a/src/graph/types.mo b/src/graph/types.mo index 173c1fa..f8261f2 100644 --- a/src/graph/types.mo +++ b/src/graph/types.mo @@ -1,4 +1,4 @@ -import Hash "mo:stdlib/hash.mo"; +import Hash "mo:stdlib/hash"; module { public type EntryId = Nat32; diff --git a/src/profile/database.mo b/src/profile/database.mo index 3e71496..8b85715 100644 --- a/src/profile/database.mo +++ b/src/profile/database.mo @@ -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; @@ -17,11 +17,11 @@ module { let hashMap : HashMap.HashMap = 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); }; @@ -82,7 +82,7 @@ module { false }; - public func seed () : () { + public func seed () { if (seeded) { return; }; let realPeople : [[Text]] = [ diff --git a/src/profile/main.mo b/src/profile/main.mo index 9ad9b9a..f3aefb0 100644 --- a/src/profile/main.mo +++ b/src/profile/main.mo @@ -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; @@ -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 { @@ -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) }; @@ -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) }; diff --git a/src/profile/types.mo b/src/profile/types.mo index fd49bb6..d37d89e 100644 --- a/src/profile/types.mo +++ b/src/profile/types.mo @@ -1,4 +1,4 @@ -import Hash "mo:stdlib/hash.mo"; +import Hash "mo:stdlib/hash"; module { public type PrincipalId = Hash.Hash; diff --git a/src/profile/utils.mo b/src/profile/utils.mo index 29c882b..ec3f794 100644 --- a/src/profile/utils.mo +++ b/src/profile/utils.mo @@ -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; @@ -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 };