Documentation ¶
Index ¶
- Constants
- Variables
- type AuthMethod
- type Post
- type PostRepository
- func (db *PostRepository) Count(ctx context.Context) (int64, error)
- func (db *PostRepository) Create(ctx context.Context, p *Post) error
- func (db *PostRepository) FindAll(ctx context.Context, page, perPage int) ([]*Post, error)
- func (db *PostRepository) GetBySlug(ctx context.Context, slug string) (*Post, error)
- func (db *PostRepository) Update(ctx context.Context, p *Post) error
- type PostRepositoryInterface
- type Subscriber
- type SubscriberRepositoryInterface
- type SubscribersRepository
- func (db *SubscribersRepository) Create(ctx context.Context, s *Subscriber) error
- func (db *SubscribersRepository) Delete(ctx context.Context, id string) error
- func (db *SubscribersRepository) GetByID(ctx context.Context, id string) (*Subscriber, error)
- func (db *SubscribersRepository) GetConfirmed(ctx context.Context) ([]*Subscriber, error)
- func (db *SubscribersRepository) Update(ctx context.Context, s *Subscriber) error
- type User
- type UserRepository
- type UserRepositoryInterface
Constants ¶
const AvgWordsPerMinute = 250
AvgWordsPerMinute is the average number of words per minute a person can read.
Variables ¶
var ( ErrValidationFailed = errors.New("ERR_VALIDATION_FAILED") ErrNotFound = errors.New("ERR_NOT_FOUND") // ErrNotFound is returned if item is not found ErrDuplicate = errors.New("ERR_DUPLICATE") // ErrDuplicate is returned if item already exists ErrUserLoginRequired = errors.New("ERR_USER_LOGIN_REQUIRED") ErrUserExternalIDRequired = errors.New("ERR_USER_EXTERNAL_ID_REQUIRED") ErrUserAuthMethodRequired = errors.New("ERR_USER_AUTH_METHOD_REQUIRED") ErrFailedToCreateUser = errors.New("ERR_FAILED_TO_CREATE_USER") ErrFailedToGetUser = errors.New("ERR_FAILED_TO_GET_USER") ErrPostURLRequired = errors.New("ERR_POST_URL_REQUIRED") ErrPostTitleRequired = errors.New("ERR_POST_TITLE_REQUIRED") ErrPostDescriptionRequired = errors.New("ERR_POST_DESCRIPTION_REQUIRED") ErrPostContentRequired = errors.New("ERR_POST_CONTENT_REQUIRED") ErrPostWrongKeywordsString = errors.New("ERR_POST_WRONG_KEYWORDS_STRING") ErrPostInvalidSlug = errors.New("ERR_POST_INVALID_SLUG") ErrPostUserIDRequired = errors.New("ERR_POST_USER_ID_REQUIRED") ErrCreateSubscription = errors.New("ERR_CREATE_SUBSCRIPTION") ErrSubscriptionEmailRequired = errors.New("ERR_SUBSCRIPTION_EMAIL_REQUIRED") ErrGetSubscription = errors.New("ERR_GET_SUBSCRIPTION") ErrGetSubscriptionEmails = errors.New("ERR_GET_SUBSCRIPTION_EMAILS") ErrDeleteSubscription = errors.New("ERR_DELETE_SUBSCRIPTION") ErrUpdateSubscription = errors.New("ERR_UPDATE_SUBSCRIPTION") )
Functions ¶
This section is empty.
Types ¶
type AuthMethod ¶
type AuthMethod string
AuthMethod is the method of authentication used by the user.
const (
GitHubAuthMethod AuthMethod = "github"
)
type Post ¶
type Post struct { ID int `json:"id" gorm:"primaryKey;autoIncrement"` Slug string `json:"slug" gorm:"uniqueIndex"` // Slug is the URL friendly version of the title Title string `json:"title"` Description string `json:"description"` Keywords string `json:"keywords"` // Keywords are comma separated Content string `json:"content"` ReadingTime int `json:"reading_time"` // ReadingTime is the estimated time to read the post in seconds UserID int `json:"user_id" gorm:"not null;constraint:OnUpdate:CASCADE;foreignKey:ID;references:ID"` SentToSubscribersAt time.Time `json:"sent_to_subscribers_at" gorm:"default:null"` // If not null, the post was sent CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` }
Post is the model for the post-data.
func (*Post) CountReadingTime ¶
CountReadingTime counts the reading time of the post.
type PostRepository ¶
type PostRepository struct {
// contains filtered or unexported fields
}
PostRepository is the database for the post data.
func NewPostRepository ¶
func NewPostRepository(conn *gorm.DB) *PostRepository
NewPostRepository creates a new PostRepository.
func (*PostRepository) Count ¶
func (db *PostRepository) Count(ctx context.Context) (int64, error)
Count returns the total number of posts.
func (*PostRepository) Create ¶
func (db *PostRepository) Create(ctx context.Context, p *Post) error
Create creates a new Post.
func (*PostRepository) FindAll ¶
FindAll returns all the posts with pagination, sorted by the created time. Selects only the necessary fields to reduce the payload - slug, title, description, keywords, created_at, sent_to_subscribers_at.
type PostRepositoryInterface ¶
type PostRepositoryInterface interface { Create(ctx context.Context, p *Post) error GetBySlug(ctx context.Context, slug string) (*Post, error) FindAll(ctx context.Context, page, perPage int) ([]*Post, error) Update(ctx context.Context, p *Post) error Count(ctx context.Context) (int64, error) }
PostRepositoryInterface is the interface for the PostRepository.
type Subscriber ¶
type Subscriber struct { ID uuid.UUID `json:"id" gorm:"primaryKey;type:uuid"` Email string `json:"email" gorm:"uniqueIndex"` IsConfirmed bool `json:"is_confirmed"` CreatedAt time.Time `json:"created_at"` }
func (*Subscriber) BeforeCreate ¶
func (s *Subscriber) BeforeCreate(_ *gorm.DB) error
func (*Subscriber) Validate ¶
func (s *Subscriber) Validate() error
type SubscriberRepositoryInterface ¶
type SubscriberRepositoryInterface interface { Create(ctx context.Context, s *Subscriber) error Update(ctx context.Context, s *Subscriber) error GetByID(ctx context.Context, id string) (*Subscriber, error) GetConfirmed(ctx context.Context) ([]*Subscriber, error) Delete(ctx context.Context, id string) error }
SubscriberRepositoryInterface is the interface for the subscriber repository.
type SubscribersRepository ¶
type SubscribersRepository struct {
// contains filtered or unexported fields
}
func NewSubscribersRepository ¶
func NewSubscribersRepository(conn *gorm.DB) *SubscribersRepository
func (*SubscribersRepository) Create ¶
func (db *SubscribersRepository) Create(ctx context.Context, s *Subscriber) error
func (*SubscribersRepository) Delete ¶
func (db *SubscribersRepository) Delete(ctx context.Context, id string) error
func (*SubscribersRepository) GetByID ¶
func (db *SubscribersRepository) GetByID(ctx context.Context, id string) (*Subscriber, error)
func (*SubscribersRepository) GetConfirmed ¶
func (db *SubscribersRepository) GetConfirmed(ctx context.Context) ([]*Subscriber, error)
func (*SubscribersRepository) Update ¶
func (db *SubscribersRepository) Update(ctx context.Context, s *Subscriber) error
type User ¶
type User struct { ID int `json:"id" gorm:"primaryKey;autoIncrement"` ExternalID string `json:"external_id" gorm:"uniqueIndex"` // ExternalID is the ID of the user in the AuthMethod Login string `json:"login"` AuthMethod AuthMethod `json:"auth_method"` // AuthMethod is the method of authentication used by the user Posts []Post `json:"posts" gorm:"constraint:OnUpdate:CASCADE,OnDelete:SET NULL;"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` }
User is the model for the user data.
type UserRepository ¶
type UserRepository struct {
// contains filtered or unexported fields
}
UserRepository is the database for the user data.
func NewUserRepository ¶
func NewUserRepository(conn *gorm.DB) *UserRepository
NewUserRepository creates a new UserRepository.
func (*UserRepository) GetByExternalID ¶
GetByExternalID returns the User data by the User.ExternalID.
type UserRepositoryInterface ¶
type UserRepositoryInterface interface { Upsert(ctx context.Context, user *User) error GetByExternalID(ctx context.Context, externalID string) (*User, error) GetByID(ctx context.Context, id int) (*User, error) }
UserRepositoryInterface is the interface for the UserRepository.