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 #127 from ku-kim/develop-BE
[team-01][BE] API - 전체 Todo 조회 요청 / 전체 History 조회 요청
- Loading branch information
Showing
23 changed files
with
428 additions
and
91 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
19 changes: 19 additions & 0 deletions
19
BE/src/main/java/codesquad/be/todoserver/config/WebConfig.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,19 @@ | ||
package codesquad.be.todoserver.config; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.method.HandlerTypePredicate; | ||
import org.springframework.web.servlet.config.annotation.EnableWebMvc; | ||
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
|
||
@Configuration | ||
@EnableWebMvc | ||
public class WebConfig implements WebMvcConfigurer { | ||
|
||
@Override | ||
public void configurePathMatch(PathMatchConfigurer configurer) { | ||
configurer | ||
.addPathPrefix("/api", | ||
HandlerTypePredicate.forBasePackage("codesquad.be.todoserver.controller")); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
BE/src/main/java/codesquad/be/todoserver/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,22 @@ | ||
package codesquad.be.todoserver.controller; | ||
|
||
import codesquad.be.todoserver.domain.History; | ||
import codesquad.be.todoserver.service.HistoryService; | ||
import java.util.List; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
public class HistoryController { | ||
|
||
private final HistoryService historiesService; | ||
|
||
public HistoryController(HistoryService historiesService) { | ||
this.historiesService = historiesService; | ||
} | ||
|
||
@GetMapping("/histories") | ||
public List<History> getAllHistory() { | ||
return historiesService.getAllHistory(); | ||
} | ||
} |
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
29 changes: 29 additions & 0 deletions
29
BE/src/main/java/codesquad/be/todoserver/domain/History.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,29 @@ | ||
package codesquad.be.todoserver.domain; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public class History { | ||
|
||
private final Long id; | ||
private final Long todoId; | ||
private final String todoTitle; | ||
private final String user; | ||
private final String action; | ||
private final String fromStatus; | ||
private final String toStatus; | ||
private final String createdAt; | ||
|
||
public History(Long id, Long todoId, String todoTitle, String user, String action, | ||
String fromStatus, String toStatus, String createdAt) { | ||
this.id = id; | ||
this.todoId = todoId; | ||
this.todoTitle = todoTitle; | ||
this.user = user; | ||
this.action = action; | ||
this.fromStatus = fromStatus; | ||
this.toStatus = toStatus; | ||
this.createdAt = createdAt; | ||
} | ||
|
||
} |
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
41 changes: 41 additions & 0 deletions
41
BE/src/main/java/codesquad/be/todoserver/repository/HistoryJdbcRepository.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,41 @@ | ||
package codesquad.be.todoserver.repository; | ||
|
||
import codesquad.be.todoserver.domain.History; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.jdbc.core.JdbcTemplate; | ||
import org.springframework.jdbc.core.RowMapper; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.List; | ||
|
||
@Repository | ||
public class HistoryJdbcRepository implements HistoryRepository { | ||
|
||
private final JdbcTemplate jdbcTemplate; | ||
|
||
@Autowired | ||
public HistoryJdbcRepository(JdbcTemplate jdbcTemplate) { | ||
this.jdbcTemplate = jdbcTemplate; | ||
} | ||
|
||
|
||
@Override | ||
public List<History> findAllHistory() { | ||
String sql = "SELECT id, todo_id, todo_title, user, action, from_status, to_status, created_at FROM HISTORY"; | ||
|
||
return jdbcTemplate.query(sql, historyRowMapper()); | ||
} | ||
|
||
private RowMapper<History> historyRowMapper() { | ||
return (rs, rowNum) -> new History( | ||
rs.getLong("id"), | ||
rs.getLong("todo_id"), | ||
rs.getString("todo_title"), | ||
rs.getString("user"), | ||
rs.getString("action"), | ||
rs.getString("from_status"), | ||
rs.getString("to_status"), | ||
rs.getString("created_at") | ||
); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
BE/src/main/java/codesquad/be/todoserver/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,11 @@ | ||
package codesquad.be.todoserver.repository; | ||
|
||
import codesquad.be.todoserver.domain.History; | ||
|
||
import java.util.List; | ||
|
||
public interface HistoryRepository { | ||
|
||
List<History> findAllHistory(); | ||
|
||
} |
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
6 changes: 5 additions & 1 deletion
6
BE/src/main/java/codesquad/be/todoserver/repository/TodoRepository.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 |
---|---|---|
@@ -1,11 +1,15 @@ | ||
package codesquad.be.todoserver.repository; | ||
|
||
import codesquad.be.todoserver.domain.Todo; | ||
import java.util.Optional; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
@Repository | ||
public interface TodoRepository { | ||
|
||
Optional<Todo> findById(Long id); | ||
|
||
List<Todo> findAllTodos(); | ||
} |
28 changes: 28 additions & 0 deletions
28
BE/src/main/java/codesquad/be/todoserver/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,28 @@ | ||
package codesquad.be.todoserver.service; | ||
|
||
import codesquad.be.todoserver.domain.History; | ||
import codesquad.be.todoserver.repository.HistoryRepository; | ||
import java.util.List; | ||
import java.util.NoSuchElementException; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class HistoryService { | ||
|
||
private final HistoryRepository historyRepository; | ||
|
||
@Autowired | ||
public HistoryService(HistoryRepository historyRepository) { | ||
this.historyRepository = historyRepository; | ||
} | ||
|
||
public List<History> getAllHistory() { | ||
List<History> histories = historyRepository.findAllHistory(); | ||
|
||
if (histories.isEmpty()) { | ||
throw new NoSuchElementException("Empty History"); | ||
} | ||
return histories; | ||
} | ||
} |
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
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
Oops, something went wrong.