This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"kontor-api-gin/internal/helpers"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Article struct {
|
||||
ID string `gorm:"type:string;primary_key;" json:"id"`
|
||||
CreatedAt time.Time `gorm:"column:created_date" json:"created_date"`
|
||||
UpdatedAt time.Time `gorm:"column:last_modified_date" json:"last_modified_date"`
|
||||
DeletedAt *time.Time `gorm:"column:deleted_date" json:"deleted_date"`
|
||||
Version int `gorm:"default:0" json:"version"`
|
||||
Title string `gorm:"uniqueIndex" json:"title"`
|
||||
ArticleAuthors []ArticleAuthor `gorm:"foreignKey:ArticleID" json:"article_authors"`
|
||||
}
|
||||
|
||||
func (article *Article) TableName() string {
|
||||
return "article"
|
||||
}
|
||||
|
||||
type ArticleDTO struct {
|
||||
ID string `json:"id" binding:"required"`
|
||||
CreatedAt helpers.KontorTime `json:"created_date"`
|
||||
UpdatedAt helpers.KontorTime `json:"last_modified_date"`
|
||||
DeletedAt *time.Time `json:"deleted_date,omitempty"`
|
||||
Version int `json:"version"`
|
||||
Title string `json:"title"`
|
||||
}
|
||||
|
||||
func ConvertArticlesToDtos(articles []Article) []ArticleDTO {
|
||||
dtos := make([]ArticleDTO, len(articles))
|
||||
for i, article := range articles {
|
||||
dtos[i] = ArticleDTO{
|
||||
ID: article.ID,
|
||||
CreatedAt: helpers.KontorTime{Time: article.CreatedAt},
|
||||
UpdatedAt: helpers.KontorTime{Time: article.UpdatedAt},
|
||||
DeletedAt: article.DeletedAt,
|
||||
Version: article.Version,
|
||||
Title: article.Title,
|
||||
}
|
||||
}
|
||||
return dtos
|
||||
}
|
||||
|
||||
type CreateArticleDTO struct {
|
||||
Title string `json:"title" binding:"required"`
|
||||
}
|
||||
|
||||
type UpdateArticleDTO struct {
|
||||
Title *string `json:"title,omitempty" binding:"omitempty"`
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"kontor-api-gin/internal/helpers"
|
||||
"time"
|
||||
)
|
||||
|
||||
type ArticleAuthor struct {
|
||||
ID string `gorm:"type:string;primary_key;" json:"id"`
|
||||
CreatedAt time.Time `gorm:"column:created_date" json:"created_date"`
|
||||
UpdatedAt time.Time `gorm:"column:last_modified_date" json:"last_modified_date"`
|
||||
DeletedAt *time.Time `gorm:"column:deleted_date" json:"deleted_date"`
|
||||
Version int `gorm:"default:0" json:"version"`
|
||||
ArticleID *string `gorm:"column:article_id" json:"article_id"`
|
||||
Article *Article `gorm:"foreignKey:ArticleID" json:"article"`
|
||||
AuthorID *string `form:"column:author_id" json:"author_id"`
|
||||
Author *Author `gorm:"foreignKey:AuthorID" json:"author"`
|
||||
}
|
||||
|
||||
func (article_author *ArticleAuthor) TableName() string {
|
||||
return "article_author"
|
||||
}
|
||||
|
||||
type ArticleAuthorDTO struct {
|
||||
ID string `json:"id" binding:"required"`
|
||||
CreatedAt helpers.KontorTime `json:"created_date"`
|
||||
UpdatedAt helpers.KontorTime `json:"last_modified_date"`
|
||||
DeletedAt *time.Time `json:"deleted_date"`
|
||||
Version int `json:"version"`
|
||||
ArticleID *string `json:"article_id"`
|
||||
AuthorID *string `json:"author_id"`
|
||||
}
|
||||
|
||||
func ConvertArticleAuthorsToDtos(article_authors []ArticleAuthor) []ArticleAuthorDTO {
|
||||
dtos := make([]ArticleAuthorDTO, len(article_authors))
|
||||
for i, article_author := range article_authors {
|
||||
dtos[i] = ArticleAuthorDTO{
|
||||
ID: article_author.ID,
|
||||
CreatedAt: helpers.KontorTime{Time: article_author.CreatedAt},
|
||||
UpdatedAt: helpers.KontorTime{Time: article_author.UpdatedAt},
|
||||
DeletedAt: article_author.DeletedAt,
|
||||
Version: article_author.Version,
|
||||
ArticleID: article_author.ArticleID,
|
||||
AuthorID: article_author.AuthorID,
|
||||
}
|
||||
}
|
||||
return dtos
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"kontor-api-gin/internal/helpers"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Author struct {
|
||||
ID string `gorm:"type:string;primary_key;" json:"id"`
|
||||
CreatedAt time.Time `gorm:"column:created_date" json:"created_date"`
|
||||
UpdatedAt time.Time `gorm:"column:last_modified_date" json:"last_modified_date"`
|
||||
DeletedAt *time.Time `gorm:"column:deleted_date" json:"deleted_date"`
|
||||
Version int `gorm:"default:0" json:"version"`
|
||||
FirstName string `gorm:"column:first_name" json:"first_name"`
|
||||
LastName string `gorm:"column:last_name" json:"last_name"`
|
||||
ArticleAuthors []ArticleAuthor `gorm:"foreignKey:AuthorID" json:"article_authors"`
|
||||
BookAuthors []BookAuthor `gorm:"foreignKey:AuthorID" json:"book_authors"`
|
||||
}
|
||||
|
||||
func (author *Author) TableName() string {
|
||||
return "author"
|
||||
}
|
||||
|
||||
type AuthorDTO struct {
|
||||
ID string `json:"id" binding:"required"`
|
||||
CreatedAt helpers.KontorTime `json:"created_date"`
|
||||
UpdatedAt helpers.KontorTime `json:"last_modified_date"`
|
||||
DeletedAt *time.Time `json:"deleted_date,omitempty"`
|
||||
Version int `json:"version"`
|
||||
FirstName string `json:"first_name"`
|
||||
LastName string `json:"last_name"`
|
||||
}
|
||||
|
||||
func ConvertAuthorsToDtos(authors []Author) []AuthorDTO {
|
||||
dtos := make([]AuthorDTO, len(authors))
|
||||
for i, author := range authors {
|
||||
dtos[i] = AuthorDTO{
|
||||
ID: author.ID,
|
||||
CreatedAt: helpers.KontorTime{Time: author.CreatedAt},
|
||||
UpdatedAt: helpers.KontorTime{Time: author.UpdatedAt},
|
||||
DeletedAt: author.DeletedAt,
|
||||
Version: author.Version,
|
||||
FirstName: author.FirstName,
|
||||
LastName: author.LastName,
|
||||
}
|
||||
}
|
||||
return dtos
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"kontor-api-gin/internal/helpers"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Book struct {
|
||||
ID string `gorm:"type:string;primary_key;" json:"id"`
|
||||
CreatedAt time.Time `gorm:"column:created_date" json:"created_date"`
|
||||
UpdatedAt time.Time `gorm:"column:last_modified_date" json:"last_modified_date"`
|
||||
DeletedAt *time.Time `gorm:"column:deleted_date" json:"deleted_date"`
|
||||
Version int `gorm:"default:0" json:"version"`
|
||||
ISBN string `gorm:"column:isbn;uniqueIndex" json:"isbn"`
|
||||
Title string `gorm:"column:title" json:"title"`
|
||||
Year int `gorm:"column:year" json:"year"`
|
||||
PublisherID string `gorm:"column:publisher_id" json:"publisher_id"`
|
||||
Publisher BookshelfPublisher `gorm:"foreignKey:PublisherID" json:"publisher"`
|
||||
BookAuthors []BookAuthor `gorm:"foreignKey:BookID" json:"book_authors"`
|
||||
}
|
||||
|
||||
func (book *Book) TableName() string {
|
||||
return "book"
|
||||
}
|
||||
|
||||
type BookDTO struct {
|
||||
ID string `json:"id" binding:"required"`
|
||||
CreatedAt helpers.KontorTime `json:"created_date"`
|
||||
UpdatedAt helpers.KontorTime `json:"last_modified_date"`
|
||||
DeletedAt *time.Time `json:"deleted_date,omitempty"`
|
||||
Version int `json:"version"`
|
||||
Title string `json:"title"`
|
||||
}
|
||||
|
||||
func ConvertBooksToDtos(books []Book) []BookDTO {
|
||||
dtos := make([]BookDTO, len(books))
|
||||
for i, book := range books {
|
||||
dtos[i] = BookDTO{
|
||||
ID: book.ID,
|
||||
CreatedAt: helpers.KontorTime{Time: book.CreatedAt},
|
||||
UpdatedAt: helpers.KontorTime{Time: book.UpdatedAt},
|
||||
DeletedAt: book.DeletedAt,
|
||||
Version: book.Version,
|
||||
Title: book.Title,
|
||||
}
|
||||
}
|
||||
return dtos
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"kontor-api-gin/internal/helpers"
|
||||
"time"
|
||||
)
|
||||
|
||||
type BookAuthor struct {
|
||||
ID string `gorm:"type:string;primary_key;" json:"id"`
|
||||
CreatedAt time.Time `gorm:"column:created_date" json:"created_date"`
|
||||
UpdatedAt time.Time `gorm:"column:last_modified_date" json:"last_modified_date"`
|
||||
DeletedAt *time.Time `gorm:"column:deleted_date" json:"deleted_date"`
|
||||
Version int `gorm:"default:0" json:"version"`
|
||||
BookID *string `gorm:"column:book_id" json:"book_id"`
|
||||
Book *Book `gorm:"foreignKey:BookID" json:"book"`
|
||||
AuthorID *string `form:"column:author_id" json:"author_id"`
|
||||
Author *Author `gorm:"foreignKey:AuthorID" json:"author"`
|
||||
}
|
||||
|
||||
func (book_author *BookAuthor) TableName() string {
|
||||
return "book_author"
|
||||
}
|
||||
|
||||
type BookAuthorDTO struct {
|
||||
ID string `json:"id" binding:"required"`
|
||||
CreatedAt helpers.KontorTime `json:"created_date"`
|
||||
UpdatedAt helpers.KontorTime `json:"last_modified_date"`
|
||||
DeletedAt *time.Time `json:"deleted_date"`
|
||||
Version int `json:"version"`
|
||||
BookID *string `json:"book_id"`
|
||||
AuthorID *string `json:"author_id"`
|
||||
}
|
||||
|
||||
func ConvertBookAuthorsToDtos(book_authors []BookAuthor) []BookAuthorDTO {
|
||||
dtos := make([]BookAuthorDTO, len(book_authors))
|
||||
for i, book_author := range book_authors {
|
||||
dtos[i] = BookAuthorDTO{
|
||||
ID: book_author.ID,
|
||||
CreatedAt: helpers.KontorTime{Time: book_author.CreatedAt},
|
||||
UpdatedAt: helpers.KontorTime{Time: book_author.UpdatedAt},
|
||||
DeletedAt: book_author.DeletedAt,
|
||||
Version: book_author.Version,
|
||||
BookID: book_author.BookID,
|
||||
AuthorID: book_author.AuthorID,
|
||||
}
|
||||
}
|
||||
return dtos
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"kontor-api-gin/internal/helpers"
|
||||
"time"
|
||||
)
|
||||
|
||||
type BookshelfPublisher struct {
|
||||
ID string `gorm:"type:string;primary_key;"`
|
||||
CreatedAt time.Time `gorm:"column:created_date" json:"created_date"`
|
||||
UpdatedAt time.Time `gorm:"column:last_modified_date" json:"last_modified_date"`
|
||||
DeletedAt *time.Time `gorm:"column:deleted_date" json:"deleted_date"`
|
||||
Version int `gorm:"default:0" json:"version"`
|
||||
Name string `gorm:"uniqueIndex" json:"name"`
|
||||
Books []Book `gorm:"foreignKey:PublisherID"`
|
||||
}
|
||||
|
||||
func (publisher *BookshelfPublisher) TableName() string {
|
||||
return "bookshelf_publisher"
|
||||
}
|
||||
|
||||
type BookshelfPublisherDTO struct {
|
||||
ID string `json:"id" binding:"required"`
|
||||
CreatedAt helpers.KontorTime `json:"created_date"`
|
||||
UpdatedAt helpers.KontorTime `json:"last_modified_date"`
|
||||
DeletedAt *time.Time `json:"deleted_date,omitempty"`
|
||||
Version int `json:"version"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
func ConvertBookshelfPublishersToDtos(publishers []BookshelfPublisher) []BookshelfPublisherDTO {
|
||||
dtos := make([]BookshelfPublisherDTO, len(publishers))
|
||||
for i, publisher := range publishers {
|
||||
dtos[i] = BookshelfPublisherDTO{
|
||||
ID: publisher.ID,
|
||||
CreatedAt: helpers.KontorTime{Time: publisher.CreatedAt},
|
||||
UpdatedAt: helpers.KontorTime{Time: publisher.UpdatedAt},
|
||||
DeletedAt: publisher.DeletedAt,
|
||||
Version: publisher.Version,
|
||||
Name: publisher.Name,
|
||||
}
|
||||
}
|
||||
return dtos
|
||||
}
|
||||
Reference in New Issue
Block a user