hngprojects / hng_boilerplate_nestjs

Description
Apache License 2.0
182 stars 105 forks source link

[FEAT] Implement API to Add Regions #35

Closed dmendie closed 2 weeks ago

dmendie commented 1 month ago

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

  1. 200 OK: if the request is successful.
  2. 422 Bad Request: If any parameter is missing or invalid
  3. 500 Internal Server Error: An unexpected error occurred on the server side

Requirements

  1. 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
  2. Create endpoints to add regions
  3. Implement logic only to return active regions
  4. Write unit test coverage for region service API

Expected Outcome

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

Sample Request

POST /v1/api/regions
{
   "region_code": "UK"
   "region_name": "United Kingdom",
   "status": "active"
}

Sample Response on Success

{
  "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:

Testing

Unit Tests:

a

markessien commented 1 month ago

frontend

dmendie commented 1 month ago

@markessien awaiting review

dmendie commented 1 month ago

Team

Github Slack: @Mendie Github Slack: @tomi_l0la Github Slack: @Oni Oluwatomiwa Github Slack: @Asin Honore