new licenceController, moved api handling & renaming things
This commit is contained in:
@@ -42,7 +42,7 @@ func (ur *UserRepository) UpdateUser(user *models.User) (*models.User, error) {
|
||||
err := database.DB.Transaction(func(tx *gorm.DB) error {
|
||||
// Check if the user exists in the database
|
||||
var existingUser models.User
|
||||
if err := tx.Preload("DriversLicence.LicenceCategories").
|
||||
if err := tx.Preload("Licence.Categories").
|
||||
Preload("Membership").
|
||||
First(&existingUser, user.ID).Error; err != nil {
|
||||
return err
|
||||
@@ -57,9 +57,9 @@ func (ur *UserRepository) UpdateUser(user *models.User) (*models.User, error) {
|
||||
}
|
||||
|
||||
// Handle the update of the LicenceCategories explicitly
|
||||
if user.DriversLicence.ID != 0 {
|
||||
// Replace the LicenceCategories with the new list
|
||||
if err := tx.Model(&existingUser.DriversLicence).Association("LicenceCategories").Replace(user.DriversLicence.LicenceCategories); err != nil {
|
||||
if user.Licence.ID != 0 {
|
||||
// Replace the Categories with the new list
|
||||
if err := tx.Model(&existingUser.Licence).Association("Categories").Replace(user.Licence.Categories); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -71,9 +71,9 @@ func (ur *UserRepository) UpdateUser(user *models.User) (*models.User, error) {
|
||||
}
|
||||
}
|
||||
|
||||
// Update the DriversLicence fields if provided
|
||||
if user.DriversLicence.ID != 0 {
|
||||
if err := tx.Model(&existingUser.DriversLicence).Updates(user.DriversLicence).Error; err != nil {
|
||||
// Update the Licence fields if provided
|
||||
if user.Licence.ID != 0 {
|
||||
if err := tx.Model(&existingUser.Licence).Updates(user.Licence).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -86,7 +86,7 @@ func (ur *UserRepository) UpdateUser(user *models.User) (*models.User, error) {
|
||||
}
|
||||
|
||||
var updatedUser models.User
|
||||
if err := database.DB.Preload("DriversLicence.LicenceCategories").
|
||||
if err := database.DB.Preload("Licence.Categories").
|
||||
Preload("Membership").
|
||||
First(&updatedUser, user.ID).Error; err != nil {
|
||||
return nil, err
|
||||
@@ -99,7 +99,7 @@ func (ur *UserRepository) GetUsers(where map[string]interface{}) (*[]models.User
|
||||
result := database.DB.
|
||||
Preload(clause.Associations).
|
||||
Preload("Membership.SubscriptionModel").
|
||||
Preload("DriversLicence.LicenceCategories").
|
||||
Preload("Licence.Categories").
|
||||
Where(where).Find(&users)
|
||||
if result.Error != nil {
|
||||
if result.Error == gorm.ErrRecordNotFound {
|
||||
@@ -115,7 +115,7 @@ func GetUserByID(userID *uint) (*models.User, error) {
|
||||
result := database.DB.
|
||||
Preload(clause.Associations).
|
||||
Preload("Membership.SubscriptionModel").
|
||||
Preload("DriversLicence.LicenceCategories").
|
||||
Preload("Licence.Categories").
|
||||
First(&user, userID)
|
||||
if result.Error != nil {
|
||||
if result.Error == gorm.ErrRecordNotFound {
|
||||
|
||||
Reference in New Issue
Block a user