From 89ba108078395b892c260a2cf6bcc3be721943c8 Mon Sep 17 00:00:00 2001 From: Marcel Schwarz Date: Wed, 13 May 2020 15:50:08 +0200 Subject: [PATCH] Add location implementation --- backend/.idea/compiler.xml | 1 + .../de/hft/geotime/entities/Location.java | 27 +++++++++++++++++++ .../hft/geotime/entities/TimetrackUser.java | 3 +++ .../UserOnlyLocationProjection.java | 19 +++++++++++++ .../repositories/LocationRepository.java | 14 ++++++++++ backend/src/main/resources/data.sql | 13 +++++---- 6 files changed, 72 insertions(+), 5 deletions(-) create mode 100644 backend/src/main/java/de/hft/geotime/entities/Location.java create mode 100644 backend/src/main/java/de/hft/geotime/entities/projections/UserOnlyLocationProjection.java create mode 100644 backend/src/main/java/de/hft/geotime/repositories/LocationRepository.java diff --git a/backend/.idea/compiler.xml b/backend/.idea/compiler.xml index eb684d8..a269fd6 100644 --- a/backend/.idea/compiler.xml +++ b/backend/.idea/compiler.xml @@ -8,6 +8,7 @@ + diff --git a/backend/src/main/java/de/hft/geotime/entities/Location.java b/backend/src/main/java/de/hft/geotime/entities/Location.java new file mode 100644 index 0000000..e8cae67 --- /dev/null +++ b/backend/src/main/java/de/hft/geotime/entities/Location.java @@ -0,0 +1,27 @@ +package de.hft.geotime.entities; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Entity +public class Location { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private long id; + + private double latitude; + private double longitude; + + private int radius; + +} diff --git a/backend/src/main/java/de/hft/geotime/entities/TimetrackUser.java b/backend/src/main/java/de/hft/geotime/entities/TimetrackUser.java index af6deb5..d3b6b8c 100644 --- a/backend/src/main/java/de/hft/geotime/entities/TimetrackUser.java +++ b/backend/src/main/java/de/hft/geotime/entities/TimetrackUser.java @@ -34,4 +34,7 @@ public class TimetrackUser { @OneToMany(mappedBy = "user", fetch = FetchType.LAZY, cascade = CascadeType.ALL) private List accounts; + @ManyToOne + private Location location; + } diff --git a/backend/src/main/java/de/hft/geotime/entities/projections/UserOnlyLocationProjection.java b/backend/src/main/java/de/hft/geotime/entities/projections/UserOnlyLocationProjection.java new file mode 100644 index 0000000..6899618 --- /dev/null +++ b/backend/src/main/java/de/hft/geotime/entities/projections/UserOnlyLocationProjection.java @@ -0,0 +1,19 @@ +package de.hft.geotime.entities.projections; + +import de.hft.geotime.entities.TimetrackUser; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.data.rest.core.config.Projection; + +@Projection(name = "onlyLocation", types = TimetrackUser.class) +public interface UserOnlyLocation { + + @Value("#{target.location.longitude}") + double getLongitude(); + + @Value("#{target.location.latitude}") + double getLatitude(); + + @Value("#{target.location.radius}") + int getRadius(); + +} diff --git a/backend/src/main/java/de/hft/geotime/repositories/LocationRepository.java b/backend/src/main/java/de/hft/geotime/repositories/LocationRepository.java new file mode 100644 index 0000000..b631c34 --- /dev/null +++ b/backend/src/main/java/de/hft/geotime/repositories/LocationRepository.java @@ -0,0 +1,14 @@ +package de.hft.geotime.repositories; + +import de.hft.geotime.entities.Location; +import org.springframework.data.repository.PagingAndSortingRepository; +import org.springframework.data.rest.core.annotation.RepositoryRestResource; + + +@RepositoryRestResource( + path = "locations", + itemResourceRel = "locations", + collectionResourceRel = "locations" +) +public interface LocationRepository extends PagingAndSortingRepository { +} diff --git a/backend/src/main/resources/data.sql b/backend/src/main/resources/data.sql index 1668db4..49f0053 100644 --- a/backend/src/main/resources/data.sql +++ b/backend/src/main/resources/data.sql @@ -6,14 +6,17 @@ DELETE FROM role; INSERT INTO role (id, `name`) VALUES (1, 'Admin'); +INSERT INTO location (id, latitude, longitude, radius) VALUES + (1, 48.804372, 9.521177, 50); + /* password is the firstname in lowercase e.g. marcel or tobias https://bcrypt-generator.com/ with 10 rounds */ -INSERT INTO timetrack_user (id, firstname, lastname, password, username, role_id) VALUES - (1, 'Marcel', 'Schwarz' ,'$2y$10$pDBv7dEaAiNs5Kr1.8g4XuTFx48zGxJu77rei4TlO.sDOF2yHWxo.', 'scma', 1), - (2, 'Tobias', 'Wieck' ,'$2y$10$Fxj5cGrZblGKjIExvS/MquEE0lgyYo1ILxPgPR2vSiaaLKkqJ.C.u', 'wito', 1), - (3, 'Tim', 'Zieger' ,'$2y$10$pYGHZhoaelceImO7aIN4nOkWJBp.oqNGFYaRAonHkYF4u9ljqPelC', 'ziti', 1), - (4, 'Simon', 'Kellner' ,'$2y$10$Puzm/Nr/Dyq3nQxlkXGIfubS5JPtXJSOf2e6mrQ6HhVYQN9YiQQsC', 'kesi', 1); +INSERT INTO timetrack_user (id, firstname, lastname, password, username, role_id, location_id) VALUES + (1, 'Marcel', 'Schwarz' ,'$2y$10$pDBv7dEaAiNs5Kr1.8g4XuTFx48zGxJu77rei4TlO.sDOF2yHWxo.', 'scma', 1, 1), + (2, 'Tobias', 'Wieck' ,'$2y$10$Fxj5cGrZblGKjIExvS/MquEE0lgyYo1ILxPgPR2vSiaaLKkqJ.C.u', 'wito', 1, 1), + (3, 'Tim', 'Zieger' ,'$2y$10$pYGHZhoaelceImO7aIN4nOkWJBp.oqNGFYaRAonHkYF4u9ljqPelC', 'ziti', 1, 1), + (4, 'Simon', 'Kellner' ,'$2y$10$Puzm/Nr/Dyq3nQxlkXGIfubS5JPtXJSOf2e6mrQ6HhVYQN9YiQQsC', 'kesi', 1, 1); INSERT INTO timetrack_account (description, `name`, revenue, user_id) VALUES ('Gleitzeit Marcel', 'Primary Marcel', 16.0, 1),