Expose user resource
Add projection withRole Remove TimetrackUser reference from TimetrackAccount
This commit is contained in:
parent
798ca8b168
commit
22df05010b
@ -1,11 +1,13 @@
|
||||
package de.hft.geotime.timetrackaccount;
|
||||
|
||||
import de.hft.geotime.user.TimetrackUser;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.persistence.*;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@ -16,8 +18,6 @@ public class TimetrackAccount {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private long id;
|
||||
@OneToOne
|
||||
private TimetrackUser timetrackUser; // TimetrackUser Id (Lazy) [REMOVE]
|
||||
private double revenue;
|
||||
private String name;
|
||||
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;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import de.hft.geotime.role.Role;
|
||||
import de.hft.geotime.timetrackaccount.TimetrackAccount;
|
||||
import lombok.AllArgsConstructor;
|
||||
@ -18,14 +19,21 @@ public class TimetrackUser {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private long id;
|
||||
|
||||
@Column(unique = true)
|
||||
private String username;
|
||||
private String password; // strip
|
||||
|
||||
@JsonIgnore
|
||||
private String password;
|
||||
|
||||
private String firstname;
|
||||
|
||||
private String lastname;
|
||||
|
||||
@OneToOne
|
||||
private Role role; // Projection (String)
|
||||
@OneToMany
|
||||
private List<TimetrackAccount> timetrackAccounts; // Lazy List
|
||||
private Role role;
|
||||
|
||||
@OneToMany(fetch = FetchType.LAZY)
|
||||
private List<TimetrackAccount> accounts;
|
||||
|
||||
}
|
||||
|
@ -1,11 +1,19 @@
|
||||
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;
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
|
@ -6,6 +6,10 @@ DELETE FROM role;
|
||||
INSERT INTO role (id, `name`) VALUES
|
||||
(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
|
||||
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),
|
||||
(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;
|
Loading…
Reference in New Issue
Block a user