Merge branch 'master' of github.com:esensar/steleks_backend
commit
b2badb1720
|
@ -6,6 +6,7 @@ import ba.steleks.util.ProxyHeaders;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.util.MultiValueMap;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -37,4 +38,38 @@ public class UserController {
|
||||||
.build();
|
.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();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,6 @@ public class AuthenticationFilter extends GenericFilterBean {
|
||||||
tokenStore,
|
tokenStore,
|
||||||
usersJpaRepository
|
usersJpaRepository
|
||||||
);
|
);
|
||||||
|
|
||||||
SecurityContextHolder.getContext().setAuthentication(authentication);
|
SecurityContextHolder.getContext().setAuthentication(authentication);
|
||||||
filterChain.doFilter(request, response);
|
filterChain.doFilter(request, response);
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue