- new table userbook linking users and book - moved rating to users book - updated demo data and tests - updated front to hide routes from non connected users
35 lines
676 B
Go
35 lines
676 B
Go
package api
|
|
|
|
import (
|
|
"git.artlef.fr/PersonalLibraryManager/internal/model"
|
|
"golang.org/x/crypto/bcrypt"
|
|
)
|
|
|
|
func (b bookPostCreate) toBook() model.Book {
|
|
return model.Book{
|
|
Title: b.Title,
|
|
Author: b.Author,
|
|
}
|
|
}
|
|
|
|
func fromUserBookDb(b *model.UserBook) bookUserGet {
|
|
return bookUserGet{
|
|
Title: b.Book.Title,
|
|
Author: b.Book.Author,
|
|
Rating: b.Rating,
|
|
}
|
|
}
|
|
|
|
func (u userSignup) toUser() (model.User, error) {
|
|
user := model.User{
|
|
Name: u.Username,
|
|
Password: "",
|
|
}
|
|
hashedPassword, err := bcrypt.GenerateFromPassword([]byte(u.Password), bcrypt.DefaultCost)
|
|
if err != nil {
|
|
return user, err
|
|
}
|
|
user.Password = string(hashedPassword)
|
|
return user, nil
|
|
}
|