Merge branch '19-find-way-to-store-location-data' into 'master'

Resolve "Find way to store location data"

Closes #19

See merge request marcel.schwarz/2020ss-qbc-geofence-timetracking!48
This commit is contained in:
Marcel Schwarz 2020-05-13 14:07:39 +00:00
commit 0e2f880755
8 changed files with 98 additions and 8 deletions

View File

@ -8,6 +8,7 @@
<processorPath useClasspath="false"> <processorPath useClasspath="false">
<entry name="$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.projectlombok/lombok/1.18.12/48e4e5d60309ebd833bc528dcf77668eab3cd72c/lombok-1.18.12.jar" /> <entry name="$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.projectlombok/lombok/1.18.12/48e4e5d60309ebd833bc528dcf77668eab3cd72c/lombok-1.18.12.jar" />
</processorPath> </processorPath>
<module name="geotime.test" />
<module name="geotime.main" /> <module name="geotime.main" />
</profile> </profile>
</annotationProcessing> </annotationProcessing>

View File

@ -1,7 +1,7 @@
package de.hft.geotime.controllers; package de.hft.geotime.controllers;
import de.hft.geotime.entities.TimetrackUser; 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 de.hft.geotime.repositories.TimetrackUserRepository;
import org.springframework.data.projection.ProjectionFactory; import org.springframework.data.projection.ProjectionFactory;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
@ -27,9 +27,9 @@ public class UserController {
} }
@GetMapping("/whoami") @GetMapping("/whoami")
public UserWithRoleProjection getUsername(Authentication authentication) { public UserAllEmbeddedProjection getUsername(Authentication authentication) {
TimetrackUser user = userRepository.findFirstByUsername(authentication.getName()); TimetrackUser user = userRepository.findFirstByUsername(authentication.getName());
return projectionFactory.createProjection(UserWithRoleProjection.class, user); return projectionFactory.createProjection(UserAllEmbeddedProjection.class, user);
} }
@PostMapping("/sign-up") @PostMapping("/sign-up")

View File

@ -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;
}

View File

@ -34,4 +34,7 @@ public class TimetrackUser {
@OneToMany(mappedBy = "user", fetch = FetchType.LAZY, cascade = CascadeType.ALL) @OneToMany(mappedBy = "user", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
private List<TimetrackAccount> accounts; private List<TimetrackAccount> accounts;
@ManyToOne
private Location location;
} }

View File

@ -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();
}

View File

@ -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();
}

View File

@ -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<Location, Long> {
}

View File

@ -6,14 +6,17 @@ DELETE FROM role;
INSERT INTO role (id, `name`) VALUES INSERT INTO role (id, `name`) VALUES
(1, 'Admin'); (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 /* password is the firstname in lowercase e.g. marcel or tobias
https://bcrypt-generator.com/ with 10 rounds https://bcrypt-generator.com/ with 10 rounds
*/ */
INSERT INTO timetrack_user (id, firstname, lastname, password, username, role_id) VALUES 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, 'Marcel', 'Schwarz' ,'$2y$10$pDBv7dEaAiNs5Kr1.8g4XuTFx48zGxJu77rei4TlO.sDOF2yHWxo.', 'scma', 1, 1),
(2, 'Tobias', 'Wieck' ,'$2y$10$Fxj5cGrZblGKjIExvS/MquEE0lgyYo1ILxPgPR2vSiaaLKkqJ.C.u', 'wito', 1), (2, 'Tobias', 'Wieck' ,'$2y$10$Fxj5cGrZblGKjIExvS/MquEE0lgyYo1ILxPgPR2vSiaaLKkqJ.C.u', 'wito', 1, 1),
(3, 'Tim', 'Zieger' ,'$2y$10$pYGHZhoaelceImO7aIN4nOkWJBp.oqNGFYaRAonHkYF4u9ljqPelC', 'ziti', 1), (3, 'Tim', 'Zieger' ,'$2y$10$pYGHZhoaelceImO7aIN4nOkWJBp.oqNGFYaRAonHkYF4u9ljqPelC', 'ziti', 1, 1),
(4, 'Simon', 'Kellner' ,'$2y$10$Puzm/Nr/Dyq3nQxlkXGIfubS5JPtXJSOf2e6mrQ6HhVYQN9YiQQsC', 'kesi', 1); (4, 'Simon', 'Kellner' ,'$2y$10$Puzm/Nr/Dyq3nQxlkXGIfubS5JPtXJSOf2e6mrQ6HhVYQN9YiQQsC', 'kesi', 1, 1);
INSERT INTO timetrack_account (description, `name`, revenue, user_id) VALUES INSERT INTO timetrack_account (description, `name`, revenue, user_id) VALUES
('Gleitzeit Marcel', 'Primary Marcel', 16.0, 1), ('Gleitzeit Marcel', 'Primary Marcel', 16.0, 1),