Verlet Intergration Soft Body
Loading...
Searching...
No Matches
PhysicsCSAlevlProject.Game1Database Class Reference

Classes

class  User
 the class repesenting the User in the datbase matching the Users table with properties for Id, Username, RoleId and Password. This class is used to deserialize user information retrieved from the database and to create new users when saving to the database. It provides a structured way to represent user data within the application and facilitates interactions with the database for user-related operations. More...
class  StructureInfo
 the class representing the structure information retrieved from the database, including properties for Id, AssignmentId, StudentId, StudentName, AssignmentTitle and SubmittedAt. More...
class  Assignment
 the class representing an assignment in the database with properties for Id, Title, Description and TeacherId. More...
class  Roles
 the class representing user roles in the database with static readonly properties for Teacher and Student role IDs. More...

Public Member Functions

 Game1Database (ImGuiLogger logger)
void TestConnection ()
List< int > GetStudents ()
 Retrieves a list of student IDs from the database by executing a SQL query that selects the IDs of users with a role_id of 2 (indicating they are students). The method opens a connection to the database, executes the query, and reads the results into a list of integers. If there are any issues during the database connection or query execution, it logs the error message using the ImGuiLogger and rethrows the exception for further handling. This method provides a way to programmatically access student information from the database for use in the application.
List< int > GetTeachers ()
 Retrieves a list of teacher IDs from the database by executing a SQL query that selects the IDs of users with a role_id of 1 (indicating they are teachers). The method opens a connection to the database, executes the query, and reads the results into a list of integers. If there are any issues during the database connection or query execution, it logs the error message using the ImGuiLogger and rethrows the exception for further handling. This method provides a way to programmatically access teacher information from the database for use in the application.
List< UserGetTeachersWithInfo ()
 Retrieves a list of teacher information from the database by executing a SQL query that selects the id, username, role_id, and password of users with a role_id of 1 (indicating they are teachers). The method opens a connection to the database, executes the query, and reads the results into a list of User objects containing the relevant information. If there are any issues during the database connection or query execution, it logs the error message using the ImGuiLogger and rethrows the exception for further handling. This method provides a way to programmatically access detailed teacher information from the database for use in the application.
Dictionary< string, string > GetStudentStructures (int studentId)
 Retrieves a dictionary of student structures from the database for a given student ID by executing a SQL query that selects the content of structures associated with the specified student. The method opens a connection to the database, executes the query, and reads the results into a dictionary where the key is "content" and the value is the JSON string representing the structure. If there are any issues during the database connection or query execution, it logs the error message using the ImGuiLogger and rethrows the exception for further handling. This method provides a way to programmatically access a student's saved structures from the database for use in the application.
User GetUser (string user)
 Retrieves a user from the database based on the provided username or user ID. If the input can be parsed as an integer, it treats it as a user ID and retrieves the user by ID. Otherwise, it treats the input as a username and retrieves the user by username. The method opens a connection to the database, executes the appropriate SQL query, and reads the results into a User object containing the relevant information. If there are any issues during the database connection or query execution, it logs the error message using the ImGuiLogger and rethrows the exception for further handling. This method provides a way to programmatically access user information from the database based on either username or user ID for use in the application.
int CreateUser (string username, int roleId)
 Creates a new user in the database with the specified username and role ID.
int CreateAssignment (string title, string description, DateTime? dueDate, int teacherId)
 Creates a new assignment in the database with the specified title, description, due date, and teacher ID.
List< StructureInfoGetStructuresForUser (int userId)
 gets all structures owned by the given userid
string GetStructureContent (int structureId)
 Retrieves the content of a structure from the database based on the provided structure ID. The method opens a connection to the database, executes a SQL query to select the content of the structure with the specified ID, and returns the content as a string. If there are any issues during the database connection or query execution, it logs the error message using the ImGuiLogger and rethrows the exception for further handling. This method provides a way to programmatically access the content of a specific structure from the database for use in the application.
int SaveStructureWithName (int studentId, string contentJson, string title=null, int? assignmentId=null)
 saves a structure to the database with the given student ID, content JSON, title and assignment ID.
List< AssignmentGetAssignmentsForTeacher (int teacherId)
 lists all assignments for a given teacher ID by querying the database and returns a list of Assignment objects
List< StructureInfoGetStructuresForAssignment (int assignmentId)
 returns a list of structures for a given assignment ID used for teachers to view all student submissions for a given assignment

Public Attributes

ImGuiLogger logger
 The ImGuiLogger instance used for logging messages related to database operations.

Private Member Functions

NpgsqlConnection OpenConnection ()
 Opens a connection to the PostgreSQL database using the provided connection string. If the connection is successful, it returns an open NpgsqlConnection object that can be used for executing queries. If there is an error during the connection process, it logs the error message using the provided ImGuiLogger and rethrows the exception to be handled by the calling code. This method centralizes the database connection logic and ensures that any issues are properly logged for debugging purposes.
User GetUserById (int userId)
 returns the User class using the userid from the database if fails returns null and logs the error

Private Attributes

readonly string _connectionString
 The connection string used to connect to the PostgreSQL database,.

Member Function Documentation

◆ CreateAssignment()

int PhysicsCSAlevlProject.Game1Database.CreateAssignment ( string title,
string description,
DateTime? dueDate,
int teacherId )
inline

Creates a new assignment in the database with the specified title, description, due date, and teacher ID.

Parameters
title
description
dueDate
teacherId
Returns

◆ CreateUser()

int PhysicsCSAlevlProject.Game1Database.CreateUser ( string username,
int roleId )
inline

Creates a new user in the database with the specified username and role ID.

Parameters
username
roleId
Returns

◆ GetAssignmentsForTeacher()

List< Assignment > PhysicsCSAlevlProject.Game1Database.GetAssignmentsForTeacher ( int teacherId)
inline

lists all assignments for a given teacher ID by querying the database and returns a list of Assignment objects

Parameters
teacherId
Returns

◆ GetStructureContent()

string PhysicsCSAlevlProject.Game1Database.GetStructureContent ( int structureId)
inline

Retrieves the content of a structure from the database based on the provided structure ID. The method opens a connection to the database, executes a SQL query to select the content of the structure with the specified ID, and returns the content as a string. If there are any issues during the database connection or query execution, it logs the error message using the ImGuiLogger and rethrows the exception for further handling. This method provides a way to programmatically access the content of a specific structure from the database for use in the application.

Parameters
structureId
Returns
StructureJson

◆ GetStructuresForAssignment()

List< StructureInfo > PhysicsCSAlevlProject.Game1Database.GetStructuresForAssignment ( int assignmentId)
inline

returns a list of structures for a given assignment ID used for teachers to view all student submissions for a given assignment

Parameters
assignmentId
Returns

◆ GetStructuresForUser()

List< StructureInfo > PhysicsCSAlevlProject.Game1Database.GetStructuresForUser ( int userId)
inline

gets all structures owned by the given userid

Parameters
userId
Returns

◆ GetStudents()

List< int > PhysicsCSAlevlProject.Game1Database.GetStudents ( )
inline

Retrieves a list of student IDs from the database by executing a SQL query that selects the IDs of users with a role_id of 2 (indicating they are students). The method opens a connection to the database, executes the query, and reads the results into a list of integers. If there are any issues during the database connection or query execution, it logs the error message using the ImGuiLogger and rethrows the exception for further handling. This method provides a way to programmatically access student information from the database for use in the application.

Returns

◆ GetStudentStructures()

Dictionary< string, string > PhysicsCSAlevlProject.Game1Database.GetStudentStructures ( int studentId)
inline

Retrieves a dictionary of student structures from the database for a given student ID by executing a SQL query that selects the content of structures associated with the specified student. The method opens a connection to the database, executes the query, and reads the results into a dictionary where the key is "content" and the value is the JSON string representing the structure. If there are any issues during the database connection or query execution, it logs the error message using the ImGuiLogger and rethrows the exception for further handling. This method provides a way to programmatically access a student's saved structures from the database for use in the application.

Parameters
studentId
Returns

◆ GetTeachers()

List< int > PhysicsCSAlevlProject.Game1Database.GetTeachers ( )
inline

Retrieves a list of teacher IDs from the database by executing a SQL query that selects the IDs of users with a role_id of 1 (indicating they are teachers). The method opens a connection to the database, executes the query, and reads the results into a list of integers. If there are any issues during the database connection or query execution, it logs the error message using the ImGuiLogger and rethrows the exception for further handling. This method provides a way to programmatically access teacher information from the database for use in the application.

Returns

◆ GetTeachersWithInfo()

List< User > PhysicsCSAlevlProject.Game1Database.GetTeachersWithInfo ( )
inline

Retrieves a list of teacher information from the database by executing a SQL query that selects the id, username, role_id, and password of users with a role_id of 1 (indicating they are teachers). The method opens a connection to the database, executes the query, and reads the results into a list of User objects containing the relevant information. If there are any issues during the database connection or query execution, it logs the error message using the ImGuiLogger and rethrows the exception for further handling. This method provides a way to programmatically access detailed teacher information from the database for use in the application.

Returns

◆ GetUser()

User PhysicsCSAlevlProject.Game1Database.GetUser ( string user)
inline

Retrieves a user from the database based on the provided username or user ID. If the input can be parsed as an integer, it treats it as a user ID and retrieves the user by ID. Otherwise, it treats the input as a username and retrieves the user by username. The method opens a connection to the database, executes the appropriate SQL query, and reads the results into a User object containing the relevant information. If there are any issues during the database connection or query execution, it logs the error message using the ImGuiLogger and rethrows the exception for further handling. This method provides a way to programmatically access user information from the database based on either username or user ID for use in the application.

Parameters
user
Returns

◆ GetUserById()

User PhysicsCSAlevlProject.Game1Database.GetUserById ( int userId)
inlineprivate

returns the User class using the userid from the database if fails returns null and logs the error

Parameters
userId
Returns

◆ OpenConnection()

NpgsqlConnection PhysicsCSAlevlProject.Game1Database.OpenConnection ( )
inlineprivate

Opens a connection to the PostgreSQL database using the provided connection string. If the connection is successful, it returns an open NpgsqlConnection object that can be used for executing queries. If there is an error during the connection process, it logs the error message using the provided ImGuiLogger and rethrows the exception to be handled by the calling code. This method centralizes the database connection logic and ensures that any issues are properly logged for debugging purposes.

Returns

◆ SaveStructureWithName()

int PhysicsCSAlevlProject.Game1Database.SaveStructureWithName ( int studentId,
string contentJson,
string title = null,
int? assignmentId = null )
inline

saves a structure to the database with the given student ID, content JSON, title and assignment ID.

Parameters
studentId
contentJson
title
assignmentId
Returns

The documentation for this class was generated from the following file:
  • PhysicsCSAlevlProject/Game1.sql.cs