hngprojects / hng_boilerplate_nestjs

Description
Apache License 2.0
182 stars 105 forks source link

[FEAT] Implement Endpoint to UPDATE About Page Content: settable from admin #235

Closed thenoblet closed 2 weeks ago

thenoblet commented 1 month ago

Description

Implement an endpoint to UPDATE the content of the About page, allowing administrators to modify the information efficiently.


Purpose


Acceptance Criteria

Update About Page Content


Requirements

Update About Page Content


Expected Outcome


Checklist

  1. Update About Page Content

    • [ ] Implement PUT /api/v1/content/about endpoint.
    • [ ] Validate incoming content and handle errors effectively.
    • [ ] Secure endpoint with authentication for administrators.
    • [ ] Document endpoint, including request and response formats.

Testing

Documentation:


Endpoint

Description: Update the content of the About page.
Endpoint: PUT /api/v1/content/about
Authentication: Required
Authorization: Administrators only
Request Body:

{
    "title": "More Than Just A BoilerPlate",
    "introduction": "Welcome to Hng Boilerplate, where passion meets innovation.",
    "custom_sections": {
      "stats": {
        "years_in_business": 10,
        "customers": 75000,
        "monthly_blog_readers": 100000,
        "social_followers": 1200000
      },
      "services": {
        "title": "Trained to Give You The Best",
        "description": "Since our founding, Hng Boilerplate has been dedicated to constantly evolving to stay ahead of the curve."
      }
    }
}

Response (Success):

{
  "message": "About page content updated successfully.",
  "status_code": 200
}

Response (Error: Server Error):

{
  "message": "Failed to update About page content.",
  "status_code": 500
}

Response (Error: Unauthenticated):

{
  "message": "Invalid authentication credentials",
  "status_code": 401
}

Response (Error: Authenticated but Unauthorised):

{
  "message": "You do not have permission to perform this action.",
  "status_code": 403
}

Additional Notes:

markessien commented 1 month ago

I suggest that you use a more generic key-value system and do not pre-define the individual pieces. This way people can add new sections to the about page

thenoblet commented 1 month ago

I suggest that you use a more generic key-value system and do not pre-define the individual pieces. This way people can add new sections to the about page

Yessir! On it. 🫡

thenoblet commented 1 month ago

@markessien, I refined the issue, Sir.

Updated Issue with Key-Value System

The updated issue uses a generic key-value system, which allows for a more dynamic and flexible approach to managing the About page content.

Updates Made

I added a customSections key that can hold any number of key-value pairs. This makes it easy to add, modify, or remove sections without changing the backend code.

Administrators can simply add a new key-value pair to the customSections object, such as "history": "Our company was founded in...", without requiring any changes to the backend.

Example: Adding a new "history" section Endpoint: PUT /api/v1/about Request Body:

{
    "title": "More Than Just A BoilerPlate",
    "introduction": "Welcome to Hng Boilerplate, where passion meets innovation.",
    "custom_sections": {
      "stats": {
        "years_in_business": 10,
        "customers": 75000,
        "monthly_blog_readers": 100000,
        "social_followers": 1200000
      },
      "services": {
        "title": "Trained to Give You The Best",
        "description": "Since our founding, Hng Boilerplate has been dedicated to constantly evolving to stay ahead of the curve."
      },
      **"history": "Our company was founded in 2010..."**
    }
}
highb33kay commented 1 month ago

More than one endpoints. Please break it up and focus on one specific endpoint for easy tracking

@thenoblet

highb33kay commented 1 month ago

Response doesnt follow org structure.

{
  "content": {
    "title": "More Than Just A BoilerPlate",
    "introduction": "Welcome to Hng Boilerplate, where passion meets innovation.",
    "customSections": {
      "stats": {
        "yearsInBusiness": 10,
        "customers": 75000,
        "monthlyBlogReaders": 100000,
        "socialFollowers": 1200000
      },
      "services": {
        "title": "Trained to Give You The Best",
        "description": "Since our founding, Hng Boilerplate has been dedicated to constantly evolving to stay ahead of the curve."
      }
    }
  },
  "updatedAt": "2024-07-18T12:00:00Z",
  "statusCode": 200
}
highb33kay commented 1 month ago

Authentication and Authorization?

thenoblet commented 1 month ago

@highb33kay, I have refined it to include authorisation & authentication, broken them into specific endpoints, and changed the Response to follow org structure.

RETRIEVE operation issue #265

githukueliud commented 1 month ago

Hello

nadduli commented 1 month ago

Hello

thenoblet commented 1 month ago

@markessien, @highb33kay

An Afterthought (DB schema): Whilst implementing this, I realised it'd be cool to track which admin made changes to the content of the About Page. So, I'll need to extend the database schema and application logic to include user information for auditing purposes.

Is that something I can do, please? The DB and Auth guys are not really coming to through for us. Painful.

@nadduli and @githukueliud, guys look out for the response here.