Skip to content

Commit

Permalink
[BE-pio] feat: CardService 구현
Browse files Browse the repository at this point in the history
Related to #9
  • Loading branch information
NB993 committed Apr 8, 2022
1 parent dde1301 commit 62e72a1
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions backend/src/main/java/com/team05/todolist/service/CardService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.team05.todolist.service;

import com.team05.todolist.controller.RequestCardDto;
import com.team05.todolist.controller.ResponseCardDto;
import com.team05.todolist.domain.Card;
import com.team05.todolist.domain.Log;
import com.team05.todolist.repository.CardRepository;
import com.team05.todolist.repository.LogRepository;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Optional;
import org.springframework.stereotype.Service;

@Service
public class CardService {

private final CardRepository cardRepository;
private final LogRepository logRepository;

public CardService(CardRepository cardRepository, LogRepository logRepository) {
this.cardRepository = cardRepository;
this.logRepository = logRepository;
}

public List<Card> findCards() {
return cardRepository.findAll();
}

public List<Log> findLogs() {
return logRepository.findAll();
}

public ResponseCardDto findOne(int id) throws NoSuchElementException {
Optional<Card> card = cardRepository.findById(id);
return card.orElseThrow();
}

public void update(RequestCardDto updateCardDto) {
Card updateTargetCard = findOne(updateCardDto.getId());
updateTargetCard.changeSection(updateCardDto.getSection());
updateTargetCard.changeTitle(updateCardDto.getTitle());
updateTargetCard.changeContent(updateCardDto.getContent());
updateTargetCard.changeOrderIndex(updateCardDto.getOrderIndex());

cardRepository.save(updateTargetCard);
}

public void delete(RequestCardDto requestCardDto) {

}
}

0 comments on commit 62e72a1

Please sign in to comment.