be consistent
This commit is contained in:
+1
-9
@@ -68,18 +68,10 @@ func (s *Server) GetActivity(ctx context.Context, request GetActivityRequestObje
|
||||
|
||||
apiActivities := make([]Activity, len(activities))
|
||||
for i, a := range activities {
|
||||
// Convert StartTime from interface{} to string
|
||||
startTimeStr := ""
|
||||
if a.StartTime != nil {
|
||||
if str, ok := a.StartTime.(string); ok {
|
||||
startTimeStr = str
|
||||
}
|
||||
}
|
||||
|
||||
apiActivities[i] = Activity{
|
||||
DocumentId: a.DocumentID,
|
||||
DeviceId: a.DeviceID,
|
||||
StartTime: startTimeStr,
|
||||
StartTime: parseTimeAny(a.StartTime),
|
||||
Title: a.Title,
|
||||
Author: a.Author,
|
||||
Duration: a.Duration,
|
||||
|
||||
+29
-30
@@ -145,15 +145,15 @@ func (e GetSearchParamsSource) Valid() bool {
|
||||
|
||||
// Activity defines model for Activity.
|
||||
type Activity struct {
|
||||
Author *string `json:"author,omitempty"`
|
||||
DeviceId string `json:"device_id"`
|
||||
DocumentId string `json:"document_id"`
|
||||
Duration int64 `json:"duration"`
|
||||
EndPercentage float32 `json:"end_percentage"`
|
||||
ReadPercentage float32 `json:"read_percentage"`
|
||||
StartPercentage float32 `json:"start_percentage"`
|
||||
StartTime string `json:"start_time"`
|
||||
Title *string `json:"title,omitempty"`
|
||||
Author *string `json:"author,omitempty"`
|
||||
DeviceId string `json:"device_id"`
|
||||
DocumentId string `json:"document_id"`
|
||||
Duration int64 `json:"duration"`
|
||||
EndPercentage float32 `json:"end_percentage"`
|
||||
ReadPercentage float32 `json:"read_percentage"`
|
||||
StartPercentage float32 `json:"start_percentage"`
|
||||
StartTime time.Time `json:"start_time"`
|
||||
Title *string `json:"title,omitempty"`
|
||||
}
|
||||
|
||||
// ActivityResponse defines model for ActivityResponse.
|
||||
@@ -200,10 +200,10 @@ type DatabaseInfo struct {
|
||||
|
||||
// Device defines model for Device.
|
||||
type Device struct {
|
||||
CreatedAt *time.Time `json:"created_at,omitempty"`
|
||||
DeviceName *string `json:"device_name,omitempty"`
|
||||
Id *string `json:"id,omitempty"`
|
||||
LastSynced *time.Time `json:"last_synced,omitempty"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
DeviceName string `json:"device_name"`
|
||||
Id string `json:"id"`
|
||||
LastSynced time.Time `json:"last_synced"`
|
||||
}
|
||||
|
||||
// DirectoryItem defines model for DirectoryItem.
|
||||
@@ -356,15 +356,15 @@ type OperationType string
|
||||
|
||||
// Progress defines model for Progress.
|
||||
type Progress struct {
|
||||
Author *string `json:"author,omitempty"`
|
||||
CreatedAt *time.Time `json:"created_at,omitempty"`
|
||||
DeviceId *string `json:"device_id,omitempty"`
|
||||
DeviceName *string `json:"device_name,omitempty"`
|
||||
DocumentId *string `json:"document_id,omitempty"`
|
||||
Percentage *float64 `json:"percentage,omitempty"`
|
||||
Progress *string `json:"progress,omitempty"`
|
||||
Title *string `json:"title,omitempty"`
|
||||
UserId *string `json:"user_id,omitempty"`
|
||||
Author *string `json:"author,omitempty"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
DeviceId *string `json:"device_id,omitempty"`
|
||||
DeviceName string `json:"device_name"`
|
||||
DocumentId string `json:"document_id"`
|
||||
Percentage float64 `json:"percentage"`
|
||||
Progress *string `json:"progress,omitempty"`
|
||||
Title *string `json:"title,omitempty"`
|
||||
UserId string `json:"user_id"`
|
||||
}
|
||||
|
||||
// ProgressListResponse defines model for ProgressListResponse.
|
||||
@@ -384,14 +384,13 @@ type ProgressResponse struct {
|
||||
|
||||
// SearchItem defines model for SearchItem.
|
||||
type SearchItem struct {
|
||||
Author *string `json:"author,omitempty"`
|
||||
FileSize *string `json:"file_size,omitempty"`
|
||||
FileType *string `json:"file_type,omitempty"`
|
||||
Id *string `json:"id,omitempty"`
|
||||
Language *string `json:"language,omitempty"`
|
||||
Series *string `json:"series,omitempty"`
|
||||
Title *string `json:"title,omitempty"`
|
||||
UploadDate *string `json:"upload_date,omitempty"`
|
||||
Author *string `json:"author,omitempty"`
|
||||
FileSize *string `json:"file_size,omitempty"`
|
||||
FileType *string `json:"file_type,omitempty"`
|
||||
Id *string `json:"id,omitempty"`
|
||||
Language *string `json:"language,omitempty"`
|
||||
Series *string `json:"series,omitempty"`
|
||||
Title *string `json:"title,omitempty"`
|
||||
}
|
||||
|
||||
// SearchResponse defines model for SearchResponse.
|
||||
|
||||
+12
-2
@@ -106,6 +106,12 @@ components:
|
||||
created_at:
|
||||
type: string
|
||||
format: date-time
|
||||
required:
|
||||
- device_name
|
||||
- percentage
|
||||
- document_id
|
||||
- user_id
|
||||
- created_at
|
||||
|
||||
UpdateProgressRequest:
|
||||
type: object
|
||||
@@ -198,6 +204,7 @@ components:
|
||||
type: string
|
||||
start_time:
|
||||
type: string
|
||||
format: date-time
|
||||
title:
|
||||
type: string
|
||||
author:
|
||||
@@ -240,8 +247,6 @@ components:
|
||||
type: string
|
||||
file_size:
|
||||
type: string
|
||||
upload_date:
|
||||
type: string
|
||||
|
||||
SearchResponse:
|
||||
type: object
|
||||
@@ -384,6 +389,11 @@ components:
|
||||
last_synced:
|
||||
type: string
|
||||
format: date-time
|
||||
required:
|
||||
- id
|
||||
- device_name
|
||||
- created_at
|
||||
- last_synced
|
||||
|
||||
SettingsResponse:
|
||||
type: object
|
||||
|
||||
+10
-10
@@ -68,11 +68,11 @@ func (s *Server) GetProgressList(ctx context.Context, request GetProgressListReq
|
||||
apiProgress[i] = Progress{
|
||||
Title: row.Title,
|
||||
Author: row.Author,
|
||||
DeviceName: &row.DeviceName,
|
||||
Percentage: &row.Percentage,
|
||||
DocumentId: &row.DocumentID,
|
||||
UserId: &row.UserID,
|
||||
CreatedAt: parseTimePtr(row.CreatedAt),
|
||||
DeviceName: row.DeviceName,
|
||||
Percentage: row.Percentage,
|
||||
DocumentId: row.DocumentID,
|
||||
UserId: row.UserID,
|
||||
CreatedAt: parseTimeAny(row.CreatedAt),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,13 +105,13 @@ func (s *Server) GetProgress(ctx context.Context, request GetProgressRequestObje
|
||||
}
|
||||
|
||||
apiProgress := Progress{
|
||||
DeviceName: &row.DeviceName,
|
||||
DeviceName: row.DeviceName,
|
||||
DeviceId: &row.DeviceID,
|
||||
Percentage: &row.Percentage,
|
||||
Percentage: row.Percentage,
|
||||
Progress: &row.Progress,
|
||||
DocumentId: &row.DocumentID,
|
||||
UserId: &row.UserID,
|
||||
CreatedAt: parseTimePtr(row.CreatedAt),
|
||||
DocumentId: row.DocumentID,
|
||||
UserId: row.UserID,
|
||||
CreatedAt: parseTime(row.CreatedAt),
|
||||
}
|
||||
|
||||
response := ProgressResponse{
|
||||
|
||||
@@ -38,7 +38,6 @@ func (s *Server) GetSearch(ctx context.Context, request GetSearchRequestObject)
|
||||
Series: ptrOf(item.Series),
|
||||
FileType: ptrOf(item.FileType),
|
||||
FileSize: ptrOf(item.FileSize),
|
||||
UploadDate: ptrOf(item.UploadDate),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+8
-8
@@ -29,10 +29,10 @@ func (s *Server) GetSettings(ctx context.Context, request GetSettingsRequestObje
|
||||
apiDevices := make([]Device, len(devices))
|
||||
for i, device := range devices {
|
||||
apiDevices[i] = Device{
|
||||
Id: &device.ID,
|
||||
DeviceName: &device.DeviceName,
|
||||
CreatedAt: parseTimePtr(device.CreatedAt),
|
||||
LastSynced: parseTimePtr(device.LastSynced),
|
||||
Id: device.ID,
|
||||
DeviceName: device.DeviceName,
|
||||
CreatedAt: parseTimeAny(device.CreatedAt),
|
||||
LastSynced: parseTimeAny(device.LastSynced),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,10 +140,10 @@ func (s *Server) UpdateSettings(ctx context.Context, request UpdateSettingsReque
|
||||
apiDevices := make([]Device, len(devices))
|
||||
for i, device := range devices {
|
||||
apiDevices[i] = Device{
|
||||
Id: &device.ID,
|
||||
DeviceName: &device.DeviceName,
|
||||
CreatedAt: parseTimePtr(device.CreatedAt),
|
||||
LastSynced: parseTimePtr(device.LastSynced),
|
||||
Id: device.ID,
|
||||
DeviceName: device.DeviceName,
|
||||
CreatedAt: parseTimeAny(device.CreatedAt),
|
||||
LastSynced: parseTimeAny(device.LastSynced),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -68,6 +68,14 @@ func parseTime(s string) time.Time {
|
||||
return t
|
||||
}
|
||||
|
||||
// parseTimeAny parses an interface{} (from SQL) to time.Time, zero on failure.
|
||||
func parseTimeAny(v interface{}) time.Time {
|
||||
if s, ok := v.(string); ok {
|
||||
return parseTime(s)
|
||||
}
|
||||
return time.Time{}
|
||||
}
|
||||
|
||||
// parseTimePtr parses an interface{} (from SQL) to *time.Time
|
||||
func parseTimePtr(v interface{}) *time.Time {
|
||||
if v == nil {
|
||||
|
||||
Reference in New Issue
Block a user