cosmium/internal/repositories/databases.go

45 lines
1.1 KiB
Go
Raw Normal View History

2024-02-10 15:17:34 +00:00
package repositories
import repositorymodels "github.com/pikami/cosmium/internal/repository_models"
var databases = []repositorymodels.Database{
2024-02-10 15:17:34 +00:00
{ID: "db1"},
{ID: "db2"},
}
func GetAllDatabases() ([]repositorymodels.Database, repositorymodels.RepositoryStatus) {
return databases, repositorymodels.StatusOk
2024-02-10 15:17:34 +00:00
}
func GetDatabase(id string) (repositorymodels.Database, repositorymodels.RepositoryStatus) {
2024-02-10 15:17:34 +00:00
for _, db := range databases {
if db.ID == id {
return db, repositorymodels.StatusOk
2024-02-10 15:17:34 +00:00
}
}
return repositorymodels.Database{}, repositorymodels.StatusNotFound
2024-02-10 15:17:34 +00:00
}
func DeleteDatabase(id string) repositorymodels.RepositoryStatus {
2024-02-10 15:17:34 +00:00
for index, db := range databases {
if db.ID == id {
databases = append(databases[:index], databases[index+1:]...)
return repositorymodels.StatusOk
2024-02-10 15:17:34 +00:00
}
}
return repositorymodels.StatusNotFound
2024-02-10 15:17:34 +00:00
}
func CreateDatabase(newDatabase repositorymodels.Database) repositorymodels.RepositoryStatus {
2024-02-10 15:17:34 +00:00
for _, db := range databases {
if db.ID == newDatabase.ID {
return repositorymodels.Conflict
2024-02-10 15:17:34 +00:00
}
}
databases = append(databases, newDatabase)
return repositorymodels.StatusOk
2024-02-10 15:17:34 +00:00
}