Change user back to account (Cleaner)
This commit is contained in:
parent
eacc0b5dc9
commit
26edac76ce
@ -12,7 +12,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package user
|
package account
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
@ -21,26 +21,26 @@ import (
|
|||||||
"xorm.io/xorm"
|
"xorm.io/xorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
// User handler
|
// Account handler
|
||||||
type User struct {
|
type Account struct {
|
||||||
db *xorm.Engine
|
db *xorm.Engine
|
||||||
}
|
}
|
||||||
|
|
||||||
// User model
|
// Account model
|
||||||
type Model struct {
|
type Model struct {
|
||||||
ID int64
|
ID int64
|
||||||
Name string `xorm:"varchar(30) unique"`
|
Username string `xorm:"varchar(30) unique"`
|
||||||
Password string `xorm:"varchar(90)"`
|
Password string `xorm:"varchar(90)"`
|
||||||
Created time.Time `xorm:"created"`
|
Created time.Time `xorm:"created"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return a new User
|
// Return a new Account
|
||||||
func New(engine *xorm.Engine) *User {
|
func New(engine *xorm.Engine) *Account {
|
||||||
// Sync engine
|
// Sync engine
|
||||||
err := engine.Sync(new(Model))
|
err := engine.Sync(new(Model))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Panic().Msg(err.Error())
|
log.Panic().Msg(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
return &User{db: engine}
|
return &Account{db: engine}
|
||||||
}
|
}
|
@ -12,22 +12,22 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package user
|
package account
|
||||||
|
|
||||||
import "github.com/rs/zerolog/log"
|
import "github.com/rs/zerolog/log"
|
||||||
|
|
||||||
// Insert a model
|
// Insert a model
|
||||||
func (u *User) Insert(name, password string) error {
|
func (a *Account) Insert(username, password string) error {
|
||||||
// Store model
|
// Store model
|
||||||
model := &Model{
|
model := &Model{
|
||||||
Name: name,
|
Username: username,
|
||||||
Password: password,
|
Password: password,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert model
|
// Insert model
|
||||||
_, err := u.db.Insert(model)
|
_, err := a.db.Insert(model)
|
||||||
if err != nil {
|
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
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -12,19 +12,19 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package user
|
package account
|
||||||
|
|
||||||
import "github.com/rs/zerolog/log"
|
import "github.com/rs/zerolog/log"
|
||||||
|
|
||||||
// Select a model by id
|
// Select a model by id
|
||||||
func (u *User) SelectByID(id int) (*Model, error) {
|
func (a *Account) SelectByID(id int) (*Model, error) {
|
||||||
// Store model
|
// Store model
|
||||||
model := &Model{}
|
model := &Model{}
|
||||||
|
|
||||||
// Select model
|
// Select model
|
||||||
_, err := u.db.Where("i_d = ?", id).Get(model)
|
_, err := a.db.Where("i_d = ?", id).Get(model)
|
||||||
if err != nil {
|
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
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,14 +32,14 @@ func (u *User) SelectByID(id int) (*Model, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Select a model by username
|
// Select a model by username
|
||||||
func (u *User) SelectByName(name string) (*Model, error) {
|
func (a *Account) SelectByUsername(username string) (*Model, error) {
|
||||||
// Store model
|
// Store model
|
||||||
model := &Model{}
|
model := &Model{}
|
||||||
|
|
||||||
// Select model
|
// Select model
|
||||||
_, err := u.db.Where("name = ?", name).Get(model)
|
_, err := a.db.Where("username = ?", username).Get(model)
|
||||||
if err != nil {
|
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
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -16,7 +16,7 @@ package database
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"git.supernets.org/perp/gopay/internal/config"
|
"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/mattn/go-sqlite3"
|
||||||
|
|
||||||
//_ "github.com/jackc/pgx/v5/stdlib"
|
//_ "github.com/jackc/pgx/v5/stdlib"
|
||||||
@ -26,7 +26,7 @@ import (
|
|||||||
|
|
||||||
// Database handler
|
// Database handler
|
||||||
type Database struct {
|
type Database struct {
|
||||||
User *user.User
|
Account *account.Account
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return a new Database
|
// Return a new Database
|
||||||
@ -43,7 +43,7 @@ func New(cfg *config.Database) *Database {
|
|||||||
|
|
||||||
// Create database
|
// Create database
|
||||||
database := &Database{
|
database := &Database{
|
||||||
User: user.New(engine),
|
Account: account.New(engine),
|
||||||
}
|
}
|
||||||
|
|
||||||
return database
|
return database
|
||||||
|
Loading…
Reference in New Issue
Block a user