friends/database/wiiu/get_user_principal_preference.go
Daniel López Guimaraes 8d8a05a7e2
Add missing error handling
Now database getters do error handling aswell, and in case of any error,
the NEX or GRPC method throws a proper error about it.

There are still some doubts on how to handle errors when a list of data
is processed, so for now skip that element on the list and continue.

Also add some constant errors to do better error handling.
2023-08-13 23:19:34 +01:00

25 lines
783 B
Go

package database_wiiu
import (
"database/sql"
"github.com/PretendoNetwork/friends/database"
friends_wiiu_types "github.com/PretendoNetwork/nex-protocols-go/friends-wiiu/types"
)
// GetUserPrincipalPreference returns the user preferences
func GetUserPrincipalPreference(pid uint32) (*friends_wiiu_types.PrincipalPreference, error) {
preference := friends_wiiu_types.NewPrincipalPreference()
err := database.Postgres.QueryRow(`SELECT show_online, show_current_game, block_friend_requests FROM wiiu.user_data WHERE pid=$1`, pid).Scan(&preference.ShowOnlinePresence, &preference.ShowCurrentTitle, &preference.BlockFriendRequests)
if err != nil {
if err == sql.ErrNoRows {
return nil, database.ErrPIDNotFound
} else {
return nil, err
}
}
return preference, nil
}