feat: 가계부·게시판 백엔드 API 구현
- com.sb.web 패키지로 재구성: account / auth / board / user / admin / common - 가계부(account): 내역(필터), 계좌·순자산, 예산, 분류, 정기 거래, 투자 포트폴리오 (종목·매매 이력, 이동평균 평단·실현/평가손익) - MyBatis + MariaDB + Redis 세션, BCrypt - 스키마 자동 초기화(db/*.sql, 멱등), 사용자별 데이터 격리(member_id) - 문서: docs/BACKEND.md, .env.example Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
9243a41385
commit
2a2f81dc32
@@ -0,0 +1,127 @@
|
||||
package com.sb.web.board.controller;
|
||||
|
||||
import com.sb.web.auth.dto.SessionUser;
|
||||
import com.sb.web.auth.web.AuthInterceptor;
|
||||
import com.sb.web.board.dto.CommentRequest;
|
||||
import com.sb.web.board.dto.CommentResponse;
|
||||
import com.sb.web.board.dto.PageResponse;
|
||||
import com.sb.web.board.dto.PostDetail;
|
||||
import com.sb.web.board.dto.PostRequest;
|
||||
import com.sb.web.board.dto.PostSummary;
|
||||
import com.sb.web.board.dto.TagCategoryResponse;
|
||||
import com.sb.web.board.service.BoardService;
|
||||
import com.sb.web.board.service.TagService;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 자유게시판 API. (전체 로그인 필요 — WebConfig 인터셉터로 /api/board/** 보호)
|
||||
* GET /api/board/posts 목록(페이징·태그·검색)
|
||||
* GET /api/board/posts/{id} 상세(조회수 증가)
|
||||
* POST /api/board/posts 작성
|
||||
* PUT /api/board/posts/{id} 수정(작성자/관리자)
|
||||
* DELETE /api/board/posts/{id} 삭제(작성자/관리자)
|
||||
* GET /api/board/tags 전체 태그
|
||||
* POST /api/board/posts/{id}/comments 댓글 작성
|
||||
* DELETE /api/board/comments/{commentId} 댓글 삭제(작성자/관리자)
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/board")
|
||||
@RequiredArgsConstructor
|
||||
public class BoardController {
|
||||
|
||||
private final BoardService boardService;
|
||||
private final TagService tagService;
|
||||
|
||||
@GetMapping("/posts")
|
||||
public PageResponse<PostSummary> list(
|
||||
@RequestParam(defaultValue = "1") int page,
|
||||
@RequestParam(defaultValue = "10") int size,
|
||||
@RequestParam(required = false) String tag,
|
||||
@RequestParam(required = false) String keyword,
|
||||
@RequestParam(required = false) String searchType) {
|
||||
return boardService.list(page, size, tag, keyword, searchType);
|
||||
}
|
||||
|
||||
@GetMapping("/posts/{id}")
|
||||
public PostDetail get(
|
||||
@PathVariable Long id,
|
||||
@RequestAttribute(AuthInterceptor.CURRENT_MEMBER) SessionUser current) {
|
||||
return boardService.get(id, current);
|
||||
}
|
||||
|
||||
@PostMapping("/posts")
|
||||
public ResponseEntity<PostDetail> create(
|
||||
@Valid @RequestBody PostRequest req,
|
||||
@RequestAttribute(AuthInterceptor.CURRENT_MEMBER) SessionUser current) {
|
||||
return ResponseEntity.status(HttpStatus.CREATED).body(boardService.create(req, current));
|
||||
}
|
||||
|
||||
@PutMapping("/posts/{id}")
|
||||
public PostDetail update(
|
||||
@PathVariable Long id,
|
||||
@Valid @RequestBody PostRequest req,
|
||||
@RequestAttribute(AuthInterceptor.CURRENT_MEMBER) SessionUser current) {
|
||||
return boardService.update(id, req, current);
|
||||
}
|
||||
|
||||
@DeleteMapping("/posts/{id}")
|
||||
public ResponseEntity<Void> delete(
|
||||
@PathVariable Long id,
|
||||
@RequestAttribute(AuthInterceptor.CURRENT_MEMBER) SessionUser current) {
|
||||
boardService.delete(id, current);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
/** 열람 제한 (관리자) */
|
||||
@PostMapping("/posts/{id}/block")
|
||||
public ResponseEntity<Void> block(
|
||||
@PathVariable Long id,
|
||||
@RequestBody(required = false) Map<String, String> body,
|
||||
@RequestAttribute(AuthInterceptor.CURRENT_MEMBER) SessionUser current) {
|
||||
boardService.setBlocked(id, true, body != null ? body.get("reason") : null, current);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
/** 열람 제한 해제 (관리자) */
|
||||
@PostMapping("/posts/{id}/unblock")
|
||||
public ResponseEntity<Void> unblock(
|
||||
@PathVariable Long id,
|
||||
@RequestAttribute(AuthInterceptor.CURRENT_MEMBER) SessionUser current) {
|
||||
boardService.setBlocked(id, false, null, current);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@GetMapping("/tags")
|
||||
public List<String> tags() {
|
||||
return boardService.allTags();
|
||||
}
|
||||
|
||||
/** 글 작성 시 선택 가능한 태그 (게시판 설정 카테고리로 제한) */
|
||||
@GetMapping("/tag-groups")
|
||||
public List<TagCategoryResponse> tagGroups() {
|
||||
return tagService.listWritableGroups();
|
||||
}
|
||||
|
||||
@PostMapping("/posts/{id}/comments")
|
||||
public ResponseEntity<CommentResponse> addComment(
|
||||
@PathVariable Long id,
|
||||
@Valid @RequestBody CommentRequest req,
|
||||
@RequestAttribute(AuthInterceptor.CURRENT_MEMBER) SessionUser current) {
|
||||
return ResponseEntity.status(HttpStatus.CREATED).body(boardService.addComment(id, req, current));
|
||||
}
|
||||
|
||||
@DeleteMapping("/comments/{commentId}")
|
||||
public ResponseEntity<Void> deleteComment(
|
||||
@PathVariable Long commentId,
|
||||
@RequestAttribute(AuthInterceptor.CURRENT_MEMBER) SessionUser current) {
|
||||
boardService.deleteComment(commentId, current);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user