From 3252f4cfe0f112aaa23dcfb8cdfc31d61bfe4053 Mon Sep 17 00:00:00 2001 From: Dumindu Madunuwan Date: Sat, 27 Jun 2026 22:14:08 +0800 Subject: [PATCH] format struct-tag - remove Books --- app/book/bookrepo/repository.go | 6 +++--- app/book/repository.go | 2 +- model/book.go | 23 ++++++++++------------- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/app/book/bookrepo/repository.go b/app/book/bookrepo/repository.go index b856788..a2c7280 100644 --- a/app/book/bookrepo/repository.go +++ b/app/book/bookrepo/repository.go @@ -21,7 +21,7 @@ func IBookRepo[T any](db *gorm.DB, opts ...clause.Expression) _IBookRepoInterfac type _IBookRepoInterface[T any] interface { typed.Interface[T] - ListBooks(ctx context.Context, limit int64, offset int64) (model.Books, error) + ListBooks(ctx context.Context, limit int64, offset int64) ([]*model.Book, error) CreateBook(ctx context.Context, data *model.Book) (*model.Book, error) ReadBook(ctx context.Context, id uuid.UUID) (*model.Book, error) UpdateBook(ctx context.Context, data *model.Book) (*model.Book, error) @@ -32,14 +32,14 @@ type _IBookRepoImpl[T any] struct { typed.Interface[T] } -func (e _IBookRepoImpl[T]) ListBooks(ctx context.Context, limit int64, offset int64) (model.Books, error) { +func (e _IBookRepoImpl[T]) ListBooks(ctx context.Context, limit int64, offset int64) ([]*model.Book, error) { var sb strings.Builder _params := make([]any, 0, 2) sb.WriteString("SELECT * FROM books LIMIT ? OFFSET ?") _params = append(_params, limit, offset) - var result model.Books + var result []*model.Book err := e.Raw(sb.String(), _params...).Scan(ctx, &result) return result, err } diff --git a/app/book/repository.go b/app/book/repository.go index 73cb3c7..db103eb 100644 --- a/app/book/repository.go +++ b/app/book/repository.go @@ -11,7 +11,7 @@ import ( //go:generate go tool gorm gen -i repository.go -o bookrepo type IBookRepo interface { // SELECT * FROM books LIMIT @limit OFFSET @offset - ListBooks(ctx context.Context, limit int64, offset int64) (model.Books, error) + ListBooks(ctx context.Context, limit int64, offset int64) ([]*model.Book, error) // INSERT INTO books (id, created_at, updated_at, title, author, published_date, image_url, description) VALUES (@data.ID, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, @data.Title, @data.Author, @data.PublishedDate, @data.ImageURL, @data.Description) // RETURNING * diff --git a/model/book.go b/model/book.go index 54c3bc9..c4c23cf 100644 --- a/model/book.go +++ b/model/book.go @@ -6,16 +6,13 @@ import ( "github.com/google/uuid" ) -type ( - Books []*Book - Book struct { - ID uuid.UUID `json:"id" gorm:"primarykey"` - Title string `json:"title"` - Author string `json:"author"` - PublishedDate time.Time `json:"published_date,format:'2006-01-02'"` - ImageURL string `json:"image_url"` - Description string `json:"description"` - CreatedAt time.Time `json:"created_at,format:RFC3339" gorm:"autoCreateTime"` - UpdatedAt time.Time `json:"updated_at,format:RFC3339" gorm:"autoUpdateTime"` - } -) +type Book struct { + ID uuid.UUID `json:"id" gorm:"primarykey"` + Title string `json:"title"` + Author string `json:"author"` + PublishedDate time.Time `json:"published_date,format:'2006-01-02'"` + ImageURL string `json:"image_url"` + Description string `json:"description"` + CreatedAt time.Time `json:"created_at,format:RFC3339" gorm:"autoCreateTime"` + UpdatedAt time.Time `json:"updated_at,format:RFC3339" gorm:"autoUpdateTime"` +}