forked from codesquad-members-2022/todo-list
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from SangHwi-Back/feature-6
함께 진행해서 바로 merge 진행합니다.
- Loading branch information
Showing
14 changed files
with
272 additions
and
2 deletions.
There are no files selected for viewing
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
25 changes: 25 additions & 0 deletions
25
Server/src/main/java/com/todolist/controller/CardController.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,25 @@ | ||
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 { | ||
|
||
private final CardService cardService; | ||
|
||
public CardController(CardService cardService) { | ||
this.cardService = cardService; | ||
} | ||
|
||
@GetMapping | ||
public List<Card> list() { | ||
return cardService.findAllCards(); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
Server/src/main/java/com/todolist/controller/HistoryController.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,14 @@ | ||
package com.todolist.controller; | ||
|
||
import com.todolist.service.HistoryService; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
public class HistoryController { | ||
|
||
private final HistoryService historyService; | ||
|
||
public HistoryController(HistoryService historyService) { | ||
this.historyService = historyService; | ||
} | ||
} |
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,48 @@ | ||
package com.todolist.domain; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
public class Card { | ||
|
||
private Integer cardId; | ||
private String cardTitle; | ||
private String cardContent; | ||
private LocalDateTime addDateTime; | ||
private Integer internalOrder; | ||
private String boardName; | ||
private boolean remove; | ||
|
||
public Card(Integer cardId, String cardTitle, String cardContent, | ||
LocalDateTime addDateTime, Integer internalOrder, String boardName) { | ||
this.cardId = cardId; | ||
this.cardTitle = cardTitle; | ||
this.cardContent = cardContent; | ||
this.addDateTime = addDateTime; | ||
this.internalOrder = internalOrder; | ||
this.boardName = boardName; | ||
} | ||
|
||
public Integer getCardId() { | ||
return cardId; | ||
} | ||
|
||
public String getCardTitle() { | ||
return cardTitle; | ||
} | ||
|
||
public String getCardContent() { | ||
return cardContent; | ||
} | ||
|
||
public LocalDateTime getAddDateTime() { | ||
return addDateTime; | ||
} | ||
|
||
public Integer getInternalOrder() { | ||
return internalOrder; | ||
} | ||
|
||
public String getBoardName() { | ||
return boardName; | ||
} | ||
} |
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,9 @@ | ||
package com.todolist.domain; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
public class History { | ||
|
||
private String actionHistory; | ||
private LocalDateTime actionTime; | ||
} |
38 changes: 38 additions & 0 deletions
38
Server/src/main/java/com/todolist/repository/CardRepository.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,38 @@ | ||
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 { | ||
|
||
private final JdbcTemplate jdbcTemplate; | ||
|
||
public CardRepository(JdbcTemplate jdbcTemplate) { | ||
this.jdbcTemplate = jdbcTemplate; | ||
} | ||
|
||
public List<Card> findAllCards() { | ||
String sql = "SELECT * FROM card WHERE remove = 0"; | ||
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; | ||
}; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
Server/src/main/java/com/todolist/repository/HistoryRepository.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,14 @@ | ||
package com.todolist.repository; | ||
|
||
import org.springframework.jdbc.core.JdbcTemplate; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public class HistoryRepository { | ||
|
||
private final JdbcTemplate jdbcTemplate; | ||
|
||
public HistoryRepository(JdbcTemplate jdbcTemplate) { | ||
this.jdbcTemplate = jdbcTemplate; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
Server/src/main/java/com/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,21 @@ | ||
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 { | ||
|
||
private final CardRepository cardRepository; | ||
|
||
public CardService(CardRepository cardRepository) { | ||
this.cardRepository = cardRepository; | ||
} | ||
|
||
public List<Card> findAllCards() { | ||
return cardRepository.findAllCards(); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
Server/src/main/java/com/todolist/service/HistoryService.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,14 @@ | ||
package com.todolist.service; | ||
|
||
import com.todolist.repository.HistoryRepository; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class HistoryService { | ||
|
||
private final HistoryRepository historyRepository; | ||
|
||
public HistoryService(HistoryRepository historyRepository) { | ||
this.historyRepository = historyRepository; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,10 @@ | ||
spring: | ||
datasource: | ||
driver-class-name: com.mysql.cj.jdbc.Driver | ||
url: jdbc:mysql://localhost:3306/todoList?serverTimezone=Asia/Seoul | ||
username: root | ||
password: Lucid123! | ||
|
||
sql: | ||
init: | ||
mode: never |
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,17 @@ | ||
INSERT INTO `user` (userId, password, name, email) VALUES | ||
('lucid1', 'aaaa', 'cid1', 'lucid1@tesla'), | ||
('lucid2', 'bbbb', 'cid2', 'lucid2@tesla'), | ||
('lucid3', 'cccc', 'cid3', 'lucid3@tesla'), | ||
('lucid4', 'dddd', 'cid4', 'lucid4@tesla'), | ||
('lucid5', 'eeee', 'cid5', 'lucid5@tesla'), | ||
('lucid6', 'ffff', 'cid6', 'lucid6@tesla'), | ||
('lucid7', 'gggg', 'cid7', 'lucid7@tesla'), | ||
('lucid8', 'hhhh', 'cid8', 'lucid8@tesla'), | ||
('lucid9', 'iiii', 'cid9', 'lucid9@tesla'), | ||
('lucid10', 'iiii', 'cid9', 'lucid9@tesla'); | ||
|
||
INSERT INTO article (writer, title, contents) VALUES | ||
('lucid1', 'title1', 'content is good!'), | ||
('lucid2', 'title3', 'content is bad,,'), | ||
('lucid2', 'title2', 'content is nice!') | ||
|
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,38 @@ | ||
DROP TABLE IF EXISTS `user`; | ||
|
||
CREATE TABLE `user` ( | ||
`userId` VARCHAR(50) NOT NULL, | ||
`password` VARCHAR(50) NOT NULL, | ||
`remove` TINYINT(1) NOT NULL DEFAULT 0, | ||
PRIMARY KEY (`userId`) | ||
); | ||
|
||
DROP TABLE IF EXISTS `card`; | ||
|
||
CREATE TABLE `card` ( | ||
`cardId` INT NOT NULL AUTO_INCREMENT, | ||
`userId` VARCHAR(50) NOT NULL, | ||
`cardTitle` VARCHAR(50) NOT NULL, | ||
`cardContent` VARCHAR(255) NOT NULL, | ||
`boardName` VARCHAR(50) NOT NULL, | ||
`internalOrder` INT NOT NULL, | ||
`addDateTime` TIMESTAMP NOT NULL, | ||
`remove` TINYINT(1) NOT NULL DEFAULT 0, | ||
PRIMARY KEY (`cardId`), | ||
FOREIGN KEY (`userId`) | ||
REFERENCES `user` (`userId`) | ||
ON UPDATE CASCADE | ||
); | ||
|
||
DROP TABLE IF EXISTS `history`; | ||
|
||
CREATE TABLE `history` ( | ||
`historyId` INT NOT NULL AUTO_INCREMENT, | ||
`userId` VARCHAR(50) NOT NULL, | ||
`actionHistory` VARCHAR(100) NOT NULL, | ||
`actionTime` TIMESTAMP NOT NULL, | ||
PRIMARY KEY (`historyId`), | ||
FOREIGN KEY (`userId`) | ||
REFERENCES `user` (`userId`) | ||
ON UPDATE CASCADE | ||
); |
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,23 @@ | ||
package com.todolist.db; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.jdbc.core.JdbcTemplate; | ||
|
||
@SpringBootTest | ||
public class DBAccessTest { | ||
|
||
@Autowired | ||
private JdbcTemplate jdbcTemplate; | ||
|
||
@Test | ||
void readDB() { | ||
String sql = "SELECT count(*) FROM user"; | ||
Integer result = jdbcTemplate.queryForObject(sql, Integer.class); | ||
assertThat(result).isEqualTo(9); | ||
} | ||
|
||
} |