From e944d34316e7a799ddbbc59da20d25807e8b0f0d Mon Sep 17 00:00:00 2001 From: Marcel Schwarz Date: Tue, 28 Apr 2020 11:06:43 +0200 Subject: [PATCH 1/7] Move User and UserRepository to the correct packages --- .../src/main/java/de/hft/geotime/{user => entities}/User.java | 2 +- .../de/hft/geotime/{user => repositories}/UserRepository.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) rename backend/src/main/java/de/hft/geotime/{user => entities}/User.java (94%) rename backend/src/main/java/de/hft/geotime/{user => repositories}/UserRepository.java (84%) diff --git a/backend/src/main/java/de/hft/geotime/user/User.java b/backend/src/main/java/de/hft/geotime/entities/User.java similarity index 94% rename from backend/src/main/java/de/hft/geotime/user/User.java rename to backend/src/main/java/de/hft/geotime/entities/User.java index f697365..196c555 100644 --- a/backend/src/main/java/de/hft/geotime/user/User.java +++ b/backend/src/main/java/de/hft/geotime/entities/User.java @@ -1,4 +1,4 @@ -package de.hft.geotime.user; +package de.hft.geotime.entities; import lombok.Data; diff --git a/backend/src/main/java/de/hft/geotime/user/UserRepository.java b/backend/src/main/java/de/hft/geotime/repositories/UserRepository.java similarity index 84% rename from backend/src/main/java/de/hft/geotime/user/UserRepository.java rename to backend/src/main/java/de/hft/geotime/repositories/UserRepository.java index 9b303ba..ac834cc 100644 --- a/backend/src/main/java/de/hft/geotime/user/UserRepository.java +++ b/backend/src/main/java/de/hft/geotime/repositories/UserRepository.java @@ -1,5 +1,6 @@ -package de.hft.geotime.user; +package de.hft.geotime.repositories; +import de.hft.geotime.entities.User; import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.data.rest.core.annotation.RepositoryRestResource; From 05cb94abf08dd531aae1478f37b44a81a7e2c56a Mon Sep 17 00:00:00 2001 From: Marcel Schwarz Date: Tue, 28 Apr 2020 11:28:44 +0200 Subject: [PATCH 2/7] Generate User Constructor with lombok --- .../src/main/java/de/hft/geotime/entities/User.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/backend/src/main/java/de/hft/geotime/entities/User.java b/backend/src/main/java/de/hft/geotime/entities/User.java index 196c555..0a3ee10 100644 --- a/backend/src/main/java/de/hft/geotime/entities/User.java +++ b/backend/src/main/java/de/hft/geotime/entities/User.java @@ -1,6 +1,8 @@ package de.hft.geotime.entities; +import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NoArgsConstructor; import javax.persistence.Entity; import javax.persistence.GeneratedValue; @@ -8,6 +10,8 @@ import javax.persistence.GenerationType; import javax.persistence.Id; @Data +@NoArgsConstructor +@AllArgsConstructor @Entity public class User { @@ -20,11 +24,4 @@ public class User { //TODO: roleid(FK) //TODO: timetrackaccounts[List] - protected User() { - } - - public User(String firstname, String lastname) { - this.firstname = firstname; - this.lastname = lastname; - } } From 60f069b63587a07416a0c57c67d240bb0f32186a Mon Sep 17 00:00:00 2001 From: Marcel Schwarz Date: Tue, 28 Apr 2020 12:28:57 +0200 Subject: [PATCH 3/7] Activate H2 console for the dev environment --- backend/src/main/resources/application-dev.properties | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/backend/src/main/resources/application-dev.properties b/backend/src/main/resources/application-dev.properties index e69de29..4497ed1 100644 --- a/backend/src/main/resources/application-dev.properties +++ b/backend/src/main/resources/application-dev.properties @@ -0,0 +1,7 @@ +spring.datasource.url=jdbc:h2:mem:testdb +spring.datasource.driverClassName=org.h2.Driver +spring.datasource.username=sa +spring.datasource.password= +spring.jpa.database-platform=org.hibernate.dialect.H2Dialect +spring.h2.console.enabled=true +spring.h2.console.path=/h2-console \ No newline at end of file From 92de6cc6f42baffa0ba6061b478afe38ee2682c9 Mon Sep 17 00:00:00 2001 From: Marcel Schwarz Date: Tue, 28 Apr 2020 12:31:04 +0200 Subject: [PATCH 4/7] Add Role, TimeRecord, TimetrackAccount and RecordType Update User to have Roles and TimetrackAccounts --- .../de/hft/geotime/entities/RecordType.java | 6 +++++ .../java/de/hft/geotime/entities/Role.java | 24 +++++++++++++++++ .../de/hft/geotime/entities/TimeRecord.java | 27 +++++++++++++++++++ .../geotime/entities/TimetrackAccount.java | 22 +++++++++++++++ .../java/de/hft/geotime/entities/User.java | 12 ++++----- 5 files changed, 85 insertions(+), 6 deletions(-) create mode 100644 backend/src/main/java/de/hft/geotime/entities/RecordType.java create mode 100644 backend/src/main/java/de/hft/geotime/entities/Role.java create mode 100644 backend/src/main/java/de/hft/geotime/entities/TimeRecord.java create mode 100644 backend/src/main/java/de/hft/geotime/entities/TimetrackAccount.java diff --git a/backend/src/main/java/de/hft/geotime/entities/RecordType.java b/backend/src/main/java/de/hft/geotime/entities/RecordType.java new file mode 100644 index 0000000..5f3a684 --- /dev/null +++ b/backend/src/main/java/de/hft/geotime/entities/RecordType.java @@ -0,0 +1,6 @@ +package de.hft.geotime.entities; + +public enum RecordType { + BREAK, + PAID +} diff --git a/backend/src/main/java/de/hft/geotime/entities/Role.java b/backend/src/main/java/de/hft/geotime/entities/Role.java new file mode 100644 index 0000000..31bc9df --- /dev/null +++ b/backend/src/main/java/de/hft/geotime/entities/Role.java @@ -0,0 +1,24 @@ +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 Role { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private long id; + private String name; + // TODO: Permission List + +} diff --git a/backend/src/main/java/de/hft/geotime/entities/TimeRecord.java b/backend/src/main/java/de/hft/geotime/entities/TimeRecord.java new file mode 100644 index 0000000..6a1cb94 --- /dev/null +++ b/backend/src/main/java/de/hft/geotime/entities/TimeRecord.java @@ -0,0 +1,27 @@ +package de.hft.geotime.entities; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.hibernate.type.TimeType; + +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.OneToOne; +import java.time.Duration; +import java.util.Date; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Entity +public class TimeRecord { + @Id + private long id; + @OneToOne + private TimetrackAccount account; + private Date startdate; + private Date enddate; + private Duration time; + private RecordType type; +} diff --git a/backend/src/main/java/de/hft/geotime/entities/TimetrackAccount.java b/backend/src/main/java/de/hft/geotime/entities/TimetrackAccount.java new file mode 100644 index 0000000..b262bdc --- /dev/null +++ b/backend/src/main/java/de/hft/geotime/entities/TimetrackAccount.java @@ -0,0 +1,22 @@ +package de.hft.geotime.entities; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import javax.persistence.*; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Entity +public class TimetrackAccount { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private long id; + @OneToOne + private User user; + private double revenue; + private String name; + private String description; +} diff --git a/backend/src/main/java/de/hft/geotime/entities/User.java b/backend/src/main/java/de/hft/geotime/entities/User.java index 0a3ee10..40fed8a 100644 --- a/backend/src/main/java/de/hft/geotime/entities/User.java +++ b/backend/src/main/java/de/hft/geotime/entities/User.java @@ -4,10 +4,8 @@ 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; +import javax.persistence.*; +import java.util.List; @Data @NoArgsConstructor @@ -21,7 +19,9 @@ public class User { private String username; private String firstname; private String lastname; - //TODO: roleid(FK) - //TODO: timetrackaccounts[List] + @OneToMany + private List roles; + @OneToMany + private List timetrackAccounts; } From 945316ae6712824e49f1365a08b78e8d37113706 Mon Sep 17 00:00:00 2001 From: Marcel Schwarz Date: Tue, 28 Apr 2020 12:31:23 +0200 Subject: [PATCH 5/7] Add Role Repository --- .../java/de/hft/geotime/repositories/RoleRepository.java | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 backend/src/main/java/de/hft/geotime/repositories/RoleRepository.java diff --git a/backend/src/main/java/de/hft/geotime/repositories/RoleRepository.java b/backend/src/main/java/de/hft/geotime/repositories/RoleRepository.java new file mode 100644 index 0000000..d646c87 --- /dev/null +++ b/backend/src/main/java/de/hft/geotime/repositories/RoleRepository.java @@ -0,0 +1,9 @@ +package de.hft.geotime.repositories; + +import de.hft.geotime.entities.Role; +import org.springframework.data.repository.PagingAndSortingRepository; +import org.springframework.data.rest.core.annotation.RepositoryRestResource; + +@RepositoryRestResource +public interface RoleRepository extends PagingAndSortingRepository { +} From 56a3ddad27cc75b7d4e1342ce2dce1c30fb8b413 Mon Sep 17 00:00:00 2001 From: Marcel Schwarz Date: Tue, 28 Apr 2020 23:04:14 +0200 Subject: [PATCH 6/7] Create TimeRecord, Timetrackaccount and Role Move Entities in correct packages --- backend/build.gradle | 1 - .../de/hft/geotime/record/RecordRepository.java | 7 +++++++ .../geotime/{entities => record}/RecordType.java | 2 +- .../geotime/{entities => record}/TimeRecord.java | 4 ++-- .../hft/geotime/repositories/RoleRepository.java | 9 --------- .../hft/geotime/repositories/UserRepository.java | 15 --------------- .../de/hft/geotime/{entities => role}/Role.java | 2 +- .../java/de/hft/geotime/role/RoleRepository.java | 7 +++++++ .../TimetrackAccount.java | 3 ++- .../TimetrackAccountRepository.java | 7 +++++++ .../de/hft/geotime/{entities => user}/User.java | 4 +++- .../java/de/hft/geotime/user/UserRepository.java | 12 ++++++++++++ backend/src/main/resources/application.properties | 1 - 13 files changed, 42 insertions(+), 32 deletions(-) create mode 100644 backend/src/main/java/de/hft/geotime/record/RecordRepository.java rename backend/src/main/java/de/hft/geotime/{entities => record}/RecordType.java (59%) rename backend/src/main/java/de/hft/geotime/{entities => record}/TimeRecord.java (85%) delete mode 100644 backend/src/main/java/de/hft/geotime/repositories/RoleRepository.java delete mode 100644 backend/src/main/java/de/hft/geotime/repositories/UserRepository.java rename backend/src/main/java/de/hft/geotime/{entities => role}/Role.java (93%) create mode 100644 backend/src/main/java/de/hft/geotime/role/RoleRepository.java rename backend/src/main/java/de/hft/geotime/{entities => timetrackaccount}/TimetrackAccount.java (84%) create mode 100644 backend/src/main/java/de/hft/geotime/timetrackaccount/TimetrackAccountRepository.java rename backend/src/main/java/de/hft/geotime/{entities => user}/User.java (80%) create mode 100644 backend/src/main/java/de/hft/geotime/user/UserRepository.java diff --git a/backend/build.gradle b/backend/build.gradle index 7811350..4ea0a22 100644 --- a/backend/build.gradle +++ b/backend/build.gradle @@ -14,7 +14,6 @@ repositories { } dependencies { - implementation 'org.springframework.boot:spring-boot-starter-data-rest' implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-actuator' diff --git a/backend/src/main/java/de/hft/geotime/record/RecordRepository.java b/backend/src/main/java/de/hft/geotime/record/RecordRepository.java new file mode 100644 index 0000000..22b7906 --- /dev/null +++ b/backend/src/main/java/de/hft/geotime/record/RecordRepository.java @@ -0,0 +1,7 @@ +package de.hft.geotime.record; + +import org.springframework.data.repository.CrudRepository; + +public interface RecordRepository extends CrudRepository { + +} diff --git a/backend/src/main/java/de/hft/geotime/entities/RecordType.java b/backend/src/main/java/de/hft/geotime/record/RecordType.java similarity index 59% rename from backend/src/main/java/de/hft/geotime/entities/RecordType.java rename to backend/src/main/java/de/hft/geotime/record/RecordType.java index 5f3a684..1744c48 100644 --- a/backend/src/main/java/de/hft/geotime/entities/RecordType.java +++ b/backend/src/main/java/de/hft/geotime/record/RecordType.java @@ -1,4 +1,4 @@ -package de.hft.geotime.entities; +package de.hft.geotime.record; public enum RecordType { BREAK, diff --git a/backend/src/main/java/de/hft/geotime/entities/TimeRecord.java b/backend/src/main/java/de/hft/geotime/record/TimeRecord.java similarity index 85% rename from backend/src/main/java/de/hft/geotime/entities/TimeRecord.java rename to backend/src/main/java/de/hft/geotime/record/TimeRecord.java index 6a1cb94..3d9e888 100644 --- a/backend/src/main/java/de/hft/geotime/entities/TimeRecord.java +++ b/backend/src/main/java/de/hft/geotime/record/TimeRecord.java @@ -1,9 +1,9 @@ -package de.hft.geotime.entities; +package de.hft.geotime.record; +import de.hft.geotime.timetrackaccount.TimetrackAccount; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; -import org.hibernate.type.TimeType; import javax.persistence.Entity; import javax.persistence.Id; diff --git a/backend/src/main/java/de/hft/geotime/repositories/RoleRepository.java b/backend/src/main/java/de/hft/geotime/repositories/RoleRepository.java deleted file mode 100644 index d646c87..0000000 --- a/backend/src/main/java/de/hft/geotime/repositories/RoleRepository.java +++ /dev/null @@ -1,9 +0,0 @@ -package de.hft.geotime.repositories; - -import de.hft.geotime.entities.Role; -import org.springframework.data.repository.PagingAndSortingRepository; -import org.springframework.data.rest.core.annotation.RepositoryRestResource; - -@RepositoryRestResource -public interface RoleRepository extends PagingAndSortingRepository { -} diff --git a/backend/src/main/java/de/hft/geotime/repositories/UserRepository.java b/backend/src/main/java/de/hft/geotime/repositories/UserRepository.java deleted file mode 100644 index ac834cc..0000000 --- a/backend/src/main/java/de/hft/geotime/repositories/UserRepository.java +++ /dev/null @@ -1,15 +0,0 @@ -package de.hft.geotime.repositories; - -import de.hft.geotime.entities.User; -import org.springframework.data.repository.PagingAndSortingRepository; -import org.springframework.data.rest.core.annotation.RepositoryRestResource; - -import javax.websocket.server.PathParam; -import java.util.List; - -@RepositoryRestResource -public interface UserRepository extends PagingAndSortingRepository { - - List findByUsername(@PathParam("username") String username); - -} diff --git a/backend/src/main/java/de/hft/geotime/entities/Role.java b/backend/src/main/java/de/hft/geotime/role/Role.java similarity index 93% rename from backend/src/main/java/de/hft/geotime/entities/Role.java rename to backend/src/main/java/de/hft/geotime/role/Role.java index 31bc9df..7b319b7 100644 --- a/backend/src/main/java/de/hft/geotime/entities/Role.java +++ b/backend/src/main/java/de/hft/geotime/role/Role.java @@ -1,4 +1,4 @@ -package de.hft.geotime.entities; +package de.hft.geotime.role; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/backend/src/main/java/de/hft/geotime/role/RoleRepository.java b/backend/src/main/java/de/hft/geotime/role/RoleRepository.java new file mode 100644 index 0000000..7e26fa7 --- /dev/null +++ b/backend/src/main/java/de/hft/geotime/role/RoleRepository.java @@ -0,0 +1,7 @@ +package de.hft.geotime.role; + +import org.springframework.data.repository.CrudRepository; + +public interface RoleRepository extends CrudRepository { + +} diff --git a/backend/src/main/java/de/hft/geotime/entities/TimetrackAccount.java b/backend/src/main/java/de/hft/geotime/timetrackaccount/TimetrackAccount.java similarity index 84% rename from backend/src/main/java/de/hft/geotime/entities/TimetrackAccount.java rename to backend/src/main/java/de/hft/geotime/timetrackaccount/TimetrackAccount.java index b262bdc..0d38a12 100644 --- a/backend/src/main/java/de/hft/geotime/entities/TimetrackAccount.java +++ b/backend/src/main/java/de/hft/geotime/timetrackaccount/TimetrackAccount.java @@ -1,5 +1,6 @@ -package de.hft.geotime.entities; +package de.hft.geotime.timetrackaccount; +import de.hft.geotime.user.User; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; diff --git a/backend/src/main/java/de/hft/geotime/timetrackaccount/TimetrackAccountRepository.java b/backend/src/main/java/de/hft/geotime/timetrackaccount/TimetrackAccountRepository.java new file mode 100644 index 0000000..38bbc91 --- /dev/null +++ b/backend/src/main/java/de/hft/geotime/timetrackaccount/TimetrackAccountRepository.java @@ -0,0 +1,7 @@ +package de.hft.geotime.timetrackaccount; + +import org.springframework.data.repository.CrudRepository; + +public interface TimetrackAccountRepository extends CrudRepository { + +} diff --git a/backend/src/main/java/de/hft/geotime/entities/User.java b/backend/src/main/java/de/hft/geotime/user/User.java similarity index 80% rename from backend/src/main/java/de/hft/geotime/entities/User.java rename to backend/src/main/java/de/hft/geotime/user/User.java index 40fed8a..70c1b6e 100644 --- a/backend/src/main/java/de/hft/geotime/entities/User.java +++ b/backend/src/main/java/de/hft/geotime/user/User.java @@ -1,5 +1,7 @@ -package de.hft.geotime.entities; +package de.hft.geotime.user; +import de.hft.geotime.role.Role; +import de.hft.geotime.timetrackaccount.TimetrackAccount; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; diff --git a/backend/src/main/java/de/hft/geotime/user/UserRepository.java b/backend/src/main/java/de/hft/geotime/user/UserRepository.java new file mode 100644 index 0000000..2755da1 --- /dev/null +++ b/backend/src/main/java/de/hft/geotime/user/UserRepository.java @@ -0,0 +1,12 @@ +package de.hft.geotime.user; + +import org.springframework.data.repository.CrudRepository; + +import javax.websocket.server.PathParam; +import java.util.List; + +public interface UserRepository extends CrudRepository { + + List findByUsername(@PathParam("username") String username); + +} diff --git a/backend/src/main/resources/application.properties b/backend/src/main/resources/application.properties index 1cf2a4f..cae4ac3 100644 --- a/backend/src/main/resources/application.properties +++ b/backend/src/main/resources/application.properties @@ -1,5 +1,4 @@ server.port=80 -spring.data.rest.basePath=/api spring.datasource.hikari.initialization-fail-timeout=0 spring.datasource.hikari.max-lifetime=300000 spring.profiles.active=prod \ No newline at end of file From 23a72fa238b00ce364cdd7d537d413c791eb31f4 Mon Sep 17 00:00:00 2001 From: Marcel Schwarz Date: Thu, 30 Apr 2020 20:42:22 +0200 Subject: [PATCH 7/7] Formatting --- backend/src/main/java/de/hft/geotime/record/RecordType.java | 2 ++ backend/src/main/java/de/hft/geotime/record/TimeRecord.java | 2 ++ .../java/de/hft/geotime/timetrackaccount/TimetrackAccount.java | 2 ++ 3 files changed, 6 insertions(+) diff --git a/backend/src/main/java/de/hft/geotime/record/RecordType.java b/backend/src/main/java/de/hft/geotime/record/RecordType.java index 1744c48..0adab48 100644 --- a/backend/src/main/java/de/hft/geotime/record/RecordType.java +++ b/backend/src/main/java/de/hft/geotime/record/RecordType.java @@ -1,6 +1,8 @@ package de.hft.geotime.record; public enum RecordType { + BREAK, PAID + } diff --git a/backend/src/main/java/de/hft/geotime/record/TimeRecord.java b/backend/src/main/java/de/hft/geotime/record/TimeRecord.java index 3d9e888..3280d37 100644 --- a/backend/src/main/java/de/hft/geotime/record/TimeRecord.java +++ b/backend/src/main/java/de/hft/geotime/record/TimeRecord.java @@ -16,6 +16,7 @@ import java.util.Date; @AllArgsConstructor @Entity public class TimeRecord { + @Id private long id; @OneToOne @@ -24,4 +25,5 @@ public class TimeRecord { private Date enddate; private Duration time; private RecordType type; + } diff --git a/backend/src/main/java/de/hft/geotime/timetrackaccount/TimetrackAccount.java b/backend/src/main/java/de/hft/geotime/timetrackaccount/TimetrackAccount.java index 0d38a12..f44e6c8 100644 --- a/backend/src/main/java/de/hft/geotime/timetrackaccount/TimetrackAccount.java +++ b/backend/src/main/java/de/hft/geotime/timetrackaccount/TimetrackAccount.java @@ -12,6 +12,7 @@ import javax.persistence.*; @AllArgsConstructor @Entity public class TimetrackAccount { + @Id @GeneratedValue(strategy = GenerationType.AUTO) private long id; @@ -20,4 +21,5 @@ public class TimetrackAccount { private double revenue; private String name; private String description; + }