This project is an ASP.NET Core Web API that provides CRUD operations for managing personal data and associated addresses. The backend uses Entity Framework Core (EF Core) to interact with a PostgreSQL database. The database contains two tables: PersonalData
and Addresses
, which are related through a foreign key relationship.
- Personal Data Management: Allows users to create, read, update, and delete personal data records.
- Address Management: Supports operations for handling address records associated with personal data.
- RESTful API: Follows REST principles, making it easy to integrate with other systems.
- Entity Framework Core: Utilizes EF Core for database interactions, including querying and updating the PostgreSQL database.
- Error Handling: Implements error handling for invalid requests, including invalid IDs and missing data.
- Controllers: Handles incoming HTTP requests and returns appropriate responses.
PersonalDataController
: Manages operations related to personal data.
- Models: Defines the data structure used in the database.
PersonalData
: Represents a person with fields likeName
,PhoneNumber
, andAddressId
.Address
: Represents an address with fields likeStreet
,City
,State
, andPostalCode
.
- Data: Contains the database context which handles communication with the PostgreSQL database.
TodoDb
: The database context that includesDbSet<PersonalData>
andDbSet<Address>
for interacting with the respective tables.
The project uses PostgreSQL as the database. It contains two tables:
-
PersonalData:
Id
(Primary Key): Unique identifier for each person.Name
: Name of the person.PhoneNumber
: Contact number of the person.IsComplete
: A boolean indicating if the record is complete.AddressId
(Foreign Key): Links to theAddress
table.
-
Addresses:
Id
(Primary Key): Unique identifier for each address.Street
: Street information.City
: City information.State
: State information.PostalCode
: Postal code information.
- Each
PersonalData
entry is associated with oneAddress
through theAddressId
foreign key. - The
Address
entity is a navigation property in thePersonalData
model, allowing for easy access and manipulation of related address data.
- GET /api/PersonalData/GetPersonalDatas: Retrieves all personal data entries.
- GET /api/PersonalData/GetTodoById/{id}: Retrieves a specific personal data entry by ID.
- GET /api/PersonalData/GetPersonalDataByName/{name}: Retrieves personal data entries by name.
- POST /api/PersonalData/PostTodo: Creates a new personal data entry.
- PUT /api/PersonalData/PutTodo/{id}: Updates an existing personal data entry by ID.
- DELETE /api/PersonalData/DeleteTodo/{id}: Deletes a personal data entry by ID.
- GET /api/Addresses/GetAddresses: Retrieves all address entries.
- GET /api/Addresses/GetAddressById/{id}: Retrieves a specific address by ID.
- POST /api/Addresses/PostAddress: Creates a new address entry.
- PUT /api/Addresses/PutAddress/{id}: Updates an existing address entry by ID.
- DELETE /api/Addresses/DeleteAddress/{id}: Deletes an address entry by ID.
- .NET 7 SDK: Required to build and run the API.
- PostgreSQL: Ensure PostgreSQL is installed and running. You will need to configure the connection string in the
appsettings.json
file.
-
Clone the repository:
git clone https://github.com/your-repo/your-project.git cd your-project
-
Configure the Database Connection:
- Open
appsettings.json
. - Update the connection string to point to your PostgreSQL database.
- Open
-
Apply Migrations:
- Open the terminal in the project directory.
- Run the following commands to apply migrations and create the database:
dotnet ef migrations add InitialCreate dotnet ef database update
-
Run the API:
dotnet run
-
Test the API:
- You can use tools like Postman or Swagger UI (available at
http://localhost:<port>/swagger
) to interact with the API.
- You can use tools like Postman or Swagger UI (available at
- Invalid ID Handling: Returns a
400 Bad Request
if the provided ID is invalid. - Not Found: Returns a
404 Not Found
if the requested resource does not exist. - Bad Request: Returns a
400 Bad Request
if the input data is not valid.
- Validation: Add more robust validation rules for input data.
- Authentication & Authorization: Secure the API by adding authentication and role-based authorization.
- Logging: Implement logging to track API usage and errors.
- Pagination: Add pagination for
GET
requests to handle large datasets efficiently.
This project is licensed under the MIT License - see the LICENSE file for details.
This `README.md` file provides a comprehensive overview of your project, including setup instructions, endpoint descriptions, and potential areas for future improvement.