Skip to content

Commit

Permalink
Merge pull request #10 from SangHwi-Back/feature-6
Browse files Browse the repository at this point in the history
함께 진행해서 바로 merge 진행합니다.
  • Loading branch information
leejohy-0223 authored Apr 6, 2022
2 parents e950806 + 6cf0e3f commit 9e1acbb
Show file tree
Hide file tree
Showing 14 changed files with 272 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ repositories {
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-jdbc'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'mysql:mysql-connector-java'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'com.h2database:h2'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

Expand Down
25 changes: 25 additions & 0 deletions Server/src/main/java/com/todolist/controller/CardController.java
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();
}
}
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;
}
}
48 changes: 48 additions & 0 deletions Server/src/main/java/com/todolist/domain/Card.java
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;
}
}
9 changes: 9 additions & 0 deletions Server/src/main/java/com/todolist/domain/History.java
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 Server/src/main/java/com/todolist/repository/CardRepository.java
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;
};
}
}
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 Server/src/main/java/com/todolist/service/CardService.java
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 Server/src/main/java/com/todolist/service/HistoryService.java
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;
}
}
1 change: 0 additions & 1 deletion Server/src/main/resources/application.properties

This file was deleted.

10 changes: 10 additions & 0 deletions Server/src/main/resources/application.yml
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
17 changes: 17 additions & 0 deletions Server/src/main/resources/data.sql
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!')

38 changes: 38 additions & 0 deletions Server/src/main/resources/schema.sql
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
);
23 changes: 23 additions & 0 deletions Server/src/test/java/com/todolist/db/DBAccessTest.java
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);
}

}

0 comments on commit 9e1acbb

Please sign in to comment.