package com.example.questionbank.service; import com.example.questionbank.domain.ExamAnswer; import com.example.questionbank.repository.ExamAnswerRepository; import com.example.questionbank.service.dto.ExamAnswerDTO; import com.example.questionbank.service.mapper.ExamAnswerMapper; import java.util.LinkedList; import java.util.List; import java.util.Optional; import java.util.stream.Collectors; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; /** * Service Implementation for managing {@link com.example.questionbank.domain.ExamAnswer}. */ @Service @Transactional public class ExamAnswerService { private static final Logger LOG = LoggerFactory.getLogger(ExamAnswerService.class); private final ExamAnswerRepository examAnswerRepository; private final ExamAnswerMapper examAnswerMapper; public ExamAnswerService(ExamAnswerRepository examAnswerRepository, ExamAnswerMapper examAnswerMapper) { this.examAnswerRepository = examAnswerRepository; this.examAnswerMapper = examAnswerMapper; } /** * Save a examAnswer. * * @param examAnswerDTO the entity to save. * @return the persisted entity. */ public ExamAnswerDTO save(ExamAnswerDTO examAnswerDTO) { LOG.debug("Request to save ExamAnswer : {}", examAnswerDTO); ExamAnswer examAnswer = examAnswerMapper.toEntity(examAnswerDTO); examAnswer = examAnswerRepository.save(examAnswer); return examAnswerMapper.toDto(examAnswer); } /** * Update a examAnswer. * * @param examAnswerDTO the entity to save. * @return the persisted entity. */ public ExamAnswerDTO update(ExamAnswerDTO examAnswerDTO) { LOG.debug("Request to update ExamAnswer : {}", examAnswerDTO); ExamAnswer examAnswer = examAnswerMapper.toEntity(examAnswerDTO); examAnswer = examAnswerRepository.save(examAnswer); return examAnswerMapper.toDto(examAnswer); } /** * Partially update a examAnswer. * * @param examAnswerDTO the entity to update partially. * @return the persisted entity. */ public Optional partialUpdate(ExamAnswerDTO examAnswerDTO) { LOG.debug("Request to partially update ExamAnswer : {}", examAnswerDTO); return examAnswerRepository .findById(examAnswerDTO.getId()) .map(existingExamAnswer -> { examAnswerMapper.partialUpdate(existingExamAnswer, examAnswerDTO); return existingExamAnswer; }) .map(examAnswerRepository::save) .map(examAnswerMapper::toDto); } /** * Get all the examAnswers. * * @return the list of entities. */ @Transactional(readOnly = true) public List findAll() { LOG.debug("Request to get all ExamAnswers"); return examAnswerRepository.findAll().stream().map(examAnswerMapper::toDto).collect(Collectors.toCollection(LinkedList::new)); } /** * Get one examAnswer by id. * * @param id the id of the entity. * @return the entity. */ @Transactional(readOnly = true) public Optional findOne(Long id) { LOG.debug("Request to get ExamAnswer : {}", id); return examAnswerRepository.findById(id).map(examAnswerMapper::toDto); } /** * Delete the examAnswer by id. * * @param id the id of the entity. */ public void delete(Long id) { LOG.debug("Request to delete ExamAnswer : {}", id); examAnswerRepository.deleteById(id); } }