diff --git a/api/openapi.json b/api/openapi.json index 4fd01db..f69b1b1 100644 --- a/api/openapi.json +++ b/api/openapi.json @@ -1,7 +1,7 @@ { "openapi": "3.0.3", "info": { - "title": "db-handler", + "title": "db-adapter", "version": "0.0.1" }, "servers": [ @@ -12,58 +12,137 @@ { "description": "staging server", "url": "http://0.0.0.0:7699" + }, + { + "description": "development server", + "url": "http://0.0.0.0:7698" } ], "paths": { - "/person_and_relationship": { - "post": { - "summary": "Create a person and relationship", - "operationId": "createPersonAndRelationship", - "requestBody": { - "required": true, - "content": { - "application/json": { - "schema": { - "type": "object", - "properties": { - "person": { - "$ref": "#/components/schemas/PersonRegistration" - }, - "relationship": { - "$ref": "#/components/schemas/FamilyRelationship" - } + "/health":{ + "get":{ + "summary": "Check the health of the server", + "operationId": "healthCheck", + "responses": { + "200": { + "description": "Server is healthy" }, - "required": ["person", "relationship"] + "503": { + "description": "Server is unhealthy" } } - } - }, - "responses": { - "200": { - "description": "Person and relationship created", - "content": { - "application/json": { - "schema": { - "type": "object", - "properties": { - "person": { - "$ref": "#/components/schemas/Person" - }, - "relationship": { - "$ref": "#/components/schemas/Relationship" - } - } - } - } - } - } } + }, + "/person_and_relationship/{id}": { + "post": { + "summary": "Create a person and relationship", + "operationId": "createPersonAndRelationship", + "parameters": [ + { + "name": "id", + "in": "path", + "required": true, + "schema": { + "type": "integer" + } + }, + { + "name": "X-User-ID", + "in": "header", + "required": true, + "schema": { + "type": "integer" + } + } + ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "person": { + "$ref": "#/components/schemas/PersonRegistration" + }, + "relationship": { + "$ref": "#/components/schemas/FamilyRelationship" + } + }, + "required": [ + "person", + "relationship" + ] + } + } + } + }, + "responses": { + "200": { + "description": "Person and relationship created", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "person": { + "$ref": "#/components/schemas/Person" + }, + "relationship": { + "$ref": "#/components/schemas/Relationship" + } + } + } + } + } + }, + "500": { + "description": "Internal server error", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "msg": { + "type": "string" + } + } + } + } + } + }, + "401": { + "description": "Unauthorized", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "msg": { + "type": "string" + } + } + } + } + } + } + } } }, "/person": { "post": { "summary": "Create a new person", "operationId": "createPerson", + "parameters": [ + { + "name": "X-User-ID", + "in": "header", + "required": true, + "schema": { + "type": "integer" + } + } + ], "requestBody": { "required": true, "content": { @@ -84,12 +163,42 @@ } } } + }, + "500": { + "description": "Internal server error", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "msg": { + "type": "string" + } + } + } + } + } + }, + "401": { + "description": "Unauthorized", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "msg": { + "type": "string" + } + } + } + } + } } } } }, "/person/{id}": { - "put": { + "patch": { "summary": "Update a person by ID", "operationId": "updatePerson", "parameters": [ @@ -100,7 +209,16 @@ "schema": { "type": "integer" } + }, + { + "name": "X-User-ID", + "in": "header", + "required": true, + "schema": { + "type": "integer" + } } + ], "requestBody": { "required": true, @@ -137,6 +255,36 @@ } } } + }, + "401": { + "description": "Unauthorized", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "msg": { + "type": "string" + } + } + } + } + } + }, + "500": { + "description": "Internal server error", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "msg": { + "type": "string" + } + } + } + } + } } } }, @@ -151,6 +299,14 @@ "schema": { "type": "integer" } + }, + { + "name": "X-User-ID", + "in": "header", + "required": true, + "schema": { + "type": "integer" + } } ], "responses": { @@ -171,6 +327,36 @@ } } } + }, + "401": { + "description": "Unauthorized", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "msg": { + "type": "string" + } + } + } + } + } + }, + "500": { + "description": "Internal server error", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "msg": { + "type": "string" + } + } + } + } + } } } } @@ -187,6 +373,14 @@ "schema": { "type": "integer" } + }, + { + "name": "X-User-ID", + "in": "header", + "required": true, + "schema": { + "type": "integer" + } } ], "responses": { @@ -207,6 +401,21 @@ } } } + }, + "500": { + "description": "Internal server error", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "msg": { + "type": "string" + } + } + } + } + } } } } @@ -225,7 +434,7 @@ } } ], - "requestBody":{ + "requestBody": { "required": true, "content": { "application/json": { @@ -344,6 +553,119 @@ } } } + }, + "500": { + "description": "Internal server error", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "msg": { + "type": "string" + } + } + } + } + } + } + } + } + }, + "/person/{id}/recipes":{ + "get":{ + "summary": "Get recipes by person ID", + "operationId": "getRecipesByPersonId", + "parameters": [ + { + "name": "id", + "in": "path", + "required": true, + "schema": { + "type": "integer" + } + }, + { + "name": "X-User-ID", + "in": "header", + "required": true, + "schema": { + "type": "integer" + } + } + ], + "responses": { + "200": { + "description": "Recipes retrieved", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "recipeRelations":{ + "type": "array", + "items": { + + "$ref": "#/components/schemas/Likes" + + } + }, + "recipes": { + "type": "array", + "items": { + "$ref": "#/components/schemas/Recipe" + } + } + } + + } + } + } + }, + "400":{ + "description": "Bad request", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "msg": { + "type": "string" + } + } + } + } + } + }, + "401": { + "description": "Unauthorized", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "msg": { + "type": "string" + } + } + } + } + } + }, + "500": { + "description": "Internal server error", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "msg": { + "type": "string" + } + } + } + } + } } } } @@ -352,6 +674,16 @@ "post": { "summary": "Create a relationship between two persons", "operationId": "createRelationship", + "parameters": [ + { + "name": "X-User-ID", + "in": "header", + "required": true, + "schema": { + "type": "integer" + } + } + ], "requestBody": { "required": true, "content": { @@ -383,6 +715,36 @@ } } } + }, + "401": { + "description": "Unauthorized", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "msg": { + "type": "string" + } + } + } + } + } + }, + "500": { + "description": "Internal server error", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "msg": { + "type": "string" + } + } + } + } + } } } } @@ -407,6 +769,14 @@ "schema": { "type": "integer" } + }, + { + "name": "X-User-ID", + "in": "header", + "required": true, + "schema": { + "type": "integer" + } } ], "responses": { @@ -434,12 +804,42 @@ } } } + }, + "401": { + "description": "Unauthorized", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "msg": { + "type": "string" + } + } + } + } + } + }, + "500": { + "description": "Internal server error", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "msg": { + "type": "string" + } + } + } + } + } } } } }, "/recipe/{id}": { - "put": { + "patch": { "summary": "Update a recipe by ID", "operationId": "updateRecipe", "parameters": [ @@ -450,6 +850,14 @@ "schema": { "type": "integer" } + }, + { + "name": "X-User-ID", + "in": "header", + "required": true, + "schema": { + "type": "integer" + } } ], "requestBody": { @@ -487,6 +895,36 @@ } } } + }, + "401": { + "description": "Unauthorized", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "msg": { + "type": "string" + } + } + } + } + } + }, + "500": { + "description": "Internal server error", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "msg": { + "type": "string" + } + } + } + } + } } } }, @@ -501,6 +939,14 @@ "schema": { "type": "integer" } + }, + { + "name": "X-User-ID", + "in": "header", + "required": true, + "schema": { + "type": "integer" + } } ], "responses": { @@ -521,6 +967,36 @@ } } } + }, + "401": { + "description": "Unauthorized", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "msg": { + "type": "string" + } + } + } + } + } + }, + "500": { + "description": "Internal server error", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "msg": { + "type": "string" + } + } + } + } + } } } } @@ -537,6 +1013,14 @@ "schema": { "type": "integer" } + }, + { + "name": "X-User-ID", + "in": "header", + "required": true, + "schema": { + "type": "integer" + } } ], "responses": { @@ -557,6 +1041,36 @@ } } } + }, + "401": { + "description": "Unauthorized", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "msg": { + "type": "string" + } + } + } + } + } + }, + "500": { + "description": "Internal server error", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "msg": { + "type": "string" + } + } + } + } + } } } } @@ -573,6 +1087,14 @@ "schema": { "type": "integer" } + }, + { + "name": "X-User-ID", + "in": "header", + "required": true, + "schema": { + "type": "integer" + } } ], "requestBody": { @@ -581,9 +1103,14 @@ "application/json": { "schema": { "type": "object", - "required": ["id", "relationship"], + "required": [ + "id", + "relationship" + ], "properties": { - "id": { "type": "integer" }, + "id": { + "type": "integer" + }, "relationship": { "type": "object", "properties": { @@ -622,6 +1149,36 @@ } } } + }, + "401": { + "description": "Unauthorized", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "msg": { + "type": "string" + } + } + } + } + } + }, + "500": { + "description": "Internal server error", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "msg": { + "type": "string" + } + } + } + } + } } } }, @@ -644,6 +1201,14 @@ "schema": { "type": "integer" } + }, + { + "name": "X-User-ID", + "in": "header", + "required": true, + "schema": { + "type": "integer" + } } ], "responses": { @@ -664,6 +1229,36 @@ } } } + }, + "401": { + "description": "Unauthorized", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "msg": { + "type": "string" + } + } + } + } + } + }, + "500": { + "description": "Internal server error", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "msg": { + "type": "string" + } + } + } + } + } } } } @@ -675,7 +1270,18 @@ "type": "object", "properties": { "allow_admin_access": { - "type": "boolean", + "type": "array", + "items": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "name": { + "type": "string" + } + } + }, "nullable": true }, "invite_code": { @@ -823,7 +1429,7 @@ "description": { "type": "string" }, - "date":{ + "date": { "type": "string", "format": "date" }, @@ -845,7 +1451,7 @@ "description": { "type": "string" }, - "date":{ + "date": { "type": "string", "format": "date" }, @@ -867,7 +1473,7 @@ "description": { "type": "string" }, - "date":{ + "date": { "type": "string", "format": "date" }, @@ -954,7 +1560,7 @@ "type": "string", "nullable": true }, - "components":{ + "components": { "type": "string", "nullable": true }, @@ -979,7 +1585,6 @@ "type": "array", "items": { "type": "object" - }, "nullable": true }, @@ -1050,7 +1655,7 @@ "format": "date", "nullable": true }, - "title":{ + "title": { "type": "string", "nullable": true }, @@ -1067,35 +1672,42 @@ } } }, - "PersonRegistration":{ - "type": "object", - "required": ["first_name", "last_name", "born", "limit", "mothers_first_name", "mothers_last_name"], - "properties": { - "first_name": { - "type": "string" - }, - "last_name": { - "type": "string" - }, - "email": { - "type": "string", - "format": "email", - "nullable": true - }, - "limit":{ - "type": "integer" - }, - "born":{ - "type": "string", - "format": "date" - }, - "mothers_first_name":{ - "type": "string" - }, - "mothers_last_name":{ - "type": "string" + "PersonRegistration": { + "type": "object", + "required": [ + "first_name", + "last_name", + "born", + "limit", + "mothers_first_name", + "mothers_last_name" + ], + "properties": { + "first_name": { + "type": "string" + }, + "last_name": { + "type": "string" + }, + "email": { + "type": "string", + "format": "email", + "nullable": true + }, + "limit": { + "type": "integer" + }, + "born": { + "type": "string", + "format": "date" + }, + "mothers_first_name": { + "type": "string" + }, + "mothers_last_name": { + "type": "string" + } } - } }, "Person": { "type": "object", @@ -1109,7 +1721,7 @@ "type": "string" } }, - "type":{ + "type": { "type": "string", "nullable": true }, @@ -1165,7 +1777,7 @@ } } }, - "OptimizedPersonNode":{ + "OptimizedPersonNode": { "type": "object", "properties": { "id": { @@ -1177,7 +1789,7 @@ "type": "string" } }, - "type":{ + "type": { "type": "string", "nullable": true }, @@ -1248,6 +1860,20 @@ "type": "string", "nullable": true }, + "allow_admin_access":{ + "type": "array", + "items": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "name": { + "type": "string" + } + } + } + }, "category": { "type": "string", "nullable": true @@ -1282,6 +1908,24 @@ "notes": { "type": "string", "nullable": true + }, + "others_said":{ + "nullable": true, + "type": "array", + "items":{ + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "name": { + "type": "string" + }, + "said":{ + "type": "string" + } + } + } } } }, diff --git a/apps/app/env.example b/apps/app/env.example index e3fc345..7b7bc86 100644 --- a/apps/app/env.example +++ b/apps/app/env.example @@ -1,6 +1,4 @@ GOOGLE_CLIENT_ID="" GOOGLE_CLIENT_SECRET="" GOOGLE_CALLBACK_URI="http://localhost:5173/login/google/callback" -MEMGRAPH_URI="bolt://localhost:7687" -MEMGRAPH_USER="memgraph" -MEMGRAPH_PASSWORD="memgraph" \ No newline at end of file +DB_ADAPTER="" \ No newline at end of file diff --git a/apps/app/src/lib/api/api.gen.ts b/apps/app/src/lib/api/api.gen.ts index 28d667b..bcc77f2 100644 --- a/apps/app/src/lib/api/api.gen.ts +++ b/apps/app/src/lib/api/api.gen.ts @@ -473,6 +473,17 @@ export interface operations { "application/json": components["schemas"]["Person"]; }; }; + /** @description Bad request */ + 400: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": { + msg?: string; + }; + }; + }; }; }; softDeletePerson: { @@ -493,6 +504,17 @@ export interface operations { }; content?: never; }; + /** @description Bad request */ + 400: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": { + msg?: string; + }; + }; + }; }; }; hardDeletePerson: { @@ -513,6 +535,17 @@ export interface operations { }; content?: never; }; + /** @description Bad request */ + 400: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": { + msg?: string; + }; + }; + }; }; }; getPersonByGoogleId: { @@ -535,6 +568,17 @@ export interface operations { "application/json": components["schemas"]["Person"]; }; }; + /** @description Bad request */ + 400: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": { + msg?: string; + }; + }; + }; }; }; createPersonByGoogleId: { @@ -561,6 +605,17 @@ export interface operations { "application/json": components["schemas"]["Person"]; }; }; + /** @description Bad request */ + 400: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": { + msg?: string; + }; + }; + }; }; }; getFamilyTreeById: { @@ -583,6 +638,17 @@ export interface operations { "application/json": components["schemas"]["FamilyTree"]; }; }; + /** @description Bad request */ + 400: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": { + msg?: string; + }; + }; + }; }; }; createRelationship: { @@ -634,6 +700,17 @@ export interface operations { "application/json": components["schemas"]["Relationship"]; }; }; + /** @description Bad request */ + 400: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": { + msg?: string; + }; + }; + }; }; }; updateRecipe: { @@ -660,6 +737,17 @@ export interface operations { "application/json": components["schemas"]["Recipe"]; }; }; + /** @description Bad request */ + 400: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": { + msg?: string; + }; + }; + }; }; }; softDeleteRecipe: { @@ -680,6 +768,17 @@ export interface operations { }; content?: never; }; + /** @description Bad request */ + 400: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": { + msg?: string; + }; + }; + }; }; }; hardDeleteRecipe: { @@ -700,6 +799,17 @@ export interface operations { }; content?: never; }; + /** @description Bad request */ + 400: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": { + msg?: string; + }; + }; + }; }; }; createRecipeRelationship: { @@ -731,6 +841,17 @@ export interface operations { "application/json": components["schemas"]["Likes"]; }; }; + /** @description Bad request */ + 400: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": { + msg?: string; + }; + }; + }; }; }; deleteRecipeRelationship: { @@ -753,6 +874,17 @@ export interface operations { }; content?: never; }; + /** @description Bad request */ + 400: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": { + msg?: string; + }; + }; + }; }; }; } diff --git a/apps/app/src/lib/server/db-handler/person.ts b/apps/app/src/lib/server/db-handler/person.ts new file mode 100644 index 0000000..e69de29 diff --git a/apps/app/src/lib/server/db-handler/recipe.ts b/apps/app/src/lib/server/db-handler/recipe.ts new file mode 100644 index 0000000..e69de29 diff --git a/apps/app/src/lib/server/db.ts b/apps/app/src/lib/server/db.ts deleted file mode 100644 index 376f481..0000000 --- a/apps/app/src/lib/server/db.ts +++ /dev/null @@ -1,11 +0,0 @@ -import memgraph from 'neo4j-driver'; -import type { Driver } from 'neo4j-driver'; -import { MEMGRAPH_URI, MEMGRAPH_USER, MEMGRAPH_PASSWORD } from '$env/static/private'; - -export const DB: Driver = memgraph.driver( - MEMGRAPH_URI || 'bolt://localhost:7687', - memgraph.auth.basic( - MEMGRAPH_USER || 'memgraph', - MEMGRAPH_PASSWORD || 'memgraph' - ) -); diff --git a/apps/app/src/lib/server/user.ts b/apps/app/src/lib/server/user.ts deleted file mode 100644 index 2c26026..0000000 --- a/apps/app/src/lib/server/user.ts +++ /dev/null @@ -1,23 +0,0 @@ -import type { Session, QueryResult } from 'neo4j-driver'; -import type { Person, PersonProperties } from '$lib/model'; -import CreatePersonQuery from '$lib/server/queries/create_person.cypher?raw'; -import UpdatePersonQuery from '$lib/server/queries/update_person.cypher?raw'; -import GetPersonByGoogleID from '$lib/server/queries/get_person_by_google_id.cypher?raw'; - -export function createUser(db: Session, Person: PersonProperties): Promise> { - return db.executeWrite(tx => tx.run( - CreatePersonQuery, { props: Person }) - ); -} - -export function updateUser(db: Session, Person: PersonProperties): Promise> { - return db.executeWrite(tx => tx.run( - UpdatePersonQuery, { props: Person }) - ); -} - -export function getUserFromGoogleId(db: Session, googleID: string): Promise> { - return db.executeRead(tx => tx.run( - GetPersonByGoogleID, { google_id: googleID }) - ); -} diff --git a/apps/db-handler/.env.example b/apps/db-handler/.env.example new file mode 100644 index 0000000..a3cabe5 --- /dev/null +++ b/apps/db-handler/.env.example @@ -0,0 +1,3 @@ +MEMGRAPH_URI="bolt://localhost:7687" +MEMGRAPH_USER="memgraph" +MEMGRAPH_PASSWORD="memgraph" \ No newline at end of file diff --git a/apps/db-handler/go.mod b/apps/db-handler/go.mod index 46326c1..0da6f9d 100644 --- a/apps/db-handler/go.mod +++ b/apps/db-handler/go.mod @@ -1,4 +1,4 @@ -module github.com/vcscsvcscs/GenerationsHeritage/apps/db-handler +module github.com/vcscsvcscs/GenerationsHeritage/apps/db-adapter go 1.24