diff options
Diffstat (limited to 'config/service.go')
| -rw-r--r-- | config/service.go | 58 | 
1 files changed, 58 insertions, 0 deletions
diff --git a/config/service.go b/config/service.go new file mode 100644 index 0000000..51e9a00 --- /dev/null +++ b/config/service.go @@ -0,0 +1,58 @@ +/* openbills - Server for web based Libre Billing Software + * Copyright (C) 2023-2025  Vidhu Kant Sharma <vidhukant@vidhukant.com> + * + * This program 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 + * (at your option) any later version. + * + * This program 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 this program.  If not, see <https://www.gnu.org/licenses/>. + */ + +package config + +import ( +	"vidhukant.com/openbills/errors" +) + +func getConfig(config *[]Config) error { +	res := db.Find(&config) + +	// TODO: handle potential errors +	if res.Error != nil { +		return res.Error +	} + +	if res.RowsAffected == 0 { +		return errors.ErrNotFound +	} + +	return nil +} + +func (c *Config) upsert() error { +	res := db.Save(c) +	// TODO: handle potential errors +	return res.Error +} + +func (c *Config) del() error { +	res := db.Where("id = ?", c.ID).Delete(c) + +	// TODO: handle potential errors +	if res.Error != nil { +		return res.Error +	} + +	if res.RowsAffected == 0 { +		return errors.ErrNotFound +	} + +	return nil +}  |