forked from codesquad-members-2022/todo-list
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Related to #9
- Loading branch information
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
backend/src/main/java/com/team05/todolist/service/CardService.java
This file contains 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
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) { | ||
|
||
} | ||
} |