Commit b6e73220 authored by Khalid Ali's avatar Khalid Ali
Browse files

Feature/5-Auto-Add-Users

parent 8a51b553
...@@ -25,6 +25,7 @@ import org.springframework.web.bind.annotation.*; ...@@ -25,6 +25,7 @@ import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -101,13 +102,21 @@ public class BookshareApiController { ...@@ -101,13 +102,21 @@ public class BookshareApiController {
return convertBidToDto(bidCreated); return convertBidToDto(bidCreated);
} }
@GetMapping(value = "/user/email/{email}") @GetMapping(value = "/user/")
ShareUserDto getByEmail(@PathVariable String email) { ShareUserDto getUser() {
ShareUser user = shareUserService.getShareUserByEmail(email); Authentication auth = SecurityContextHolder.getContext().getAuthentication();
if (user == null) { if (auth != null
return new ShareUserDto("", ""); && auth.getPrincipal() != null
&& auth.getPrincipal() instanceof UserDetails) {
String username = ((UserDetails) auth.getPrincipal()).getUsername();
ShareUser user = shareUserService.getShareUserByEmail(username);
if (user == null) {
ShareUser newUser = new ShareUser(username, "default", new HashSet<>(), new HashSet<>());
user = shareUserService.addShareUser(newUser);
}
return convertShareUserToDto(user);
} }
return convertShareUserToDto(user); return new ShareUserDto("", "");
} }
@GetMapping(value = "/user/id/{id}") @GetMapping(value = "/user/id/{id}")
...@@ -119,14 +128,6 @@ public class BookshareApiController { ...@@ -119,14 +128,6 @@ public class BookshareApiController {
return convertShareUserToDto(user); return convertShareUserToDto(user);
} }
@PostMapping(value = "/user", consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.CREATED)
public ShareUserDto newListing(@RequestBody ShareUserDto shareUserDto) {
ShareUser user = convertShareUserToEntity(shareUserDto);
ShareUser userCreated = shareUserService.addShareUser(user);
return convertShareUserToDto(userCreated);
}
@GetMapping(name = "/login") @GetMapping(name = "/login")
public String index(ModelMap modelMap) { public String index(ModelMap modelMap) {
Authentication auth = SecurityContextHolder.getContext() Authentication auth = SecurityContextHolder.getContext()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment