import sources from develop/0.1.0
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
package tysc
|
||||
|
||||
import (
|
||||
"gitlab.thpeetz.de/kontor/kontor-go/pkg/dao"
|
||||
|
||||
mgo "gopkg.in/mgo.v2"
|
||||
"gopkg.in/mgo.v2/bson"
|
||||
)
|
||||
|
||||
// ParallelSetDAO extends the type BaseDAO.
|
||||
type ParallelSetDAO struct {
|
||||
Db dao.BaseDAO
|
||||
}
|
||||
|
||||
const (
|
||||
// PARALLELSETCOLLECTION defines the collection name for storing parallel sets.
|
||||
PARALLELSETCOLLECTION = "parallelSet"
|
||||
// PARALLELSETMODEL defines the name of the parallel set data model.
|
||||
PARALLELSETMODEL = "kontor.tysc.parallelSet"
|
||||
)
|
||||
|
||||
// FindAll retrieves the list of parallel sets from the database.
|
||||
func (m *ParallelSetDAO) FindAll() ([]ParallelSet, error) {
|
||||
m.Db.Connect()
|
||||
var parallelSets []ParallelSet
|
||||
err := m.Db.MongoDb.C(PARALLELSETCOLLECTION).Find(bson.M{"model": PARALLELSETMODEL}).All(¶llelSets)
|
||||
return parallelSets, err
|
||||
}
|
||||
|
||||
// FindByID returns a parallel set with given id or returns the error.
|
||||
func (m *ParallelSetDAO) FindByID(id string) (ParallelSet, error) {
|
||||
m.Db.Connect()
|
||||
var parallelSet ParallelSet
|
||||
err := m.Db.MongoDb.C(PARALLELSETCOLLECTION).FindId(bson.ObjectIdHex(id)).One(¶llelSet)
|
||||
return parallelSet, err
|
||||
}
|
||||
|
||||
// FindByManufacturer returns a paralle set with given manufacturer or returns the error.
|
||||
func (m *ParallelSetDAO) FindByManufacturer(manufacturer string) ([]ParallelSet, error) {
|
||||
m.Db.Connect()
|
||||
var parallelSets []ParallelSet
|
||||
err := m.Db.MongoDb.C(PARALLELSETCOLLECTION).Find(bson.M{"model": PARALLELSETMODEL, "manufacturer": bson.ObjectIdHex(manufacturer)}).All(¶llelSets)
|
||||
return parallelSets, err
|
||||
}
|
||||
|
||||
// FindByName returns a parallel set with given name or returns the error.
|
||||
func (m *ParallelSetDAO) FindByName(name string) (ParallelSet, error) {
|
||||
m.Db.Connect()
|
||||
var parallelSet ParallelSet
|
||||
err := m.Db.MongoDb.C(PARALLELSETCOLLECTION).Find(bson.M{"name": name, "model": PARALLELSETMODEL}).One(¶llelSet)
|
||||
return parallelSet, err
|
||||
}
|
||||
|
||||
// Insert a parallel set into database.
|
||||
func (m *ParallelSetDAO) Insert(parallelSet ParallelSet) error {
|
||||
m.Db.Connect()
|
||||
parallelSet.Model = PARALLELSETMODEL
|
||||
err := m.Db.MongoDb.C(PARALLELSETCOLLECTION).Insert(¶llelSet)
|
||||
return err
|
||||
}
|
||||
|
||||
// Upsert a parallel set into database.
|
||||
func (m *ParallelSetDAO) Upsert(parallelSet ParallelSet) (*mgo.ChangeInfo, error) {
|
||||
m.Db.Connect()
|
||||
parallelSet.Model = PARALLELSETMODEL
|
||||
info, err := m.Db.MongoDb.C(PARALLELSETCOLLECTION).Upsert(bson.M{"name": parallelSet.Name}, ¶llelSet)
|
||||
return info, err
|
||||
}
|
||||
|
||||
// Update an existing parallel set.
|
||||
func (m *ParallelSetDAO) Update(parallelSet ParallelSet) error {
|
||||
m.Db.Connect()
|
||||
err := m.Db.MongoDb.C(PARALLELSETCOLLECTION).UpdateId(parallelSet.ID, ¶llelSet)
|
||||
return err
|
||||
}
|
||||
|
||||
// Delete an existing parallel set.
|
||||
func (m *ParallelSetDAO) Delete(parallelSet ParallelSet) error {
|
||||
m.Db.Connect()
|
||||
err := m.Db.MongoDb.C(PARALLELSETCOLLECTION).Remove(¶llelSet)
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user