Raw
 1package adminui
 2
 3import (
 4	"context"
 5	"errors"
 6
 7	"tug/internal/service/admin"
 8	"tug/internal/transport/web"
 9)
10
11func (b Backend) PendingAccount(ctx context.Context, id string) (web.AdminPendingAccount, error) {
12	a, err := b.service.PendingAccount(ctx, id)
13	if err != nil {
14		return web.AdminPendingAccount{}, mapError(err)
15	}
16	return web.AdminPendingAccount{Username: a.Username, Spent: a.Spent, ExpiresAt: a.ExpiresAt}, nil
17}
18
19func (b Backend) ConfirmAccount(ctx context.Context, actor, id, code string) error {
20	err := b.service.ConfirmAccount(ctx, actor, id, code)
21	switch {
22	case errors.Is(err, admin.ErrConfirmCode):
23		return web.ErrAdminConfirmCode
24	case errors.Is(err, admin.ErrConfirmSpent):
25		return web.ErrAdminConfirmSpent
26	}
27	return mapError(err)
28}
29
30func (b Backend) RejectAccount(ctx context.Context, actor, id string) error {
31	return mapError(b.service.RejectAccount(ctx, actor, id))
32}