Thanks to visit codestin.com
Credit goes to github.com

Skip to content

sthenusan/sit725-hd-task

Repository files navigation

Barter Trading System

Overview

This project is a barter trading system that allows users to trade items with each other. It includes features for user authentication, item management, trade creation, and more.

Features

  • User Authentication: Register, login, and manage user profiles.
  • Item Management: Create, update, and delete items for trade.
  • Trade Creation: Propose trades between users with offered and requested items.
  • Trade Status Updates: Accept or reject trades, which updates the status of the items involved.
  • Messaging: Users can send messages within a trade to communicate.

Testing

The project includes comprehensive tests to ensure functionality and reliability.

Running Tests

To run the tests, use the following command:

npm test

To run the tests serially (recommended to avoid race conditions), use:

npm test -- --runInBand

Technologies Used

  • Node.js: Backend runtime environment.
  • Express.js: Web framework for building the API.
  • MongoDB: Database for storing user and item data.
  • Mongoose: ODM for MongoDB.
  • Jest: Testing framework for unit and integration tests.
  • Cypress: End-to-end testing framework.

Getting Started

  1. Clone the repository.
  2. Install dependencies:
    npm install
  3. Set up your environment variables (e.g., MONGODB_URI).
  4. Run the application:
    npm run dev
  5. Run the tests:
    npm test

Docker Setup and Running Instructions

Prerequisites

  • Docker installed on your system
  • Docker Compose (optional, for easier management)

Step 1: Create Docker Network

First, create a Docker network for container communication:

docker network create my-network

Step 2: Start MongoDB Container

Start the MongoDB container:

docker run --network my-network \
  -p 27017:27017 \
  --name mongodb \
  mongo

Verify MongoDB is running:

docker ps | grep mongodb

Step 3: Build Application Image

Build the Docker image for the application:

docker build -t thenusan/barter-trading-system .

Step 4: Run Application Container

Run the application container with MongoDB connection:

docker run -p 3000:3000 \
  --network my-network \
  -e MONGODB_URI=mongodb://mongodb:27017/barter-trading \
  thenusan/barter-trading-system

Step 5: Verify Setup

  1. Check if MongoDB is accessible:
docker exec -it mongodb mongosh --eval "db.runCommand({ ping: 1 })"
  1. Access the application in your browser:
http://localhost:3000

Troubleshooting

If MongoDB Connection Fails:

  1. Check MongoDB container status:
docker ps | grep mongodb
  1. Check network connectivity:
docker network inspect my-network
  1. Verify MongoDB logs:
docker logs mongodb

If Application Container Fails:

  1. Check application logs:
docker logs <container_id>
  1. Verify environment variables:
docker exec -it <container_id> env | grep MONGODB_URI

Cleanup

When you're done, you can clean up the containers and network:

# Stop containers
docker stop mongodb
docker stop <app_container_id>

# Remove containers
docker rm mongodb
docker rm <app_container_id>

# Remove network
docker network rm my-network

# Remove image
docker rmi thenusan/barter-trading-system

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •