Skip to content

Cloud Computing Course First Project: an Advertisement Registration System using Cloud Services

License

Notifications You must be signed in to change notification settings

amir78729/advertisment-registration

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Advertisement Registration using Cloud Services

Cloud Computing Course Project

Architecture

graph TD;
    Clinet-->ServerA;
    ServerA-->Clinet;
    MongoAtlas-->ServerB;
    Imagga-->ServerB;
    ServerB-->Imagga;
    ServerB-->MailGun;
    ServerA-->S3;
    ServerA-->RabbitMQ;
    ServerA-->MongoAtlas;
    RabbitMQ-->ServerB;
    S3-->ServerB;

Sequence Diagram

sequenceDiagram
    loop ServerA: Listenint to Client
        Client->>+ServerA: Request
        ServerA->>+MongoAtlas: Add Data to Database
        MongoAtlas-->>-ServerA: ACK
        ServerA->>+ArvanCloudS3: Upload Image to S3
        ArvanCloudS3-->>-ServerA: ACK
        ServerA->>+AmqpCloud: Send ID
        AmqpCloud-->>-ServerA: ACK
        ServerA-->>-Client: Response
    end
    loop ServerB: Listening to Queue
        AmqpCloud-->>+ServerB: ID
        ServerB-->>+Imagga: Image URL
        Imagga-->>-ServerB: Process Result
        ServerB->>+MongoAtlas: Update Ad Status
        MongoAtlas-->>-ServerB: ACK
        ServerB->>+Mailgun: Send Email
        Mailgun-->>-ServerB: ACK
    end

Instructions

Installing Packages

Run the following command to install needed packages:

npm i

Adding credential info to project

Create a src/credentials.js with this content:

const credentials = {
    mongodb: {
        url: '...',
    },
    mailgun: {
        domain: '...',
        apiKey: '...',
    },
    imagga: {
        authorization: '...',
    },
    amqp: {
        url: '...',
        queueKey: '...',
    },
    s3: {
        secretKey: '...',
        accessKey: '...',
        endpointUrl: '...',
        region: '...',
        bucketName: '...',
        bucketContentUrlPrefix: '...',
    },
}

module.exports = credentials;

Starting servers

Following command will start server A on port 3001 and server B on port 3002 and clients will be able to sent their request to server A.

node src  # running src/index.js

APIs

Check Server A

localhost:3001/

response Example:

{
    "result": "OK",
    "message": "Server A is UP!"
}

Get List of Advertisements

localhost:3001/ad

response Example:

{
    "result": "OK",
    "data": [
        {
            "id": 1,
            "description": "a simple description",
            "email": "[email protected]",
            "state": "PENDING",
            "category": "UNKNOWN",
            "image": "..."
        },
        {
            "id": 2,
            "description": "a great red sport car!",
            "email": "[email protected]",
            "state": "APPROVED",
            "category": "sports car",
            "image": "..."
        },
    ]
}

Get a single Advertisements

localhost:3001/ad/:id

response Example:

{
    "result": "OK",
    "data": {
        "id": 2,
        "description": "a great red sport car!",
        "email": "[email protected]",
        "state": "APPROVED",
        "category": "sports car",
        "image": "..."
    }
}

Submiting an Advertisement

localhost:3001/ad

Body (Form Data):

Field Name Type
image File (.jpg)
email String
description String

response Example:

{
    "result": "OK",
    "message": "آگهی شما با شناسه‌ی 3 ثبت گردید.",
    "data": {
        "id": 3,
        "description": "a simple description",
        "email": "[email protected]",
        "state": "PENDING",
        "image": "...",
        "category": "UNKNOWN"
    }
}

Removing an Advertisement

localhost:3001/ad/:id

response Example:

{
    "result": "OK",
    "data": {
        "acknowledged": true,
        "deletedCount": 1
    }
}

Removing All Advertisement

localhost:3001/ad

response Example:

{
    "result": "OK",
    "data": {
        "acknowledged": true,
        "deletedCount": 20
    }
}