Skip to content

Commit

Permalink
Merge pull request #24 from Mala1180/feature/devices-frontend
Browse files Browse the repository at this point in the history
feature/devices-frontend
  • Loading branch information
paga16-hash authored Jan 30, 2024
2 parents 21cbe83 + 8e104dc commit 1575377
Show file tree
Hide file tree
Showing 13 changed files with 227 additions and 163 deletions.
64 changes: 20 additions & 44 deletions alarm/db/alarm-init.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ db.createCollection('anomaly')

db.anomaly.insert([
{
_id: '65b514200718dbb3580fb9e6',
_id: ObjectId('65b514200718dbb3580fb9e6'),
deviceId: {
type: 'SENSOR',
code: 'sen-01'
Expand All @@ -17,7 +17,7 @@ db.anomaly.insert([
__v: 0
},
{
_id: '65b514240718dbb3580fb9e8',
_id: ObjectId('65b514240718dbb3580fb9e8'),
deviceId: {
type: 'CAMERA',
code: 'cam-03'
Expand All @@ -34,17 +34,17 @@ db.createCollection('notification')

db.notification.insert([
{
_id: '65b5113633b1c7e038248937',
anomalyId: '65b514200718dbb3580fb9e6',
_id: ObjectId('65b5113633b1c7e038248937'),
anomalyId: ObjectId('65b514200718dbb3580fb9e6'),
anomalyType: 'EXCEEDING',
timestamp: {
$date: '2024-01-27T14:20:38.950Z'
},
__v: 0
},
{
_id: '65b513ef0718dbb3580fb9e3',
anomalyId: '65b514240718dbb3580fb9e8',
_id: ObjectId('65b513ef0718dbb3580fb9e3'),
anomalyId: ObjectId('65b514240718dbb3580fb9e8'),
anomalyType: 'INTRUSION',
timestamp: {
$date: '2024-01-27T14:32:15.925Z'
Expand All @@ -56,30 +56,24 @@ db.notification.insert([
db.createCollection('securityRule')
db.securityRule.insert([
{
_id: '65b527590fa38e9a5422537c',
_id: ObjectId('65b527590fa38e9a5422537c'),
deviceId: {
type: 'SENSOR',
code: 'sen-01'
},
creatorId: 'aaaaaaaaaaaaaaaaaaaaaaaa',
creatorId: ObjectId('aaaaaaaaaaaaaaaaaaaaaaaa'),
description: 'Exceeding rule description',
minValue: 0,
maxValue: 25,
measure: 'TEMPERATURE',
contacts: [
{
type: 'SMS',
value: '3333333333',
_id: {
$oid: '65b527590fa38e9a5422537d'
}
value: '3333333333'
},
{
type: 'EMAIL',
value: 'email@gmail.com',
_id: {
$oid: '65b527590fa38e9a5422537e'
}
value: 'email@gmail.com'
}
],
from: {
Expand All @@ -91,28 +85,22 @@ db.securityRule.insert([
__v: 0
},
{
_id: '65b52e53cffd8e469604ef10',
_id: ObjectId('65b52e53cffd8e469604ef10'),
deviceId: {
type: 'CAMERA',
code: 'cam-01'
},
creatorId: 'aaaaaaaaaaaaaaaaaaaaaaab',
creatorId: ObjectId('aaaaaaaaaaaaaaaaaaaaaaab'),
description: 'Intrusion rule description',
objectClass: 'PERSON',
contacts: [
{
type: 'SMS',
value: '3333333333',
_id: {
$oid: '65b52e53cffd8e469604ef11'
}
value: '3333333333'
},
{
type: 'EMAIL',
value: 'email@gmail.com',
_id: {
$oid: '65b52e53cffd8e469604ef12'
}
value: 'email@gmail.com'
}
],
from: {
Expand All @@ -129,43 +117,31 @@ db.createCollection('recognizingNode')

db.recognizingNode.insert([
{
_id: '65a020d5de7178fe501e7dda',
_id: ObjectId('65a020d5de7178fe501e7dda'),
ipAddress: '192.168.1.2',
deviceIds: [
{
type: 'CAMERA',
code: 'cam-01',
_id: {
$oid: '65a10044aa628f95323324a9'
}
code: 'cam-01'
},
{
type: 'SENSOR',
code: 'sen-01',
_id: {
$oid: '65a10044aa628f95323324aa'
}
code: 'sen-01'
}
],
__v: 0
},
{
_id: '65a020d5de7178fe501e7ddb',
_id: ObjectId('65a020d5de7178fe501e7ddb'),
ipAddress: '192.168.1.2',
deviceIds: [
{
type: 'CAMERA',
code: 'cam-02',
_id: {
$oid: '65a10044aa628f95323324b9'
}
code: 'cam-02'
},
{
type: 'SENSOR',
code: 'sen-02',
_id: {
$oid: '65a10044aa628f95323324ac'
}
code: 'sen-02'
}
],
__v: 0
Expand Down
2 changes: 1 addition & 1 deletion alarm/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const app: Express = express()
app.use(express.json())
app.use(cors())

const PORT: number = Number(process.env.PORT) || 4000
const PORT: number = Number(process.env.ALARM_PORT) || 4002

app.use((req: Request, res: Response, next: NextFunction) => {
const authHeader = req.headers.authorization
Expand Down
4 changes: 2 additions & 2 deletions auth/db/auth-init.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ db.createCollection('user')
//TODO to test
db.user.insertMany([
{
_id: 'aaaaaaaaaaaaaaaaaaaaaaaa',
_id: ObjectId('aaaaaaaaaaaaaaaaaaaaaaaa'),
name: 'Mattia',
surname: 'Matteini',
username: 'mattia',
Expand All @@ -18,7 +18,7 @@ db.user.insertMany([
]
},
{
_id: 'aaaaaaaaaaaaaaaaaaaaaaab',
_id: ObjectId('aaaaaaaaaaaaaaaaaaaaaaab'),
name: 'Mario',
surname: 'Rossi',
username: 'paga16',
Expand Down
4 changes: 3 additions & 1 deletion domain/src/domain/device/repositories/DeviceRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@ export interface DeviceRepository {

updateSensor(sensor: Sensor): Promise<void>

deleteDevice(deviceId: DeviceId): Promise<void>
deleteCamera(code: string): Promise<void>

deleteSensor(code: string): Promise<void>
}
45 changes: 20 additions & 25 deletions domain/src/storage/device/DeviceRepositoryImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,30 +142,25 @@ export class DeviceRepositoryImpl implements DeviceRepository {
.orFail()
}

async deleteDevice(deviceId: DeviceId): Promise<void> {
switch (deviceId.type) {
case DeviceType.CAMERA:
await this.cameraModel
.deleteOne({
_id: {
type: DeviceTypeConverter.convertToString(deviceId.type),
code: deviceId.code
}
})
.orFail()
break
case DeviceType.SENSOR:
await this.sensorModel
.deleteOne({
_id: {
type: DeviceTypeConverter.convertToString(deviceId.type),
code: deviceId.code
}
})
.orFail()
break
default:
throw new Error('Error while deleting device')
}
async deleteCamera(code: string): Promise<void> {
await this.cameraModel
.deleteOne({
_id: {
type: 'CAMERA',
code: code
}
})
.orFail()
}

async deleteSensor(code: string): Promise<void> {
await this.sensorModel
.deleteOne({
_id: {
type: 'SENSOR',
code: code
}
})
.orFail()
}
}
34 changes: 18 additions & 16 deletions frontend/src/components/devices/NewDevicePopup.vue
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
<script setup lang="ts">
import { Measure } from 'domain/dist/domain/device/core/impl/enum/Measure'
import { ref } from 'vue'
import { DeviceType } from '@domain/device/core'
import { ref, toRaw } from 'vue'
import { type Camera, DeviceType, type Sensor } from '@domain/device/core'
import type { DeviceFactory, DeviceIdFactory, ResolutionFactory } from '@domain/device/factories'
import {
DeviceFactoryImpl,
DeviceIdFactoryImpl,
ResolutionFactoryImpl
} from '@domain/device/factories'
import { AnomalyType } from 'domain/dist/domain/anomaly/core'
import type { ExceedingRule, IntrusionRule } from 'domain/dist/domain/security-rule/core'
import type { Contact } from 'domain/dist/domain/monitoring/core'
const emit = defineEmits<{
(e: 'update-devices'): void
(e: 'insert-camera', camera: Camera): void
(e: 'insert-sensor', sensor: Sensor): void
}>()
const deviceIdFactory: DeviceIdFactory = new DeviceIdFactoryImpl()
Expand Down Expand Up @@ -41,24 +46,21 @@ const options = ref([
const addNewDevice = () => {
if (deviceType.value == DeviceType.SENSOR) {
console.log(
deviceFactory.createSensor(
deviceIdFactory.createSensorId(code),
ipAddress,
intervalMillis,
measures.value
)
const newSensor: Sensor = deviceFactory.createSensor(
deviceIdFactory.createSensorId(code.value),
ipAddress.value,
intervalMillis.value,
measures.value
)
emit('insert-sensor', newSensor)
} else if (deviceType.value == DeviceType.CAMERA) {
console.log(
deviceFactory.createCamera(
deviceIdFactory.createCameraId(code),
ipAddress,
resolutionFactory.createResolution(width, height)
)
const newCamera: Camera = deviceFactory.createCamera(
deviceIdFactory.createCameraId(code.value),
ipAddress.value,
resolutionFactory.createResolution(width.value, height.value)
)
emit('insert-camera', newCamera)
}
emit('update-devices')
}
</script>

Expand Down
2 changes: 2 additions & 0 deletions frontend/src/env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ interface ImportMetaEnv {
readonly VITE_MONITORING_PORT: string
readonly VITE_AUTH_HOST: string
readonly VITE_AUTH_PORT: string
readonly VITE_ALARM_HOST: string
readonly VITE_ALARM_PORT: string
}

interface ImportMeta {
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/utils/RequestHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ type Headers = {

export const authHost: string = import.meta.env.VITE_AUTH_HOST || 'localhost'
export const authPort: string = import.meta.env.VITE_AUTH_PORT || '4000'
export const monitoringHost: string = import.meta.env.VITE_MONITORING_HOST || 'localhost'
export const monitoringPort: string = import.meta.env.VITE_MONITORING_PORT || '4001'
export const alarmHost: string = import.meta.env.VITE_ALARM_HOST || 'localhost'
export const alarmPort: string = import.meta.env.VITE_ALARM_PORT || '4002'

export default class RequestHelper {
static getHeaders(): Headers {
return { headers: { Authorization: `Bearer ${userStore().accessToken}` } }
return { headers: { Authorization: `Bearer apikey-dev` } } //${userStore().accessToken}
}

static async get(url: string, params?: any): Promise<AxiosResponse> {
Expand Down
Loading

0 comments on commit 1575377

Please sign in to comment.