1
0

Refactor adding more details to tasks (#739)

Refactor adding more details to tasks

Co-authored-by: kolaente <k@knt.li>
Reviewed-on: https://kolaente.dev/vikunja/api/pulls/739
Co-Authored-By: konrad <konrad@kola-entertainments.de>
Co-Committed-By: konrad <konrad@kola-entertainments.de>
This commit is contained in:
konrad
2020-12-18 13:54:36 +00:00
parent ccfa019870
commit 8d739b2cf9
3 changed files with 114 additions and 60 deletions

View File

@ -141,6 +141,22 @@ func GetUserWithEmail(user *User) (userOut *User, err error) {
return getUser(user, true)
}
// GetUsersByIDs returns a map of users from a slice of user ids
func GetUsersByIDs(userIDs []int64) (users map[int64]*User, err error) {
users = make(map[int64]*User)
err = x.In("id", userIDs).Find(&users)
if err != nil {
return
}
// Obfuscate all user emails
for _, u := range users {
u.Email = ""
}
return
}
// getUser is a small helper function to avoid having duplicated code for almost the same use case
func getUser(user *User, withEmail bool) (userOut *User, err error) {
userOut = &User{} // To prevent a panic if user is nil