add missing files
This commit is contained in:
32
services/shopItemService.go
Normal file
32
services/shopItemService.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package services
|
||||
|
||||
import(
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
|
||||
"example.com/gin/test/models"
|
||||
"example.com/gin/test/repositories"
|
||||
)
|
||||
|
||||
var(
|
||||
ShopItems ShopItemService = ShopItemService{}
|
||||
)
|
||||
|
||||
type ShopItemService struct {}
|
||||
|
||||
func (u *ShopItemService) Create(name string, email string, password string) (models.User, error) {
|
||||
//hash pw
|
||||
hash, err := bcrypt.GenerateFromPassword([]byte(password), 10)
|
||||
|
||||
if err != nil {
|
||||
return models.User{}, err
|
||||
}
|
||||
|
||||
user := models.User{Name: name, Email: email, Password: string(hash)}
|
||||
_, err = repositories.Users.Create(user)
|
||||
|
||||
if err != nil {
|
||||
return models.User{}, err
|
||||
}
|
||||
|
||||
return user, nil
|
||||
}
|
||||
Reference in New Issue
Block a user