Skip to content

CorpEdward/backendTechnicalAssignment

Repository files navigation

Smartphone Catalog API

A Laravel 12 backend application that serves a smartphone product catalog with real-time currency conversion (USD to UAH) using the National Bank of Ukraine (NBU) exchange rates.

Features

  • Browse smartphone catalog sourced from DummyJSON
  • View prices in USD (original) or UAH (converted via NBU rates)
  • Retrieve the current USD/UAH exchange rate from the NBU API
  • Modular domain-driven architecture for the Currency module

Tech Stack

  • PHP ^8.2
  • Laravel 12
  • PHPUnit 11 for testing
  • Docker via Laravel Sail (PHP 8.5, MySQL 8.4, Redis, Memcached)

API Endpoints

GET /api/catalog/{currency}

Returns a list of smartphones with prices in the requested currency.

Parameter Type Allowed Values Description
currency string usd, uah Currency for product prices

Response (200):

{
  "data": [
    {
      "id": 1,
      "title": "iPhone 5s",
      "price": 199.99,
      "rating": 2.83,
      "thumbnail": "https://cdn.dummyjson.com/..."
    }
  ]
}

Unsupported currencies return 404.

GET /api/exchangeRate/USD

Returns the current USD to UAH exchange rate from the NBU.

Response (200):

{
  "data": {
    "currencyCode": "USD",
    "rate": 43.0996,
    "exchangeDate": "02.03.2026"
  }
}

Project Structure

app/
├── Http/
│   ├── Controllers/
│   │   └── CatalogController.php       # Smartphone catalog endpoint
│   └── Requests/
│       └── CatalogRequest.php           # Validates currency parameter
├── Models/
│   └── User.php
└── Modules/
    └── Currency/
        ├── Application/
        │   ├── Facades/
        │   │   └── CurrencyExchangeFacade.php   # Entry point for currency operations
        │   └── Http/
        │       ├── Controllers/
        │       │   └── ExchangeRateController.php
        │       └── Requests/
        │           └── ExchangeRateRequest.php
        ├── Domain/
        │   ├── ConvertedPrice.php               # DTO for converted price data
        │   ├── CurrencyExchangeService.php      # Core exchange logic
        │   └── CurrencyRate.php                 # DTO for rate data
        ├── Infrastructure/
        │   └── NbuApiCurrencyRepository.php     # NBU API integration
        └── Providers/
            └── CurrencyServiceProvider.php      # DI bindings

Getting Started

Prerequisites

  • PHP 8.2+ (or Docker)
  • Composer
  • Node.js & npm

Quick Setup

composer setup

This runs composer install, copies .env.example to .env, generates the app key, runs migrations, and builds frontend assets.

Using Docker (Laravel Sail)

cp .env.example .env

# Start the containers
./vendor/bin/sail up -d

# Install dependencies and set up the application
./vendor/bin/sail composer setup

The application will be available at http://localhost.

Local Development

composer dev

This starts the Laravel dev server, queue worker, log watcher (Pail), and Vite concurrently.

Running Tests

composer test

Or directly with PHPUnit:

php artisan test

Tests use Http::fake() to mock external API calls (DummyJSON and NBU), so no network access is needed.

Test Coverage

  • Catalog endpoint — USD/UAH responses, price conversion, currency validation, HTTP method restrictions
  • Exchange rate endpoint — JSON structure, rate values, HTTP method restrictions
  • Both endpoints verified to not require authentication

External APIs

API Purpose URL
DummyJSON Smartphone product data https://dummyjson.com/products/category/smartphones
NBU USD/UAH exchange rate https://bank.gov.ua/NBUStatService/v1/statdirectory/exchange

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors