@@ -7,9 +7,15 @@ import (
77)
88
99type Book struct {
10- ID uint `json:"id" gorm:"primaryKey"`
10+ ID uint `json:"id" gorm:"primaryKey"`
11+
12+ // External API fields
13+ ExternalID * string `json:"external_id,omitempty" gorm:"index"`
14+ Source * string `json:"source,omitempty" gorm:"size:50"`
15+
16+ // Book metadata
1117 Title string `json:"title" gorm:"size:255;not null"`
12- Author * string `json:"author,omitempty" gorm:"size:255"`
18+ Author * string `json:"author,omitempty" gorm:"size:255"`
1319 CoverURL * string `json:"cover_url,omitempty" gorm:"type:text"`
1420 Genre * string `json:"genre,omitempty" gorm:"size:100"`
1521 Pages * int `json:"pages,omitempty"`
@@ -18,25 +24,71 @@ type Book struct {
1824 Description * string `json:"description,omitempty" gorm:"type:text"`
1925 Rating * float32 `json:"rating,omitempty" gorm:"type:decimal(2,1)" validate:"omitempty,gte=0,lte=5"`
2026
27+ // Platform-specific analytics (simplified)
28+ ReadCount int `json:"read_count" gorm:"default:0"`
29+ LocalRating * float32 `json:"local_rating,omitempty" gorm:"type:decimal(2,1)"`
30+ RatingCount int `json:"rating_count" gorm:"default:0"`
31+ IsClubFavorite bool `json:"is_club_favorite" gorm:"default:false"`
32+ IsTrending bool `json:"is_trending" gorm:"default:false"`
33+
34+ // Cache management
35+ CachedAt * time.Time `json:"cached_at,omitempty"`
36+ LastAccessed * time.Time `json:"last_accessed,omitempty"`
37+
2138 CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
2239 UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"`
2340 DeletedAt gorm.DeletedAt `json:"-" gorm:"index"`
2441}
2542
43+ type ExternalBook struct {
44+ ExternalID string `json:"external_id"`
45+ Source string `json:"source"`
46+ Title string `json:"title"`
47+ Author * string `json:"author,omitempty"`
48+ CoverURL * string `json:"cover_url,omitempty"`
49+ Genre * string `json:"genre,omitempty"`
50+ Pages * int `json:"pages,omitempty"`
51+ PublishedYear * int `json:"published_year,omitempty"`
52+ ISBN * string `json:"isbn,omitempty"`
53+ Description * string `json:"description,omitempty"`
54+ Rating * float32 `json:"rating,omitempty"`
55+ }
56+
57+ func (eb * ExternalBook ) ToBook () * Book {
58+ now := time .Now ()
59+ return & Book {
60+ ExternalID : & eb .ExternalID ,
61+ Source : & eb .Source ,
62+ Title : eb .Title ,
63+ Author : eb .Author ,
64+ CoverURL : eb .CoverURL ,
65+ Genre : eb .Genre ,
66+ Pages : eb .Pages ,
67+ PublishedYear : eb .PublishedYear ,
68+ ISBN : eb .ISBN ,
69+ Description : eb .Description ,
70+ Rating : eb .Rating ,
71+ CachedAt : & now ,
72+ LastAccessed : & now ,
73+ }
74+ }
75+
2676type CreateBookRequest struct {
2777 Title string `json:"title" validate:"required,min=1,max=255"`
28- Author * string `json:"author,omitempty" validate:"omitempty,min=1,max=255"`
78+ Author * string `json:"author,omitempty" validate:"omitempty,min=1,max=255"`
2979 CoverURL * string `json:"cover_url,omitempty" validate:"omitempty,url"`
3080 Genre * string `json:"genre,omitempty" validate:"omitempty,min=1,max=100"`
3181 Pages * int `json:"pages,omitempty" validate:"omitempty,gte=1"`
3282 PublishedYear * int `json:"published_year,omitempty" validate:"omitempty,gte=0,lte=2100"`
3383 ISBN * string `json:"isbn,omitempty" validate:"omitempty,isbn"`
3484 Description * string `json:"description,omitempty" validate:"omitempty,min=1"`
85+ ExternalID * string `json:"external_id,omitempty"`
86+ Source * string `json:"source,omitempty"`
3587}
3688
3789type UpdateBookRequest struct {
3890 Title * string `json:"title,omitempty" validate:"omitempty,min=1,max=255"`
39- Author * string `json:"author,omitempty" validate:"omitempty,min=1,max=255"`
91+ Author * string `json:"author,omitempty" validate:"omitempty,min=1,max=255"`
4092 CoverURL * string `json:"cover_url,omitempty" validate:"omitempty,url"`
4193 Genre * string `json:"genre,omitempty" validate:"omitempty,min=1,max=100"`
4294 Pages * int `json:"pages,omitempty" validate:"omitempty,gte=1"`
@@ -46,35 +98,61 @@ type UpdateBookRequest struct {
4698 Rating * float32 `json:"rating,omitempty" validate:"omitempty,gte=0,lte=5"`
4799}
48100
101+ type BookSearchRequest struct {
102+ Query string `json:"query" form:"q" validate:"required,min=1"`
103+ Limit int `json:"limit" form:"limit" validate:"omitempty,gte=1,lte=100"`
104+ Source string `json:"source" form:"source" validate:"omitempty,oneof=local external all"`
105+ }
106+
49107type BookResponse struct {
50108 ID uint `json:"id"`
109+ ExternalID * string `json:"external_id,omitempty"`
110+ Source * string `json:"source,omitempty"`
51111 Title string `json:"title"`
52- Author * string `json:"author,omitempty"`
112+ Author * string `json:"author,omitempty"`
53113 CoverURL * string `json:"cover_url,omitempty"`
54114 Genre * string `json:"genre,omitempty"`
55115 Pages * int `json:"pages,omitempty"`
56116 PublishedYear * int `json:"published_year,omitempty"`
57117 ISBN * string `json:"isbn,omitempty"`
58118 Description * string `json:"description,omitempty"`
59119 Rating * float32 `json:"rating,omitempty"`
120+ LocalRating * float32 `json:"local_rating,omitempty"`
121+
122+ ReadCount int `json:"read_count"`
123+ RatingCount int `json:"rating_count"`
124+ IsClubFavorite bool `json:"is_club_favorite"`
125+ IsTrending bool `json:"is_trending"`
126+
127+ ClubCount * int `json:"club_count,omitempty"`
128+
129+ UserRating * float32 `json:"user_rating,omitempty"`
130+ ReadingStatus * string `json:"reading_status,omitempty"`
60131
61132 CreatedAt time.Time `json:"created_at"`
62133 UpdatedAt time.Time `json:"updated_at"`
63134}
64135
65136func (b * Book ) ToResponse () BookResponse {
66137 return BookResponse {
67- ID : b .ID ,
68- Title : b .Title ,
69- Author : b .Author ,
70- CoverURL : b .CoverURL ,
71- Genre : b .Genre ,
72- Pages : b .Pages ,
73- PublishedYear : b .PublishedYear ,
74- ISBN : b .ISBN ,
75- Description : b .Description ,
76- Rating : b .Rating ,
77- CreatedAt : b .CreatedAt ,
78- UpdatedAt : b .UpdatedAt ,
138+ ID : b .ID ,
139+ ExternalID : b .ExternalID ,
140+ Source : b .Source ,
141+ Title : b .Title ,
142+ Author : b .Author ,
143+ CoverURL : b .CoverURL ,
144+ Genre : b .Genre ,
145+ Pages : b .Pages ,
146+ PublishedYear : b .PublishedYear ,
147+ ISBN : b .ISBN ,
148+ Description : b .Description ,
149+ Rating : b .Rating ,
150+ LocalRating : b .LocalRating ,
151+ ReadCount : b .ReadCount ,
152+ RatingCount : b .RatingCount ,
153+ IsClubFavorite : b .IsClubFavorite ,
154+ IsTrending : b .IsTrending ,
155+ CreatedAt : b .CreatedAt ,
156+ UpdatedAt : b .UpdatedAt ,
79157 }
80- }
158+ }
0 commit comments