api

package
v0.0.0-...-246b59b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 25, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WriteJSON

func WriteJSON(w http.ResponseWriter, status int, v any) error

Types

type APIServer

type APIServer struct {
	// contains filtered or unexported fields
}

func NewAPIServer

func NewAPIServer(listenAddr string, store Storage) *APIServer

func (*APIServer) Run

func (s *APIServer) Run()

type Account

type Account struct {
	ID                int       `json:"id"`
	FirstName         string    `json:"firstName"`
	LastName          string    `json:"lastName"`
	Number            int64     `json:"number"`
	EncryptedPassword string    `json:"-"`
	Balance           int64     `json:"balance"`
	CreatedAt         time.Time `json:"createdAt"`
}

func NewAccount

func NewAccount(firstName, lastName, password string) (*Account, error)

func (*Account) ValidPassword

func (a *Account) ValidPassword(pw string) bool

type ApiError

type ApiError struct {
	Error string `json:"error"`
}

type ContextKey

type ContextKey string
const ContextUserIDKey ContextKey = "userid"

type CreateAccountRequest

type CreateAccountRequest struct {
	FirstName string `json:"firstName"`
	LastName  string `json:"lastName"`
	Password  string `json:"password"`
}

type JWTClaims

type JWTClaims struct {
	UserID int `json:"userid"`
	jwt.RegisteredClaims
}

type LoginRequest

type LoginRequest struct {
	Number   int64  `json:"number"`
	Password string `json:"password"`
}

type LoginResponse

type LoginResponse struct {
	Number int64  `json:"number"`
	Token  string `json:"token"`
}

type Reader

type Reader interface {
	Get(id int) (*Account, error)
}

type Repository

type Repository interface {
	Reader
	Writer
}

Repository interface

type Storage

type Storage struct {
	// contains filtered or unexported fields
}

func (Storage) CreateAccount

func (Storage) CreateAccount(account *Account) error

func (Storage) DeleteAccount

func (Storage) DeleteAccount(id int) error

func (Storage) GetAccountByID

func (Storage) GetAccountByID(id int) (Account, error)

func (Storage) GetAccountByNumber

func (Storage) GetAccountByNumber(int) (Account, error)

func (Storage) GetAccounts

func (Storage) GetAccounts() ([]Account, error)

type TransferRequest

type TransferRequest struct {
	ToAccount int `json:"toAccount"`
	Amount    int `json:"amount"`
}

type UseCase

type UseCase interface {
	Get(id int) (*Account, error)
	Create(ID int, FirstName string, LastName string, Number int64, EncryptedPassword string, Balance int64, CreatedAt time.Time) (int, error)
}

UseCase interface

type Writer

type Writer interface {
	Create(e *Account) (int, error)
}

Writer book writer

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL