<commit_before>package app.services;

import app.model.Book;
import app.model.User;
import app.repository.UserRepository;
import app.rest.model.CreateUserCommand;
import app.rest.model.UserInfo;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;
import java.util.stream.Collectors;


@Service
public class UserService {

    private final UserRepository userRepository;

    public UserService(UserRepository userRepository) {
        this.userRepository = userRepository;
    }

    public List<UserInfo> findAll() {
        return userRepository.findAll().stream()
            .map(UserService::toUserInfo)
            .collect(Collectors.toList());
    }

    public UserInfo findOne(Long id) {
        return toUserInfo(userRepository.findOne(id));
    }

    public static UserInfo toUserInfo(User user) {
        UserInfo userInfo = new UserInfo(user.getId(), user.getName(), user.getPhone(), user.getPassword());
        userInfo.setBooks(
            user.getBooks().stream()
                .map(BookService::toBookInfo)
                .collect(Collectors.toList())
        );
        return userInfo;
    }

    @Transactional
    public UserInfo save(CreateUserCommand user) {
        User newUser = new User(user.getName(), user.getPhone(), user.getPassword());
        return toUserInfo(userRepository.save(newUser));
    }

    @Transactional
    public void delete(Long id) {
        userRepository.delete(id);
    }


//    нифига не обновляет связи!!!!
    @Transactional
    public void patch(Long id, Long bookId) {
       User user = userRepository.findOne(id);
       Book toDelete = user.getBooks().stream().filter((book)->book.getId() == bookId).findAny().orElse(null);
       if(toDelete!=null){
           user.getBooks().remove(toDelete);
       }
       userRepository.save(user);
    }


    @Transactional
    public void delete(User user) {
        userRepository.delete(user);
    }

    @Transactional
    public void deleteAll() {
        userRepository.deleteAll();
    }
}
<commit_msg>MSB-28<commit_after>package app.services;

import app.model.Book;
import app.model.User;
import app.repository.UserRepository;
import app.rest.model.CreateUserCommand;
import app.rest.model.UserInfo;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;
import java.util.stream.Collectors;


@Service
public class UserService {

    private final UserRepository userRepository;

    public UserService(UserRepository userRepository) {
        this.userRepository = userRepository;
    }

    public List<UserInfo> findAll() {
        return userRepository.findAll().stream()
            .map(UserService::toUserInfo)
            .collect(Collectors.toList());
    }

    public UserInfo findOne(Long id) {
        return toUserInfo(userRepository.findOne(id));
    }

    public static UserInfo toUserInfo(User user) {
        UserInfo userInfo = new UserInfo(user.getId(), user.getName(), user.getPhone(), user.getPassword());
        userInfo.setBooks(
            user.getBooks().stream()
                .map(BookService::toBookInfo)
                .collect(Collectors.toList())
        );
        return userInfo;
    }

    @Transactional
    public UserInfo save(CreateUserCommand user) {
        User newUser = new User(user.getName(), user.getPhone(), user.getPassword());
        return toUserInfo(userRepository.save(newUser));
    }

    @Transactional
    public void delete(Long id) {
        userRepository.delete(id);
    }


//    нифига не обновляет связи!!!!
    @Transactional
    public void patch(Long id, Long bookId) {
       User user = userRepository.findOne(id);
       user.setBooks(user.getBooks().stream().filter(book -> !book.getId().equals(bookId)).collect(Collectors.toList()));
       User u = userRepository.saveAndFlush(user);
    }


    @Transactional
    public void delete(User user) {
        userRepository.delete(user);
    }

    @Transactional
    public void deleteAll() {
        userRepository.deleteAll();
    }
}

{'fraction_non_alphanumeric': 0.11433447098976109, 'fraction_numerical': 0.00048756704046806434, 'mean_word_length': 2.97577519379845, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7479193', 'n_tokens_mistral': 1181, 'n_tokens_neox': 1152, 'n_words': 228}