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/controllers/UserController.java b/backend/src/main/java/de/hft/geotime/controllers/UserController.java
index 3a52cb4..e1cd793 100644
--- a/backend/src/main/java/de/hft/geotime/controllers/UserController.java
+++ b/backend/src/main/java/de/hft/geotime/controllers/UserController.java
@@ -1,7 +1,7 @@
package de.hft.geotime.controllers;
import de.hft.geotime.entities.TimetrackUser;
-import de.hft.geotime.entities.projections.UserWithRoleProjection;
+import de.hft.geotime.entities.projections.UserAllEmbeddedProjection;
import de.hft.geotime.repositories.TimetrackUserRepository;
import org.springframework.data.projection.ProjectionFactory;
import org.springframework.http.HttpStatus;
@@ -27,9 +27,9 @@ public class UserController {
}
@GetMapping("/whoami")
- public UserWithRoleProjection getUsername(Authentication authentication) {
+ public UserAllEmbeddedProjection getUsername(Authentication authentication) {
TimetrackUser user = userRepository.findFirstByUsername(authentication.getName());
- return projectionFactory.createProjection(UserWithRoleProjection.class, user);
+ return projectionFactory.createProjection(UserAllEmbeddedProjection.class, user);
}
@PostMapping("/sign-up")
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/UserAllEmbeddedProjection.java b/backend/src/main/java/de/hft/geotime/entities/projections/UserAllEmbeddedProjection.java
new file mode 100644
index 0000000..535ae5d
--- /dev/null
+++ b/backend/src/main/java/de/hft/geotime/entities/projections/UserAllEmbeddedProjection.java
@@ -0,0 +1,23 @@
+package de.hft.geotime.entities.projections;
+
+import de.hft.geotime.entities.Location;
+import de.hft.geotime.entities.Role;
+import de.hft.geotime.entities.TimetrackUser;
+import org.springframework.data.rest.core.config.Projection;
+
+@Projection(name = "allEmbedded", types = TimetrackUser.class)
+public interface UserAllEmbeddedProjection {
+
+ long getId();
+
+ String getFirstname();
+
+ String getLastname();
+
+ String getUsername();
+
+ Role getRole();
+
+ Location getLocation();
+
+}
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..1419a0b
--- /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 UserOnlyLocationProjection {
+
+ @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),