domain

package
v0.0.0-...-91b1530 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2023 License: CC0-1.0 Imports: 5 Imported by: 0

Documentation

Overview

【Go】Gormの使い方(CRUD) https://zenn.dev/a_ichi1/articles/4b113d4c46857a

Index

Constants

This section is empty.

Variables

View Source
var (
	// labstack/echo Variables
	// https://pkg.go.dev/github.com/labstack/echo#pkg-variables
	// Any Internal Server Error occurs
	ErrInternalServerError = errors.New("internal server error")
	// The requested item does not exist
	ErrNotFound = errors.New("your requested item is not found")
	// The current action already exists
	ErrConflict = errors.New("your item already exist")
	// The request-body is not valid
	ErrBadRequestBodyInput = errors.New("given param is not valid")
	// The param is not valid
	ErrBadParamInput      = errors.New("given param is not valid")
	ErrRowsAffectedNotOne = errors.New("the number of affected rows is not 1")
)

Functions

This section is empty.

Types

type Article

type Article struct {
	ID        uuid.UUID `gorm:"type:char(36);primary_key;not null" param:"id" json:"id"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
	EventId   string    `gorm:"type:char(36);not null" validate:"required" json:"event_id"`
	Title     string    `gorm:"type:text" validate:"required" json:"title"`
	Body      string    `gorm:"type:text" validate:"required" json:"body"`
	Public    bool      `gorm:"type:boolean" validate:"required" json:"public"`
	// belongs to
	UserID uuid.UUID `gorm:"type:char(36);not null" json:"user_id"`
	User   User      `gorm:"PRELOAD:false" json:"user"`
	// has one
	ArticleGameContent ArticleGameContent `gorm:"foreignKey:ID" json:"article_game_content"`
	// has many
	ArticleOwners    []ArticleOwner    `json:"article_owners"`
	ArticleTags      []ArticleTag      `json:"article_tags"`
	ArticleComments  []ArticleComment  `json:"article_comments"`
	ArticleImageURLs []ArticleImageURL `json:"article_image_urls"`
}

https://stackoverflow.com/questions/66810464/unsupported-relations-in-gorm https://zenn.dev/skanehira/articles/2020-09-19-go-echo-bind-tips

func (*Article) TableName

func (*Article) TableName() string

type ArticleComment

type ArticleComment struct {
	ID        uuid.UUID `gorm:"type:char(36);primaryKey;not null" json:"id"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
	ArticleID uuid.UUID `gorm:"type:char(36);not null" json:"article_id"`
	Body      string    `gorm:"type:text" validate:"required" json:"body"`
	Rate      int       `validate:"required,gte=1,lte=5" json:"rate"` // 1-5
}

func (*ArticleComment) TableName

func (*ArticleComment) TableName() string

type ArticleCommentRepository

type ArticleCommentRepository interface {
	GetByID(id uuid.UUID) (ArticleComment, error)
	GetByArticleID(id uuid.UUID) ([]ArticleComment, error)
	Insert(ac *ArticleComment) error
	Update(ac *ArticleComment) error
	Delete(id uuid.UUID) error
	DeleteByArticleID(id uuid.UUID) error
}

type ArticleCommentUsecase

type ArticleCommentUsecase interface {
	GetByID(c context.Context, id uuid.UUID) (ArticleComment, error)
	GetByArticleID(c context.Context, id uuid.UUID) ([]ArticleComment, error)
	Insert(c context.Context, ac *ArticleComment) error
	Update(c context.Context, ac *ArticleComment) error
	Delete(c context.Context, id uuid.UUID) error
	DeleteByArticleID(c context.Context, id uuid.UUID) error
}

type ArticleGameContent

type ArticleGameContent struct {
	// ArticleID
	ID        uuid.UUID `gorm:"type:char(36);primaryKey;not null" json:"id"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
	ExecPath  string    `gorm:"type:text" validate:"required" json:"exec_path"`
	ZipURL    string    `gorm:"type:text" validate:"required" json:"zip_url"`
}

func (*ArticleGameContent) TableName

func (*ArticleGameContent) TableName() string

type ArticleGameContentRepository

type ArticleGameContentRepository interface {
	GetByID(id uuid.UUID) (ArticleGameContent, error)
	GetByArticleID(id uuid.UUID) (ArticleGameContent, error)
	Insert(agc *ArticleGameContent) error
	Update(agc *ArticleGameContent) error
	Delete(id uuid.UUID) error
}

type ArticleImageURL

type ArticleImageURL struct {
	ID        uuid.UUID `gorm:"type:char(36);primaryKey;not null" json:"id"`
	ArticleID uuid.UUID `gorm:"type:char(36);not null" json:"article_id"`
	ImageURL  string    `gorm:"type:text" validate:"required" json:"image_url"`
}

func (*ArticleImageURL) TableName

func (*ArticleImageURL) TableName() string

type ArticleImageURLRepository

type ArticleImageURLRepository interface {
	GetByID(id uuid.UUID) (ArticleImageURL, error)
	GetByArticleID(id uuid.UUID) ([]ArticleImageURL, error)
	Insert(aiu *ArticleImageURL) error
	Update(aiu *ArticleImageURL) error
	Delete(id uuid.UUID) error
}

type ArticleOwner

type ArticleOwner struct {
	ID        uuid.UUID `gorm:"type:char(36);primaryKey;not null" json:"id"`
	ArticleID uuid.UUID `gorm:"type:char(36);not null" json:"article_id"`
	// has one
	// User User `gorm:"foreignKey:ID" json:"-"`
	UserID uuid.UUID `gorm:"type:char(36);not null" json:"user_id"`
	User   User      `gorm:"foreignKey:UserID" json:"user"`
}

func (*ArticleOwner) TableName

func (*ArticleOwner) TableName() string

type ArticleOwnerRepository

type ArticleOwnerRepository interface {
	GetByID(id uuid.UUID) (ArticleOwner, error)
	GetByArticleID(id uuid.UUID) ([]ArticleOwner, error)
	Insert(ao *ArticleOwner) error
	Update(ao *ArticleOwner) error
	Delete(id uuid.UUID) error
}

type ArticleRepository

type ArticleRepository interface {
	Fetch(cursor string, numString string) (articles []Article, nextCursor string, err error)
	GetByID(id uuid.UUID) (Article, error)
	GetByTitle(title string) (Article, error)
	Insert(ar *Article) error
	Update(ar *Article) error
	Delete(id uuid.UUID) error
}

type ArticleTag

type ArticleTag struct {
	ID        uuid.UUID `gorm:"type:char(36);primaryKey;not null" json:"id"`
	ArticleID uuid.UUID `gorm:"type:char(36);not null" json:"article_id"`
	Name      string    `gorm:"type:text" validate:"required" json:"name"`
}

func (*ArticleTag) TableName

func (*ArticleTag) TableName() string

type ArticleTagRepository

type ArticleTagRepository interface {
	GetByID(id uuid.UUID) (ArticleTag, error)
	GetByArticleID(id uuid.UUID) ([]ArticleTag, error)
	Insert(at *ArticleTag) error
	Update(at *ArticleTag) error
	Delete(id uuid.UUID) error
}

type ArticleUsecase

type ArticleUsecase interface {
	Fetch(c context.Context, cursor string, numString string) ([]Article, string, error)
	GetByID(c context.Context, id uuid.UUID) (Article, error)
	GetByTitle(c context.Context, title string) (Article, error)
	Insert(c context.Context, ar *Article) error
	Update(c context.Context, ar *Article) error
	Delete(c context.Context, id uuid.UUID) error
}

type Migration

type Migration struct {
	Migrate  func(db *gorm.DB) error
	Rollback func(db *gorm.DB) error
}

type User

type User struct {
	ID        uuid.UUID `gorm:"type:char(36);primary_key;not null" json:"id"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
	Role      string    `gorm:"type:text" validate:"required" json:"role"`
	Name      string    `gorm:"type:text" validate:"required" json:"name"`
}

func (*User) TableName

func (*User) TableName() string

type UserRepository

type UserRepository interface {
	Fetch(cursor string, numString string) ([]User, string, error)
	GetByID(id uuid.UUID) (User, error)
	Insert(u *User) error
	Update(u *User) error
}

type UserUsecase

type UserUsecase interface {
	Fetch(c context.Context, cursor string, numString string) ([]User, string, error)
	GetByID(c context.Context, id uuid.UUID) (User, error)
	Insert(c context.Context, u *User) error
	Update(c context.Context, u *User) error
}

Jump to

Keyboard shortcuts

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