From a007e53b037a08ce34efd0b936dfa03127c2b7d1 Mon Sep 17 00:00:00 2001 From: Kevin Chabowski Date: Fri, 30 Aug 2013 23:46:32 +0200 Subject: Added {,Set}Location to model --- model/dbmodel.go | 3 +++ model/mysql/queries.go | 2 ++ model/mysql/users.go | 26 ++++++++++++++++++-------- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/model/dbmodel.go b/model/dbmodel.go index cc4a6d7..2889908 100644 --- a/model/dbmodel.go +++ b/model/dbmodel.go @@ -34,6 +34,9 @@ type User interface { ActivationCode() string SetActivationCode(string) error + Location() *time.Location + SetLocation(*time.Location) error + Delete() error } diff --git a/model/mysql/queries.go b/model/mysql/queries.go index 7d7b860..e579df7 100644 --- a/model/mysql/queries.go +++ b/model/mysql/queries.go @@ -20,6 +20,7 @@ const ( qInsertJob qInsertUser qSetChronos + qSetLocation qEnd ) @@ -48,4 +49,5 @@ var queries = map[int]string{ qInsertJob: "INSERT INTO `jobs` (`user`, `subject`, `content`, `next`, `chronos`) VALUES (?, ?, ?, ?, ?)", qInsertUser: "INSERT INTO `users` (`email`, `passwd`, `location`, `active`, `activationcode`, `added`) VALUES (?, ?, ?, ?, ?, ?)", qSetChronos: "UPDATE `jobs` SET `chronos` = ? WHERE `id` = ?", + qSetLocation: "UPDATE `users` SET `location` = ? WHERE `id` = ?", } diff --git a/model/mysql/users.go b/model/mysql/users.go index 017d34f..f4e3c1c 100644 --- a/model/mysql/users.go +++ b/model/mysql/users.go @@ -62,16 +62,17 @@ func (con *MySQLDBCon) UserByMail(email string) (model.User, error) { return userFromSQL(con, row) } -func (u *User) ID() model.DBID { return u.id } -func (u *User) Email() string { return u.email } -func (u *User) PWHash() []byte { return []byte(u.passwd) } -func (u *User) Active() bool { return u.active } -func (u *User) ActivationCode() string { return u.acCode } +func (u *User) ID() model.DBID { return u.id } +func (u *User) Email() string { return u.email } +func (u *User) PWHash() []byte { return []byte(u.passwd) } +func (u *User) Active() bool { return u.active } +func (u *User) ActivationCode() string { return u.acCode } +func (u *User) Location() *time.Location { return u.location } func (u *User) SetPWHash(_pwhash []byte) error { pwhash := string(_pwhash) - if _, err := u.con.stmt[qSetPWHash].Query(pwhash, uint64(u.id)); err != nil { + if _, err := u.con.stmt[qSetPWHash].Exec(pwhash, uint64(u.id)); err != nil { return err } @@ -80,7 +81,7 @@ func (u *User) SetPWHash(_pwhash []byte) error { } func (u *User) SetActive(b bool) error { - if _, err := u.con.stmt[qSetActive].Query(b2i(b), uint64(u.id)); err != nil { + if _, err := u.con.stmt[qSetActive].Exec(b2i(b), uint64(u.id)); err != nil { return err } @@ -89,7 +90,7 @@ func (u *User) SetActive(b bool) error { } func (u *User) SetActivationCode(c string) error { - if _, err := u.con.stmt[qSetAcCode].Query(c, uint64(u.id)); err != nil { + if _, err := u.con.stmt[qSetAcCode].Exec(c, uint64(u.id)); err != nil { return err } @@ -97,6 +98,15 @@ func (u *User) SetActivationCode(c string) error { return nil } +func (u *User) SetLocation(loc *time.Location) error { + if _, err := u.con.stmt[qSetLocation].Exec(loc.String(), uint64(u.id)); err != nil { + return err + } + + u.location = loc + return nil +} + func (u *User) Delete() error { tx, err := u.con.con.Begin() if err != nil { -- cgit v1.2.3-54-g00ecf