Backend:Real world movement
This commit is contained in:
@@ -25,6 +25,15 @@ type UserRepositoryInterface interface {
|
||||
|
||||
type UserRepository struct{}
|
||||
|
||||
func PasswordExists(userID *uint) (bool, error) {
|
||||
var user models.User
|
||||
result := database.DB.Select("password").First(&user, userID)
|
||||
if result.Error != nil {
|
||||
return false, result.Error
|
||||
}
|
||||
return user.Password != "", nil
|
||||
}
|
||||
|
||||
func (ur *UserRepository) CreateUser(user *models.User) (uint, error) {
|
||||
result := database.DB.Create(user)
|
||||
if result.Error != nil {
|
||||
@@ -57,30 +66,6 @@ func (ur *UserRepository) UpdateUser(user *models.User) (*models.User, error) {
|
||||
return errors.ErrNoRowsAffected
|
||||
}
|
||||
|
||||
// Handle the update or creation of Licence and its Categories
|
||||
// if user.Licence != nil {
|
||||
// if existingUser.Licence == nil {
|
||||
// // Create new Licence if it doesn't exist
|
||||
// logger.Error.Printf("Licence creation: %+v", user.Licence)
|
||||
// if err := tx.Create(user.Licence).Error; err != nil {
|
||||
// return err
|
||||
// }
|
||||
// // Update user with new licence ID
|
||||
// // if err := tx.Model(&existingUser).Update("licence_id", user.Licence.ID).Error; err != nil {
|
||||
// // return err
|
||||
// // }
|
||||
// } else {
|
||||
// // Update existing licence
|
||||
// if err := tx.Model(&existingUser.Licence).Updates(user.Licence).Error; err != nil {
|
||||
// return err
|
||||
// }
|
||||
// }
|
||||
// // Replace the Categories with the new list
|
||||
// if err := tx.Model(&existingUser.Licence).Association("Categories").Replace(user.Licence.Categories); err != nil {
|
||||
// return err
|
||||
// }
|
||||
// }
|
||||
|
||||
// Update the Membership if provided
|
||||
if user.Membership.ID != 0 {
|
||||
if err := tx.Model(&existingUser.Membership).Updates(user.Membership).Error; err != nil {
|
||||
|
||||
Reference in New Issue
Block a user