cosmium/internal/repositories/collections.go

54 lines
1.3 KiB
Go
Raw Normal View History

2024-02-10 16:52:41 +00:00
package repositories
var collections = []Collection{
{ID: "db1"},
{ID: "db2"},
}
func GetAllCollections(databaseId string) ([]Collection, RepositoryStatus) {
dbCollections := make([]Collection, 0)
2024-02-10 16:52:41 +00:00
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,
}
2024-02-10 16:52:41 +00:00
collections = append(collections, newCollection)
return StatusOk
}