From bd91bfbb459e6588b6bc02d25211a8bc9abe4cca Mon Sep 17 00:00:00 2001 From: SimonFJ20 Date: Thu, 13 Mar 2025 17:18:53 +0100 Subject: [PATCH] move models* into models/ --- backend/src/controllers/carts.c | 2 +- backend/src/controllers/general.c | 2 +- backend/src/controllers/products.c | 2 +- backend/src/controllers/sessions.c | 2 +- backend/src/controllers/users.c | 2 +- backend/src/db/db.h | 2 +- backend/src/db/db_sqlite.c | 2 +- backend/src/main.c | 4 +-- backend/src/{ => models}/models.c | 42 +++++++++++++++++++------- backend/src/{ => models}/models.h | 0 backend/src/{ => models}/models_json.h | 2 +- 11 files changed, 40 insertions(+), 22 deletions(-) rename backend/src/{ => models}/models.c (93%) rename backend/src/{ => models}/models.h (100%) rename backend/src/{ => models}/models_json.h (96%) diff --git a/backend/src/controllers/carts.c b/backend/src/controllers/carts.c index 3aec523..6f393da 100644 --- a/backend/src/controllers/carts.c +++ b/backend/src/controllers/carts.c @@ -1,4 +1,4 @@ -#include "../models_json.h" +#include "../models/models_json.h" #include "../str_util.h" #include "controllers.h" diff --git a/backend/src/controllers/general.c b/backend/src/controllers/general.c index 3496b34..db4a0d7 100644 --- a/backend/src/controllers/general.c +++ b/backend/src/controllers/general.c @@ -1,5 +1,5 @@ #include "../http/http.h" -#include "../models_json.h" +#include "../models/models_json.h" #include "controllers.h" void route_get_index(HttpCtx* ctx) diff --git a/backend/src/controllers/products.c b/backend/src/controllers/products.c index ff9430c..75aabbc 100644 --- a/backend/src/controllers/products.c +++ b/backend/src/controllers/products.c @@ -1,5 +1,5 @@ #include "../http/http.h" -#include "../models_json.h" +#include "../models/models_json.h" #include "../str_util.h" #include "controllers.h" diff --git a/backend/src/controllers/sessions.c b/backend/src/controllers/sessions.c index 6ca0a72..459d900 100644 --- a/backend/src/controllers/sessions.c +++ b/backend/src/controllers/sessions.c @@ -1,5 +1,5 @@ #include "../http/http.h" -#include "../models_json.h" +#include "../models/models_json.h" #include "../str_util.h" #include "controllers.h" #include diff --git a/backend/src/controllers/users.c b/backend/src/controllers/users.c index 30e7af7..3c628c3 100644 --- a/backend/src/controllers/users.c +++ b/backend/src/controllers/users.c @@ -1,5 +1,5 @@ #include "../http/http.h" -#include "../models_json.h" +#include "../models/models_json.h" #include "../str_util.h" #include "controllers.h" #include diff --git a/backend/src/db/db.h b/backend/src/db/db.h index 20fbe45..8f922aa 100644 --- a/backend/src/db/db.h +++ b/backend/src/db/db.h @@ -1,7 +1,7 @@ #pragma once #include "../collection.h" -#include "../models.h" +#include "../models/models.h" #include DEFINE_VEC(int64_t, Ids, ids, 8) diff --git a/backend/src/db/db_sqlite.c b/backend/src/db/db_sqlite.c index 05cd81e..decb0c8 100644 --- a/backend/src/db/db_sqlite.c +++ b/backend/src/db/db_sqlite.c @@ -1,5 +1,5 @@ #include "db_sqlite.h" -#include "../models.h" +#include "../models/models.h" #include "../str_util.h" #include "db.h" #include diff --git a/backend/src/main.c b/backend/src/main.c index ff6ed7f..be91371 100644 --- a/backend/src/main.c +++ b/backend/src/main.c @@ -1,9 +1,7 @@ #include "controllers/controllers.h" #include "db/db_sqlite.h" #include "http/http.h" -#include "json.h" -#include "models.h" -#include "models_json.h" +#include "models/models_json.h" #include "str_util.h" #include #include diff --git a/backend/src/models.c b/backend/src/models/models.c similarity index 93% rename from backend/src/models.c rename to backend/src/models/models.c index 11ef2ec..7f31e77 100644 --- a/backend/src/models.c +++ b/backend/src/models/models.c @@ -1,7 +1,7 @@ #include "models.h" -#include "json.h" +#include "../json.h" +#include "../str_util.h" #include "models_json.h" -#include "str_util.h" #include #include #include @@ -83,7 +83,11 @@ char* user_to_json_string(const User* m) "\"password_hash\":\"%s\"," "\"balance_dkk_cent\":%ld" "}", - m->id, m->name, m->email, m->password_hash, m->balance_dkk_cent); + m->id, + m->name, + m->email, + m->password_hash, + m->balance_dkk_cent); char* result = string_copy(&string); string_destroy(&string); @@ -102,7 +106,9 @@ char* coord_to_json_string(const Coord* m) "\"x\":%ld," "\"y\":%ld" "}", - m->id, m->x, m->y); + m->id, + m->x, + m->y); char* result = string_copy(&string); string_destroy(&string); @@ -124,7 +130,12 @@ char* product_to_json_string(const Product* m) "\"coord_id\":%ld," "\"barcode\":\"%s\"" "}", - m->id, m->name, m->description, m->price_dkk_cent, m->coord_id, m->barcode); + m->id, + m->name, + m->description, + m->price_dkk_cent, + m->coord_id, + m->barcode); char* result = string_copy(&string); string_destroy(&string); @@ -143,7 +154,9 @@ char* product_price_to_json_string(const ProductPrice* m) "\"product_id\":%ld," "\"price_dkk_cent\":%ld" "}", - m->id, m->product_id, m->price_dkk_cent); + m->id, + m->product_id, + m->price_dkk_cent); char* result = string_copy(&string); string_destroy(&string); @@ -161,7 +174,8 @@ char* cart_to_json_string(const Cart* m) "\"id\":%ld," "\"user_id\":%ld" "}", - m->id, m->user_id); + m->id, + m->user_id); char* result = string_copy(&string); string_destroy(&string); @@ -181,7 +195,10 @@ char* cart_item_to_json_string(const CartItem* m) "\"product_id\":%ld," "\"amount\":%ld" "}", - m->id, m->cart_id, m->product_id, m->amount); + m->id, + m->cart_id, + m->product_id, + m->amount); char* result = string_copy(&string); string_destroy(&string); @@ -200,7 +217,9 @@ char* users_register_req_to_json(const UsersRegisterReq* m) "\"email\":\"%s\"," "\"password\":\"%s\"" "}", - m->name, m->email, m->password); + m->name, + m->email, + m->password); char* result = string_copy(&string); string_destroy(&string); @@ -218,7 +237,8 @@ char* auth_login_req_to_json(const AuthLoginReq* m) "\"email\":\"%s\"," "\"password\":\"%s\"" "}", - m->email, m->password); + m->email, + m->password); char* result = string_copy(&string); string_destroy(&string); @@ -299,7 +319,7 @@ int product_from_json(Product* m, const JsonValue* json) ObjField fields[] = { { "id", JsonType_Number }, { "name", JsonType_String }, - { "description", JsonType_String}, + { "description", JsonType_String }, { "price_dkk_cent", JsonType_Number }, { "coord_id", JsonType_Number }, { "barcode", JsonType_String }, diff --git a/backend/src/models.h b/backend/src/models/models.h similarity index 100% rename from backend/src/models.h rename to backend/src/models/models.h diff --git a/backend/src/models_json.h b/backend/src/models/models_json.h similarity index 96% rename from backend/src/models_json.h rename to backend/src/models/models_json.h index da34362..64cd75f 100644 --- a/backend/src/models_json.h +++ b/backend/src/models/models_json.h @@ -1,4 +1,4 @@ -#include "json.h" +#include "../json.h" #include "models.h" #define DEFINE_MODEL_JSON(TYPE, PREFIX) \