Files
Govor/docs/endpoints/friendshipcontroller.md
T
2025-07-24 20:35:50 +07:00

2.8 KiB

description
description
Description: Controller for managing friendship-related operations, including searching for users and retrieving the list of friends for the current user.

FriendshipController

Controller Description

  • Route: api/friends
  • Authorize: Requires authenticated user ([Authorize]).

Endpoints

  • Description: Searches for users based on a query string.
  • Route: [GET] api/friends/search?query=
  • HTTP Method: GET
  • Request:
    • Query Parameter: query (string, required)
  • Responses:
    • 200 OK: Returns a list of matching users.

      [
        {
          "id": "Guid",
          "username": "string",
          "description": "string",
          "wasOnline": "DateTime",
          "iconId": "Guid"
        }
      ]
      
    • 400 Bad Request: If the query is empty.

      "Query cannot be empty"
      
    • 403 Forbidden: If user lacks authorization.

      "string"
      
    • 500 Internal Server Error: Indicates an unexpected error.

      {
        "error": "Internal error during user search."
      }
      

GetFriends

  • Description: Retrieves the list of friends for the authenticated user.
  • Route: [GET] api/friends
  • HTTP Method: GET
  • Request: None
  • Responses:
    • 200 OK: Returns a list of the user's friends or an empty list if none.

      [
        {
          "id": "Guid",
          "username": "string",
          "description": "string",
          "wasOnline": "DateTime",
          "iconId": "Guid"
        }
      ]
      
    • 403 Forbidden: If user lacks authorization.

      "string"
      
    • 500 Internal Server Error: Indicates an unexpected error.

      {
        "error": "Internal server error."
      }
      

Data Models

UserDto

  • Description: Data transfer object for user information.

  • Structure:

    {
      "id": "Guid",
      "username": "string",
      "description": "string",
      "wasOnline": "DateTime",
      "iconId": "Guid"
    }
    

Error Handling

  • Invalid User ID: Handled by ICurrentUserService, aborts if invalid.
  • Invalid Operations: Returns 400 Bad Request for empty query.
  • Unexpected Errors: Caught and returned as 500 Internal Server Error.

Logging

  • Logs warnings for SearchUsersException.
  • Logs errors for unexpected exceptions and InvalidOperationException.