mirror of
https://github.com/pushbits/server.git
synced 2025-06-05 12:12:03 +02:00
Partially implement updates of models
This commit is contained in:
parent
6a77df8373
commit
d621333b6e
9 changed files with 158 additions and 19 deletions
|
@ -3,6 +3,7 @@ package database
|
|||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/eikendev/pushbits/assert"
|
||||
"github.com/eikendev/pushbits/model"
|
||||
|
||||
"gorm.io/gorm"
|
||||
|
@ -18,28 +19,37 @@ func (d *Database) DeleteApplication(application *model.Application) error {
|
|||
return d.gormdb.Delete(application).Error
|
||||
}
|
||||
|
||||
// UpdateApplication updates an application.
|
||||
func (d *Database) UpdateApplication(application *model.Application) error {
|
||||
return d.gormdb.Save(application).Error
|
||||
}
|
||||
|
||||
// GetApplicationByID returns the application with the given ID or nil.
|
||||
func (d *Database) GetApplicationByID(ID uint) (*model.Application, error) {
|
||||
var app model.Application
|
||||
var application model.Application
|
||||
|
||||
err := d.gormdb.First(&app, ID).Error
|
||||
err := d.gormdb.First(&application, ID).Error
|
||||
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &app, err
|
||||
assert.Assert(application.ID == ID)
|
||||
|
||||
return &application, err
|
||||
}
|
||||
|
||||
// GetApplicationByToken returns the application with the given token or nil.
|
||||
func (d *Database) GetApplicationByToken(token string) (*model.Application, error) {
|
||||
var app model.Application
|
||||
var application model.Application
|
||||
|
||||
err := d.gormdb.Where("token = ?", token).First(&app).Error
|
||||
err := d.gormdb.Where("token = ?", token).First(&application).Error
|
||||
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &app, err
|
||||
assert.Assert(application.Token == token)
|
||||
|
||||
return &application, err
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package database
|
|||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/eikendev/pushbits/assert"
|
||||
"github.com/eikendev/pushbits/model"
|
||||
|
||||
"gorm.io/gorm"
|
||||
|
@ -24,6 +25,11 @@ func (d *Database) DeleteUser(user *model.User) error {
|
|||
return d.gormdb.Delete(user).Error
|
||||
}
|
||||
|
||||
// UpdateUser updates a user.
|
||||
func (d *Database) UpdateUser(user *model.User) error {
|
||||
return d.gormdb.Save(user).Error
|
||||
}
|
||||
|
||||
// GetUserByID returns the user with the given ID or nil.
|
||||
func (d *Database) GetUserByID(ID uint) (*model.User, error) {
|
||||
var user model.User
|
||||
|
@ -34,6 +40,8 @@ func (d *Database) GetUserByID(ID uint) (*model.User, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
assert.Assert(user.ID == ID)
|
||||
|
||||
return &user, err
|
||||
}
|
||||
|
||||
|
@ -47,6 +55,8 @@ func (d *Database) GetUserByName(name string) (*model.User, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
assert.Assert(user.Name == name)
|
||||
|
||||
return &user, err
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue