Fixed couple of endpoints, implemented more of the frontend

This commit is contained in:
2023-10-25 01:24:28 +03:00
parent e4de55f255
commit 0baac602e4
18 changed files with 300 additions and 204 deletions

View File

@@ -8,6 +8,9 @@ import com.faf223.expensetrackerfaf.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
@@ -33,11 +36,16 @@ public class UserController {
}
}
@GetMapping("/{userUuid}")
public ResponseEntity<UserDTO> getUser(@PathVariable String userUuid) {
User user = userService.getUserById(userUuid);
if (user != null) return ResponseEntity.ok(userMapper.toDto(user));
else return ResponseEntity.notFound().build();
@GetMapping("/getUserData")
public ResponseEntity<UserDTO> getUser() {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication != null && authentication.getPrincipal() instanceof UserDetails userDetails) {
User user = userService.getUserByEmail(userDetails.getUsername());
if (user != null) return ResponseEntity.ok(userMapper.toDto(user));
else return ResponseEntity.notFound().build();
}
return ResponseEntity.notFound().build();
}
@GetMapping()