feat: update callback handler and repository for user
All checks were successful
Backend ci / build (push) Successful in 3m23s
All checks were successful
Backend ci / build (push) Successful in 3m23s
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"database/sql"
|
||||
|
||||
"gitea.d3m0k1d.ru/d3m0k1d/d3m0k1d.ru/backend/internal/logger"
|
||||
"gitea.d3m0k1d.ru/d3m0k1d/d3m0k1d.ru/backend/internal/storage"
|
||||
)
|
||||
|
||||
type authRepository struct {
|
||||
@@ -18,5 +19,23 @@ func NewAuthRepository(db *sql.DB) AuthRepository {
|
||||
logger: logger.New(false),
|
||||
}
|
||||
}
|
||||
func (a *authRepository) Test(ctx context.Context) {
|
||||
|
||||
func (a *authRepository) Register(ctx context.Context, user storage.UserReg) error {
|
||||
_, err := a.db.Exec(
|
||||
"INSERT INTO users(email, github_id, github_login, avatar_url) VALUES(?, ?, ?, ?)",
|
||||
)
|
||||
if err != nil {
|
||||
a.logger.Error("error scan: " + err.Error())
|
||||
return err
|
||||
}
|
||||
a.logger.Info("User registered:", "email", user.Email)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *authRepository) IsRegistered(ctx context.Context, github_id int) (bool, error) {
|
||||
row := a.db.QueryRow("SELECT id FROM users WHERE github_id = ?", github_id)
|
||||
if row != nil {
|
||||
return true, nil
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
|
||||
@@ -15,5 +15,6 @@ type PostRepository interface {
|
||||
}
|
||||
|
||||
type AuthRepository interface {
|
||||
Test(ctx context.Context)
|
||||
Register(ctx context.Context, user storage.UserReg) error
|
||||
IsRegistered(ctx context.Context, github_id int) (bool, error)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user