GetAdminUser 返回第一个 is_admin=true 的用户。
()
| 692 | |
| 693 | // GetAdminUser 返回第一个 is_admin=true 的用户。 |
| 694 | func (s *UserStore) GetAdminUser() (users.User, error) { |
| 695 | var id, username, password string |
| 696 | err := s.db.QueryRow(context.Background(), |
| 697 | `SELECT id, username, password FROM users WHERE is_admin = TRUE LIMIT 1`, |
| 698 | ).Scan(&id, &username, &password) |
| 699 | if errors.Is(err, pgx.ErrNoRows) { |
| 700 | return users.User{}, users.ErrUserNotFound |
| 701 | } |
| 702 | if err != nil { |
| 703 | return users.User{}, err |
| 704 | } |
| 705 | return users.User{ID: id, Username: username, Password: password, IsAdmin: true}, nil |
| 706 | } |
| 707 | |
| 708 | // SetIsAdmin 设置指定用户的管理员标记。 |
| 709 | func (s *UserStore) SetIsAdmin(userID string, isAdmin bool) error { |