user patch

master
Dino Dizdarevic 2018-09-16 23:23:54 +02:00
parent 63bb3473c6
commit 93347be390
2 changed files with 35 additions and 1 deletions

View File

@ -6,6 +6,7 @@ import ba.steleks.util.ProxyHeaders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
@ -37,4 +38,38 @@ public class UserController {
.build();
}
}
@RequestMapping(path = "/users/current", method = RequestMethod.PATCH)
public ResponseEntity<?> updateCurrentUser(@RequestHeader(ProxyHeaders.USER_ID) String userIdString, @RequestBody Map<String, Object> newUser) {
long userId = Long.parseLong(userIdString);
System.out.println("hepek");
User user = usersJpaRepository.findOne(userId);
if (user != null) {
System.out.println("Found user with id: " + userId);
if (newUser.get("firstName") != null) {
user.setFirstName(newUser.get("firstName").toString());
}
if (newUser.get("lastName") != null) {
user.setLastName(newUser.get("lastName").toString());
}
if (newUser.get("username") != null) {
user.setUsername(newUser.get("username").toString());
}
if (newUser.get("contactNumber") != null) {
user.setContactNumber(newUser.get("contactNumber").toString());
}
if (newUser.get("email") != null) {
user.setEmail(newUser.get("email").toString());
}
usersJpaRepository.save(user);
return ResponseEntity
.ok()
.body(user);
} else {
System.out.println("Found no user with id: " + userId);
return ResponseEntity
.status(HttpStatus.NOT_FOUND)
.build();
}
}
}

View File

@ -35,7 +35,6 @@ public class AuthenticationFilter extends GenericFilterBean {
tokenStore,
usersJpaRepository
);
SecurityContextHolder.getContext().setAuthentication(authentication);
filterChain.doFilter(request, response);
}