-
Notifications
You must be signed in to change notification settings - Fork 13
[Spring Core] 강인화 과제 제출합니다. #2
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
kih1015
wants to merge
62
commits into
BCSDLab-Edu:main
Choose a base branch
from
kih1015:feat
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
62 commits
Select commit
Hold shift + click to select a range
bc460cb
feat: ErrorCode 구현
kih1015 6523f0f
feat: ArticleErrorCode 구현
kih1015 8f46c93
feat: BoardErrorCode 구현
kih1015 0f8680a
feat: MemberErrorCode 구현
kih1015 3672b07
feat: CommonErrorCode 구현
kih1015 30ec81a
refactor: exception.error 패키지로 이동
kih1015 14da25c
feat: RestApiException 구현
kih1015 7bdf905
feat: ErrorResponse 구현
kih1015 167fd5c
feat: GlobalExceptionHandler 구현
kih1015 4e57ccf
refactor: handleCustomException 메서드 분리
kih1015 100b4df
feat: handleEmptyResultException 구현
kih1015 4e257c0
feat: from 메서드 구현
kih1015 8b32f21
feat: getArticles 메서드 구현
kih1015 b050442
feat: 조회 예외처리 controller 구현
kih1015 ef348a1
feat: 사용자 수정 예외처리 구현
kih1015 43e903e
feat: 게시물 수정 예외처리 구현
kih1015 78042a1
feat: 공통 생성 예외처리 구현
kih1015 bfaca10
feat: 게시물 생성 예외처리 구현
kih1015 9169d55
feat: 사용자 삭제 예외처리 구현
kih1015 dfe6627
feat: 게시판 삭제 예외처리 구현
kih1015 0dbe606
style: import 최적회
kih1015 b60661c
style: 들여쓰기 정리
kih1015 aaec70e
refactor: 공통 mapping 추가
kih1015 efc13e2
style: 논리식 조건문 삽입
kih1015 47d00c7
fix: 오류 수정
kih1015 e74feed
feat: JPA 의존성 추가
kih1015 7f76725
refactor: refactor Article to Entity
kih1015 a7b41c3
refactor: refactor Board to Entity
kih1015 bbf44c6
refactor: refactor member to Entity
kih1015 28ff372
refactor: refactor ArticleRepository impl
kih1015 fe2be17
refactor: refactor BoardRepository impl
kih1015 4b2ad7f
refactor: refactor MemberRepository impl
kih1015 2384531
refactor: refactor update methods
kih1015 807ac1a
refactor: alter ArticleRepository to Spring Data JPA
kih1015 b468327
refactor: alter BoardRepository to Spring Data JPA
kih1015 93acc08
refactor: alter MemberRepository to Spring Data JPA
kih1015 b5abb8a
refactor: refactor ArticleService
kih1015 a145eab
refactor: refactor BoardService
kih1015 9e5b1cf
refactor: refactor MemberService
kih1015 c7aa9de
refactor: makes Article have many-to-one mapping
kih1015 966fbac
refactor: makes Board have one-to-many mapping
kih1015 0d35924
refactor: makes member have one-to-many mapping
kih1015 f3405c6
refactor: alter to lazy fetch
kih1015 c2ba88a
refactor: modify create, update logic in ArticleService
kih1015 93c1057
feat: add articles getter
kih1015 9b5c19e
feat: 양방향 연관관계 적용하도록 변경
kih1015 7600bd2
style: 필드간 개행
kih1015 5c65b1c
feat: add dependencies
kih1015 adbb0c0
feat: add POST /members/login and /members/join
kih1015 21f7c37
feat: add AuthenticationConfig
kih1015 98c649a
feat: add dependency
kih1015 f0228e9
feat: add JwtUtil
kih1015 7ab68c1
feat: add login method
kih1015 e33138e
feat: add dependency
kih1015 164a7c7
feat: add JwtFilter class
kih1015 f16ec8c
feat: 회원가입 시 이메일 중복 방지 기능 추가
kih1015 4c30465
feat: 이메일로 검색 기능 추가
kih1015 756e6eb
feat: EncoderConfig 추가
kih1015 82c04a8
feat: 이메일 존재하지 않음, 패스워드 불일치 에러 추가
kih1015 9efdca4
feat: 로그인 dto 추가
kih1015 384823e
feat: login 메서드 추가
kih1015 2947fbc
feat: get 요청을 허용하도록 변경
kih1015 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
44 changes: 44 additions & 0 deletions
44
src/main/java/com/example/demo/configuration/AuthenticationConfig.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,44 @@ | ||
| package com.example.demo.configuration; | ||
|
|
||
| import com.example.demo.jwt.JwtFilter; | ||
| import com.example.demo.service.MemberService; | ||
| import org.springframework.beans.factory.annotation.Value; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.http.HttpMethod; | ||
| import org.springframework.security.config.annotation.web.builders.HttpSecurity; | ||
| import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; | ||
| import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; | ||
| import org.springframework.security.web.SecurityFilterChain; | ||
| import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; | ||
|
|
||
| @Configuration | ||
| @EnableWebSecurity | ||
| public class AuthenticationConfig { | ||
|
|
||
| private final MemberService memberService; | ||
|
|
||
| @Value("${jwt.secret}") | ||
| private String secretKey; | ||
|
|
||
| public AuthenticationConfig(MemberService memberService) { | ||
| this.memberService = memberService; | ||
| } | ||
|
|
||
| @Bean | ||
| public SecurityFilterChain filterChain(HttpSecurity httpSecurity) throws Exception { | ||
| httpSecurity | ||
| .csrf(AbstractHttpConfigurer::disable) | ||
| .formLogin(AbstractHttpConfigurer::disable) | ||
| .authorizeHttpRequests(authorize -> authorize | ||
| .requestMatchers("/members/join").permitAll() | ||
| .requestMatchers("/members/login").permitAll() | ||
| .requestMatchers(HttpMethod.POST).authenticated() | ||
| .requestMatchers(HttpMethod.GET).permitAll() | ||
| .anyRequest().authenticated() | ||
| ) | ||
| .addFilterBefore(new JwtFilter(memberService, secretKey), UsernamePasswordAuthenticationFilter.class); | ||
| return httpSecurity.build(); | ||
| } | ||
|
|
||
| } |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/example/demo/configuration/EncoderConfig.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,15 @@ | ||
| package com.example.demo.configuration; | ||
|
|
||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; | ||
|
|
||
| @Configuration | ||
| public class EncoderConfig { | ||
|
|
||
| @Bean | ||
| public BCryptPasswordEncoder encoder() { | ||
| return new BCryptPasswordEncoder(); | ||
| } | ||
|
|
||
| } |
75 changes: 39 additions & 36 deletions
75
src/main/java/com/example/demo/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
45 changes: 28 additions & 17 deletions
45
src/main/java/com/example/demo/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 |
|---|---|---|
| @@ -1,61 +1,72 @@ | ||
| package com.example.demo.controller; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.DeleteMapping; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.PathVariable; | ||
| import org.springframework.web.bind.annotation.PostMapping; | ||
| import org.springframework.web.bind.annotation.PutMapping; | ||
| import org.springframework.web.bind.annotation.RequestBody; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| import com.example.demo.controller.dto.request.BoardCreateRequest; | ||
| import com.example.demo.controller.dto.request.BoardUpdateRequest; | ||
| import com.example.demo.controller.dto.response.BoardResponse; | ||
| import com.example.demo.exception.RestApiException; | ||
| import com.example.demo.exception.error.BoardErrorCode; | ||
| import com.example.demo.exception.error.CommonErrorCode; | ||
| import com.example.demo.service.ArticleService; | ||
| import com.example.demo.service.BoardService; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.*; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @RestController | ||
| @RequestMapping("/boards") | ||
| public class BoardController { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 여기도 |
||
|
|
||
| private final BoardService boardService; | ||
| private final ArticleService articleService; | ||
|
|
||
| public BoardController(BoardService boardService) { | ||
| public BoardController(BoardService boardService, ArticleService articleService) { | ||
| this.boardService = boardService; | ||
| this.articleService = articleService; | ||
| } | ||
|
|
||
| @GetMapping("/boards") | ||
| @GetMapping() | ||
| public List<BoardResponse> getBoards() { | ||
| return boardService.getBoards(); | ||
| } | ||
|
|
||
| @GetMapping("/boards/{id}") | ||
| @GetMapping("/{id}") | ||
| public BoardResponse getBoard( | ||
| @PathVariable Long id | ||
| ) { | ||
| if (boardService.getBoards().stream().noneMatch(res -> res.id().equals(id))) { | ||
| throw new RestApiException(CommonErrorCode.RESOURCE_NOT_FOUND); | ||
| } | ||
| return boardService.getBoardById(id); | ||
| } | ||
|
|
||
| @PostMapping("/boards") | ||
| @PostMapping() | ||
| public BoardResponse createBoard( | ||
| @RequestBody BoardCreateRequest request | ||
| ) { | ||
| if (request.name() == null) { | ||
| throw new RestApiException(CommonErrorCode.NULL_PARAMETER); | ||
| } | ||
| return boardService.createBoard(request); | ||
| } | ||
|
|
||
| @PutMapping("/boards/{id}") | ||
| @PutMapping("/{id}") | ||
| public BoardResponse updateBoard( | ||
| @PathVariable Long id, | ||
| @RequestBody BoardUpdateRequest updateRequest | ||
| ) { | ||
| return boardService.update(id, updateRequest); | ||
| } | ||
|
|
||
| @DeleteMapping("/boards/{id}") | ||
| @DeleteMapping("/{id}") | ||
| public ResponseEntity<Void> deleteBoard( | ||
| @PathVariable Long id | ||
| ) { | ||
| if (articleService.getArticles() | ||
| .stream() | ||
| .anyMatch(res -> res.boardId().equals(id))) { | ||
| throw new RestApiException(BoardErrorCode.ARTICLE_EXISTENCE); | ||
| } | ||
| boardService.deleteBoard(id); | ||
| return ResponseEntity.noContent().build(); | ||
| } | ||
|
|
||
72 changes: 42 additions & 30 deletions
72
src/main/java/com/example/demo/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
4 changes: 4 additions & 0 deletions
4
src/main/java/com/example/demo/controller/dto/request/MemberLoginRequest.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,4 @@ | ||
| package com.example.demo.controller.dto.request; | ||
|
|
||
| public record MemberLoginRequest(String email, String password) { | ||
| } |
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.
지금 공통적으로
"/articles"가 있는데@RequestMapping("/articles")를 해놓으면 해당하는 클래스에 공통적으로 적용돼서 뺄수 있습니다!