Implement API to add new user region. This feature is targeted at the overall admin of the application. As the application gains wide acceptance in different locations and regions, the need to effectively and continuously manage regions will come into play
Acceptance Criteria
Authentication
The endpoint should be protected and require the user to be authenticated.
If the user is not authenticated, the endpoint should return a 401 Unauthorized status with an appropriate error message.
Even after being authenticated, only an admin user can access the endpoint
Add Region
The endpoint should allow authenticated admin users to add a new region.
The region submission should include necessary fields like “region_code”, "region_name", "status"
Responses
200 OK: if the request is successful.
422 Bad Request: If any parameter is missing or invalid
500 Internal Server Error: An unexpected error occurred on the server side
Requirements
Create a database table for regions with the following columns
RegionCode - primary key
RegionName - region name/description
Status - indicates status
CreatedOn - for audit purposes
CreatedBy - for audit purposes
ModifiedOn - for audit purposes
ModifiedBy - for audit purposes
Create endpoints to add regions
Implement logic only to return active regions
Write unit test coverage for region service API
Expected Outcome
Admin users can add new regions through the provided API endpoints securely and efficiently.
Database Design
CREATE TABLE [dbo].[Region]
(
[RegionCode] NVARCHAR(20) NOT NULL,
[RegionName] NVARCHAR(100) NOT NULL,
[Status] INT NOT NULL,
[CreatedOn] DATETIME NOT NULL,
[CreatedBy] NVARCHAR (255) NOT NULL,
[ModifiedOn] DATETIME NOT NULL,
[ModifiedBy] NVARCHAR (255) NOT NULL,
CONSTRAINT [PK_Region] PRIMARY KEY ([RegionCode]),
)
[POST] v1/api/regions
This endpoint creates a region
{
"status_code": 200,
"message": "Operation was successful"
}
Sample Response on Error
{
"status_code": 422,
"data":
[
{
"message": "Region code is required"
"field": "region_code"
},
{
"message": "Region name is required"
"field": "region_name"
}
]
}
Purpose
This is to enhance user experience by enabling users to interact with the application in their preferred languages/regions. User contents can be filtered based on this feature
Security
Data Security:
Validation: Validate all inputs to prevent SQL injection and other security vulnerabilities.
Testing
Unit Tests:
Write unit tests to ensure the endpoint correctly stores the region.
Test various scenarios, including:
Multiple regions with the same region_code in the database.
Description
Implement API to add new user region. This feature is targeted at the overall admin of the application. As the application gains wide acceptance in different locations and regions, the need to effectively and continuously manage regions will come into play
Acceptance Criteria
Authentication
Add Region
Responses
Requirements
Expected Outcome
Database Design
[POST] v1/api/regions
This endpoint creates a regionSample Request
Sample Response on Success
Sample Response on Error
Purpose
This is to enhance user experience by enabling users to interact with the application in their preferred languages/regions. User contents can be filtered based on this feature
Security
Data Security:
Testing
Unit Tests: