Giter VIP home page Giter VIP logo

minimalchat.api's Introduction

Chat Application Backend

This is the backend implementation of a minimal chat application using ASP.NET Core and Entity Framework. The goal of this project is to provide a set of APIs that enable user registration, authentication, conversation management, and message handling.

Tech Stack

  • ASP.NET Core 7
  • EF Core 7 with Code-First approach
  • SQL Server Express
  • JWT-based Authentication

Project Structure

The project is organized as follows:

  • Controllers: Contains API controllers for user registration, login, user listing, message management, and log retrieval.

  • Models: Defines the data models used in the application, such as User and Message.

  • Services: Contains the business logic for user registration, authentication, message handling, and logging.

  • Data: Includes the database context and migration files for Entity Framework.

  • Middleware: Contains the custom request-logging middleware for capturing API request details.

  • Repositories: Implements the repository pattern for data access.

Implemented Functionalities

User Registration

  • API Endpoint: POST /api/register
  • Request Parameters: email, name, password
  • Responses: 200 OK, 400 Bad Request, 409 Conflict
  • Response Body: userId, name, email (in case of success), error (in case of failure)
  • Passwords are securely hashed and stored in the database.

User Login

  • API Endpoint: POST /api/login
  • Request Parameters: email, password
  • Responses: 200 OK, 400 Bad Request, 401 Unauthorized
  • Response Body: token (JWT token), profile (user details), error (in case of failure)
  • JWT token is generated upon successful login and used for authentication.

Retrieve User List

  • API Endpoint: GET /api/users
  • Responses: 200 OK, 401 Unauthorized
  • Response Body: users (array of user objects), error (in case of failure)
  • The list of users does not include the user making the request.

Send Message

  • API Endpoint: POST /api/messages
  • Request Parameters: receiverId, content
  • Request Headers: Authorization (Bearer token)
  • Responses: 200 OK, 400 Bad Request, 401 Unauthorized
  • Response Body: messageId, senderId, receiverId, content, timestamp (in case of success), error (in case of failure)

Edit Message

  • API Endpoint: PUT /api/messages/{messageId}
  • Request Parameters: messageId, content
  • Request Headers: Authorization (Bearer token)
  • Responses: 200 OK, 400 Bad Request, 401 Unauthorized, 404 Not Found
  • Response Body: error (in case of failure)
  • Users can only edit their own messages.

Delete Message

  • API Endpoint: DELETE /api/messages/{messageId}
  • Request Parameters: messageId
  • Request Headers: Authorization (Bearer token)
  • Responses: 200 OK, 401 Unauthorized, 404 Not Found
  • Response Body: error (string): Error message indicating the cause of the failure

Note: Users can only delete messages sent by them and not by other users.

Retrieve Conversation History

  • API Endpoint: GET /api/messages
  • Request Parameters: userId, before, count, sort
  • Request Headers: Authorization (Bearer token)
  • Responses: 200 OK, 400 Bad Request, 401 Unauthorized, 404 Not Found
  • Response Body: messages (array of message objects), error (in case of failure)

Request-Logging Middleware

  • Custom middleware logs API requests with details like IP, request body, time, and username (if authenticated).
  • API to fetch logs:
    • Endpoint: GET /api/log
    • Request Parameters: EndTime, StartTime
    • Request Headers: Authorization (Bearer token)
    • Responses: 200 OK, 400 Bad Request, 401 Unauthorized, 404 Not Found
    • Response Body: Logs (array of log objects), error (in case of failure)

Getting Started

  1. Clone this repository to your local machine.
  2. Set up the database connection string in appsettings.json to SQL Server.
  3. Run the Entity Framework migrations to create the database: dotnet ef database update.
  4. Build and run the application using dotnet run.
  5. Access the API endpoints as described above.

Contributing

  1. Fork the repository.
  2. Create a feature branch (git checkout -b feature/your-feature-name).
  3. Commit your changes (git commit -m 'Add some feature').
  4. Push to the branch (git push origin feature/your-feature-name).
  5. Create a new Pull Request.

Code Review

To review the code, please check the dev branch. All code should be merged into the dev branch for testing and review before being merged into the main branch for production deployment.

Your feedback and contributions are highly appreciated!

License

This project is licensed under the MIT License.

minimalchat.api's People

Contributors

vipul1432 avatar vipul143212 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

duckmahn

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.