Merge branch '49-create-accounts-rest-controller' into 'master'
Resolve "Create accounts rest controller" Closes #49 See merge request marcel.schwarz/2020ss-qbc-geofence-timetracking!47
This commit is contained in:
commit
d47733cc6f
@ -4,6 +4,7 @@ import org.springframework.boot.SpringApplication;
|
|||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
|
import org.springframework.data.projection.SpelAwareProxyProjectionFactory;
|
||||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
@ -19,4 +20,9 @@ public class GeotimeApplication {
|
|||||||
return new BCryptPasswordEncoder();
|
return new BCryptPasswordEncoder();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public SpelAwareProxyProjectionFactory projectionFactory() {
|
||||||
|
return new SpelAwareProxyProjectionFactory();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
package de.hft.geotime.user;
|
package de.hft.geotime.controllers;
|
||||||
|
|
||||||
|
import de.hft.geotime.entities.TimetrackUser;
|
||||||
|
import de.hft.geotime.entities.projections.UserWithRoleProjection;
|
||||||
|
import de.hft.geotime.repositories.TimetrackUserRepository;
|
||||||
|
import org.springframework.data.projection.ProjectionFactory;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.security.core.Authentication;
|
import org.springframework.security.core.Authentication;
|
||||||
@ -14,16 +18,18 @@ public class UserController {
|
|||||||
|
|
||||||
private final TimetrackUserRepository userRepository;
|
private final TimetrackUserRepository userRepository;
|
||||||
private final BCryptPasswordEncoder bCryptPasswordEncoder;
|
private final BCryptPasswordEncoder bCryptPasswordEncoder;
|
||||||
|
private final ProjectionFactory projectionFactory;
|
||||||
|
|
||||||
public UserController(TimetrackUserRepository userRepository, BCryptPasswordEncoder bCryptPasswordEncoder) {
|
public UserController(TimetrackUserRepository userRepository, BCryptPasswordEncoder bCryptPasswordEncoder, ProjectionFactory projectionFactory) {
|
||||||
this.userRepository = userRepository;
|
this.userRepository = userRepository;
|
||||||
this.bCryptPasswordEncoder = bCryptPasswordEncoder;
|
this.bCryptPasswordEncoder = bCryptPasswordEncoder;
|
||||||
|
this.projectionFactory = projectionFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/whoami")
|
@GetMapping("/whoami")
|
||||||
public String getUsername(Authentication authentication) {
|
public UserWithRoleProjection getUsername(Authentication authentication) {
|
||||||
TimetrackUser timetrackUser = userRepository.findFirstByUsername(authentication.getName());
|
TimetrackUser user = userRepository.findFirstByUsername(authentication.getName());
|
||||||
return "Welcome back " + timetrackUser.getFirstname() + " " + timetrackUser.getLastname();
|
return projectionFactory.createProjection(UserWithRoleProjection.class, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/sign-up")
|
@PostMapping("/sign-up")
|
@ -1,4 +1,4 @@
|
|||||||
package de.hft.geotime.record;
|
package de.hft.geotime.entities;
|
||||||
|
|
||||||
public enum RecordType {
|
public enum RecordType {
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package de.hft.geotime.role;
|
package de.hft.geotime.entities;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
@ -1,6 +1,5 @@
|
|||||||
package de.hft.geotime.record;
|
package de.hft.geotime.entities;
|
||||||
|
|
||||||
import de.hft.geotime.timetrackaccount.TimetrackAccount;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
@ -1,6 +1,5 @@
|
|||||||
package de.hft.geotime.timetrackaccount;
|
package de.hft.geotime.entities;
|
||||||
|
|
||||||
import de.hft.geotime.user.TimetrackUser;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
@ -1,8 +1,6 @@
|
|||||||
package de.hft.geotime.user;
|
package de.hft.geotime.entities;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import de.hft.geotime.role.Role;
|
|
||||||
import de.hft.geotime.timetrackaccount.TimetrackAccount;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
@ -0,0 +1,18 @@
|
|||||||
|
package de.hft.geotime.entities.projections;
|
||||||
|
|
||||||
|
import de.hft.geotime.entities.TimetrackAccount;
|
||||||
|
import de.hft.geotime.entities.TimetrackUser;
|
||||||
|
import org.springframework.data.rest.core.config.Projection;
|
||||||
|
|
||||||
|
@Projection(name = "withUser", types = TimetrackAccount.class)
|
||||||
|
public interface AccountWithUserProjection {
|
||||||
|
|
||||||
|
double getRevenue();
|
||||||
|
|
||||||
|
String getName();
|
||||||
|
|
||||||
|
String getDescription();
|
||||||
|
|
||||||
|
TimetrackUser getUser();
|
||||||
|
|
||||||
|
}
|
@ -1,10 +1,11 @@
|
|||||||
package de.hft.geotime.user;
|
package de.hft.geotime.entities.projections;
|
||||||
|
|
||||||
|
import de.hft.geotime.entities.TimetrackUser;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.data.rest.core.config.Projection;
|
import org.springframework.data.rest.core.config.Projection;
|
||||||
|
|
||||||
@Projection(name = "withRole", types = TimetrackUser.class)
|
@Projection(name = "withRole", types = TimetrackUser.class)
|
||||||
public interface BasicUserProjection {
|
public interface UserWithRoleProjection {
|
||||||
|
|
||||||
String getFirstname();
|
String getFirstname();
|
||||||
|
|
@ -1,5 +1,6 @@
|
|||||||
package de.hft.geotime.record;
|
package de.hft.geotime.repositories;
|
||||||
|
|
||||||
|
import de.hft.geotime.entities.TimeRecord;
|
||||||
import org.springframework.data.repository.CrudRepository;
|
import org.springframework.data.repository.CrudRepository;
|
||||||
|
|
||||||
public interface RecordRepository extends CrudRepository<TimeRecord, Long> {
|
public interface RecordRepository extends CrudRepository<TimeRecord, Long> {
|
@ -1,5 +1,6 @@
|
|||||||
package de.hft.geotime.role;
|
package de.hft.geotime.repositories;
|
||||||
|
|
||||||
|
import de.hft.geotime.entities.Role;
|
||||||
import org.springframework.data.repository.CrudRepository;
|
import org.springframework.data.repository.CrudRepository;
|
||||||
|
|
||||||
public interface RoleRepository extends CrudRepository<Role, Long> {
|
public interface RoleRepository extends CrudRepository<Role, Long> {
|
@ -0,0 +1,14 @@
|
|||||||
|
package de.hft.geotime.repositories;
|
||||||
|
|
||||||
|
import de.hft.geotime.entities.TimetrackAccount;
|
||||||
|
import org.springframework.data.repository.PagingAndSortingRepository;
|
||||||
|
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
|
||||||
|
|
||||||
|
@RepositoryRestResource(
|
||||||
|
path = "accounts",
|
||||||
|
itemResourceRel = "accounts",
|
||||||
|
collectionResourceRel = "accounts"
|
||||||
|
)
|
||||||
|
public interface TimetrackAccountRepository extends PagingAndSortingRepository<TimetrackAccount, Long> {
|
||||||
|
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
package de.hft.geotime.user;
|
package de.hft.geotime.repositories;
|
||||||
|
|
||||||
|
import de.hft.geotime.entities.TimetrackUser;
|
||||||
import org.springframework.data.repository.PagingAndSortingRepository;
|
import org.springframework.data.repository.PagingAndSortingRepository;
|
||||||
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
|
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
|
||||||
import org.springframework.data.rest.core.annotation.RestResource;
|
import org.springframework.data.rest.core.annotation.RestResource;
|
@ -1,5 +1,7 @@
|
|||||||
package de.hft.geotime.user;
|
package de.hft.geotime.security;
|
||||||
|
|
||||||
|
import de.hft.geotime.entities.TimetrackUser;
|
||||||
|
import de.hft.geotime.repositories.TimetrackUserRepository;
|
||||||
import org.springframework.security.core.userdetails.User;
|
import org.springframework.security.core.userdetails.User;
|
||||||
import org.springframework.security.core.userdetails.UserDetails;
|
import org.springframework.security.core.userdetails.UserDetails;
|
||||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
import org.springframework.security.core.userdetails.UserDetailsService;
|
@ -1,6 +1,5 @@
|
|||||||
package de.hft.geotime.security;
|
package de.hft.geotime.security;
|
||||||
|
|
||||||
import de.hft.geotime.user.UserDetailsServiceImpl;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.http.HttpMethod;
|
import org.springframework.http.HttpMethod;
|
||||||
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
||||||
|
@ -1,7 +0,0 @@
|
|||||||
package de.hft.geotime.timetrackaccount;
|
|
||||||
|
|
||||||
import org.springframework.data.repository.CrudRepository;
|
|
||||||
|
|
||||||
public interface TimetrackAccountRepository extends CrudRepository<TimetrackAccount, Long> {
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user