Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.fastcampus.proejct.auth.controller;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.fastcampus.proejct.auth.converter.dto.UserInfoDto;
import org.fastcampus.proejct.global.converter.BaseResponse;
import org.fastcampus.proejct.user.service.UserInfoService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RequiredArgsConstructor
@RestController
public class AuthController {
private final UserInfoService service;

@PostMapping("/signup")
public BaseResponse<UserInfoDto> signup() {
UserInfoDto dto = service.saveUser("email@email", "{noop}123", "조옹찬");
return new BaseResponse<>(200, "정상 호출", dto);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.fastcampus.proejct.board.converter.dto.BoardDto;
import org.fastcampus.proejct.board.converter.response.ResponseBoardDto;
import org.fastcampus.proejct.board.service.BoardService;
import org.fastcampus.proejct.board.service.TaskService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RequiredArgsConstructor
@Controller
Expand All @@ -18,7 +21,11 @@ public class BoardController {
private final TaskService taskService;

@GetMapping("/board")
public String getBoardsView() {
public String getBoardsView(Model model) {
List<ResponseBoardDto> boards = boardService.getBoards().stream()
.map(ResponseBoardDto::from)
.toList();
model.addAttribute("boards", boards);
return "tables";
}

Expand Down Expand Up @@ -55,8 +62,8 @@ public String postBoardUpdate(@PathVariable Long id, BoardDto board) {
return "redirect:/board";
}

@DeleteMapping("/board/{id}/delete")
public String getBoardDelete(@PathVariable Long id) {
@GetMapping("/board/{id}/delete")
public String deleteBoard(@PathVariable Long id) {
boardService.deleteBoard(id);
return "redirect:/board";
}
Expand Down
4 changes: 2 additions & 2 deletions proejct/src/main/resources/templates/board/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ <h2 th:text="${board.title}">제목</h2>
</div>
</div>
<a href="/board" class="btn btn-secondary">목록으로</a>
<a th:href="@{/board/{id}/update(id=${board.id})}" th:method="post" class="btn btn-primary">수정</a>
<a th:href="@{/board/{id}/delete(id=${board.id})}" th:method="delete" class="btn btn-danger">삭제</a>
<a th:href="@{/board/{id}/update(id=${board.id})}" th:method="get" class="btn btn-primary">수정</a>
<a th:href="@{/board/{id}/delete(id=${board.id})}" th:method="get" class="btn btn-danger">삭제</a>
</main>
<footer>
&copy; 2023
Expand Down
3 changes: 3 additions & 0 deletions proejct/src/main/resources/templates/board/detail.th.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<attr sel="#delete-board-form" th:action="'/board/' + *{id} + '/delete'" th:method="post">
<attr sel="#update-board" th:href="'/board/' + *{id} + '/form'"/>
</attr>
75 changes: 13 additions & 62 deletions proejct/src/main/resources/templates/tables.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en">
<html lang="ko" xmlns:th="http://www.thymeleaf.org">

<head>
<meta charset="utf-8">
Expand Down Expand Up @@ -382,7 +382,7 @@ <h6 class="m-0 font-weight-bold text-primary">Created Task</h6>
<div class="card-body">
<div class="table-responsive">
<table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
<thead>
<!-- <thead>-->
<tr>
<th>Number</th>
<th>Title</th>
Expand All @@ -391,69 +391,20 @@ <h6 class="m-0 font-weight-bold text-primary">Created Task</h6>
<th>Start date</th>
<th>End date</th>
</tr>
</thead>
<tbody>
<script>
window.onload = function () {
var boardList = getBoardList();
$(document).ready(function () {
// 게시글 목록을 가져옵니다.
var xhr = new XMLHttpRequest();
xhr.open("GET", "/board/list");
xhr.send();

// 응답을 처리합니다.
xhr.onload = function () {
if (xhr.status == 200) {
// 응답 데이터를 JSON으로 파싱합니다.
boardList = JSON.parse(xhr.responseText);
// 게시글 목록을 출력합니다.
for (var i = 0; i < boardList.length; i++) {
var board = boardList[i];
// 게시글을 출력합니다.
var tr = $("<tr onclick=location.href='/board/" + board.id + "'>");
tr.append($("<td>" + (i + 1) + "</td>"));
tr.append($("<td>" + board.title + "</td>"));
tr.append($("<td>" + board.host + "</td>"));
tr.append($("<td>" + board.content + "</td>"));
tr.append($("<td>" + "시작일" + "</td>"));
tr.append($("<td>" + "종료일" + "</td>"));
// 게시글을 tbody 태그에 추가합니다.
$("tbody").append(tr);
}
} else {
// 에러 처리

}
};

return null;
});

function getBoardList() {
// 게시글 목록을 가져오는 API를 호출합니다.
var xhr = new XMLHttpRequest();
xhr.open("GET", "/board/list");
xhr.send();

// 응답을 처리합니다.
xhr.onload = function () {
if (xhr.status == 200) {
// 응답 데이터를 JSON으로 파싱합니다.
return JSON.parse(xhr.responseText);
} else {
// 에러 처리
}
};

return null;
}
<!-- </thead>-->
<!-- <tbody>-->
<script th:inline="javascript">
function redirectToBoard(id) {
window.location.href = '/board/' + id;
}
</script>
<tr>
<th></th>

<tr th:each="board : ${boards}" th:onclick="'javascript:redirectToBoard(' + ${board.id} + ')'">
<td th:text="${board.id}">id</td>
<td th:text="${board.title}">title</td>
<td th:text="${board.host}">host</td>
<td th:text="${board.content}">content</td>
</tr>
</tbody>
</table>
</div>
</div>
Expand Down