Created
August 20, 2021 14:06
-
-
Save JuliaKrivonos/a29349f18b2b0f13b7d94c7cf06d76b6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package org.jazzteam.fitnesclub.service.impl; | |
| import com.google.common.collect.Lists; | |
| import org.jazzteam.fitnesclub.dto.PassDto; | |
| import org.jazzteam.fitnesclub.dto.PassTypeDto; | |
| import org.jazzteam.fitnesclub.model.Pass; | |
| import org.jazzteam.fitnesclub.model.PassType; | |
| import org.jazzteam.fitnesclub.model.persons.Client; | |
| import org.jazzteam.fitnesclub.repository.ClientRepository; | |
| import org.jazzteam.fitnesclub.repository.PassRepository; | |
| import org.jazzteam.fitnesclub.repository.addictional.PassTypeRepository; | |
| import org.jazzteam.fitnesclub.repository.addictional.impl.PassTypeRepositoryImpl; | |
| import org.jazzteam.fitnesclub.repository.impl.ClientRepositoryImpl; | |
| import org.jazzteam.fitnesclub.repository.impl.PassRepositoryImpl; | |
| import org.jazzteam.fitnesclub.service.PassService; | |
| import java.time.LocalDateTime; | |
| import java.util.List; | |
| public class PassServiceImpl implements PassService { | |
| private final PassRepository passRepository = new PassRepositoryImpl(); | |
| private final ClientRepository clientRepository = new ClientRepositoryImpl(); | |
| private final PassTypeRepository passTypeRepository = new PassTypeRepositoryImpl(); | |
| @Override | |
| public Pass savePass(PassDto passDto, Long clientId) { | |
| Client client = clientRepository.findById(clientId); | |
| PassType passType = passTypeRepository.findById(passDto.getType().getId()); | |
| Pass pass = Pass.builder() | |
| .timeOfCreated(LocalDateTime.now()) | |
| .timeOfUpdated(LocalDateTime.now()) | |
| .type(passType) | |
| .amountOfVisiting(passType.getMaxAmount()) | |
| .client(client).build(); | |
| return passRepository.save(pass); | |
| } | |
| @Override | |
| public Pass updatePass(PassDto passDto) { | |
| Pass pass = passRepository.findById(passDto.getId()); | |
| pass.setTimeOfUpdated(LocalDateTime.now()); | |
| pass.setAmountOfVisiting(passDto.getAmountOfVisiting()); | |
| pass.setType(passTypeRepository.findById(passDto.getType().getId())); | |
| return passRepository.save(pass); | |
| } | |
| @Override | |
| public void deletePass(PassDto Pass) { | |
| Pass passToDelete = passRepository.findById(Pass.getId()); | |
| passRepository.delete(passToDelete); | |
| } | |
| @Override | |
| public PassType savePassType(PassTypeDto passTypeDto, Long clientId) { | |
| PassType passType = new PassType(1L, passTypeDto.getType(), passTypeDto.getMaxAmount(), Lists.newArrayList()); | |
| return passTypeRepository.save(passType); | |
| } | |
| @Override | |
| public PassType updatePassType(PassTypeDto passTypeDto) { | |
| PassType passType = passTypeRepository.findById(passTypeDto.getId()); | |
| passType.setType(passTypeDto.getType()); | |
| passType.setMaxAmount(passTypeDto.getMaxAmount()); | |
| return passTypeRepository.save(passType); | |
| } | |
| @Override | |
| public void deletePassType(PassTypeDto passType) { | |
| PassType passTypeToDelete = passTypeRepository.findById(passType.getId()); | |
| passTypeRepository.delete(passTypeToDelete); | |
| } | |
| @Override | |
| public List<PassType> findAllPassTypes() { | |
| return passTypeRepository.findAll(); | |
| } | |
| @Override | |
| public List<Pass> findAllByClient(Long clientId) { | |
| Client client = clientRepository.findById(clientId); | |
| return passRepository.findByClient(client); | |
| } | |
| @Override | |
| public List<Pass> findAllPasses() { | |
| return passRepository.findAll(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment