Merge branch '47-create-users-rest-controller' into 'master'
Resolve "Create users rest controller" Closes #47 See merge request marcel.schwarz/2020ss-qbc-geofence-timetracking!39
This commit is contained in:
commit
48fd0cfdc0
@ -1,11 +1,13 @@
|
|||||||
package de.hft.geotime.timetrackaccount;
|
package de.hft.geotime.timetrackaccount;
|
||||||
|
|
||||||
import de.hft.geotime.user.TimetrackUser;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.GenerationType;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@ -16,8 +18,6 @@ public class TimetrackAccount {
|
|||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
private long id;
|
private long id;
|
||||||
@OneToOne
|
|
||||||
private TimetrackUser timetrackUser; // TimetrackUser Id (Lazy) [REMOVE]
|
|
||||||
private double revenue;
|
private double revenue;
|
||||||
private String name;
|
private String name;
|
||||||
private String description;
|
private String description;
|
||||||
|
@ -0,0 +1,18 @@
|
|||||||
|
package de.hft.geotime.user;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.data.rest.core.config.Projection;
|
||||||
|
|
||||||
|
@Projection(name = "withRole", types = TimetrackUser.class)
|
||||||
|
public interface BasicUserProjection {
|
||||||
|
|
||||||
|
String getFirstname();
|
||||||
|
|
||||||
|
String getLastname();
|
||||||
|
|
||||||
|
String getUsername();
|
||||||
|
|
||||||
|
@Value("#{target.role.name}")
|
||||||
|
String getRole();
|
||||||
|
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
package de.hft.geotime.user;
|
package de.hft.geotime.user;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import de.hft.geotime.role.Role;
|
import de.hft.geotime.role.Role;
|
||||||
import de.hft.geotime.timetrackaccount.TimetrackAccount;
|
import de.hft.geotime.timetrackaccount.TimetrackAccount;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
@ -18,14 +19,21 @@ public class TimetrackUser {
|
|||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
private long id;
|
private long id;
|
||||||
|
|
||||||
@Column(unique = true)
|
@Column(unique = true)
|
||||||
private String username;
|
private String username;
|
||||||
private String password; // strip
|
|
||||||
|
@JsonIgnore
|
||||||
|
private String password;
|
||||||
|
|
||||||
private String firstname;
|
private String firstname;
|
||||||
|
|
||||||
private String lastname;
|
private String lastname;
|
||||||
|
|
||||||
@OneToOne
|
@OneToOne
|
||||||
private Role role; // Projection (String)
|
private Role role;
|
||||||
@OneToMany
|
|
||||||
private List<TimetrackAccount> timetrackAccounts; // Lazy List
|
@OneToMany(fetch = FetchType.LAZY)
|
||||||
|
private List<TimetrackAccount> accounts;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,19 @@
|
|||||||
package de.hft.geotime.user;
|
package de.hft.geotime.user;
|
||||||
|
|
||||||
import org.springframework.data.repository.CrudRepository;
|
import org.springframework.data.repository.PagingAndSortingRepository;
|
||||||
|
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
|
||||||
|
import org.springframework.data.rest.core.annotation.RestResource;
|
||||||
|
|
||||||
import javax.websocket.server.PathParam;
|
import javax.websocket.server.PathParam;
|
||||||
|
|
||||||
public interface TimetrackUserRepository extends CrudRepository<TimetrackUser, Long> {
|
@RepositoryRestResource(
|
||||||
|
path = "users",
|
||||||
|
itemResourceRel = "users",
|
||||||
|
collectionResourceRel = "users"
|
||||||
|
)
|
||||||
|
public interface TimetrackUserRepository extends PagingAndSortingRepository<TimetrackUser, Long> {
|
||||||
|
|
||||||
|
@RestResource(path = "byUsername", rel = "byUsername")
|
||||||
TimetrackUser findFirstByUsername(@PathParam("username") String username);
|
TimetrackUser findFirstByUsername(@PathParam("username") String username);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,10 @@ DELETE FROM role;
|
|||||||
INSERT INTO role (id, `name`) VALUES
|
INSERT INTO role (id, `name`) VALUES
|
||||||
(1, 'Admin');
|
(1, 'Admin');
|
||||||
|
|
||||||
|
INSERT INTO timetrack_account (id, description, `name`, revenue) VALUES
|
||||||
|
(1, 'Gleitzeit Marcel', 'Primary Marcel', 16.0),
|
||||||
|
(2, 'Festgeld Marcel', 'Secondary Marcel', 25.0);
|
||||||
|
|
||||||
/* 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
|
||||||
*/
|
*/
|
||||||
@ -15,4 +19,8 @@ INSERT INTO timetrack_user (id, firstname, lastname, password, username, role_id
|
|||||||
(3, 'Tim', 'Zieger' ,'$2y$10$pYGHZhoaelceImO7aIN4nOkWJBp.oqNGFYaRAonHkYF4u9ljqPelC', 'ziti', 1),
|
(3, 'Tim', 'Zieger' ,'$2y$10$pYGHZhoaelceImO7aIN4nOkWJBp.oqNGFYaRAonHkYF4u9ljqPelC', 'ziti', 1),
|
||||||
(4, 'Simon', 'Kellner' ,'$2y$10$Puzm/Nr/Dyq3nQxlkXGIfubS5JPtXJSOf2e6mrQ6HhVYQN9YiQQsC', 'kesi', 1);
|
(4, 'Simon', 'Kellner' ,'$2y$10$Puzm/Nr/Dyq3nQxlkXGIfubS5JPtXJSOf2e6mrQ6HhVYQN9YiQQsC', 'kesi', 1);
|
||||||
|
|
||||||
|
INSERT INTO timetrack_user_accounts (timetrack_user_id, accounts_id) VALUES
|
||||||
|
(1, 1),
|
||||||
|
(1, 2);
|
||||||
|
|
||||||
SET FOREIGN_KEY_CHECKS=1;
|
SET FOREIGN_KEY_CHECKS=1;
|
Loading…
Reference in New Issue
Block a user