This project is a .NET 8 backend API that connects to a PostgreSQL database. It provides endpoints for managing categories, questions, and answers, including uploading and streaming video files associated with answers.
- Server
The server application provides a RESTful API for:
- Categories: Managing categories for organizing questions.
- Questions: CRUD operations for interview questions.
- Answers: Handling video uploads and streaming for recorded answers.
Retrieves all categories.
-
Response:
-
Status:
200 OK -
Body:
[ { "id": "uuid", "name": "Databases" }, { "id": "uuid", "name": "Design Patterns" } ]
-
Retrieves all categories and the number of its submitted questions.
-
Response:
-
Status:
200 OK -
Body:
[ { "id": "uuid", "name": "Databases", "questionsCount": 1 }, { "id": "uuid", "name": "Design Patterns", "questionsCount": 1 } ]
-
Retrieves a specific category.
-
Response:
-
Status:
200 OK -
Body:
{ "id": "uuid", "name": "Databases" }
-
Adds a new category.
-
Request:
-
Headers:
Content-Type: application/json
-
Body:
{ "name": "Category Name" }
-
-
Response:
-
Status:
201 Created -
Body:
"uuid"
-
Updates an existing category.
-
Parameters:
id(required): UUID of the category to update.
-
Request:
-
Headers:
Content-Type: application/json
-
Body:
{ "name": "Category Name" }
-
-
Response:
-
Status:
200 OK -
Body:
{ "id": "uuid", "name": "Category Name" }
-
Deletes a category and its associated questions/answers.
-
Parameters:
id(required): UUID of the category to delete.
-
Response:
- Status:
204 No Content
- Status:
Retrieves questions and its answers, optionally filtered by category.
-
Parameters:
categoryId(optional): Optional category to filter questions by.content(optional): Optional content to filter questions by (case-insensitive).pageNumber: Optional page number for pagination. Defaults to 1.pageSize: Optional page size for pagination. If not provided, all matching questions are returned.
-
Response:
-
Status:
200 OK -
Body:
[ { "id": "uuid", "categoryId": "uuid", "content": "Question content", "hint": "Optional hint", "answersCount": 5 } ]
-
Retrieves a random question, optionally filtered by category.
-
Parameters:
categoryId(optional): UUID of the category to filter questions.
-
Response:
-
Status:
200 OK -
Body:
{ "id": "uuid", "categoryId": "uuid", "content": "Random question content", "hint": "Optional hint" }
-
Gets a specific question and its answers.
-
Parameters:
id(required): UUID of the question.
-
Response:
-
Status:
200 OK -
Body:
{ "question": { "id": "uuid", "categoryId": "uuid", "content": "Question content", "hint": "Optional hint" }, "answers": [ { "id": "uuid", "questionId": "uuid", "videoFileName": "123.webm", "createdAt": "Date" } ] }
-
Adds a new question.
-
Request:
-
Headers:
Content-Type: application/json
-
Body:
{ "categoryId": "uuid", "content": "New question content", "hint": "Optional hint" }
-
-
Response:
-
Status:
201 Created -
Body:
"uuid"
-
Updates an existing question.
-
Parameters:
id(required): UUID of the question to update.
-
Request:
-
Headers:
Content-Type: application/json
-
Body:
{ "categoryId": "uuid", "content": "Updated question content", "hint": "Updated hint" }
-
-
Response:
-
Status:
200 OK -
Body:
{ "id": "uuid", "categoryId": "uuid", "content": "Updated question content", "hint": "Updated hint" }
-
Deletes a question and its associated answers.
-
Parameters:
id(required): UUID of the question to delete.
-
Response:
- Status:
204 No Content
- Status:
Uploads a new answer video for a question.
-
Request:
-
Headers:
Content-Type: multipart/form-data
-
Body:
questionId(form field): UUID of the question being answered.videoFile(form field): The video file to upload.
-
-
Response:
-
Status:
201 Created -
Body:
"uuid"
-
Streams the video associated with the specific answer ID.
-
Parameters:
id(required): UUID of the answer.
-
Response:
-
Status:
200 OK -
Headers:
Content-Type: video/webm(or appropriate video MIME type)Accept-Ranges: bytes
-
Body:
- Binary video data.
-
-
Note: This endpoint supports video streaming with byte-range requests.
Gets an answer and its metadata.
-
Parameters:
id(required): UUID of the answer.
-
Response:
-
Status:
200 OK -
Body:
{ "id": "uuid", "questionId": "uuid", "videoFileName": "123.webm" }
-
Deletes an answer and its associated video file.
-
Parameters:
id(required): UUID of the answer to delete.
-
Response:
- Status:
204 No Content
- Status:
- Fields:
id: UUID (Primary Key)name: String
- Fields:
id: UUID (Primary Key)categoryId: UUID (Foreign key to Categories)content: Texthint: Text (Nullable)createdAt: TimestampupdatedAt: Timestamp
- Fields:
id: UUID (Primary Key)questionId: UUID (Foreign key to Questions)videoFilename: StringcreatedAt: TimestampupdatedAt: Timestamp
- .NET 8 SDK: Ensure you have the .NET 8 SDK installed.
- PostgreSQL: A running PostgreSQL instance.
- Entity Framework Core CLI: For running migrations.
-
Connection String
Update the
appsettings.jsonfile with your PostgreSQL connection string and the file path for storing video files:{ "ConnectionStrings": { "DefaultConnection": "Host=localhost;Database=YourDatabase;Username=YourUsername;Password=YourPassword" }, "VideoStorage": { "FilePath": "/videos/" } } -
Environment Variables
Alternatively, you can use environment variables to set the connection string.
-
Apply Migrations
Use Entity Framework Core to apply migrations and create the database schema.
dotnet ef database update
-
Run the Application
dotnet run
The API will be accessible at
http://localhost:5000(or the configured port).
Examples of how to manage migrations:
-
Add a Migration
dotnet ef migrations add InitialCreate --project Br1InterviewPreparation.Infrastructure --startup-project Br1InterviewPreparation.API
-
Update the Database
dotnet ef database update --project Br1InterviewPreparation.Infrastructure --startup-project Br1InterviewPreparation.API
Contributions are welcome! If you'd like to contribute to this project, please follow these steps:
-
Fork the Repository
Click the "Fork" button at the top right of the repository page to create a copy of the repository on your account.
-
Create a Feature Branch
git checkout -b feature/YourFeatureName
-
Commit Your Changes
git commit -am 'Add some feature' -
Push to the Branch
git push origin feature/YourFeatureName
-
Open a Pull Request
Go to your forked repository and click the "New Pull Request" button.
This project is licensed under the MIT License. See the LICENSE file for details.