30 lines
486 B
Go
30 lines
486 B
Go
|
|
package user
|
||
|
|
|
||
|
|
import "database/sql"
|
||
|
|
|
||
|
|
type Repository interface {
|
||
|
|
getUserId(userUuid string) (string, error)
|
||
|
|
}
|
||
|
|
|
||
|
|
type repo struct {
|
||
|
|
db *sql.DB
|
||
|
|
}
|
||
|
|
|
||
|
|
func newRepository(db *sql.DB) Repository {
|
||
|
|
return &repo{
|
||
|
|
db: db,
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func (r *repo) getUserId(userUuid string) (string, error) {
|
||
|
|
q := `SELECT id FROM users WHERE uuid = $1 AND deleted_at IS NULL LIMIT 1`
|
||
|
|
row := r.db.QueryRow(q, userUuid)
|
||
|
|
|
||
|
|
var id string
|
||
|
|
if err := row.Scan(&id); err != nil {
|
||
|
|
return "", err
|
||
|
|
}
|
||
|
|
|
||
|
|
return id, nil
|
||
|
|
}
|