api

package
v0.0.0-...-1b54e00 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2025 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateUniqueID

func GenerateUniqueID() string

GenerateUniqueID generates a unique ID for a new user

func HashCode

func HashCode(s string) int64

HashCode converts a string to a 64-bit integer hash This is a simple implementation and is not cryptographically secure

Types

type AuthProvider

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

AuthProvider handles API authentication

func NewAuthProvider

func NewAuthProvider(tokens []string) *AuthProvider

NewAuthProvider creates a new authentication provider with the given tokens

func (*AuthProvider) AddToken

func (a *AuthProvider) AddToken(token string)

AddToken adds a new token to the provider

func (*AuthProvider) Authenticate

func (a *AuthProvider) Authenticate(token string) bool

Authenticate validates the provided token Returns true if the token is valid

func (*AuthProvider) HasTokens

func (a *AuthProvider) HasTokens() bool

HasTokens returns true if there are tokens configured

func (*AuthProvider) RemoveToken

func (a *AuthProvider) RemoveToken(token string)

RemoveToken removes a token from the provider

type BulkUploadRequest

type BulkUploadRequest struct {
	Emails []string `json:"emails,omitempty"`
}

BulkUploadRequest represents the JSON payload for bulk email upload

type BulkUploadResponse

type BulkUploadResponse struct {
	Total     int      `json:"total"`
	Success   int      `json:"success"`
	Failed    int      `json:"failed"`
	Duplicate int      `json:"duplicate"`
	Failures  []string `json:"failures,omitempty"`
}

BulkUploadResponse represents the JSON response for bulk upload

type EmailRequest

type EmailRequest struct {
	Email string `json:"email"`
}

EmailRequest represents the JSON payload for email submission

type EmailResponse

type EmailResponse struct {
	ID      string `json:"id,omitempty"`
	Status  string `json:"status"`
	Message string `json:"message,omitempty"`
}

EmailResponse represents the JSON response for email submission

type ErrorResponse

type ErrorResponse struct {
	Error   string `json:"error"`
	Code    int    `json:"code"`
	Details string `json:"details,omitempty"`
}

ErrorResponse represents the JSON response for errors

type ReportResponse

type ReportResponse struct {
	Type      string         `json:"type"`
	From      string         `json:"from"`
	To        string         `json:"to"`
	Count     int            `json:"count"`
	Users     []*domain.User `json:"users,omitempty"`
	Generated time.Time      `json:"generated"`
}

ReportResponse represents the JSON response for report requests

type Server

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

Server represents the REST API server

func New

func New(cfg *config.Config, svc ServiceInterface, log *logger.Logger) (*Server, error)

New creates a new API server

func (*Server) Start

func (s *Server) Start() error

Start starts the API server

func (*Server) Stop

func (s *Server) Stop() error

Stop stops the API server

type ServiceInterface

type ServiceInterface interface {
	CheckEmailStatus(ctx any, userID int64, email string) (string, *domain.User, error)
	RedeemCocktail(ctx any, userID int64, email string) (time.Time, error)
	UpdateUser(ctx any, user *domain.User) error
	AddUser(ctx any, user *domain.User) error
	GenerateReport(ctx any, reportType string, fromDate, toDate time.Time) ([]*domain.User, error)
	Close() error
}

ServiceInterface defines the required methods from the service layer

Jump to

Keyboard shortcuts

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