diff --git a/backend/config/db.js b/backend/config/db.js
index 38f0589..adae119 100644
--- a/backend/config/db.js
+++ b/backend/config/db.js
@@ -3,7 +3,10 @@ const dotenv = require('dotenv');
dotenv.config();
-const sequelize = new Sequelize(process.env.DATABASE_URL, {
+const isProduction = process.env.NODE_ENV === 'production';
+const databaseUrl = isProduction ? process.env.DATABASE_URL : process.env.DEV_DATABASE_URL;
+
+const sequelize = new Sequelize(databaseUrl, {
dialect: 'postgres',
logging: false,
});
diff --git a/backend/server.js b/backend/server.js
index 286ba45..dcd5baf 100644
--- a/backend/server.js
+++ b/backend/server.js
@@ -29,9 +29,22 @@ const startServer = async () => {
await initModels();
const PORT = process.env.PORT || 5100;
- app.listen(PORT, () => {
+ const FALLBACK_PORT = 5200;
+
+ const server = app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});
+
+ server.on('error', (err) => {
+ if (err.code === 'EADDRINUSE') {
+ console.error(`Port ${PORT} is already in use. Trying port ${FALLBACK_PORT}...`);
+ app.listen(FALLBACK_PORT, () => {
+ console.log(`Server is running on port ${FALLBACK_PORT}`);
+ });
+ } else {
+ console.error('Server error:', err);
+ }
+ });
};
startServer();
\ No newline at end of file
diff --git a/frontend/src/app/admin/components/table/table.component.html b/frontend/src/app/admin/components/table/table.component.html
index a646ff7..d05b826 100644
--- a/frontend/src/app/admin/components/table/table.component.html
+++ b/frontend/src/app/admin/components/table/table.component.html
@@ -14,33 +14,33 @@
{{ row[column.key] }}
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
|
diff --git a/frontend/src/app/admin/pages/locations/locations.component.html b/frontend/src/app/admin/pages/locations/locations.component.html
index 50b6083..48b3191 100644
--- a/frontend/src/app/admin/pages/locations/locations.component.html
+++ b/frontend/src/app/admin/pages/locations/locations.component.html
@@ -1 +1 @@
-Lokacije
\ No newline at end of file
+
\ No newline at end of file
diff --git a/frontend/src/app/admin/pages/locations/locations.component.ts b/frontend/src/app/admin/pages/locations/locations.component.ts
index 68a77ca..fe35c37 100644
--- a/frontend/src/app/admin/pages/locations/locations.component.ts
+++ b/frontend/src/app/admin/pages/locations/locations.component.ts
@@ -1,14 +1,40 @@
import { Component } from '@angular/core';
import { RouterLink } from '@angular/router';
+import { Location } from 'src/app/shared/models/location.model';
+import { LocationService } from 'src/app/shared/services/location.service';
+import { TableComponent } from '../../components/table/table.component';
@Component({
selector: 'app-locations',
standalone: true,
- imports: [RouterLink],
+ imports: [RouterLink, TableComponent],
templateUrl: './locations.component.html',
styleUrls: ['./locations.component.scss']
})
export class LocationsComponent {
+ columns = [
+ { key: 'id', label: 'ID' },
+ { key: 'image', label: 'Slika' },
+ { key: 'name', label: 'Ime' },
+ { key: 'description', label: 'Opis' },
+ { key: 'actions', label: 'Akcije' }
+ ];
+ locations: Location[] = [];
+ constructor(private locationService: LocationService) {}
+
+ ngOnInit(): void {
+ this.getUsers();
+ }
+
+ getUsers() {
+ this.locationService.getLocations().subscribe({
+ next: (locations: Location[]) => {
+ this.locations = locations;
+ },
+ error: err => console.error('Observable emitted an error: ' + err),
+ complete: () => console.log('Observable emitted the complete notification')
+ });
+ }
onClick() {
console.log('Link clicked!');
}
diff --git a/frontend/src/app/home/components/item-list/item-list.component.html b/frontend/src/app/home/components/item-list/item-list.component.html
index b2e69b4..dac4c7f 100644
--- a/frontend/src/app/home/components/item-list/item-list.component.html
+++ b/frontend/src/app/home/components/item-list/item-list.component.html
@@ -9,7 +9,7 @@
class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-8">
-
+
{{item.name}}
diff --git a/frontend/src/app/home/components/location-card/location-card.component.html b/frontend/src/app/home/components/location-card/location-card.component.html
index 71b49c3..fbf9079 100644
--- a/frontend/src/app/home/components/location-card/location-card.component.html
+++ b/frontend/src/app/home/components/location-card/location-card.component.html
@@ -11,14 +11,14 @@
+ src="../../../../assets/images/{{location.image}}" alt="{{ location.name }}">
-
{{ location.type }}
+
{{ location.Category.name }}
{{ location.description | slice:0:300 }}
diff --git a/frontend/src/app/home/pages/home/home.component.ts b/frontend/src/app/home/pages/home/home.component.ts
index b7f4a38..8038105 100644
--- a/frontend/src/app/home/pages/home/home.component.ts
+++ b/frontend/src/app/home/pages/home/home.component.ts
@@ -15,6 +15,7 @@ import { Title, Meta } from '@angular/platform-browser';
})
export class HomeComponent implements OnInit {
locations: Location[] = [];
+
constructor(private locationService: LocationService, private title: Title, private meta: Meta) {
this.title.setTitle('Početna - Dobro došli');
this.meta.addTags([
@@ -25,7 +26,7 @@ export class HomeComponent implements OnInit {
ngOnInit() {
this.locationService.getLocations().subscribe(data => {
- this.locations = data.locations; // Assuming 'locations' is the key in your JSON
+ this.locations = data; // Assuming 'locations' is the key in your JSON
});
}
}
diff --git a/frontend/src/app/home/pages/location/location.component.html b/frontend/src/app/home/pages/location/location.component.html
index 15859d6..a4b78b5 100644
--- a/frontend/src/app/home/pages/location/location.component.html
+++ b/frontend/src/app/home/pages/location/location.component.html
@@ -1,28 +1,32 @@
-
+
+
-
-
-
-
+
0; else noData">
+
+
+
+
+
+
+
+
-
+
-
-
+
+
{{ infoWindowContent.name }}
@@ -31,4 +35,4 @@
{{ infoWindowContent.name }}
-
+
\ No newline at end of file
diff --git a/frontend/src/app/home/pages/location/location.component.ts b/frontend/src/app/home/pages/location/location.component.ts
index f05ce9b..5a626f5 100644
--- a/frontend/src/app/home/pages/location/location.component.ts
+++ b/frontend/src/app/home/pages/location/location.component.ts
@@ -26,6 +26,7 @@ export class LocationComponent implements OnInit {
};
zoom = 12;
markers: Marker[] = [];
+ loading: boolean = true;
options: google.maps.MapOptions = {
mapTypeId: 'hybrid',
zoomControl: true,
@@ -59,17 +60,25 @@ export class LocationComponent implements OnInit {
constructor(private locationService: LocationService) {}
ngOnInit() {
- this.locationService.getLocations().subscribe(data => {
- this.locations = data.locations; // Assuming 'locations' is the key in your JSON
- this.loadMarkers();
- })
+ this.locationService.getLocations().subscribe({
+ next: (locations: Location[]) => {
+ this.locations = locations;
+ this.loadMarkers();
+ },
+ error: err => this.loading = false,
+ complete: () => this.loading = false
+ });
}
loadMarkers() {
- this.locations.forEach(location => {
+ this.locations.forEach((location: Location) => {
+ let coordinates = {
+ lat: location.latitude,
+ lng: location.longitude
+ }
this.markers.push(
{
- position: location.coordinates,
+ position: coordinates,
title: location.name,
image: location.image
},
diff --git a/frontend/src/app/shared/models/location.model.ts b/frontend/src/app/shared/models/location.model.ts
index cd5ebbc..3aafc70 100644
--- a/frontend/src/app/shared/models/location.model.ts
+++ b/frontend/src/app/shared/models/location.model.ts
@@ -4,13 +4,18 @@ export interface WorkingHours {
close: string; // e.g., "17:00"
}
export interface Location {
+ latitude: number;
+ longitude: number,
id: number;
name: string;
description: string,
address: string;
type: string;
image?: string;
- coordinates: google.maps.LatLngLiteral;
+ Category: {
+ name: string,
+ id: number
+ }
}
export interface LocationWithHours extends Location {
diff --git a/frontend/src/app/shared/services/location.service.ts b/frontend/src/app/shared/services/location.service.ts
index 84698f3..4e5c8ed 100644
--- a/frontend/src/app/shared/services/location.service.ts
+++ b/frontend/src/app/shared/services/location.service.ts
@@ -1,16 +1,18 @@
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/internal/Observable';
import { HttpClient } from '@angular/common/http';
+import { Location } from '../models/location.model';
+import { environment } from 'src/environments/environment';
@Injectable({
providedIn: 'root'
})
export class LocationService {
- private jsonUrl = 'assets/data/data.json'; // Path to your JSON file
+ private apiUrl = environment.apiUrl;
constructor(private http: HttpClient) {}
- getLocations(): Observable {
- return this.http.get(this.jsonUrl);
+ getLocations(): Observable {
+ return this.http.get(this.apiUrl + '/locations');
}
}
diff --git a/frontend/src/assets/images/smet.jpg b/frontend/src/assets/images/konjicki_klub_smet.jpg
similarity index 100%
rename from frontend/src/assets/images/smet.jpg
rename to frontend/src/assets/images/konjicki_klub_smet.jpg
diff --git a/frontend/src/environments/environment.ts b/frontend/src/environments/environment.ts
index 30ba284..fe36f2f 100644
--- a/frontend/src/environments/environment.ts
+++ b/frontend/src/environments/environment.ts
@@ -1,4 +1,4 @@
export const environment = {
production: false,
- apiUrl: 'http://localhost:5500/api'
+ apiUrl: 'http://localhost:4000/api'
};