Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“ˆ Stock Market Portfolio API

A robust RESTful Web API built with .NET 8.0 for managing stock portfolios, including user authentication, stock tracking, comments, and portfolio management.

.NET C# SQL Server JWT Swagger


πŸš€ Features

  • User Authentication β€” Secure registration and login with JWT tokens
  • Stock Management β€” Full CRUD operations for stocks with filtering/sorting
  • Comment System β€” Users can comment on stocks
  • Portfolio Management β€” Track and manage user stock portfolios
  • API Documentation β€” Interactive Swagger UI for testing endpoints

πŸ“¦ Tech Stack

Technology Purpose
ASP.NET Core 8.0 Web API Framework
Entity Framework Core 8.0 ORM & Database Access
SQL Server Database
ASP.NET Identity User Authentication
JWT Bearer Tokens Authorization
Swagger/OpenAPI API Documentation
Newtonsoft.Json JSON Serialization

πŸ—‚οΈ Project Structure

API/
β”œβ”€β”€ Controllers/          # API Endpoints
β”‚   β”œβ”€β”€ AccountController.cs      # User registration & login
β”‚   β”œβ”€β”€ StockController.cs        # Stock CRUD operations
β”‚   β”œβ”€β”€ CommentController.cs      # Comment management
β”‚   └── PortfolioController.cs    # Portfolio management
β”œβ”€β”€ Models/               # Entity Models
β”‚   β”œβ”€β”€ AppUser.cs               # User model (extends IdentityUser)
β”‚   β”œβ”€β”€ Stock.cs                 # Stock entity
β”‚   β”œβ”€β”€ Comment.cs               # Comment entity
β”‚   └── Portfolio.cs             # Portfolio entity
β”œβ”€β”€ Dtos/                 # Data Transfer Objects
β”‚   β”œβ”€β”€ Account/                 # Login, Register, NewUser DTOs
β”‚   β”œβ”€β”€ Stock/                   # Stock request/response DTOs
β”‚   └── Comment/                 # Comment DTOs
β”œβ”€β”€ Repository/           # Data Access Layer
β”‚   β”œβ”€β”€ StockRepository.cs
β”‚   β”œβ”€β”€ CommentRepository.cs
β”‚   └── PortfolioRepository.cs
β”œβ”€β”€ Interfaces/           # Repository Interfaces
β”œβ”€β”€ Mappers/              # Entity <-> DTO Mappers
β”œβ”€β”€ Helpers/              # Query objects & utilities
β”œβ”€β”€ Extensions/           # Extension methods
β”œβ”€β”€ Service/              # Token service
β”œβ”€β”€ Data/                 # Database context
β”œβ”€β”€ Program.cs            # Application entry point
β”œβ”€β”€ appsettings.json      # Configuration
└── api.csproj            # Project file

πŸ”Œ API Endpoints

πŸ” Authentication

Method Endpoint Description Auth Required
POST /api/Account/register Register new user βœ…
POST /api/Account/login Login & get JWT token βœ…

πŸ“Š Stocks

Method Endpoint Description Auth Required
GET /api/stock Get all stocks (with filters) βœ…
GET /api/stock/{id} Get stock by ID βœ…
POST /api/stock Create new stock βœ…
PUT /api/stock/{id} Update stock βœ…
DELETE /api/stock/{id} Delete stock βœ…

Query Parameters for GET /api/stock:

  • Symbol β€” Filter by stock symbol
  • CompanyName β€” Filter by company name
  • SortBy β€” Sort results by field
  • IsDescending β€” Sort direction (true/false)

πŸ’¬ Comments

Method Endpoint Description Auth Required
GET /api/comment Get all comments βœ…
GET /api/comment/{id} Get comment by ID βœ…
POST /api/comment/{stockId} Add comment to stock βœ…
PUT /api/comment/{id} Update comment βœ…
DELETE /api/comment/{id} Delete comment βœ…

πŸ“ Portfolio

Method Endpoint Description Auth Required
GET /api/portfolio Get user's portfolio βœ…
POST /api/portfolio?symbol=XXX Add stock to portfolio βœ…

πŸ› οΈ Getting Started

Prerequisites

Installation

  1. Clone the repository

    git clone <repository-url>
    cd API
  2. Update the connection string

    Edit appsettings.json with your SQL Server details:

    {
      "ConnectionStrings": {
        "DefaultConnection": "server=YOUR_SERVER;database=YOUR_DATABASE;trusted_connection=true;TrustServerCertificate=true"
      }
    }
  3. Configure JWT settings (optional)

    Update JWT settings in appsettings.json:

    {
      "JWT": {
        "Issuer": "http://localhost:5246",
        "Audience": "http://localhost:5246",
        "SigningKey": "your-secure-signing-key-min-64-chars"
      }
    }
  4. Apply database migrations

    dotnet ef database update
  5. Run the application

    dotnet run
  6. Access Swagger UI

    Navigate to: https://localhost:5001/swagger or http://localhost:5000/swagger


πŸ”’ Authentication Flow

  1. Register a new user via POST /api/Account/register

    {
      "username": "johndoe",
      "email": "john@example.com",
      "password": "SecurePass123!"
    }
  2. Login via POST /api/Account/login to receive JWT token

    {
      "userName": "johndoe",
      "password": "SecurePass123!"
    }
  3. Use the token in subsequent requests:

    Authorization: Bearer <your-jwt-token>
    

Password Requirements

  • Minimum 8 characters
  • At least 1 uppercase letter
  • At least 1 lowercase letter
  • At least 1 digit
  • At least 1 special character
  • At least 1 unique character

πŸ“Š Data Models

Stock

Field Type Description
Id int Primary key
Symbol string Stock ticker symbol
CompanyName string Company name
Purchase decimal Purchase price
LastDiv decimal Last dividend
Industry string Industry sector
MarketCap long Market capitalization

Comment

Field Type Description
Id int Primary key
Title string Comment title
Content string Comment content
CreatedOn DateTime Creation timestamp
StockId int Related stock ID
AppUserId string Author user ID

Portfolio

Field Type Description
AppUserId string User ID (FK)
StockId int Stock ID (FK)

πŸ“ Sample Requests

Create a Stock

curl -X POST "https://localhost:5001/api/stock" \
  -H "Content-Type: application/json" \
  -d '{
    "symbol": "AAPL",
    "companyName": "Apple Inc.",
    "purchase": 150.00,
    "lastDiv": 0.24,
    "industry": "Technology",
    "marketCap": 2500000000000
  }'

Get Stocks with Filtering

curl -X GET "https://localhost:5001/api/stock?Symbol=AAPL&SortBy=CompanyName&IsDescending=true" \
  -H "Authorization: Bearer <your-token>"

πŸ§ͺ Testing with Swagger

  1. Run the application
  2. Open Swagger UI in your browser
  3. Click Authorize button (πŸ”)
  4. Enter: Bearer <your-jwt-token>
  5. Test any endpoint interactively

πŸ“„ License

This project is open source and available under the MIT License.


🀝 Contributing

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

πŸ“§ Contact

For questions or suggestions, please open an issue in the repository.


Made with ❀️ using .NET 8.0

About

A .Net 8 RESTfull API

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages