67 lines
1.9 KiB
Go
67 lines
1.9 KiB
Go
|
|
// myMatchScore provides functions to set and retrieve match score point values.
|
|
// Each mate desire has a point value.
|
|
// We add a desire's point value to a peer's match score if they fulfill a user's desires.
|
|
|
|
package myMatchScore
|
|
|
|
import "seekia/internal/myDatastores/myMap"
|
|
import "seekia/internal/helpers"
|
|
|
|
import "errors"
|
|
|
|
var myMatchScorePointsMapDatastore *myMap.MyMap
|
|
|
|
// This function must be called whenever we sign in to an app user
|
|
func InitializeMyMatchScorePointsDatastore()error{
|
|
|
|
newMyMatchScorePointsMapDatastore, err := myMap.CreateNewMap("MyMatchScorePoints")
|
|
if (err != nil) { return err }
|
|
|
|
myMatchScorePointsMapDatastore = newMyMatchScorePointsMapDatastore
|
|
|
|
return nil
|
|
}
|
|
|
|
func SetMyMatchScoreDesirePoints(desireName string, points int)error{
|
|
|
|
if (desireName == ""){
|
|
return errors.New("SetMyMatchScoreDesirePoints called with empty desireName.")
|
|
}
|
|
|
|
if (points < 1 || points > 100) {
|
|
return errors.New("SetMyMatchScoreDesirePoints called with invalid points value.")
|
|
}
|
|
|
|
pointsString := helpers.ConvertIntToString(points)
|
|
|
|
err := myMatchScorePointsMapDatastore.SetMapEntry(desireName, pointsString)
|
|
if (err != nil) { return err }
|
|
|
|
return nil
|
|
}
|
|
|
|
func GetMyMatchScoreDesirePoints(desireName string)(int, error){
|
|
|
|
if (desireName == ""){
|
|
return 0, errors.New("GetMyMatchScoreDesirePoints called with empty desireName.")
|
|
}
|
|
|
|
entryExists, currentPoints, err := myMatchScorePointsMapDatastore.GetMapEntry(desireName)
|
|
if (err != nil) { return 0, err }
|
|
if (entryExists == false){
|
|
return 1, nil
|
|
}
|
|
|
|
currentPointsInt, err := helpers.ConvertStringToInt(currentPoints)
|
|
if (err != nil){
|
|
return 0, errors.New("My current match score desire points is invalid: Not an int: " + currentPoints)
|
|
}
|
|
if (currentPointsInt < 1 || currentPointsInt > 100){
|
|
return 0, errors.New("My current match score desire points is invalid: Out of range: " + currentPoints)
|
|
}
|
|
|
|
return currentPointsInt, nil
|
|
}
|
|
|
|
|