mirror of
https://gitea.phreedom.club/localhost_frssoft/bloat.git
synced 2025-05-01 09:34:21 +00:00
Initial commit
This commit is contained in:
commit
5e4da01c3a
43 changed files with 3429 additions and 0 deletions
54
repository/appRepository.go
Normal file
54
repository/appRepository.go
Normal file
|
@ -0,0 +1,54 @@
|
|||
package repository
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
|
||||
"web/model"
|
||||
)
|
||||
|
||||
type appRepository struct {
|
||||
db *sql.DB
|
||||
}
|
||||
|
||||
func NewAppRepository(db *sql.DB) (*appRepository, error) {
|
||||
_, err := db.Exec(`CREATE TABLE IF NOT EXISTS app
|
||||
(instance_url varchar, client_id varchar, client_secret varchar)`,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &appRepository{
|
||||
db: db,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (repo *appRepository) Add(a model.App) (err error) {
|
||||
_, err = repo.db.Exec("INSERT INTO app VALUES (?, ?, ?)", a.InstanceURL, a.ClientID, a.ClientSecret)
|
||||
return
|
||||
}
|
||||
|
||||
func (repo *appRepository) Update(instanceURL string, clientID string, clientSecret string) (err error) {
|
||||
_, err = repo.db.Exec("UPDATE app SET client_id = ?, client_secret = ? where instance_url = ?", clientID, clientSecret, instanceURL)
|
||||
return
|
||||
}
|
||||
|
||||
func (repo *appRepository) Get(instanceURL string) (a model.App, err error) {
|
||||
rows, err := repo.db.Query("SELECT * FROM app WHERE instance_url = ?", instanceURL)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
if !rows.Next() {
|
||||
err = model.ErrAppNotFound
|
||||
return
|
||||
}
|
||||
|
||||
err = rows.Scan(&a.InstanceURL, &a.ClientID, &a.ClientSecret)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
54
repository/sessionRepository.go
Normal file
54
repository/sessionRepository.go
Normal file
|
@ -0,0 +1,54 @@
|
|||
package repository
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
|
||||
"web/model"
|
||||
)
|
||||
|
||||
type sessionRepository struct {
|
||||
db *sql.DB
|
||||
}
|
||||
|
||||
func NewSessionRepository(db *sql.DB) (*sessionRepository, error) {
|
||||
_, err := db.Exec(`CREATE TABLE IF NOT EXISTS session
|
||||
(id varchar, instance_url varchar, access_token varchar)`,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &sessionRepository{
|
||||
db: db,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (repo *sessionRepository) Add(s model.Session) (err error) {
|
||||
_, err = repo.db.Exec("INSERT INTO session VALUES (?, ?, ?)", s.ID, s.InstanceURL, s.AccessToken)
|
||||
return
|
||||
}
|
||||
|
||||
func (repo *sessionRepository) Update(sessionID string, accessToken string) (err error) {
|
||||
_, err = repo.db.Exec("UPDATE session SET access_token = ? where id = ?", accessToken, sessionID)
|
||||
return
|
||||
}
|
||||
|
||||
func (repo *sessionRepository) Get(id string) (s model.Session, err error) {
|
||||
rows, err := repo.db.Query("SELECT * FROM session WHERE id = ?", id)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
if !rows.Next() {
|
||||
err = model.ErrSessionNotFound
|
||||
return
|
||||
}
|
||||
|
||||
err = rows.Scan(&s.ID, &s.InstanceURL, &s.AccessToken)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue