models

package
v0.0.0-...-3ee0d69 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Migrate

func Migrate(migrater AutoMigrater)

Migrate migrates the DB

Types

type AutoMigrater

type AutoMigrater interface {
	AutoMigrate(values ...interface{}) *gorm.DB
}

AutoMigrater auto migrate the DB

type AutoMigraterMock

type AutoMigraterMock struct {
	mock.Mock
}

AutoMigraterMock logs errors.

func (*AutoMigraterMock) AutoMigrate

func (m *AutoMigraterMock) AutoMigrate(values ...interface{}) *gorm.DB

AutoMigrate is a method mock

type Config

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

Config is the cmd configuration struct.

func NewConfig

func NewConfig() *Config

NewConfig returns the configuration object.

type Creator

type Creator interface {
	Create(value interface{}) *gorm.DB
}

Creator interface

type Database

type Database interface {
	Creator
	Finder
}

Database interface

type Email

type Email struct {
	gorm.Model
	Email     string `gorm:"type:varchar(100);not null;index:email" valid:"email"`
	ServiceID uint
}

Email is the email struct

type EmailsGatherer

type EmailsGatherer interface {
	GatherEmails(service *Service)
}

EmailsGatherer gather emails

type Finder

type Finder interface {
	Model(value interface{}) *gorm.DB
}

Finder interface

type Image

type Image struct {
	gorm.Model
	Src       string `gorm:"size:255;not null;index:src" valid:"url"`
	ServiceID uint
}

Image is the image struct

type Link struct {
	gorm.Model
	URL       string `gorm:"size:255;not null;" valid:"url"`
	ServiceID uint
}

Link is the link struct

type NameProcessor

type NameProcessor interface {
	ProcessName(service *Service)
}

NameProcessor processes names

type Phone

type Phone struct {
	gorm.Model
	Phone     string `gorm:"type:varchar(100);not null;index:phone"`
	ServiceID uint
}

Phone is the email struct

type PhonesGatherer

type PhonesGatherer interface {
	GatherPhones(service *Service)
}

PhonesGatherer gather phones

type Service

type Service struct {
	gorm.Model
	URL         string           `gorm:"size:255;not null;unique_index;" valid:"url"`
	Source      string           `gorm:"size:255;not null;index:source;" valid:"required"`
	Title       string           `gorm:"size:255;not null;" valid:"required"`
	Description string           `gorm:"type:text;index:description;"`
	FullName    string           `gorm:"type:varchar(255);"`
	FirstName   string           `gorm:"type:varchar(255);"`
	MiddleName  string           `gorm:"type:varchar(255);"`
	LastName    string           `gorm:"type:varchar(255);"`
	Country     string           `gorm:"type:varchar(255);"`
	City        string           `gorm:"type:varchar(255);"`
	Address     string           `gorm:"index:addr"`
	Avatar      string           `gorm:"size:255;" valid:"url,optional"`
	Phones      []Phone          `gorm:"foreignkey:ServiceID"`
	Emails      []Email          `gorm:"foreignkey:ServiceID"`
	Images      []Image          `gorm:"foreignkey:ServiceID"`
	Links       []Link           `gorm:"foreignkey:ServiceID"`
	Processor   ServiceProcessor `gorm:"-"`
}

Service is the service struct

func (*Service) BeforeSave

func (s *Service) BeforeSave() (err error)

BeforeSave runs before saving the object

func (*Service) Validate

func (s *Service) Validate(db *gorm.DB)

Validate validates struct

type ServiceProcessor

type ServiceProcessor interface {
	NameProcessor
	EmailsGatherer
	PhonesGatherer
}

ServiceProcessor interface

type ServiceProcessorMock

type ServiceProcessorMock struct {
	mock.Mock
}

ServiceProcessorMock is a mock struct

func (*ServiceProcessorMock) GatherEmails

func (s *ServiceProcessorMock) GatherEmails(service *Service)

GatherEmails is a method mock

func (*ServiceProcessorMock) GatherPhones

func (s *ServiceProcessorMock) GatherPhones(service *Service)

GatherPhones is a method mock

func (*ServiceProcessorMock) ProcessName

func (s *ServiceProcessorMock) ProcessName(service *Service)

ProcessName is a method mock

type ServiceRepository

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

ServiceRepository is the service repository struct

func NewServiceRepository

func NewServiceRepository(database Database) *ServiceRepository

NewServiceRepository return a new ServiceRepository

func (*ServiceRepository) AppendImage

func (r *ServiceRepository) AppendImage(src string, service *Service)

AppendImage adds an image to the service.

func (r *ServiceRepository) AppendLink(url string, service *Service)

AppendLink adds a link to the service.

func (*ServiceRepository) AppendPhone

func (r *ServiceRepository) AppendPhone(phone string, service *Service)

AppendPhone adds a phone to the service.

func (*ServiceRepository) CreateService

func (r *ServiceRepository) CreateService(service *Service) []error

CreateService creates a new service

func (*ServiceRepository) GatherEmails

func (r *ServiceRepository) GatherEmails(service *Service)

GatherEmails tries to get the emails from the description

func (*ServiceRepository) GatherPhones

func (r *ServiceRepository) GatherPhones(service *Service)

GatherPhones tries to get the phones from the description

func (*ServiceRepository) IsServiceWithURLExists

func (r *ServiceRepository) IsServiceWithURLExists(url string) bool

IsServiceWithURLExists checks if a service with the provided URL exists

func (*ServiceRepository) NewService

func (r *ServiceRepository) NewService(url, source, title string) *Service

NewService return a service object

func (*ServiceRepository) ProcessName

func (r *ServiceRepository) ProcessName(service *Service)

ProcessName tries to get the first name and last name from the full name

Jump to

Keyboard shortcuts

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