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 { ...@@ -128,9 +128,13 @@ func (nT *nullableTitle) ToTitle(title *schemas.TitleSchema) bool {
} }
if nT.UnlockScore.Valid { if nT.UnlockScore.Valid {
title.UnlockScore = int32(nT.UnlockScore.Int64) title.UnlockScore = int32(nT.UnlockScore.Int64)
} else {
title.UnlockScore = -1
} }
if nT.UnlockWin.Valid { if nT.UnlockWin.Valid {
title.UnlockWin = int32(nT.UnlockWin.Int64) title.UnlockWin = int32(nT.UnlockWin.Int64)
} else {
title.UnlockWin = -1
} }
return nT.ID.Valid && nT.Name.Valid return nT.ID.Valid && nT.Name.Valid
} }
......
...@@ -66,6 +66,9 @@ func (MySQLFriendQuery) SelectByID(userID uint32) ([]schemas.InfoUserSchema, err ...@@ -66,6 +66,9 @@ func (MySQLFriendQuery) SelectByID(userID uint32) ([]schemas.InfoUserSchema, err
var tmpSubjectDepartment sql.NullString var tmpSubjectDepartment sql.NullString
var tmpSubjectDescription sql.NullString var tmpSubjectDescription sql.NullString
var tmpUnlockScore sql.NullInt32
var tmpUnlockWin sql.NullInt32
if errFetch := rows.Scan( if errFetch := rows.Scan(
&tmpFriend.ID, &tmpFriend.ID,
&tmpFriend.Username, &tmpFriend.Username,
...@@ -79,8 +82,8 @@ func (MySQLFriendQuery) SelectByID(userID uint32) ([]schemas.InfoUserSchema, err ...@@ -79,8 +82,8 @@ func (MySQLFriendQuery) SelectByID(userID uint32) ([]schemas.InfoUserSchema, err
&(tmpSubjectShortForm), &(tmpSubjectShortForm),
&(tmpSubjectDepartment), &(tmpSubjectDepartment),
&(tmpSubjectDescription), &(tmpSubjectDescription),
&tmpFriend.SelectedTitle.UnlockScore, &tmpUnlockScore,
&tmpFriend.SelectedTitle.UnlockWin, &tmpUnlockWin,
); errFetch != nil { ); errFetch != nil {
return nil, fmt.Errorf("Cannot scan db values into friends list. " + errFetch.Error()) 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 ...@@ -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) friends = append(friends, tmpFriend)
} }
...@@ -209,6 +224,9 @@ func (MySQLFriendQuery) Insert(userID, userIDToAdd uint32) ([]schemas.InfoUserSc ...@@ -209,6 +224,9 @@ func (MySQLFriendQuery) Insert(userID, userIDToAdd uint32) ([]schemas.InfoUserSc
var tmpSubjectDepartment sql.NullString var tmpSubjectDepartment sql.NullString
var tmpSubjectDescription sql.NullString var tmpSubjectDescription sql.NullString
var tmpUnlockScore sql.NullInt32
var tmpUnlockWin sql.NullInt32
if errResult := rows.Scan( if errResult := rows.Scan(
&tmpFriend.ID, &tmpFriend.ID,
&tmpFriend.Username, &tmpFriend.Username,
...@@ -222,8 +240,8 @@ func (MySQLFriendQuery) Insert(userID, userIDToAdd uint32) ([]schemas.InfoUserSc ...@@ -222,8 +240,8 @@ func (MySQLFriendQuery) Insert(userID, userIDToAdd uint32) ([]schemas.InfoUserSc
&(tmpSubjectShortForm), &(tmpSubjectShortForm),
&(tmpSubjectDepartment), &(tmpSubjectDepartment),
&(tmpSubjectDescription), &(tmpSubjectDescription),
&tmpFriend.SelectedTitle.UnlockScore, &tmpUnlockScore,
&tmpFriend.SelectedTitle.UnlockWin, &tmpUnlockWin,
); errResult != nil { ); errResult != nil {
if tmpSubjectName.Valid { if tmpSubjectName.Valid {
tmpFriend.SelectedTitle.Subject = &schemas.Subject{ tmpFriend.SelectedTitle.Subject = &schemas.Subject{
...@@ -235,6 +253,18 @@ func (MySQLFriendQuery) Insert(userID, userIDToAdd uint32) ([]schemas.InfoUserSc ...@@ -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()) return nil, fmt.Errorf("failed to provide updated friends list." + errResult.Error())
} }
result = append(result, tmpFriend) result = append(result, tmpFriend)
...@@ -309,6 +339,9 @@ func (MySQLFriendQuery) Delete(userID, userIDToRemove uint32) ([]schemas.InfoUse ...@@ -309,6 +339,9 @@ func (MySQLFriendQuery) Delete(userID, userIDToRemove uint32) ([]schemas.InfoUse
var tmpSubjectDepartment sql.NullString var tmpSubjectDepartment sql.NullString
var tmpSubjectDescription sql.NullString var tmpSubjectDescription sql.NullString
var tmpUnlockScore sql.NullInt32
var tmpUnlockWin sql.NullInt32
if errResult := rows.Scan( if errResult := rows.Scan(
&user.ID, &user.ID,
&user.Username, &user.Username,
...@@ -322,8 +355,8 @@ func (MySQLFriendQuery) Delete(userID, userIDToRemove uint32) ([]schemas.InfoUse ...@@ -322,8 +355,8 @@ func (MySQLFriendQuery) Delete(userID, userIDToRemove uint32) ([]schemas.InfoUse
&(tmpSubjectShortForm), &(tmpSubjectShortForm),
&(tmpSubjectDepartment), &(tmpSubjectDepartment),
&(tmpSubjectDescription), &(tmpSubjectDescription),
&user.SelectedTitle.UnlockScore, &tmpUnlockScore,
&user.SelectedTitle.UnlockWin, &tmpUnlockWin,
); errResult != nil { ); errResult != nil {
if tmpSubjectName.Valid { if tmpSubjectName.Valid {
user.SelectedTitle.Subject = &schemas.Subject{ user.SelectedTitle.Subject = &schemas.Subject{
...@@ -335,6 +368,18 @@ func (MySQLFriendQuery) Delete(userID, userIDToRemove uint32) ([]schemas.InfoUse ...@@ -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()) return nil, fmt.Errorf("failed to provide updated friends list." + errResult.Error())
} }
result = append(result, user) result = append(result, user)
......
...@@ -176,6 +176,9 @@ func (MySQLUserQuery) Select(id uint32) ([]schemas.FullUserSchema, error) { ...@@ -176,6 +176,9 @@ func (MySQLUserQuery) Select(id uint32) ([]schemas.FullUserSchema, error) {
var tmpSubjectDepartment sql.NullString var tmpSubjectDepartment sql.NullString
var tmpSubjectDescription sql.NullString var tmpSubjectDescription sql.NullString
var tmpUnlockScore sql.NullInt32
var tmpUnlockWin sql.NullInt32
//make sql query and save response to the user pointer //make sql query and save response to the user pointer
err = stmt.QueryRow(id).Scan( err = stmt.QueryRow(id).Scan(
&users[0].ID, &users[0].ID,
...@@ -194,8 +197,8 @@ func (MySQLUserQuery) Select(id uint32) ([]schemas.FullUserSchema, error) { ...@@ -194,8 +197,8 @@ func (MySQLUserQuery) Select(id uint32) ([]schemas.FullUserSchema, error) {
&(tmpSubjectShortForm), &(tmpSubjectShortForm),
&(tmpSubjectDepartment), &(tmpSubjectDepartment),
&(tmpSubjectDescription), &(tmpSubjectDescription),
&users[0].SelectedTitle.UnlockScore, &tmpUnlockScore,
&users[0].SelectedTitle.UnlockWin, &tmpUnlockWin,
&users[0].Verified, &users[0].Verified,
&users[0].University, &users[0].University,
&users[0].Level) &users[0].Level)
...@@ -217,6 +220,18 @@ func (MySQLUserQuery) Select(id uint32) ([]schemas.FullUserSchema, error) { ...@@ -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 with no errors
return users, nil return users, nil
} }
...@@ -244,6 +259,9 @@ func (MySQLUserQuery) SelectByUsername(username string) ([]schemas.InfoUserSchem ...@@ -244,6 +259,9 @@ func (MySQLUserQuery) SelectByUsername(username string) ([]schemas.InfoUserSchem
var tmpSubjectDepartment sql.NullString var tmpSubjectDepartment sql.NullString
var tmpSubjectDescription sql.NullString var tmpSubjectDescription sql.NullString
var tmpUnlockScore sql.NullInt32
var tmpUnlockWin sql.NullInt32
//make sql query and save response to the user pointer //make sql query and save response to the user pointer
err = stmt.QueryRow(username).Scan( err = stmt.QueryRow(username).Scan(
&user[0].ID, &user[0].ID,
...@@ -258,8 +276,8 @@ func (MySQLUserQuery) SelectByUsername(username string) ([]schemas.InfoUserSchem ...@@ -258,8 +276,8 @@ func (MySQLUserQuery) SelectByUsername(username string) ([]schemas.InfoUserSchem
&(tmpSubjectShortForm), &(tmpSubjectShortForm),
&(tmpSubjectDepartment), &(tmpSubjectDepartment),
&(tmpSubjectDescription), &(tmpSubjectDescription),
&user[0].SelectedTitle.UnlockScore, &tmpUnlockScore,
&user[0].SelectedTitle.UnlockWin) &tmpUnlockWin)
if err != nil { if err != nil {
return nil, err return nil, err
} }
...@@ -274,6 +292,18 @@ func (MySQLUserQuery) SelectByUsername(username string) ([]schemas.InfoUserSchem ...@@ -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 with no errors
return user, nil return user, nil
} }
...@@ -463,6 +493,9 @@ func (MySQLUserQuery) SelectAll() ([]schemas.InfoUserSchema, error) { ...@@ -463,6 +493,9 @@ func (MySQLUserQuery) SelectAll() ([]schemas.InfoUserSchema, error) {
var tmpSubjectDepartment sql.NullString var tmpSubjectDepartment sql.NullString
var tmpSubjectDescription sql.NullString var tmpSubjectDescription sql.NullString
var tmpUnlockScore sql.NullInt32
var tmpUnlockWin sql.NullInt32
errScan := rows.Scan( errScan := rows.Scan(
&tmpUser.ID, &tmpUser.ID,
&tmpUser.Username, &tmpUser.Username,
...@@ -476,8 +509,8 @@ func (MySQLUserQuery) SelectAll() ([]schemas.InfoUserSchema, error) { ...@@ -476,8 +509,8 @@ func (MySQLUserQuery) SelectAll() ([]schemas.InfoUserSchema, error) {
&(tmpSubjectShortForm), &(tmpSubjectShortForm),
&(tmpSubjectDepartment), &(tmpSubjectDepartment),
&(tmpSubjectDescription), &(tmpSubjectDescription),
&tmpUser.SelectedTitle.UnlockScore, &tmpUnlockScore,
&tmpUser.SelectedTitle.UnlockWin, &tmpUnlockWin,
) )
if errScan != nil { if errScan != nil {
...@@ -494,6 +527,18 @@ func (MySQLUserQuery) SelectAll() ([]schemas.InfoUserSchema, error) { ...@@ -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) 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