Resolved confilics with master
Signed-off-by: Marcin Woźniak <y0rune@aol.com>
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
package com.plannaplan.services;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.plannaplan.entities.Assignment;
|
||||
import com.plannaplan.entities.Commision;
|
||||
@ -21,12 +22,13 @@ public class AssignmentService {
|
||||
public AssignmentService() {
|
||||
}
|
||||
|
||||
/*
|
||||
* save
|
||||
* @param assignment which assignment should be save in service
|
||||
/**
|
||||
* Save given assignment
|
||||
* @param assignment assignment to save
|
||||
* @return assignment saved assignment with database id
|
||||
*/
|
||||
public void save(Assignment assignment) {
|
||||
this.repo.save(assignment);
|
||||
public Assignment save(Assignment assignment) {
|
||||
return this.repo.save(assignment);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -44,4 +46,13 @@ public class AssignmentService {
|
||||
public long getAssignmentsAmmount() {
|
||||
return this.repo.count();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get assigmnent by id
|
||||
* @param id id of assigmnent
|
||||
* @return Optional of assignment
|
||||
*/
|
||||
public Optional<Assignment> getById(Long id) {
|
||||
return this.repo.findById(id);
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import java.util.Optional;
|
||||
|
||||
import com.plannaplan.entities.Commision;
|
||||
import com.plannaplan.entities.User;
|
||||
import com.plannaplan.repositories.AssignmentRepository;
|
||||
import com.plannaplan.repositories.CommisionRepository;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -18,6 +19,8 @@ import org.springframework.stereotype.Service;
|
||||
public class CommisionService {
|
||||
@Autowired
|
||||
private CommisionRepository repo;
|
||||
@Autowired
|
||||
private AssignmentRepository aRepository;
|
||||
|
||||
public CommisionService() {
|
||||
}
|
||||
@ -29,6 +32,14 @@ public class CommisionService {
|
||||
* @return commision
|
||||
*/
|
||||
public Commision save(Commision commision) {
|
||||
Optional<Commision> lastCommision = this.getNewestCommision(commision.getCommisionOwner());
|
||||
if (lastCommision.isPresent()) {
|
||||
final Commision lastCom = lastCommision.get();
|
||||
lastCom.getAssignments().forEach(assignment -> {
|
||||
assignment.setPastAssignment(true);
|
||||
this.aRepository.save(assignment);
|
||||
});
|
||||
}
|
||||
this.repo.save(commision);
|
||||
return commision;
|
||||
|
||||
|
@ -1,7 +1,11 @@
|
||||
package com.plannaplan.services;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.function.Function;
|
||||
|
||||
import com.plannaplan.entities.Groups;
|
||||
import com.plannaplan.repositories.GroupRepository;
|
||||
@ -30,8 +34,7 @@ public class GroupService {
|
||||
}
|
||||
|
||||
public Groups save(Groups group) {
|
||||
this.repo.save(group);
|
||||
return group;
|
||||
return this.repo.save(group);
|
||||
}
|
||||
|
||||
public void delete(Groups groups) {
|
||||
@ -55,4 +58,30 @@ public class GroupService {
|
||||
return Optional.empty();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param groups list of groups you want to get taken places ammount
|
||||
* @return HashMap<Long, Integer> where Long is group id and Integer is how many
|
||||
* places in gorup is already taken
|
||||
*/
|
||||
public HashMap<Long, Integer> getTakenPlaces(List<Groups> groups) {
|
||||
HashMap<Long, Integer> response = new HashMap<>();
|
||||
|
||||
List<Object[]> respoonses = this.repo
|
||||
.getAssignedAmounts(groups.stream().filter(Objects::nonNull).map(new Function<Groups, Long>() {
|
||||
@Override
|
||||
public Long apply(Groups p) {
|
||||
final Long id = p.getId();
|
||||
response.put(id, 0);
|
||||
return id;
|
||||
}
|
||||
}).collect(Collectors.toList()));
|
||||
|
||||
for (Object[] element : respoonses) {
|
||||
response.put(((Groups) element[0]).getId(), ((Long) element[1]).intValue());
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
}
|
@ -34,8 +34,8 @@ public class UserService {
|
||||
return token;
|
||||
}
|
||||
|
||||
public void save(User user) {
|
||||
this.repo.save(user);
|
||||
public User save(User user) {
|
||||
return this.repo.save(user);
|
||||
}
|
||||
|
||||
public User getUserByEmail(String email) throws UserNotFoundException {
|
||||
|
Reference in New Issue
Block a user