Skip to content
Snippets Groups Projects
files.go 1.97 KiB
Newer Older
  • Learn to ignore specific revisions
  • Christian Pointner's avatar
    Christian Pointner committed
    //
    //  tank
    //
    //  Import and Playlist Daemon for autoradio project
    //
    //
    //  Copyright (C) 2017 Christian Pointner <equinox@helsinki.at>
    //
    //  This file is part of tank.
    //
    //  tank is free software: you can redistribute it and/or modify
    //  it under the terms of the GNU General Public License as published by
    //  the Free Software Foundation, either version 3 of the License, or
    //  any later version.
    //
    //  tank is distributed in the hope that it will be useful,
    //  but WITHOUT ANY WARRANTY; without even the implied warranty of
    //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    //  GNU General Public License for more details.
    //
    //  You should have received a copy of the GNU General Public License
    //  along with tank. If not, see <http://www.gnu.org/licenses/>.
    //
    
    package store
    
    import (
    
    Christian Pointner's avatar
    Christian Pointner committed
    	"encoding/json"
    
    	"github.com/coreos/bbolt"
    
    Christian Pointner's avatar
    Christian Pointner committed
    func getFileBucket(tx *bolt.Tx, group string) (files *bolt.Bucket, err error) {
    	var gb *bolt.Bucket
    	if gb, err = getGroupBucket(tx, group); err != nil {
    		return
    	}
    	if gb == nil {
    		return nil, nil
    	}
    	files = gb.Bucket([]byte(filesBn))
    	return
    
    Christian Pointner's avatar
    Christian Pointner committed
    func (st *Store) ListFiles(group string) (files Files, err error) {
    	err = st.db.View(func(tx *bolt.Tx) error {
    		fb, err := getFileBucket(tx, group)
    		if err != nil {
    			return err
    		}
    		if fb != nil {
    			return nil
    		}
    		err = fb.ForEach(func(k, v []byte) error {
    			var file File
    			if err := json.Unmarshal(v, file); err != nil {
    				return err
    			}
    			files = append(files, file)
    			return nil
    		})
    		return err
    	})
    	return
    }
    
    func (st *Store) CreateFile(group, id string, file *File) error {
    
    Christian Pointner's avatar
    Christian Pointner committed
    	// TODO: implement this
    
    Christian Pointner's avatar
    Christian Pointner committed
    	return ErrNotImplented
    
    Christian Pointner's avatar
    Christian Pointner committed
    }
    
    func (st *Store) GetFile(group, id string) (*File, error) {
    	// TODO: implement this
    	return nil, ErrNotImplented
    }
    
    func (st *Store) UpdateFile(group, id string, new File) (*File, error) {
    	// TODO: implement this
    	return nil, ErrNotImplented
    }
    
    func (st *Store) DeleteFile(group, id string) error {
    	// TODO: implement this
    	return ErrNotImplented
    }