2020-01-23 20:05:54 +01:00
|
|
|
package query
|
|
|
|
|
|
|
|
// MomentsTimeResult contains photo counts per month and year
|
|
|
|
type MomentsTimeResult struct {
|
|
|
|
PhotoYear int
|
|
|
|
PhotoMonth int
|
|
|
|
Count int
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetMomentsTime counts photos per month and year
|
2020-05-08 15:41:01 +02:00
|
|
|
func GetMomentsTime() (results []MomentsTimeResult, err error) {
|
|
|
|
s := UnscopedDb()
|
2020-01-23 20:05:54 +01:00
|
|
|
|
2020-03-28 17:17:41 +01:00
|
|
|
s = s.Table("photos").
|
2020-01-23 20:05:54 +01:00
|
|
|
Where("deleted_at IS NULL").
|
|
|
|
Select("photos.photo_year, photos.photo_month, COUNT(*) AS count").
|
|
|
|
Group("photos.photo_year, photos.photo_month").
|
|
|
|
Order("photos.photo_year DESC, photos.photo_month DESC")
|
|
|
|
|
2020-03-28 17:17:41 +01:00
|
|
|
if result := s.Scan(&results); result.Error != nil {
|
2020-01-23 20:05:54 +01:00
|
|
|
return results, result.Error
|
|
|
|
}
|
|
|
|
|
|
|
|
return results, nil
|
|
|
|
}
|