#20 -- some improvements
parent
4fd8a510f3
commit
fb0c605206
@ -1,19 +0,0 @@
|
|||||||
package ru.ulstu.extractor.model;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class Changes {
|
|
||||||
private List<FileChange> fileChanges = new ArrayList<>();
|
|
||||||
|
|
||||||
public Changes() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public Changes(List<FileChange> fileChanges) {
|
|
||||||
this.fileChanges = fileChanges;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<FileChange> getFileChanges() {
|
|
||||||
return fileChanges;
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2021 Anton Romanov - All Rights Reserved
|
||||||
|
* You may use, distribute and modify this code, please write to: romanov73@gmail.com.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package ru.ulstu.extractor.service;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import ru.ulstu.extractor.model.Author;
|
||||||
|
import ru.ulstu.extractor.repository.AuthorRepository;
|
||||||
|
|
||||||
|
import javax.transaction.Transactional;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class AuthorService {
|
||||||
|
private final AuthorRepository authorRepository;
|
||||||
|
|
||||||
|
public AuthorService(AuthorRepository authorRepository) {
|
||||||
|
this.authorRepository = authorRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public Author findOrCreate(Author author) {
|
||||||
|
Optional<Author> newAuthor = authorRepository.findByName(author.getName()).stream().findAny();
|
||||||
|
if (newAuthor.isEmpty()) {
|
||||||
|
return authorRepository.save(author);
|
||||||
|
}
|
||||||
|
return newAuthor.get();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2021 Anton Romanov - All Rights Reserved
|
||||||
|
* You may use, distribute and modify this code, please write to: romanov73@gmail.com.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package ru.ulstu.extractor.service;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import ru.ulstu.extractor.model.Branch;
|
||||||
|
import ru.ulstu.extractor.model.Commit;
|
||||||
|
import ru.ulstu.extractor.model.Repository;
|
||||||
|
import ru.ulstu.extractor.repository.BranchRepository;
|
||||||
|
|
||||||
|
import javax.transaction.Transactional;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class BranchService {
|
||||||
|
private final BranchRepository branchRepository;
|
||||||
|
private final CommitService commitService;
|
||||||
|
|
||||||
|
public BranchService(BranchRepository branchRepository,
|
||||||
|
CommitService commitService) {
|
||||||
|
this.branchRepository = branchRepository;
|
||||||
|
this.commitService = commitService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public Branch save(Branch branch, List<Commit> commits) {
|
||||||
|
List<Commit> commitsToRemove = branch.getCommits();
|
||||||
|
branch.getCommits().clear();
|
||||||
|
commitService.delete(commitsToRemove);
|
||||||
|
branch.setCommits(commitService.save(commits));
|
||||||
|
return branchRepository.save(branch);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Branch findByRepositoryAndName(Repository repository, String branchName) {
|
||||||
|
return branchRepository.findByRepositoryAndName(repository, branchName);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue