func CheckReleaseFilter(w traffic.ResponseWriter, r *traffic.Request) { artistId := r.URL.Query().Get("artist_id") releaseId := r.URL.Query().Get("release_id") if releaseId == "" { return } if !models.IsValidUUID(releaseId) { w.WriteHeader(http.StatusBadRequest) return } if artistId != "" { if !models.IsValidUUID(artistId) { w.WriteHeader(http.StatusBadRequest) return } if artist.HasRelease(artistId, releaseId) { return } ReleaseNotFoundHandler(w, r) return } if !release.Exists(releaseId) { ReleaseNotFoundHandler(w, r) return } }
func ById(id string) (*models.Release, error) { release := &models.Release{} if !models.IsValidUUID(id) { return release, models.InvalidUUID{id} } var status *sql.NullString var packaging *sql.NullString var _type *sql.NullString var artistCredit int row := models.DB.QueryRow(queryById, id) err := row.Scan(&release.Id, &release.Name, &release.Comment, &artistCredit, &status, &packaging, &_type) if err != nil { return release, err } if status != nil { release.Status = status.String } if packaging != nil { release.Packaging = packaging.String } if _type != nil { release.Type = _type.String } release.Artists = artist.AllByArtistCredit(artistCredit) return release, nil }
func ById(id string) (*models.Artist, error) { artist := &models.Artist{} if !models.IsValidUUID(id) { return artist, models.InvalidUUID{id} } var _type *sql.NullString var beginDateYear *sql.NullInt64 var beginDateMonth *sql.NullInt64 var beginDateDay *sql.NullInt64 var endDateYear *sql.NullInt64 var endDateMonth *sql.NullInt64 var endDateDay *sql.NullInt64 row := models.DB.QueryRow(queryById, id) err := row.Scan(&artist.Id, &artist.Name, &artist.SortName, &artist.Comment, &beginDateYear, &beginDateMonth, &beginDateDay, &endDateYear, &endDateMonth, &endDateDay, &_type) if err != nil { return artist, err } if beginDateYear != nil { date := fmt.Sprintf("%d", beginDateYear.Int64) if beginDateMonth != nil { date = fmt.Sprintf("%s-%02d", date, beginDateMonth.Int64) } if beginDateDay != nil { date = fmt.Sprintf("%s-%02d", date, beginDateDay.Int64) } artist.BeginDate = date } if endDateYear != nil { date := fmt.Sprintf("%d", endDateYear.Int64) if endDateMonth != nil { date = fmt.Sprintf("%s-%02d", date, endDateMonth.Int64) } if endDateDay != nil { date = fmt.Sprintf("%s-%02d", date, endDateDay.Int64) } artist.EndDate = date } if _type != nil { artist.Type = _type.String } return artist, nil }
func HasReleaseGroup(artistId, releaseGroupId string) bool { if !models.IsValidUUID(artistId) { return false } if !models.IsValidUUID(releaseGroupId) { return false } var found int row := models.DB.QueryRow(queryHasReleaseGroup, artistId, releaseGroupId) err := row.Scan(&found) if err != nil { return false } return true }
func ByArtistIdAndId(artistId, id string) (*models.ReleaseGroup, error) { releaseGroup := &models.ReleaseGroup{} if !models.IsValidUUID(artistId) { return releaseGroup, models.InvalidUUID{artistId} } if !models.IsValidUUID(id) { return releaseGroup, models.InvalidUUID{id} } row := models.DB.QueryRow(queryByArtistIdAndId, artistId, id) err := ScanRecord(row, releaseGroup) if err == nil { releaseGroup.Artists = artist.AllByArtistCredit(releaseGroup.ArtistCredit) } return releaseGroup, err }
func ByReleaseIdAndId(releaseId, id string) (*models.Recording, error) { recording := &models.Recording{} if !models.IsValidUUID(releaseId) { return recording, models.InvalidUUID{releaseId} } if !models.IsValidUUID(id) { return recording, models.InvalidUUID{id} } var artistCredit int row := models.DB.QueryRow(queryByReleaseIdAndId, releaseId, id) err := row.Scan(&recording.Id, &recording.Name, &recording.Comment, &recording.Length, &artistCredit) if err != nil { return recording, err } recording.Artists = artist.AllByArtistCredit(artistCredit) return recording, nil }
func Exists(id string) bool { if !models.IsValidUUID(id) { return false } var found int row := models.DB.QueryRow(queryExists, id) err := row.Scan(&found) if err != nil { return false } return true }
func CheckArtistFilter(w traffic.ResponseWriter, r *traffic.Request) { artistId := r.URL.Query().Get("artist_id") if artistId == "" { return } if !models.IsValidUUID(artistId) { w.WriteHeader(http.StatusBadRequest) return } if !artist.Exists(artistId) { ArtistNotFoundHandler(w, r) return } }
func AllByArtistId(artistId string) ([]*models.ReleaseGroup, error) { releaseGroups := make([]*models.ReleaseGroup, 0) if !models.IsValidUUID(artistId) { return releaseGroups, models.InvalidUUID{artistId} } rows, err := models.DB.Query(queryAllByArtistId, artistId) if err != nil { return releaseGroups, err } for rows.Next() { releaseGroup := &models.ReleaseGroup{} err := ScanRecord(rows, releaseGroup) if err != nil { return releaseGroups, err } releaseGroups = append(releaseGroups, releaseGroup) } return releaseGroups, nil }
func AllByReleaseId(releaseId string) ([]*models.Recording, error) { recordings := make([]*models.Recording, 0) if !models.IsValidUUID(releaseId) { return recordings, models.InvalidUUID{releaseId} } rows, err := models.DB.Query(queryAllByReleaseId, releaseId) if err != nil { return recordings, err } for rows.Next() { recording := &models.Recording{} err := rows.Scan(&recording.Id, &recording.Name, &recording.Comment, &recording.Length) if err != nil { return recordings, err } recordings = append(recordings, recording) } return recordings, nil }