Skip to content

User APIs

Sulabh Mehta (Dominik) edited this page Nov 10, 2023 · 2 revisions

Models

The following models are used in the project:

  • User: Represents a user in the system.

Controllers

The following controllers handle the incoming requests:

  • UserController: Handles requests related to users.

Services

The following methods are used in the user service:

  • GetUserByEmail: Retrieves a user by their email address.
  • GetUserByProviderAccountId: Retrieves a user by their provider account ID.
  • InsertUser: Inserts a new user into the database.
  • UpdateUserByProviderAccountID: Updates a user by their provider account ID.

Routes

The following routes are available:

  • /api/login: Creates a new user or updates an existing user.
  • /api/user: Retrieves a user by their email address.

Routes Documentation

Create or Update User Account upon Login

/api/login

Method: POST

Request body:

{
  "username": "string",
  "name": "string",
  "email": "string",
  "role": "string",
  "provider": "string",
  "providerAccountId": "string"
}

Response body:

{
  "_id": "primitive.ObjectID",
  "username": "string",
  "name": "string",
  "email": "string",
  "role": "string",
  "provider": "string",
  "providerAccountId": "string"
}

Example Usage

To create a new user, send a POST request to the /api/login route with the following request body:

{
  "username": "johndoe",
  "name": "John Doe",
  "email": "john.doe@example.com",
  "role": "user",
  "provider": "google",
  "providerAccountId": "1234567890"
}

If the user is created successfully, the response body will contain the user's data.

Get User by Email

/api/user

Method: POST

Request body:

{
  "email": "string",
}

Response body:

{
  "_id": "primitive.ObjectID",
  "username": "string",
  "name": "string",
  "email": "string",
  "role": "string",
  "provider": "string",
  "providerAccountId": "string"
}

Example Usage

To retrieve a user by their email address, send a POST request to the /api/user route with the following request body:

{
    "email": "john.doe@example.com",
}

If the user is found, the response body will contain the user's data.

Clone this wiki locally