mirror of
https://github.com/usatiuk/y.git
synced 2025-10-28 18:37:47 +01:00
simple user viewing
This commit is contained in:
@@ -13,6 +13,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
import java.security.Principal;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Stream;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(value = "/person", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
@@ -35,8 +36,8 @@ public class PersonController {
|
||||
return PersonMapper.makeDto(created);
|
||||
}
|
||||
|
||||
@GetMapping(path = "/{username}")
|
||||
public PersonTo get(@PathVariable String username) throws UserNotFoundException {
|
||||
@GetMapping(path = "/by-username/{username}")
|
||||
public PersonTo getByUsername(@PathVariable String username) throws UserNotFoundException {
|
||||
Optional<Person> found = personService.readByUsername(username);
|
||||
|
||||
if (found.isEmpty()) throw new UserNotFoundException();
|
||||
@@ -44,7 +45,17 @@ public class PersonController {
|
||||
return PersonMapper.makeDto(found.get());
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
@GetMapping(path = "/by-uuid/{uuid}")
|
||||
public PersonTo getByUuid(@PathVariable String uuid) throws UserNotFoundException {
|
||||
Optional<Person> found = personService.readById(uuid);
|
||||
|
||||
if (found.isEmpty()) throw new UserNotFoundException();
|
||||
|
||||
return PersonMapper.makeDto(found.get());
|
||||
}
|
||||
|
||||
|
||||
@GetMapping(path = "/self")
|
||||
public PersonTo getSelf(Principal principal) throws UserNotFoundException {
|
||||
Optional<Person> found = personService.readById(principal.getName());
|
||||
|
||||
@@ -53,6 +64,11 @@ public class PersonController {
|
||||
return PersonMapper.makeDto(found.get());
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public Stream<PersonTo> getAll() throws UserNotFoundException {
|
||||
return StreamSupport.stream(personService.readAll().spliterator(), false).map(PersonMapper::makeDto);
|
||||
}
|
||||
|
||||
@GetMapping(path = "/followers")
|
||||
public Stream<PersonTo> getFollowers(Principal principal) throws UserNotFoundException {
|
||||
return personService.getFollowers(principal.getName()).stream().map(PersonMapper::makeDto);
|
||||
|
||||
@@ -63,7 +63,9 @@ public class WebSecurityConfig {
|
||||
.requestMatchers(mvc.pattern(HttpMethod.GET, "/post/*")).permitAll()
|
||||
.requestMatchers(mvc.pattern(HttpMethod.GET, "/post*")).permitAll()
|
||||
.requestMatchers(mvc.pattern(HttpMethod.POST, "/person")).permitAll()
|
||||
.requestMatchers(mvc.pattern(HttpMethod.GET, "/person/*")).permitAll()
|
||||
.requestMatchers(mvc.pattern(HttpMethod.GET, "/person")).permitAll()
|
||||
.requestMatchers(mvc.pattern(HttpMethod.GET, "/person/by-username/*")).permitAll()
|
||||
.requestMatchers(mvc.pattern(HttpMethod.GET, "/person/by-uuid/*")).permitAll()
|
||||
.requestMatchers(mvc.pattern(HttpMethod.POST, "/token")).permitAll()
|
||||
.anyRequest().hasAuthority(UserRoles.ROLE_USER.name()))
|
||||
.sessionManagement((session) -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
|
||||
|
||||
@@ -37,7 +37,7 @@ public class PersonControllerTest extends DemoDataDbTest {
|
||||
|
||||
@Test
|
||||
void shouldGet() {
|
||||
var response = restTemplate.exchange(addr + "/person/" + person1.getUsername(),
|
||||
var response = restTemplate.exchange(addr + "/person/by-username/" + person1.getUsername(),
|
||||
HttpMethod.GET, HttpEntity.EMPTY, PersonTo.class);
|
||||
|
||||
Assertions.assertNotNull(response);
|
||||
@@ -52,7 +52,7 @@ public class PersonControllerTest extends DemoDataDbTest {
|
||||
|
||||
@Test
|
||||
void shouldGetSelf() {
|
||||
var response = restTemplate.exchange(addr + "/person",
|
||||
var response = restTemplate.exchange(addr + "/person/self",
|
||||
HttpMethod.GET, new HttpEntity<>(createAuthHeaders(person1Auth)), PersonTo.class);
|
||||
|
||||
Assertions.assertNotNull(response);
|
||||
|
||||
Reference in New Issue
Block a user