added user signup feature

This commit is contained in:
2025-09-26 23:57:36 +02:00
parent 2f0a9b5127
commit 57355fe9ac
15 changed files with 242 additions and 14 deletions

View File

@@ -1,9 +1,27 @@
package api
import "git.artlef.fr/PersonalLibraryManager/internal/model"
import (
"git.artlef.fr/PersonalLibraryManager/internal/model"
"golang.org/x/crypto/bcrypt"
)
func (b bookPostCreate) toBook() model.Book {
return model.Book{Title: b.Title,
return model.Book{
Title: b.Title,
Author: b.Author,
Rating: b.Rating}
Rating: b.Rating,
}
}
func (u userPostCreate) 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
}