-
Notifications
You must be signed in to change notification settings - Fork 25
[이동훈_BackEnd] 11주차 과제 제출합니다. #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dh2906
wants to merge
143
commits into
BCSDLab-Edu:main
Choose a base branch
from
dh2906:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
143 commits
Select commit
Hold shift + click to select a range
8e22a22
chore. 컨트롤러 패키지 생성
dh2906 1b912fb
feat. /introduce GET API 구현
dh2906 d704ab8
feat. name 쿼리 파라미터 추가
dh2906 6e88df3
feat. /json GET API 구현
dh2906 332295f
feat. /articles/{id} GET API 구현
dh2906 4307c73
feat. /articles POST API 구현
dh2906 74b762f
refactory. 불필요한 변수 제거
dh2906 5f0624b
feat. /articles/{id} PUT API 구현
dh2906 18f3873
feat. /articles/{id} DELETE API 구현
dh2906 3df0a52
refactory. 메소드명 수정
dh2906 5f14d54
refactory. 존재하지 않는 게시글 조회 시 404 에러 코드 반환
dh2906 f8f98c8
fix. /introduce 뷰 반환되도록 수정
dh2906 12c0b10
refactory. update 메소드 객체 의존 관계 제거
dh2906 0669227
refactory. 메소드명 수정
dh2906 e34cd16
feat. 전체 article 조회 기능 구현
dh2906 041cffc
refactory. article 조회 시 존재하지 않는 예외 처리 모듈화
dh2906 1a65ff9
refactory. Article 작성자 필드 추가, DTO 생성 및 수정용으로 분할
dh2906 d9d6d2c
fix. 모든 게시물 조회 시 게시물이 존재하지 않는 경우 예외 발생 삭제
dh2906 4a86d9f
feat. 모든 article을 보여주는 뷰 구현
dh2906 82f3877
feat. Board 모델 생성
dh2906 77d5cd1
feat. Member 모델 생성
dh2906 cace9ac
refactory. 게시글 속성에 id, 작성자 id, 게시판 id 추가
dh2906 5dee925
refactory. 응답 DTO 구현
dh2906 2f8f400
feat. 멤버 CRUD 구현
dh2906 8b41935
feat. article의 authorId와 Member의 id 속성 매핑해서 작성자 이름 반환되도록 구현
dh2906 d56dc92
chore. DTO 패키지 request, response 구분
dh2906 f027197
build. 롬복 의존성 추가
dh2906 82aaf7f
refactory. 롬복 게터, 생성자 어노테이션 적용
dh2906 65c163a
build. 롬복 어노테이션 프로세서 추가
dh2906 442fcd6
refactory. 엔티티 -> 응답 DTO로 변환하는 로직을 DTO 내부로 이동, 빌더 패턴 적용
dh2906 ecf3468
refactory. 빌더 패턴 적용
dh2906 730fb70
refactory. 응답 DTO -> 엔티티 변환 로직 DTO에 생성
dh2906 9d75c87
chore. dto 패키지 경로 변경
dh2906 5d99bd4
refactory. 전역으로 예외 처리
dh2906 ec28113
refactory. Repository 인터페이스로 추상화
dh2906 2fa05c1
refacotry. Repository에서 단일 개체 조회 시 Optional 타입으로 반환
dh2906 7a8b1e3
fix. 글 작성자를 게시글 id로 조회하는 문제 수정
dh2906 06a7c7f
refactory. 게시글 응답 DTO에 게시글 id 속성 추가
dh2906 417bfe1
refactory. 예외 발생 시 에러 메세지 로깅 처리
dh2906 2cfc2a7
chore. 불필요한 import문 제거
dh2906 16fd87f
refactory. 존재하지 않는 자원의 삭제 요청에 대한 예외 처리
dh2906 dd7100c
feat. 커스텀 예외 클래스, 메세지 Enum 생성
dh2906 0d7dfc8
feat. 커스텀 예외, 메세지 구현
dh2906 5ef8285
fix. MemberRepository 구현체로 지정
dh2906 aa2731c
refactory. 인터페이스에 의존하도록 수정
dh2906 37ad92e
refactory. 빌더 패턴 적용
dh2906 73fb67f
refactory. 생성자 최적화
dh2906 a8aedbe
refactory. 엔티티 생성 시 id 동시성 문제를 해결하기 위해 AtomicLong 사용
dh2906 a6c80a4
chore. 불필요한 줄바꿈 제거
dh2906 54aa469
refactory. 모든 DTO 클래스 -> 레코드 변환
dh2906 906d131
fix. 메소드명 오타 수정
dh2906 0a8fc6f
refactory. ExceptionMessage 클래스 필드에 에러 코드 추가
dh2906 21f907e
fix. 수정 메소드명 더 명확하게 수정
dh2906 2269ada
build. JDBC 의존성 추가
dh2906 317142d
feat. 게시글 Repository JDBC로 구현
dh2906 692f5f4
chore. @Repository 어노테이션 제거
dh2906 873ebc5
fix. 인터페이스에 의존하도록 수정
dh2906 e4f7aca
feat. 멤버 Repository 구현
dh2906 08591d2
fix. 멤버 필드 중 비밀번호 pw -> password로 수정
dh2906 94e0890
fix. 멤버 RowMapper id도 매핑하도록 수정
dh2906 cc864e9
feat. 게시판 CRUD 구현
dh2906 966fc54
fix. 자원 생성 시 자동으로 할당된 id값 반환받을 수 있도록 수정
dh2906 bd04075
style. css 수정
dh2906 7ef2047
feat. 게시판 id로 게시물 조회하는 기능 구현
dh2906 504f957
feat. 게시판 id로 게시물 뷰 보여주는 기능 구현
dh2906 ec6e270
refactory. 중복되는 로직 private 메소드로 모듈화
dh2906 e67f287
fix. /posts 요청 시 게시판을 구분하여 게시글 제공하도록 수정
dh2906 4240d0b
refactory. 비슷한 로직 모듈화
dh2906 0797782
feat. @Transactional 어노테이션 추가
dh2906 78d5fe6
refactory. 공통된 메소드를 제거하기 위해 CRUDRepostiory 인터페이스 생성
dh2906 6aa6c31
build. BCrypt 의존성 추가
dh2906 2177960
feat. 멤버 비밀번호 암호화
dh2906 5f2a58c
style. 줄바꿈 추가
dh2906 2ad8656
fix. 단건 데이터 조회 메소드를 수정하여 커스텀 예외로 처리
dh2906 edd6d7a
fix. Repository에 있는 @Transactional 어노테이션 Service로 이동
dh2906 9d84e2c
fix. 불필요한 문자 제거
dh2906 044201a
fix. 클래스 단에 있는 @Transactional(readOnly=true) 읽기 메소드로 각각 이동
dh2906 1a22c95
build. Validation 의존성 추가
dh2906 36bf954
feat. Article 관련 클래스에 유효성 검증 어노테이션 추가
dh2906 b90af9b
feat. 예외 검증을 위한 클래스 생성
dh2906 b7d6c90
feat. 존재하지 않는 자원에 대한 참조 예외 처리 구현
dh2906 47cdce1
refactory. Article 수정 요청에 게시판, 멤버도 바꿀 수 있도록 수정
dh2906 f05c2ff
chore. 필드 순서 변경
dh2906 f03a27c
refactory. 참조 무결성 검증 메소드 분할 및 예외는 검증에서 발생하도록 수정
dh2906 f4262b8
feat. 멤버 예외 검증 구현
dh2906 022d2be
refactory. 게시글 참조성 검증 메소드 통합
dh2906 556577b
fix. 순환 참조 문제 해결
dh2906 08927a9
fix. SQL 쿼리문 쉼표 오류 수정
dh2906 0d82418
feat. 멤버 삭제 시 멤버가 작성한 게시글이 존재하면 예외 발생 구현
dh2906 c538251
feat. 게시판 삭제 시 게시판에 작성된 게시글이 존재하면 예외 발생 구현
dh2906 c08debd
feat. 비밀번호 역직렬화하면서 암호화하도록 구현
dh2906 f722633
refactory. 게시글 유효성 검증 어노테이션에 에러 메세지 추가
dh2906 6dc53a6
feat. Board 관련 클래스에 유효성 검증 어노테이션 추가
dh2906 eefc560
feat. Member 관련 클래스에 유효성 검증 어노테이션 추가
dh2906 3ee138a
fix. 예외 처리 메소드 명 변경
dh2906 42ca928
feat. valid 어노테이션으로 발생하는 예외 처리
dh2906 92e6d5d
chore. 예외 처리 패키지 global 패키지 내부로 이동
dh2906 6ee4818
feat. POST, PUT 요청 시 요청 바디 내용을 로깅하기 위한 필터 구현
dh2906 1ca7568
fix. @Valid 어노테이션 누락된 것 추가
dh2906 b5f1da2
chore. 줄바꿈 및 공백 문자 정리
dh2906 e4b6002
build. JPA 의존성 추가
dh2906 02b2dbd
chore. Repository 종류(jdbc, jpa, 인메모리)에 따라 패키지 분류
dh2906 ecf925a
feat. jpa 사용하는 Repository 생성
dh2906 caa96d6
feat. JPA 도입에 따른 엔티티 관련 어노테이션 추가
dh2906 7018d45
chore. JPA 도입으로 이전 버전의 Repository 코드 주석 처리
dh2906 16912f4
feat. 게시물 JPA Repository 구현
dh2906 327a6ed
feat. 게시판 JPA Repository 구현
dh2906 9ab2b2d
feat. 멤버 JPA Repository 구현
dh2906 284aa6a
refactory. JPA Dirty Check 기능으로 Repository의 수정 로직이 필요 없어서 삭제
dh2906 04fdb16
feat. 게시판 이름 중복 시 예외 발생 구현
dh2906 04c18f5
refactory. 예외 발생시 예외 핸들러에서 로깅하는 로직을 필터로 이동
dh2906 540e953
fix. 자원 생성 시 ResponseEntity 반환 방식 변경
dh2906 3e7a73e
fix. 생성, 수정 일시 어노테이션 변경
dh2906 453871a
fix. 삭제 로직 오류 수정
dh2906 d330be0
refacotry. 세터 제거
dh2906 bddb1f1
refactory. @Column 어노테이션에 속성 추가
dh2906 6dbccee
feat. 엔티티간 연관 관계 설정
dh2906 00acfa1
refactory. 연관 관계 설정으로 인한 로직 수정
dh2906 4ab7b02
refactory. 자원 존재 여부 검증 이후 중복 조회를 막기 위해 조회한 자원 반환하도록 수정
dh2906 8bedeae
feat. 생성, 수정 시간 체크를 위한 어노테이션 추가
dh2906 22cc9a3
chore. 주석 처리
dh2906 2f607d0
refactory. Spring Data Jpa 도입
dh2906 60ec609
refactory. 사용안하는 필드 삭제 및 검증 후 중복 조회 방지하도록 수정
dh2906 3e0c776
feat. 연관 객체 영속성 전이, 고아 객체 적용
dh2906 5408e79
fix. 게시판 삭제 시 게시물이 존재하면 예외 발생하지 않도록 수정
dh2906 04cf14e
feat. 지연로딩 설정
dh2906 0907a52
fix. 엔티티 기본 생성자 접근 제한 범위 protected로 수정
dh2906 e38d779
fix. 영속성 전이 속성 수정
dh2906 f17cacc
fix. 영속성 전이 REMOVE 속성 다시 추가
dh2906 054f19f
feat. 회원가입 구현
dh2906 971b0ea
refactory. 비밀번호 암호화 시점 역직렬화 -> 서비스 계층으로 수정
dh2906 6d8178b
feat. 로그인 로직 구현
dh2906 08975c3
feat. 로그아웃 기능 구현
dh2906 19ff25f
feat. 특정 요청에 대한 멤버의 로그인 여부 검증 필터 구현
dh2906 eeca8ab
feat. 멤버의 컬럼으로 role 추가
dh2906 f271153
fix. 로그인 검증 필터 통과 경로를 /auth 로 수정
dh2906 21f4915
fix. /posts 로그인 여부 상관없이 통과하도록 수정
dh2906 023acdc
fix. 디폴트 값이 적용 안되는 문제 해결
dh2906 bf1b126
refactory. 필터를 Config 클래스에서 등록하고 적용 경로 추가
dh2906 dbee59f
feat. 멤버 응답 DTO에 role 추가
dh2906 e049240
feat. 인터셉터를 통한 자원의 수정, 삭제 요청 시 인가 처리 로직 구현
dh2906 2b92f23
fix. 어드민 권한 없으면 /members 로 자원 추가하지 못하도록 수정
dh2906 5b62582
fix. 멤버 추가 시 엔티티 role 필드에 디폴트 값 적용되지 않는 문제 해결
dh2906 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
71 changes: 71 additions & 0 deletions
71
src/main/java/com/example/bcsd/controller/ArticleController.java
This file contains hidden or 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,71 @@ | ||
| package com.example.bcsd.controller; | ||
|
|
||
| import com.example.bcsd.dto.request.ArticleCreateRequest; | ||
| import com.example.bcsd.dto.request.ArticleUpdateRequest; | ||
| import com.example.bcsd.dto.resopnse.ArticleResponse; | ||
| import com.example.bcsd.service.ArticleService; | ||
| import jakarta.validation.Valid; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.*; | ||
|
|
||
| import java.net.URI; | ||
| import java.util.List; | ||
|
|
||
| @RestController | ||
| @RequestMapping("/articles") | ||
| @RequiredArgsConstructor | ||
| public class ArticleController { | ||
| private final ArticleService articleService; | ||
|
|
||
| @GetMapping | ||
| public ResponseEntity<List<ArticleResponse>> getAllArticles() { | ||
| return ResponseEntity | ||
| .ok(articleService.getAllArticles()); | ||
| } | ||
|
|
||
| @GetMapping("/{id}") | ||
| public ResponseEntity<ArticleResponse> getArticleById( | ||
| @PathVariable Long id | ||
| ) { | ||
| return ResponseEntity | ||
| .ok(articleService.getArticleById(id)); | ||
| } | ||
|
|
||
| @GetMapping(params = "boardId") | ||
| public ResponseEntity<List<ArticleResponse>> getArticlesByBoardId( | ||
| @RequestParam Long boardId | ||
| ) { | ||
| return ResponseEntity | ||
| .ok(articleService.getArticlesByBoardId(boardId)); | ||
| } | ||
|
|
||
| @PostMapping | ||
| public ResponseEntity<ArticleResponse> createArticle( | ||
| @RequestBody @Valid ArticleCreateRequest request | ||
| ) { | ||
| ArticleResponse response = articleService.createArticle(request); | ||
|
|
||
| return ResponseEntity | ||
| .created(URI.create("/articles/" + response.id())) | ||
| .body(response); | ||
| } | ||
|
|
||
| @PutMapping("/{id}") | ||
| public ResponseEntity<ArticleResponse> updateArticleById( | ||
| @PathVariable Long id, | ||
| @RequestBody @Valid ArticleUpdateRequest request | ||
| ) { | ||
| return ResponseEntity | ||
| .ok(articleService.updateArticleById(id, request)); | ||
| } | ||
|
|
||
| @DeleteMapping("/{id}") | ||
| public ResponseEntity<Void> deleteArticleById( | ||
| @PathVariable Long id | ||
| ) { | ||
| articleService.deleteArticleById(id); | ||
|
|
||
| return ResponseEntity.noContent().build(); | ||
| } | ||
| } |
38 changes: 38 additions & 0 deletions
38
src/main/java/com/example/bcsd/controller/ArticleViewController.java
This file contains hidden or 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.example.bcsd.controller; | ||
|
|
||
| import com.example.bcsd.dto.resopnse.ArticleViewResponse; | ||
| import com.example.bcsd.service.ArticleViewService; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Controller; | ||
| import org.springframework.ui.Model; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RequestParam; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| @Controller | ||
| @RequestMapping("/posts") | ||
| @RequiredArgsConstructor | ||
| public class ArticleViewController { | ||
| private final ArticleViewService articleViewService; | ||
|
|
||
| @GetMapping | ||
| public String getAllArticlesView(Model model) { | ||
| Map<String, List<ArticleViewResponse>> ArticleListGroupByBoard = articleViewService.getAllPostViews(); | ||
|
|
||
| model.addAttribute("articleListGroupByBoard", ArticleListGroupByBoard); | ||
|
|
||
| return "post"; | ||
| } | ||
|
|
||
| @GetMapping(params = "boardId") | ||
| public String getAllArticlesViewByBoardId(Model model, @RequestParam Long boardId) { | ||
| Map<String, List<ArticleViewResponse>> articleViewResponseList = articleViewService.getAllPostViewsByBoardId(boardId); | ||
|
|
||
| model.addAttribute("articleListGroupByBoard", articleViewResponseList); | ||
|
|
||
| return "post"; | ||
| } | ||
| } | ||
68 changes: 68 additions & 0 deletions
68
src/main/java/com/example/bcsd/controller/AuthController.java
This file contains hidden or 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,68 @@ | ||
| package com.example.bcsd.controller; | ||
|
|
||
| import com.example.bcsd.dto.request.LoginRequest; | ||
| import com.example.bcsd.dto.request.MemberRequest; | ||
| import com.example.bcsd.dto.resopnse.MemberResponse; | ||
| import com.example.bcsd.service.AuthService; | ||
| import jakarta.servlet.http.Cookie; | ||
| import jakarta.servlet.http.HttpServletRequest; | ||
| import jakarta.servlet.http.HttpServletResponse; | ||
| import jakarta.servlet.http.HttpSession; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.http.HttpStatus; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.PostMapping; | ||
| import org.springframework.web.bind.annotation.RequestBody; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| @RestController | ||
| @RequestMapping("/auth") | ||
| @RequiredArgsConstructor | ||
| public class AuthController { | ||
| private final AuthService authService; | ||
|
|
||
| @PostMapping("/register") | ||
| public ResponseEntity<MemberResponse> registerMember(@RequestBody MemberRequest request) { | ||
| MemberResponse response = authService.register(request); | ||
|
|
||
| return ResponseEntity | ||
| .status(HttpStatus.CREATED) | ||
| .body(response); | ||
| } | ||
|
|
||
| @PostMapping("/login") | ||
| public ResponseEntity<MemberResponse> loginMember( | ||
| @RequestBody LoginRequest request, | ||
| HttpServletRequest httpServletRequest | ||
| ) { | ||
| MemberResponse response = authService.login(request); | ||
|
|
||
| HttpSession session = httpServletRequest.getSession(true); | ||
|
|
||
| session.setAttribute("SESSION_ID", response.id()); | ||
|
|
||
| return ResponseEntity | ||
| .ok(response); | ||
| } | ||
|
|
||
| @PostMapping("/logout") | ||
| public ResponseEntity<Void> logoutMember( | ||
| HttpServletRequest httpServletRequest, | ||
| HttpServletResponse httpServletResponse | ||
| ) { | ||
| HttpSession session = httpServletRequest.getSession(false); | ||
|
|
||
| if (session != null) { | ||
| session.invalidate(); | ||
|
|
||
| Cookie cookie = new Cookie("JSESSIONID", null); | ||
| cookie.setMaxAge(0); | ||
| cookie.setPath("/"); | ||
| cookie.setHttpOnly(true); | ||
| httpServletResponse.addCookie(cookie); | ||
| } | ||
|
|
||
| return ResponseEntity.ok().build(); | ||
| } | ||
| } |
55 changes: 55 additions & 0 deletions
55
src/main/java/com/example/bcsd/controller/BoardController.java
This file contains hidden or 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,55 @@ | ||
| package com.example.bcsd.controller; | ||
|
|
||
| import com.example.bcsd.dto.request.BoardRequest; | ||
| import com.example.bcsd.dto.resopnse.BoardResponse; | ||
| import com.example.bcsd.service.BoardService; | ||
| import jakarta.validation.Valid; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.*; | ||
|
|
||
| import java.net.URI; | ||
| import java.util.List; | ||
|
|
||
| @RestController | ||
| @RequestMapping("/boards") | ||
| @RequiredArgsConstructor | ||
| public class BoardController { | ||
| private final BoardService boardService; | ||
|
|
||
| @GetMapping | ||
| public ResponseEntity<List<BoardResponse>> getAllBoards() { | ||
| return ResponseEntity | ||
| .ok(boardService.getAllBoards()); | ||
| } | ||
|
|
||
| @GetMapping("/{id}") | ||
| public ResponseEntity<BoardResponse> getBoardById(@PathVariable Long id) { | ||
| return ResponseEntity | ||
| .ok(boardService.getBoardById(id)); | ||
| } | ||
|
|
||
| @PostMapping | ||
| public ResponseEntity<BoardResponse> createBoard(@RequestBody @Valid BoardRequest request) { | ||
| BoardResponse response = boardService.createBoard(request); | ||
|
|
||
| return ResponseEntity | ||
| .created(URI.create("/boards/" + response.id())) | ||
| .body(response); | ||
| } | ||
|
|
||
| @PutMapping("/{id}") | ||
| public ResponseEntity<BoardResponse> updateArticleById( | ||
| @PathVariable Long id, @RequestBody @Valid BoardRequest request | ||
| ) { | ||
| return ResponseEntity | ||
| .ok(boardService.updateBoardById(id, request)); | ||
| } | ||
|
|
||
| @DeleteMapping("/{id}") | ||
| public ResponseEntity<Void> deleteBoardById(@PathVariable Long id) { | ||
| boardService.deleteBoardById(id); | ||
|
|
||
| return ResponseEntity.noContent().build(); | ||
| } | ||
| } |
2 changes: 1 addition & 1 deletion
2
...ava/com/example/bcsd/HelloController.java → ...mple/bcsd/controller/HelloController.java
This file contains hidden or 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
21 changes: 21 additions & 0 deletions
21
src/main/java/com/example/bcsd/controller/IntroduceController.java
This file contains hidden or 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.example.bcsd.controller; | ||
|
|
||
| import org.springframework.stereotype.Controller; | ||
| import org.springframework.ui.Model; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RequestParam; | ||
|
|
||
| @Controller | ||
| @RequestMapping("/introduce") | ||
| public class IntroduceController { | ||
| @GetMapping | ||
| public String getIntroduce( | ||
| @RequestParam(name = "name", defaultValue="이동훈", required = false) String name, | ||
| Model model | ||
| ) { | ||
| model.addAttribute("name" , name); | ||
|
|
||
| return "hello"; | ||
| } | ||
| } |
18 changes: 18 additions & 0 deletions
18
src/main/java/com/example/bcsd/controller/JsonController.java
This file contains hidden or 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,18 @@ | ||
| package com.example.bcsd.controller; | ||
|
|
||
| import com.example.bcsd.dto.resopnse.JsonResponse; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| @RestController | ||
| @RequestMapping("/json") | ||
| public class JsonController { | ||
| @GetMapping | ||
| public ResponseEntity<JsonResponse> getJson() { | ||
| JsonResponse response = new JsonResponse(24, "이동훈"); | ||
|
|
||
| return ResponseEntity.ok(response); | ||
| } | ||
| } |
51 changes: 51 additions & 0 deletions
51
src/main/java/com/example/bcsd/controller/MemberController.java
This file contains hidden or 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,51 @@ | ||
| package com.example.bcsd.controller; | ||
|
|
||
| import com.example.bcsd.dto.request.MemberRequest; | ||
| import com.example.bcsd.dto.resopnse.MemberResponse; | ||
| import com.example.bcsd.service.MemberService; | ||
| import jakarta.validation.Valid; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.*; | ||
|
|
||
| import java.net.URI; | ||
| import java.util.List; | ||
|
|
||
| @RestController | ||
| @RequestMapping("/members") | ||
| @RequiredArgsConstructor | ||
| public class MemberController { | ||
| private final MemberService memberService; | ||
|
|
||
| @GetMapping | ||
| public ResponseEntity<List<MemberResponse>> getAllMembers() { | ||
| return ResponseEntity.ok(memberService.getAllMembers()); | ||
| } | ||
|
|
||
| @GetMapping("/{id}") | ||
| public ResponseEntity<MemberResponse> getMemberById(@PathVariable Long id) { | ||
| return ResponseEntity | ||
| .ok(memberService.getMemberById(id)); | ||
| } | ||
|
|
||
| @PostMapping() | ||
| public ResponseEntity<MemberResponse> createMember(@RequestBody @Valid MemberRequest request) { | ||
| MemberResponse response = memberService.createMember(request); | ||
|
|
||
| return ResponseEntity.created(URI.create("/members/" + response.id())) | ||
| .body(response); | ||
| } | ||
|
|
||
| @PutMapping("/{id}") | ||
| public ResponseEntity<MemberResponse> updateMember(@PathVariable Long id, @RequestBody @Valid MemberRequest request) { | ||
| return ResponseEntity | ||
| .ok(memberService.updateMember(id, request)); | ||
| } | ||
|
|
||
| @DeleteMapping("/{id}") | ||
| public ResponseEntity<Void> deleteMember(@PathVariable Long id) { | ||
| memberService.deleteMember(id); | ||
|
|
||
| return ResponseEntity.noContent().build(); | ||
| } | ||
| } |
32 changes: 32 additions & 0 deletions
32
src/main/java/com/example/bcsd/dto/request/ArticleCreateRequest.java
This file contains hidden or 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,32 @@ | ||
| package com.example.bcsd.dto.request; | ||
|
|
||
| import com.example.bcsd.model.Article; | ||
| import com.example.bcsd.model.Board; | ||
| import com.example.bcsd.model.Member; | ||
| import jakarta.validation.constraints.NotBlank; | ||
| import jakarta.validation.constraints.NotNull; | ||
| import jakarta.validation.constraints.Size; | ||
|
|
||
| public record ArticleCreateRequest( | ||
| @NotNull(message = "작성자 ID가 누락되었습니다.") | ||
| Long authorId, | ||
|
|
||
| @NotNull(message = "게시판 ID가 누락되었습니다.") | ||
| Long boardId, | ||
|
|
||
| @NotBlank(message = "제목이 누락되었습니다.") | ||
| @Size(max = 255, message = "제목의 최대 길이를 벗어났습니다. (최대 길이 : 255자)") | ||
| String title, | ||
|
|
||
| @NotBlank(message = "본문이 누락되었습니다.") | ||
| String content | ||
| ) { | ||
| public Article toEntity(Member author, Board board) { | ||
| return Article.builder() | ||
| .title(title) | ||
| .author(author) | ||
| .board(board) | ||
| .content(content) | ||
| .build(); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GetMapping에 이런 옵션이 있었네요 👀
RequestParam와 관련이 있는 옵션인가요 ??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
원래 params 옵션을 안주고 RequestParam을 사용하면 쿼리 파라미터를 보내냐 안보내냐에 따라서 메소드가 오버로딩 되지 않을까? 하는 생각이었지만 막상 구현하고 실행해보니 두 메소드는 결국 /posts 에 대한 GET 요청이므로 중복의 문제로 실행되지 않아서 어떻게 해결해야 할 지 구글링 해봤는데 저런 옵션이 있다는 것을 알았습니다!
쿼리 파라미터가 있다고 명시하므로 중복되는 요청이 아님을 판단할 수 있는 것 같아보입니다.