mirror of
https://github.com/usatiuk/y.git
synced 2025-10-28 10:37:47 +01:00
entire services in transactions
This commit is contained in:
@@ -14,7 +14,7 @@ import java.lang.annotation.Target;
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@ApiResponse(
|
||||
responseCode = "409",
|
||||
description = "Conflict - creating/updating what is requested would conflict with existing data",
|
||||
description = "Conflict - creating/updating what is requested would conflict with existing data (e.g. usernames must be unique)",
|
||||
content = @Content(
|
||||
mediaType = "application/json",
|
||||
schema = @Schema(implementation = ErrorTo.class)
|
||||
|
||||
@@ -29,7 +29,7 @@ public class Message {
|
||||
private Person author;
|
||||
|
||||
@CreationTimestamp
|
||||
private Instant createdAt;
|
||||
private Instant createdAt = Instant.now();
|
||||
|
||||
@Lob
|
||||
@NotBlank(message = "Message can't be empty")
|
||||
|
||||
@@ -30,5 +30,5 @@ public class Post {
|
||||
private String text;
|
||||
|
||||
@CreationTimestamp
|
||||
private Instant createdAt;
|
||||
private Instant createdAt = Instant.now();
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.usatiuk.tjv.y.server.repository.ChatRepository;
|
||||
import com.usatiuk.tjv.y.server.service.exceptions.BadInputException;
|
||||
import com.usatiuk.tjv.y.server.service.exceptions.NotFoundException;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.transaction.Transactional;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -20,6 +21,7 @@ import java.util.Collection;
|
||||
import java.util.Objects;
|
||||
|
||||
@Service("chatService")
|
||||
@Transactional
|
||||
public class ChatServiceImpl implements ChatService {
|
||||
|
||||
private final ChatRepository chatRepository;
|
||||
|
||||
@@ -3,12 +3,14 @@ package com.usatiuk.tjv.y.server.service;
|
||||
import com.usatiuk.tjv.y.server.dto.TokenRequestTo;
|
||||
import com.usatiuk.tjv.y.server.dto.TokenResponseTo;
|
||||
import com.usatiuk.tjv.y.server.security.JwtTokenService;
|
||||
import jakarta.transaction.Transactional;
|
||||
import org.springframework.security.authentication.AuthenticationManager;
|
||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@Transactional
|
||||
public class LoginTokenServiceImpl implements LoginTokenService {
|
||||
private final AuthenticationManager authenticationManager;
|
||||
private final JwtTokenService jwtTokenService;
|
||||
|
||||
@@ -9,6 +9,7 @@ import com.usatiuk.tjv.y.server.entity.Person;
|
||||
import com.usatiuk.tjv.y.server.repository.MessageRepository;
|
||||
import com.usatiuk.tjv.y.server.service.exceptions.NotFoundException;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.transaction.Transactional;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -17,6 +18,7 @@ import java.util.Objects;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
@Service("messageService")
|
||||
@Transactional
|
||||
public class MessageServiceImpl implements MessageService {
|
||||
|
||||
private final MessageRepository messageRepository;
|
||||
|
||||
@@ -20,6 +20,7 @@ import java.util.Optional;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
@Service
|
||||
@Transactional
|
||||
public class PersonServiceImpl implements PersonService {
|
||||
private final PersonRepository personRepository;
|
||||
private final PasswordEncoder passwordEncoder;
|
||||
@@ -76,7 +77,6 @@ public class PersonServiceImpl implements PersonService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public PersonTo update(Authentication authentication, PersonCreateTo person) {
|
||||
var found = personRepository.findById(authentication.getName()).orElseThrow(NotFoundException::new);
|
||||
|
||||
@@ -90,7 +90,6 @@ public class PersonServiceImpl implements PersonService {
|
||||
return personMapper.makeDto(found);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void deleteByUuid(String uuid) {
|
||||
var person = personRepository.findById(uuid).orElseThrow(NotFoundException::new);
|
||||
for (Chat c : person.getChats()) {
|
||||
@@ -104,7 +103,6 @@ public class PersonServiceImpl implements PersonService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void deleteSelf(Authentication authentication) {
|
||||
deleteByUuid(authentication.getName());
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import com.usatiuk.tjv.y.server.entity.Post;
|
||||
import com.usatiuk.tjv.y.server.repository.PostRepository;
|
||||
import com.usatiuk.tjv.y.server.service.exceptions.NotFoundException;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.transaction.Transactional;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -16,6 +17,7 @@ import java.util.Objects;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
@Service("postService")
|
||||
@Transactional
|
||||
public class PostServiceImpl implements PostService {
|
||||
private final PostRepository postRepository;
|
||||
private final PostMapper postMapper;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.usatiuk.tjv.y.server.spasupport;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Hidden;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.http.MediaType;
|
||||
@@ -14,6 +15,7 @@ import java.nio.file.Files;
|
||||
@RestController
|
||||
@RequestMapping(value = "/app", produces = MediaType.TEXT_HTML_VALUE)
|
||||
@Profile("prod")
|
||||
@Hidden
|
||||
class AppRootContoller {
|
||||
private final File indexFile;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user