donation

package
v0.0.0-...-a40a463 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterHandlers

func RegisterHandlers(r *routing.RouteGroup, service Service, authHandler routing.Handler, logger log.Logger)

RegisterHandlers sets up the routing of the HTTP handlers.

Types

type CreateDonationRequest

type CreateDonationRequest struct {
	Email         string    `json:"email"`
	MakeAnonymous bool      `json:"make_anonymous"`
	Recurring     bool      `json:"recurring"`
	Campaign      string    `json:"campaign"`
	Amount        float32   `json:"amount"`
	City          string    `json:"city"`
	State         string    `json:"state"`
	FirstDonation bool      `json:"first_donation"`
	DonatedAt     time.Time `json:"donated_at"`
}

CreateDonationRequest represents an donation creation request.

func (CreateDonationRequest) Validate

func (m CreateDonationRequest) Validate() error

Validate validates the CreateDonationRequest fields.

type Donation

type Donation struct {
	entity.Donation
}

Donation represents the data about an donation.

type MonthlyMemberResponse

type MonthlyMemberResponse struct {
	Month       time.Time `json:"month"`
	MemberCount int       `json:"member_count"`
}

CreateDonationRequest represents an donation creation request.

type Repository

type Repository interface {
	// Get returns the donation with the specified donation ID.
	Get(ctx context.Context, id string) (entity.Donation, error)
	// Count returns the number of donations.
	Count(ctx context.Context, filter map[string]interface{}) (int, error)
	// Query returns the list of donations with the given offset and limit.
	Query(ctx context.Context, offset, limit int) ([]entity.Donation, error)
	// Create saves a new donation in the storage.
	Create(ctx context.Context, donation entity.Donation) error
	// Update updates the donation with given ID in the storage.
	Update(ctx context.Context, donation entity.Donation) error
	// Delete removes the donation with given ID from the storage.
	Delete(ctx context.Context, id string) error

	CountMonthlyMembers(ctx context.Context, startRange time.Time, endRange time.Time) (int, error)
	GetMonthlySums(ctx context.Context, startRange time.Time, endRange time.Time) (int, error)
}

Repository encapsulates the logic to access donations from the data source.

func NewRepository

func NewRepository(db *dbcontext.DB, logger log.Logger) Repository

NewRepository creates a new donation repository

type Service

type Service interface {
	Get(ctx context.Context, id string) (Donation, error)
	Query(ctx context.Context, offset, limit int) ([]Donation, error)
	Count(ctx context.Context, filter map[string]interface{}) (int, error)
	Create(ctx context.Context, input CreateDonationRequest) (Donation, error)
	Update(ctx context.Context, id string, input UpdateDonationRequest) (Donation, error)
	Delete(ctx context.Context, id string) (Donation, error)

	CountMonthlyMembers(ctx context.Context, dateinput string) (MonthlyMemberResponse, error)
	GetMonthlySums(ctx context.Context, dateinput string) (MonthlyMemberResponse, error)
}

Service encapsulates usecase logic for donations.

func NewService

func NewService(repo Repository, logger log.Logger) Service

NewService creates a new donation service.

type UpdateDonationRequest

type UpdateDonationRequest struct {
	Email         string    `json:"email"`
	MakeAnonymous bool      `json:"make_anonymous"`
	Recurring     bool      `json:"recurring"`
	Campaign      string    `json:"campaign"`
	Amount        float32   `json:"amount"`
	City          string    `json:"city"`
	State         string    `json:"state"`
	FirstDonation bool      `json:"first_donation"`
	DonatedAt     time.Time `json:"donated_at"`
}

UpdateDonationRequest represents an donation update request.

func (UpdateDonationRequest) Validate

func (m UpdateDonationRequest) Validate() error

Validate validates the CreateDonationRequest fields.

Jump to

Keyboard shortcuts

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