Skip to content

Commit

Permalink
Fix: whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
Stanley Jones committed Feb 6, 2020
1 parent a793faa commit 999dff8
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 33 deletions.
12 changes: 6 additions & 6 deletions src/graph/database.mo
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ module {
type Entry = Types.Entry;
type EntryId = Types.EntryId;

public class Entries () {
public class Entries() {

func natEq (x : Nat32, y : Nat32) : Bool { x == y };
func hashEntryId (x : EntryId) : Hash.Hash { Nat.toWord32(Nat.fromNat32(x)) };
func natEq(x : Nat32, y : Nat32) : Bool { x == y };
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 All @@ -28,15 +28,15 @@ module {
ignore hashMap.set(fromUser, updated);
};

func getEntry (entryId : EntryId) : Entry {
func getEntry(entryId : EntryId) : Entry {
let existing = hashMap.get(entryId);
switch (existing) {
case (?existing) { existing };
case (null) { { id = entryId; connections = []; invitations = []; } };
};
};

public func getConnections (userId : EntryId) : [EntryId] {
public func getConnections(userId : EntryId) : [EntryId] {
let entry = getEntry(userId);
entry.connections
};
Expand Down
6 changes: 3 additions & 3 deletions src/graph/main.mo
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ type EntryId = Types.EntryId;
actor Graph {
var entries : Database.Entries = Database.Entries();

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

// Connections

// "public" makes this method available as Graph.connect
public func connect (caller : Nat32, userId : Nat32) : async () {
public func connect(caller : Nat32, userId : Nat32) : async () {
entries.addConnection(caller, userId);
};

public func getConnections (userId : EntryId) : async [EntryId] {
public func getConnections(userId : EntryId) : async [EntryId] {
entries.getConnections(userId)
};

Expand Down
28 changes: 14 additions & 14 deletions src/profile/database.mo
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,31 @@ module {
type Profile = Types.Profile;
type PrincipalId = Types.PrincipalId;

public class Directory () {
public class Directory() {
// The "database" is just a local hash map
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);
};

public func findOne (userId : PrincipalId) : ?Profile {
public func findOne(userId : PrincipalId) : ?Profile {
hashMap.get(userId)
};

public func findMany (userIds : [PrincipalId]) : [Profile] {
func getProfile (userId : PrincipalId) : Profile {
public func findMany(userIds : [PrincipalId]) : [Profile] {
func getProfile(userId : PrincipalId) : Profile {
Option.unwrap<Profile>(hashMap.get(userId))
};
Array.map<PrincipalId, Profile>(getProfile, userIds)
};

public func findBy (term : Text) : [Profile] {
public func findBy(term : Text) : [Profile] {
var profiles : [Profile] = [];
for ((id, profile) in hashMap.iter()) {
let fullName = profile.firstName # " " # profile.lastName;
Expand All @@ -62,7 +62,7 @@ module {
}
};

func includesText (string : Text, term : Text) : Bool {
func includesText(string : Text, term : Text) : Bool {
let stringArray = Iter.toArray<Char>(string.chars());
let termArray = Iter.toArray<Char>(term.chars());

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

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

let realPeople : [[Text]] = [
Expand Down Expand Up @@ -116,7 +116,7 @@ module {
[
"Barack",
"Obama",
"President (Retired)",
"President(Retired)",
"United States of America",
"**President**, USA \nJan 2009 – Jan 2017 \nWashington, DC",
"**Harvard University** \nJD, Law",
Expand Down Expand Up @@ -245,7 +245,7 @@ module {
seeded := true;
};

func realProfile (row : [Text], index : Nat) : Profile {
func realProfile(row : [Text], index : Nat) : Profile {
{
id = Nat.toWord32(1000 + index);
firstName = row[0];
Expand All @@ -258,7 +258,7 @@ module {
}
};

func mockProfile (row : [Text], index : Nat) : Profile {
func mockProfile(row : [Text], index : Nat) : Profile {
{
id = Nat.toWord32(2000 + index);
firstName = row[0];
Expand All @@ -272,8 +272,8 @@ module {
};
};

func init () : HashMap.HashMap<PrincipalId, Profile> {
func passthrough (hash : PrincipalId) : PrincipalId { hash };
func init() : HashMap.HashMap<PrincipalId, Profile> {
func passthrough(hash : PrincipalId) : PrincipalId { hash };
HashMap.HashMap<PrincipalId, Profile>(1, Hash.Hash.hashEq, passthrough)
};
};
20 changes: 10 additions & 10 deletions src/profile/utils.mo
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module {
type PrincipalId = Types.PrincipalId;

// Profiles
public func getProfile (directory : Database.Directory, userId : PrincipalId) : Profile {
public func getProfile(directory : Database.Directory, userId : PrincipalId) : Profile {
let existing = directory.findOne(userId);
switch (existing) {
case (?existing) { existing };
Expand All @@ -33,16 +33,16 @@ module {

// Connections

public func getConnectionProfiles (directory : Database.Directory, entryIds : [Nat32]) : [Profile] {
public func getConnectionProfiles(directory : Database.Directory, entryIds : [Nat32]) : [Profile] {
let profileIds = Array.map<Nat32, PrincipalId>(fromEntryId, entryIds);
directory.findMany(profileIds)
};

public func toEntryId (userId : PrincipalId) : Nat32 { Nat.toNat32(Nat.fromWord32(userId)) };
public func fromEntryId (entryId : Nat32) : PrincipalId { Nat.toWord32(Nat.fromNat32(entryId)) };
public func toEntryId(userId : PrincipalId) : Nat32 { Nat.toNat32(Nat.fromWord32(userId)) };
public func fromEntryId(entryId : Nat32) : PrincipalId { Nat.toWord32(Nat.fromNat32(entryId)) };

public func includes (x : Nat32, xs : [Nat32]) : Bool {
func isX (y : Nat32) : Bool { x == y };
public func includes(x : Nat32, xs : [Nat32]) : Bool {
func isX(y : Nat32) : Bool { x == y };
switch (Array.find<Nat32>(isX, xs)) {
case (null) { false };
case (_) { true };
Expand All @@ -53,14 +53,14 @@ module {

let adminIds : [PrincipalId] = [];

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

public func isAdmin (userId : PrincipalId) : Bool {
func identity (x : PrincipalId) : Bool { x == userId };
public func isAdmin(userId : PrincipalId) : Bool {
func identity(x : PrincipalId) : Bool { x == userId };
Option.isSome<PrincipalId>(Array.find<PrincipalId>(identity, adminIds))
};

public func hasAccess (userId : PrincipalId, profile : Profile) : Bool {
public func hasAccess(userId : PrincipalId, profile : Profile) : Bool {
userId == profile.id or isAdmin(userId)
};
};

0 comments on commit 999dff8

Please sign in to comment.