Change user back to account (Cleaner)

This commit is contained in:
perp 2024-06-03 14:01:59 +01:00
parent eacc0b5dc9
commit 26edac76ce
4 changed files with 23 additions and 23 deletions

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package user
package account
import (
"time"
@ -21,26 +21,26 @@ import (
"xorm.io/xorm"
)
// User handler
type User struct {
// Account handler
type Account struct {
db *xorm.Engine
}
// User model
// Account model
type Model struct {
ID int64
Name string `xorm:"varchar(30) unique"`
Username string `xorm:"varchar(30) unique"`
Password string `xorm:"varchar(90)"`
Created time.Time `xorm:"created"`
}
// Return a new User
func New(engine *xorm.Engine) *User {
// Return a new Account
func New(engine *xorm.Engine) *Account {
// Sync engine
err := engine.Sync(new(Model))
if err != nil {
log.Panic().Msg(err.Error())
}
return &User{db: engine}
return &Account{db: engine}
}

View File

@ -12,22 +12,22 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package user
package account
import "github.com/rs/zerolog/log"
// Insert a model
func (u *User) Insert(name, password string) error {
func (a *Account) Insert(username, password string) error {
// Store model
model := &Model{
Name: name,
Username: username,
Password: password,
}
// Insert model
_, err := u.db.Insert(model)
_, err := a.db.Insert(model)
if err != nil {
log.Err(err).Str("table", "user").Msg("Could not insert row")
log.Err(err).Str("table", "account").Msg("Could not insert row")
return err
}

View File

@ -12,19 +12,19 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package user
package account
import "github.com/rs/zerolog/log"
// Select a model by id
func (u *User) SelectByID(id int) (*Model, error) {
func (a *Account) SelectByID(id int) (*Model, error) {
// Store model
model := &Model{}
// Select model
_, err := u.db.Where("i_d = ?", id).Get(model)
_, err := a.db.Where("i_d = ?", id).Get(model)
if err != nil {
log.Err(err).Str("table", "user").Str("type", "id").Msg("Could not select row")
log.Err(err).Str("table", "account").Str("type", "id").Msg("Could not select row")
return nil, err
}
@ -32,14 +32,14 @@ func (u *User) SelectByID(id int) (*Model, error) {
}
// Select a model by username
func (u *User) SelectByName(name string) (*Model, error) {
func (a *Account) SelectByUsername(username string) (*Model, error) {
// Store model
model := &Model{}
// Select model
_, err := u.db.Where("name = ?", name).Get(model)
_, err := a.db.Where("username = ?", username).Get(model)
if err != nil {
log.Err(err).Str("table", "user").Str("type", "name").Msg("Could not select row")
log.Err(err).Str("table", "account").Str("type", "name").Msg("Could not select row")
return nil, err
}

View File

@ -16,7 +16,7 @@ package database
import (
"git.supernets.org/perp/gopay/internal/config"
"git.supernets.org/perp/gopay/internal/database/user"
"git.supernets.org/perp/gopay/internal/database/account"
_ "github.com/mattn/go-sqlite3"
//_ "github.com/jackc/pgx/v5/stdlib"
@ -26,7 +26,7 @@ import (
// Database handler
type Database struct {
User *user.User
Account *account.Account
}
// Return a new Database
@ -43,7 +43,7 @@ func New(cfg *config.Database) *Database {
// Create database
database := &Database{
User: user.New(engine),
Account: account.New(engine),
}
return database