43 lines
1.1 KiB
Java
Executable File
43 lines
1.1 KiB
Java
Executable File
package com.plannaplan.services;
|
|
|
|
import java.util.List;
|
|
import java.util.Optional;
|
|
|
|
import com.plannaplan.entities.Commision;
|
|
import com.plannaplan.entities.User;
|
|
import com.plannaplan.repositories.CommisionRepository;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
/**
|
|
* Service of CommisionService which can save commision, get user's commisions, get newest user's commision, get ammount of commisions.
|
|
*/
|
|
|
|
@Service
|
|
public class CommisionService {
|
|
@Autowired
|
|
private CommisionRepository repo;
|
|
|
|
public CommisionService() {
|
|
}
|
|
|
|
public Commision save(Commision commision) {
|
|
this.repo.save(commision);
|
|
return commision;
|
|
|
|
}
|
|
|
|
public List<Commision> getUsersCommisions(User user) {
|
|
return this.repo.getUsers(user.getId());
|
|
}
|
|
|
|
public Optional<Commision> getNewestCommision(User user) {
|
|
return this.repo.getNewestCommision(user.getId()).stream().findFirst();
|
|
}
|
|
|
|
public long getCommisionsAmmount() {
|
|
return this.repo.count();
|
|
}
|
|
}
|