-
Notifications
You must be signed in to change notification settings - Fork 8
/
get_object_ratings_with_slot_by_data_id_with_password.go
56 lines (42 loc) · 1.57 KB
/
get_object_ratings_with_slot_by_data_id_with_password.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package datastore_db
import (
"database/sql"
"github.com/PretendoNetwork/nex-go"
datastore_types "github.com/PretendoNetwork/nex-protocols-go/datastore/types"
"github.com/PretendoNetwork/super-mario-maker-secure/database"
"github.com/PretendoNetwork/super-mario-maker-secure/globals"
)
func GetObjectRatingsWithSlotByDataIDWithPassword(dataID uint64, password uint64) ([]*datastore_types.DataStoreRatingInfoWithSlot, uint32) {
errCode := IsObjectAvailableWithPassword(dataID, password)
if errCode != 0 {
return nil, errCode
}
ratings := make([]*datastore_types.DataStoreRatingInfoWithSlot, 0)
rows, err := database.Postgres.Query(`SELECT slot, total_value, count, initial_value FROM datastore.object_ratings WHERE data_id=$1`, dataID)
if err != nil {
if err == sql.ErrNoRows {
return nil, nex.Errors.DataStore.NotFound
}
globals.Logger.Error(err.Error())
// TODO - Send more specific errors?
return nil, nex.Errors.DataStore.Unknown
}
defer rows.Close()
for rows.Next() {
rating := datastore_types.NewDataStoreRatingInfoWithSlot()
rating.Rating = datastore_types.NewDataStoreRatingInfo()
err := rows.Scan(&rating.Slot, &rating.Rating.TotalValue, &rating.Rating.Count, &rating.Rating.InitialValue)
if err != nil {
globals.Logger.Error(err.Error())
// TODO - Send more specific errors?
return nil, nex.Errors.DataStore.Unknown
}
ratings = append(ratings, rating)
}
if err := rows.Err(); err != nil {
globals.Logger.Error(err.Error())
// TODO - Send more specific errors?
return nil, nex.Errors.DataStore.Unknown
}
return ratings, 0
}