Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 17 additions & 18 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,30 @@ name: Node.js CI

on:
push:
branches: [ "main", "CI_CD" ]
branches: ['main', 'CI_CD']
pull_request:
branches: [ "main" ]
branches: ['main']
workflow_dispatch:

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
node-version: [ 22.x]
node-version: [22.x]
mongodb-version: [8.0]
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- name: Start MongoDB
uses: supercharge/mongodb-github-action@1.12.0
with:
mongodb-version: ${{ matrix.mongodb-version }}
- run: |
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- name: Start MongoDB
uses: supercharge/mongodb-github-action@1.12.0
with:
mongodb-version: ${{ matrix.mongodb-version }}
- run: |
echo "TZ=UTC" >> .env
echo "PORT=8000" >> .env
echo "HOST=localhost" >> .env
Expand All @@ -38,6 +37,6 @@ jobs:
echo "SESSION_DRIVER=cookie" >> .env
echo "MONGO_URI=mongodb://localhost:27017/citium" >> .env
echo "JWT_SECRET=$(openssl rand -base64 32)" >> .env
- run: npm ci
- run: node ace generate:key
- run: node ace test --force-exit
- run: npm ci
- run: node ace generate:key
- run: node ace test --force-exit
24 changes: 20 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,47 @@
Innovative web platform for monitoring small construction sites in the city of Trento. This repository contains the backend services responsible for authentication, user management, construction site data, and real-time notifications.

## 🚀 Features

- 🔐 **Authentication & Authorization** – Secure stateful API authentication using MongoDB.
- 🏗 **Construction Site Management** – CRUD operations for managing construction sites.
- 🔔 **Real-time Notifications** – Subscription system for users to receive updates on construction sites.
- 📊 **API Documentation** – Fully documented REST APIs.
- 📦 **Scalability** – Built with AdonisJS for a modular and maintainable backend.

## 🛠️ Tech Stack

- **Framework**: AdonisJS
- **Database**: MongoDB
- **Authentication**: Stateful authentication with JWT
- **Messaging**: WebSockets for real-time notifications

## 🚀 Getting Started

### 1️⃣ Prerequisites

Make sure you have the following installed:

- [Node.js](https://nodejs.org/) (>= 16.x)
- [MongoDB](https://www.mongodb.com/)
- [NPM](https://www.npmjs.com/)

### 2️⃣ Installation

```bash
git clone https://github.com/fiatlinuxorg/citium.git
cd citium
```

Install dependencies:

```bash
npm install
```

### 3️⃣ Environment Setup

Create a `.env` file in the root directory and configure your environment variables:

```
TZ=UTC
PORT=8000
Expand All @@ -52,12 +61,15 @@ JWT_SECRET=YOUR_SECRET_KEY
```

### 4️⃣ Run the Backend Server
development:

development:

```bash
npm run dev
```

production:
production:

```bash
npm run build
cd build
Expand All @@ -68,18 +80,22 @@ node bin/server.js
The API will be available at `http://localhost:8000`.

## 📖 API Documentation

API documentation is available via Swagger:

```
http://localhost:8000/api/docs
```

## 🛡️ Security Considerations

- **JWT Authentication**: Protecting API endpoints
- **CORS**: Configured to allow secure cross-origin requests


## 📜 License

This project is licensed under the [MIT License](LICENSE).

---
💡 *Building a smarter city, one construction site at a time!*

💡 _Building a smarter city, one construction site at a time!_
2 changes: 1 addition & 1 deletion adonisrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default defineConfig({
},
() => import('@adonisjs/core/providers/vinejs_provider'),
() => import('@adonisjs/cors/cors_provider'),
() => import('@adonisjs/session/session_provider')
() => import('@adonisjs/session/session_provider'),
],

/*
Expand Down
25 changes: 18 additions & 7 deletions app/controllers/construction_sites_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ export default class ConstructionSitesController {
* @returns list with the construction site with the given id
*/
show({ params }: HttpContext) {
// S
let constructionSite = ConstructionSite.findById(params.id)
return constructionSite
}

/**
Expand Down Expand Up @@ -77,18 +78,28 @@ export default class ConstructionSitesController {
* @param params: id of the construction site, request: construction site data to update
* @returns the updated construction site
*/
update({ params, request }: HttpContext) {
let constructionSite = ConstructionSite.findByIdAndUpdate(params.id, request.all())
return constructionSite
async update({ params, request, response }: HttpContext) {
try {
let constructionSite = await ConstructionSite.findByIdAndUpdate(params.id, request.all())
return response.ok(constructionSite)
} catch (error) {
return response.notFound()
}
}

/**
* Method for deleting a construction site.
* @param params: id of the construction site
* @returns the deleted construction site
*/
destroy({ params }: HttpContext) {
let constructionSite = ConstructionSite.findByIdAndDelete(params.id)
return constructionSite
async destroy({ params, response }: HttpContext) {
try {
await ConstructionSite.findByIdAndDelete(params.id)
// Also delete all subscriptions to this construction site
await Subscription.deleteMany({ construction_site_id: params.id })
return response.noContent()
} catch (error) {
return response.notFound()
}
}
}
4 changes: 2 additions & 2 deletions config/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const sessionConfig = defineConfig({
*/
stores: {
cookie: stores.cookie(),
}
},
})

export default sessionConfig
export default sessionConfig
Loading