Updates stuff
This commit is contained in:
parent
7ec0ce5a45
commit
28c5f546fe
6 changed files with 64 additions and 16 deletions
|
@ -26,14 +26,52 @@ type MediaMetadata struct {
|
|||
Name string
|
||||
}
|
||||
|
||||
// TODO: Figure out how to actually manage media. Because this current idea sucks
|
||||
// One idea would be to make another storage provider, but purely focused on handling the files
|
||||
// and then using this section to store metadata about the files it knows
|
||||
func (s *Storage) NewMediaMetadata(url, mediaType, name string) (*MediaMetadata, error) {
|
||||
func (s *Storage) NewMediaMetadata(location, mediaType, name string) (*MediaMetadata, error) {
|
||||
newMedia := MediaMetadata{
|
||||
Location: url,
|
||||
Location: location,
|
||||
Name: name,
|
||||
Type: mediaType,
|
||||
}
|
||||
s.db.Create(&newMedia)
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (s *Storage) FuzzyFindMediaMetadataByName(name string) ([]MediaMetadata, error) {
|
||||
notes := []MediaMetadata{}
|
||||
err := s.db.Where("name LIKE %?%", name).Find(notes).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return notes, nil
|
||||
}
|
||||
|
||||
func (s *Storage) GetMediaMetadataById(id string) (*MediaMetadata, error) {
|
||||
media := MediaMetadata{ID: id}
|
||||
err := s.db.First(&media).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &media, nil
|
||||
}
|
||||
|
||||
func (s *Storage) FuzzyFindMediaMetadataByLocation(location string) ([]MediaMetadata, error) {
|
||||
data := []MediaMetadata{}
|
||||
if err := s.db.Where("location LIKE %?%", location).Find(data).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func (s *Storage) DeleteMediaMetadataById(id string) error {
|
||||
return s.db.Delete(MediaMetadata{ID: id}).Error
|
||||
}
|
||||
|
||||
func (s *Storage) DeleteMediaMetadataByFuzzyLocation(location string) error {
|
||||
var tmp MediaMetadata
|
||||
return s.db.Where("location LIKE %?%", location).Delete(&tmp).Error
|
||||
}
|
||||
|
||||
func (s *Storage) DeleteMediaMetadataByFuzzyName(name string) error {
|
||||
var tmp MediaMetadata
|
||||
return s.db.Where("name LIKE %?%", name).Delete(&tmp).Error
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue