Commit 84df1f3a authored by Julien Schröter's avatar Julien Schröter

Allow unlock_score=null and unlock_win=null outside of title repository

parent 47d7405f
Pipeline #2040 passed with stage
in 11 minutes and 30 seconds
......@@ -128,9 +128,13 @@ func (nT *nullableTitle) ToTitle(title *schemas.TitleSchema) bool {
}
if nT.UnlockScore.Valid {
title.UnlockScore = int32(nT.UnlockScore.Int64)
} else {
title.UnlockScore = -1
}
if nT.UnlockWin.Valid {
title.UnlockWin = int32(nT.UnlockWin.Int64)
} else {
title.UnlockWin = -1
}
return nT.ID.Valid && nT.Name.Valid
}
......
......@@ -66,6 +66,9 @@ func (MySQLFriendQuery) SelectByID(userID uint32) ([]schemas.InfoUserSchema, err
var tmpSubjectDepartment sql.NullString
var tmpSubjectDescription sql.NullString
var tmpUnlockScore sql.NullInt32
var tmpUnlockWin sql.NullInt32
if errFetch := rows.Scan(
&tmpFriend.ID,
&tmpFriend.Username,
......@@ -79,8 +82,8 @@ func (MySQLFriendQuery) SelectByID(userID uint32) ([]schemas.InfoUserSchema, err
&(tmpSubjectShortForm),
&(tmpSubjectDepartment),
&(tmpSubjectDescription),
&tmpFriend.SelectedTitle.UnlockScore,
&tmpFriend.SelectedTitle.UnlockWin,
&tmpUnlockScore,
&tmpUnlockWin,
); errFetch != nil {
return nil, fmt.Errorf("Cannot scan db values into friends list. " + errFetch.Error())
}
......@@ -95,6 +98,18 @@ func (MySQLFriendQuery) SelectByID(userID uint32) ([]schemas.InfoUserSchema, err
}
}
if tmpUnlockScore.Valid {
tmpFriend.SelectedTitle.UnlockScore = tmpUnlockScore.Int32
} else {
tmpFriend.SelectedTitle.UnlockScore = -1
}
if tmpUnlockWin.Valid {
tmpFriend.SelectedTitle.UnlockWin = tmpUnlockWin.Int32
} else {
tmpFriend.SelectedTitle.UnlockWin = -1
}
friends = append(friends, tmpFriend)
}
......@@ -209,6 +224,9 @@ func (MySQLFriendQuery) Insert(userID, userIDToAdd uint32) ([]schemas.InfoUserSc
var tmpSubjectDepartment sql.NullString
var tmpSubjectDescription sql.NullString
var tmpUnlockScore sql.NullInt32
var tmpUnlockWin sql.NullInt32
if errResult := rows.Scan(
&tmpFriend.ID,
&tmpFriend.Username,
......@@ -222,8 +240,8 @@ func (MySQLFriendQuery) Insert(userID, userIDToAdd uint32) ([]schemas.InfoUserSc
&(tmpSubjectShortForm),
&(tmpSubjectDepartment),
&(tmpSubjectDescription),
&tmpFriend.SelectedTitle.UnlockScore,
&tmpFriend.SelectedTitle.UnlockWin,
&tmpUnlockScore,
&tmpUnlockWin,
); errResult != nil {
if tmpSubjectName.Valid {
tmpFriend.SelectedTitle.Subject = &schemas.Subject{
......@@ -235,6 +253,18 @@ func (MySQLFriendQuery) Insert(userID, userIDToAdd uint32) ([]schemas.InfoUserSc
}
}
if tmpUnlockScore.Valid {
tmpFriend.SelectedTitle.UnlockScore = tmpUnlockScore.Int32
} else {
tmpFriend.SelectedTitle.UnlockScore = -1
}
if tmpUnlockWin.Valid {
tmpFriend.SelectedTitle.UnlockWin = tmpUnlockWin.Int32
} else {
tmpFriend.SelectedTitle.UnlockWin = -1
}
return nil, fmt.Errorf("failed to provide updated friends list." + errResult.Error())
}
result = append(result, tmpFriend)
......@@ -309,6 +339,9 @@ func (MySQLFriendQuery) Delete(userID, userIDToRemove uint32) ([]schemas.InfoUse
var tmpSubjectDepartment sql.NullString
var tmpSubjectDescription sql.NullString
var tmpUnlockScore sql.NullInt32
var tmpUnlockWin sql.NullInt32
if errResult := rows.Scan(
&user.ID,
&user.Username,
......@@ -322,8 +355,8 @@ func (MySQLFriendQuery) Delete(userID, userIDToRemove uint32) ([]schemas.InfoUse
&(tmpSubjectShortForm),
&(tmpSubjectDepartment),
&(tmpSubjectDescription),
&user.SelectedTitle.UnlockScore,
&user.SelectedTitle.UnlockWin,
&tmpUnlockScore,
&tmpUnlockWin,
); errResult != nil {
if tmpSubjectName.Valid {
user.SelectedTitle.Subject = &schemas.Subject{
......@@ -335,6 +368,18 @@ func (MySQLFriendQuery) Delete(userID, userIDToRemove uint32) ([]schemas.InfoUse
}
}
if tmpUnlockScore.Valid {
user.SelectedTitle.UnlockScore = tmpUnlockScore.Int32
} else {
user.SelectedTitle.UnlockScore = -1
}
if tmpUnlockWin.Valid {
user.SelectedTitle.UnlockWin = tmpUnlockWin.Int32
} else {
user.SelectedTitle.UnlockWin = -1
}
return nil, fmt.Errorf("failed to provide updated friends list." + errResult.Error())
}
result = append(result, user)
......
......@@ -176,6 +176,9 @@ func (MySQLUserQuery) Select(id uint32) ([]schemas.FullUserSchema, error) {
var tmpSubjectDepartment sql.NullString
var tmpSubjectDescription sql.NullString
var tmpUnlockScore sql.NullInt32
var tmpUnlockWin sql.NullInt32
//make sql query and save response to the user pointer
err = stmt.QueryRow(id).Scan(
&users[0].ID,
......@@ -194,8 +197,8 @@ func (MySQLUserQuery) Select(id uint32) ([]schemas.FullUserSchema, error) {
&(tmpSubjectShortForm),
&(tmpSubjectDepartment),
&(tmpSubjectDescription),
&users[0].SelectedTitle.UnlockScore,
&users[0].SelectedTitle.UnlockWin,
&tmpUnlockScore,
&tmpUnlockWin,
&users[0].Verified,
&users[0].University,
&users[0].Level)
......@@ -217,6 +220,18 @@ func (MySQLUserQuery) Select(id uint32) ([]schemas.FullUserSchema, error) {
}
}
if tmpUnlockScore.Valid {
users[0].SelectedTitle.UnlockScore = tmpUnlockScore.Int32
} else {
users[0].SelectedTitle.UnlockScore = -1
}
if tmpUnlockWin.Valid {
users[0].SelectedTitle.UnlockWin = tmpUnlockWin.Int32
} else {
users[0].SelectedTitle.UnlockWin = -1
}
//return with no errors
return users, nil
}
......@@ -244,6 +259,9 @@ func (MySQLUserQuery) SelectByUsername(username string) ([]schemas.InfoUserSchem
var tmpSubjectDepartment sql.NullString
var tmpSubjectDescription sql.NullString
var tmpUnlockScore sql.NullInt32
var tmpUnlockWin sql.NullInt32
//make sql query and save response to the user pointer
err = stmt.QueryRow(username).Scan(
&user[0].ID,
......@@ -258,8 +276,8 @@ func (MySQLUserQuery) SelectByUsername(username string) ([]schemas.InfoUserSchem
&(tmpSubjectShortForm),
&(tmpSubjectDepartment),
&(tmpSubjectDescription),
&user[0].SelectedTitle.UnlockScore,
&user[0].SelectedTitle.UnlockWin)
&tmpUnlockScore,
&tmpUnlockWin)
if err != nil {
return nil, err
}
......@@ -274,6 +292,18 @@ func (MySQLUserQuery) SelectByUsername(username string) ([]schemas.InfoUserSchem
}
}
if tmpUnlockScore.Valid {
user[0].SelectedTitle.UnlockScore = tmpUnlockScore.Int32
} else {
user[0].SelectedTitle.UnlockScore = -1
}
if tmpUnlockWin.Valid {
user[0].SelectedTitle.UnlockWin = tmpUnlockWin.Int32
} else {
user[0].SelectedTitle.UnlockWin = -1
}
//return with no errors
return user, nil
}
......@@ -463,6 +493,9 @@ func (MySQLUserQuery) SelectAll() ([]schemas.InfoUserSchema, error) {
var tmpSubjectDepartment sql.NullString
var tmpSubjectDescription sql.NullString
var tmpUnlockScore sql.NullInt32
var tmpUnlockWin sql.NullInt32
errScan := rows.Scan(
&tmpUser.ID,
&tmpUser.Username,
......@@ -476,8 +509,8 @@ func (MySQLUserQuery) SelectAll() ([]schemas.InfoUserSchema, error) {
&(tmpSubjectShortForm),
&(tmpSubjectDepartment),
&(tmpSubjectDescription),
&tmpUser.SelectedTitle.UnlockScore,
&tmpUser.SelectedTitle.UnlockWin,
&tmpUnlockScore,
&tmpUnlockWin,
)
if errScan != nil {
......@@ -494,6 +527,18 @@ func (MySQLUserQuery) SelectAll() ([]schemas.InfoUserSchema, error) {
}
}
if tmpUnlockScore.Valid {
tmpUser.SelectedTitle.UnlockScore = tmpUnlockScore.Int32
} else {
tmpUser.SelectedTitle.UnlockScore = -1
}
if tmpUnlockWin.Valid {
tmpUser.SelectedTitle.UnlockWin = tmpUnlockWin.Int32
} else {
tmpUser.SelectedTitle.UnlockWin = -1
}
users = append(users, tmpUser)
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment