Skip to content

Commit

Permalink
feat : Card 목록 구현
Browse files Browse the repository at this point in the history
GET /todolist 요청 URL 을 통해 모든 Card 를 List 형태로 받아오도록 구현했습니다.
  • Loading branch information
juni8453 committed Apr 6, 2022
1 parent 59efcef commit eec3fbd
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Server/src/main/java/com/todolist/controller/CardController.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
package com.todolist.controller;

import com.todolist.domain.Card;
import com.todolist.service.CardService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("/todolist")
@RestController
public class CardController {

Expand All @@ -11,4 +17,9 @@ public class CardController {
public CardController(CardService cardService) {
this.cardService = cardService;
}

@GetMapping
public List<Card> list() {
return cardService.findAllCards();
}
}
26 changes: 26 additions & 0 deletions Server/src/main/java/com/todolist/repository/CardRepository.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package com.todolist.repository;

import com.todolist.domain.Card;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowCallbackHandler;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class CardRepository {

Expand All @@ -11,4 +16,25 @@ public class CardRepository {
public CardRepository(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}

public List<Card> findAllCards() {
String sql = "SELECT * from card";

return jdbcTemplate.query(sql, cardRowMapper());
}

private RowMapper<Card> cardRowMapper() {
return (resultSet, rowNum) -> {
Card card = new Card(
resultSet.getInt("cardId"),
resultSet.getString("cardTitle"),
resultSet.getString("cardContent"),
resultSet.getTimestamp("addDateTime").toLocalDateTime(),
resultSet.getInt("internalOrder"),
resultSet.getString("boardName")
);

return card;
};
}
}
7 changes: 7 additions & 0 deletions Server/src/main/java/com/todolist/service/CardService.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.todolist.service;

import com.todolist.domain.Card;
import com.todolist.repository.CardRepository;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CardService {

Expand All @@ -11,4 +14,8 @@ public class CardService {
public CardService(CardRepository cardRepository) {
this.cardRepository = cardRepository;
}

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

0 comments on commit eec3fbd

Please sign in to comment.