diff --git a/README.md b/README.md index 886f120..9286bfd 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,12 @@ You can override this value by specifying a `PIGEON_PATH` ENV var. |Done?|Verb |Noun | Flag / arg 1 | Flag 2 | |-----|------------|--------|---------------|-----------| + | |follow |peer | user mhash | | + | |show |peers | | | + | |show |peers | --blocked | | | |block |peer | user mhash | | + | |unblock |peer | user mhash | | + | |unfollow |peer | | | | |create |blob | file path | | | |create |blob | pipe | | | |create |bundle | | | @@ -28,15 +33,10 @@ You can override this value by specifying a `PIGEON_PATH` ENV var. | |find |blob | | | | |find |message | --all | | | |find |message | --last | | - | |follow |peer | user mhash | | | |ingest |bundle | | | | |publish |draft | | | | |show |draft | | | | |show |message | message mhash | | - | |show |peers | | | - | |show |peers | --blocked | | - | |unblock |peer | user mhash | | - | |unfollow |peer | | | | |update |draft | --key=? | --value=? | | X |show |identity| | | | X |create |identity| | | diff --git a/coverage.sh b/coverage.sh old mode 100644 new mode 100755 diff --git a/project/peers.go b/project/peers.go new file mode 100644 index 0000000..299bf6d --- /dev/null +++ b/project/peers.go @@ -0,0 +1,36 @@ +package main + +import ( + "database/sql" + "log" +) + +type peerStatus string + +const ( + following peerStatus = "following" + blocked = "blocked" + unknown = "unknown" +) + +func getPeerStatus(mHash string) peerStatus { + sqlStatement := `SELECT status FROM users WHERE mhash=$1;` + var status peerStatus + row := Database.QueryRow(sqlStatement, mHash) + switch err := row.Scan(&status); err { + case sql.ErrNoRows: + return "unknown" + case nil: + return status + default: + log.Fatalf("getPeerStatus failure: %s", err) + panic(err) + } +} + +// func followPeer() {} +// func showPeers() {} +// func showBlockedPeers() {} +// func blockPeer() {} +// func unblockPeer() {} +// func unfollowPeer() {} diff --git a/project/peers_test.go b/project/peers_test.go new file mode 100644 index 0000000..63da678 --- /dev/null +++ b/project/peers_test.go @@ -0,0 +1,16 @@ +package main + +import ( + "testing" +) + +// TEST CASE: Attempting to getPeerStatus() of peer that +// does not exist. +func TestGetPeerStatus(t *testing.T) { + resetDB() + mHash := "USER.RJFSFK8YZ8XGTGKQDMSQCQPQXKH8GPRCDY86YZCFQ1QRKYEF48MG" + status := getPeerStatus(mHash) + if status != peerStatus("unknown") { + t.Fatalf("Expected `unknown`, got %s", status) + } +}