mirror of
https://github.com/usatiuk/y.git
synced 2025-10-28 18:37:47 +01:00
somewhat working hater management
This commit is contained in:
@@ -5,17 +5,20 @@ import com.usatiuk.tjv.y.server.dto.MessageTo;
|
||||
import com.usatiuk.tjv.y.server.dto.converters.MessageMapper;
|
||||
import com.usatiuk.tjv.y.server.entity.Message;
|
||||
import com.usatiuk.tjv.y.server.entity.Person;
|
||||
import com.usatiuk.tjv.y.server.security.UserRoles;
|
||||
import com.usatiuk.tjv.y.server.service.ChatService;
|
||||
import com.usatiuk.tjv.y.server.service.MessageService;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Stream;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(value = "/message", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
@@ -75,4 +78,13 @@ public class MessageController {
|
||||
messageService.deleteById(id);
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public Stream<MessageTo> getAll(Authentication authentication) {
|
||||
if (!authentication.getAuthorities().contains(new SimpleGrantedAuthority(UserRoles.ROLE_ADMIN.name())))
|
||||
throw new ResponseStatusException(HttpStatus.UNAUTHORIZED);
|
||||
|
||||
return StreamSupport.stream(messageService.readAll().spliterator(), false).map(messageMapper::makeDto);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.usatiuk.tjv.y.server.dto.PersonTo;
|
||||
import com.usatiuk.tjv.y.server.dto.converters.PersonMapper;
|
||||
import com.usatiuk.tjv.y.server.entity.Chat;
|
||||
import com.usatiuk.tjv.y.server.entity.Person;
|
||||
import com.usatiuk.tjv.y.server.security.UserRoles;
|
||||
import com.usatiuk.tjv.y.server.service.ChatService;
|
||||
import com.usatiuk.tjv.y.server.service.PersonService;
|
||||
import com.usatiuk.tjv.y.server.service.exceptions.UserAlreadyExistsException;
|
||||
@@ -12,6 +13,7 @@ import com.usatiuk.tjv.y.server.service.exceptions.UserNotFoundException;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
@@ -96,6 +98,26 @@ public class PersonController {
|
||||
personService.deleteById(authentication.getName());
|
||||
}
|
||||
|
||||
@DeleteMapping(path = "/by-uuid/{uuid}")
|
||||
@ResponseStatus(HttpStatus.NO_CONTENT)
|
||||
public void deleteByUuid(Authentication authentication, @PathVariable String uuid) throws UserNotFoundException {
|
||||
if (!authentication.getAuthorities().contains(new SimpleGrantedAuthority(UserRoles.ROLE_ADMIN.name())))
|
||||
throw new ResponseStatusException(HttpStatus.UNAUTHORIZED);
|
||||
|
||||
var person = personService.readById(uuid).orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND));
|
||||
for (Chat c : person.getChats()) {
|
||||
c.getMembers().remove(person);
|
||||
chatService.update(c);
|
||||
}
|
||||
for (Person p : person.getFollowers()) {
|
||||
p.getFollowing().remove(person);
|
||||
personService.update(p);
|
||||
}
|
||||
|
||||
personService.deleteById(person.getUuid());
|
||||
}
|
||||
|
||||
|
||||
@GetMapping
|
||||
public Stream<PersonTo> getAll() throws UserNotFoundException {
|
||||
return StreamSupport.stream(personService.readAll().spliterator(), false).map(personMapper::makeDto);
|
||||
|
||||
@@ -5,17 +5,20 @@ import com.usatiuk.tjv.y.server.dto.PostTo;
|
||||
import com.usatiuk.tjv.y.server.dto.converters.PostMapper;
|
||||
import com.usatiuk.tjv.y.server.entity.Person;
|
||||
import com.usatiuk.tjv.y.server.entity.Post;
|
||||
import com.usatiuk.tjv.y.server.security.UserRoles;
|
||||
import com.usatiuk.tjv.y.server.service.PostService;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Stream;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(value = "/post", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
@@ -87,4 +90,12 @@ public class PostController {
|
||||
postService.deleteById(id);
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public Stream<PostTo> getAll(Authentication authentication) {
|
||||
if (!authentication.getAuthorities().contains(new SimpleGrantedAuthority(UserRoles.ROLE_ADMIN.name())))
|
||||
throw new ResponseStatusException(HttpStatus.UNAUTHORIZED);
|
||||
|
||||
return StreamSupport.stream(postService.readAll().spliterator(), false).map(postMapper::makeDto);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user