Skip to content

Commit

Permalink
Git fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
b-j-roberts committed Apr 22, 2024
1 parent 7864f16 commit 249eae4
Showing 1 changed file with 29 additions and 29 deletions.
58 changes: 29 additions & 29 deletions backend/routes/colors.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type Colors struct {
func InitColorsRoutes() {
http.HandleFunc("/get-colors", GetAllColors)
http.HandleFunc("/get-color", GetSingleColor)
http.HandleFunc("/init-colors", InitColors)
http.HandleFunc("/init-colors", InitColors)
}

func GetAllColors(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -96,32 +96,32 @@ func GetSingleColor(w http.ResponseWriter, r *http.Request) {
}

func InitColors(w http.ResponseWriter, r *http.Request) {
// TODO: Add authentication and/or check if colors already exist
reqBody, err := io.ReadAll(r.Body)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
w.Write([]byte(err.Error()))
return
}

var colors []string
err = json.Unmarshal(reqBody, &colors)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
w.Write([]byte(err.Error()))
return
}

for _, color := range colors {
_, err = core.ArtPeaceBackend.Databases.Postgres.Exec(context.Background(), "INSERT INTO colors (hex) VALUES ($1)", color)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(err.Error()))
return
}
}

w.WriteHeader(http.StatusOK)
w.Write([]byte("Colors initialized"))
fmt.Println("Colors initialized")
// TODO: Add authentication and/or check if colors already exist
reqBody, err := io.ReadAll(r.Body)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
w.Write([]byte(err.Error()))
return
}

var colors []string
err = json.Unmarshal(reqBody, &colors)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
w.Write([]byte(err.Error()))
return
}

for _, color := range colors {
_, err = core.ArtPeaceBackend.Databases.Postgres.Exec(context.Background(), "INSERT INTO colors (hex) VALUES ($1)", color)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(err.Error()))
return
}
}

w.WriteHeader(http.StatusOK)
w.Write([]byte("Colors initialized"))
fmt.Println("Colors initialized")
}

0 comments on commit 249eae4

Please sign in to comment.