cosmium/internal/repositories/collections.go
2024-02-10 20:17:33 +02:00

54 lines
1.3 KiB
Go

package repositories
var collections = []Collection{
{ID: "db1"},
{ID: "db2"},
}
func GetAllCollections(databaseId string) ([]Collection, RepositoryStatus) {
var dbCollections []Collection
for _, coll := range collections {
if coll.internals.databaseId == databaseId {
dbCollections = append(dbCollections, coll)
}
}
return dbCollections, StatusOk
}
func GetCollection(databaseId string, id string) (Collection, RepositoryStatus) {
for _, coll := range collections {
if coll.internals.databaseId == databaseId && coll.ID == id {
return coll, StatusOk
}
}
return Collection{}, StatusNotFound
}
func DeleteCollection(databaseId string, id string) RepositoryStatus {
for index, coll := range collections {
if coll.internals.databaseId == databaseId && coll.ID == id {
collections = append(collections[:index], collections[index+1:]...)
return StatusOk
}
}
return StatusNotFound
}
func CreateCollection(databaseId string, newCollection Collection) RepositoryStatus {
for _, coll := range collections {
if coll.internals.databaseId == databaseId && coll.ID == newCollection.ID {
return Conflict
}
}
newCollection.internals = struct{ databaseId string }{
databaseId: databaseId,
}
collections = append(collections, newCollection)
return StatusOk
}