From b184e754ceb78d9c79f419b54afc0b352ef3077f Mon Sep 17 00:00:00 2001
From: Frederico Santos <frederico.f.santos@tecnico.ulisboa.pt>
Date: Wed, 10 Jul 2024 20:32:16 +0100
Subject: [PATCH] chore: Refactor FetchDiscordIdByUsername and
 FetchGoogleIdByUsername to handle null values

---
 db/account.go | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/db/account.go b/db/account.go
index b78eb4c..d463211 100644
--- a/db/account.go
+++ b/db/account.go
@@ -89,23 +89,31 @@ func FetchUsernameByGoogleId(googleId string) (string, error) {
 }
 
 func FetchDiscordIdByUsername(username string) (string, error) {
-	var discordId string
+	var discordId sql.NullString
 	err := handle.QueryRow("SELECT discordId FROM accounts WHERE username = ?", username).Scan(&discordId)
 	if err != nil {
 		return "", err
 	}
 
-	return discordId, nil
+	if !discordId.Valid {
+		return "", nil
+	}
+
+	return discordId.String, nil
 }
 
 func FetchGoogleIdByUsername(username string) (string, error) {
-	var googleId string
+	var googleId sql.NullString
 	err := handle.QueryRow("SELECT googleId FROM accounts WHERE username = ?", username).Scan(&googleId)
 	if err != nil {
 		return "", err
 	}
 
-	return googleId, nil
+	if !googleId.Valid {
+		return "", nil
+	}
+
+	return googleId.String, nil
 }
 
 func FetchUsernameBySessionToken(token []byte) (string, error) {