aboutsummaryrefslogtreecommitdiff
path: root/api/internal/controllers/preferences.go
diff options
context:
space:
mode:
Diffstat (limited to 'api/internal/controllers/preferences.go')
-rw-r--r--api/internal/controllers/preferences.go13
1 files changed, 9 insertions, 4 deletions
diff --git a/api/internal/controllers/preferences.go b/api/internal/controllers/preferences.go
index a1bcf4f..da52e74 100644
--- a/api/internal/controllers/preferences.go
+++ b/api/internal/controllers/preferences.go
@@ -1,22 +1,27 @@
1package controllers 1package controllers
2 2
3import ( 3import (
4 "github.com/gin-gonic/gin"
5 "net/http"
6 "database/sql" 4 "database/sql"
5 "net/http"
7 "water/api/internal/database" 6 "water/api/internal/database"
8 "water/api/internal/models" 7 "water/api/internal/models"
8
9 "github.com/gin-gonic/gin"
9) 10)
10 11
11func GetSizes(c *gin.Context) { 12func GetSizes(c *gin.Context) {
12 db := database.EstablishDBConnection() 13 db, err := database.EstablishDBConnection()
14 if err != nil {
15 c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
16 return
17 }
13 defer func(db *sql.DB) { 18 defer func(db *sql.DB) {
14 err := db.Close() 19 err := db.Close()
15 if err != nil { 20 if err != nil {
16 c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) 21 c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
17 } 22 }
18 }(db) 23 }(db)
19 24
20 rows, err := db.Query("SELECT id, size, unit FROM Sizes") 25 rows, err := db.Query("SELECT id, size, unit FROM Sizes")
21 if err != nil { 26 if err != nil {
22 c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) 27 c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})