-
Notifications
You must be signed in to change notification settings - Fork 113
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
경북대 BE_김영인 6주차 과제 (2단계) #237
Open
Youngini
wants to merge
40
commits into
kakao-tech-campus-2nd-step2:youngini
Choose a base branch
from
Youngini:step2
base: youngini
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
40 commits
Select commit
Hold shift + click to select a range
199525a
feat: setup the project
Youngini cd6fec9
feat : merge the project
Youngini 6748dfc
docs(README.md) : API 명세서 수정 사항 점검 리스트
Youngini 62b5448
feat(Member) : 일반 회원가입 로직 확인
Youngini 0096f76
feat(Member) : 일반 로그인 로직 확인
Youngini c3fb376
feat(Product) : 제품 옵션 조회
Youngini 597895b
feat(Product) : 특정 제품의 옵션 조회
Youngini 6363d39
feat(Product) : 특정 카테고리별 상품 목록 조회
Youngini 2e76903
feat(Category) : 모든 카테고리 조회
Youngini 5d6dbed
feat(wish) : 위시 리스트에 추가
Youngini 0ef82ad
feat(wish) : 위시 리스트에서 삭제
Youngini f5152fb
feat(wish) : 위시 리스트 목록 반환
Youngini 5825161
feat(Order) : 주문 생성
Youngini 2e270c5
refactor : 실행 시 발생하는 오류 수정
Youngini 974ee7a
feat(WebConfig) : Swagger 사용 시 발생하는 HttpMediaTypeNotAcceptableExcepti…
Youngini 55fa3ac
refactor(JoinResponse) : 회원가입 시, 응답 용어 수정
Youngini f835073
refactor(Order) : 주문생성시, Request와 Response 용어 api 명세서와 일치시킴
Youngini 5fd2840
refactor(Category) :카테고리 목록의, Request와 Response 용어 api 명세서와 일치시킴
Youngini 71432fd
refactor(Product) : Product API의, Request와 Response 용어 api 명세서와 일치시킴
Youngini 38e745e
refactor(Order) : Order API의, Request와 Response 용어 api 명세서와 일치시킴
Youngini 51f5d20
refactor(wish) : wish API의, Request와 Response 용어 api 명세서와 일치시킴
Youngini 3d71aa0
refactor(Member) : 생성자 만듦
Youngini 471460d
refactor(Member) : Json 인식 못하는 문제 해결
Youngini bff484a
refactor(JwtConfig) : token 생성 오류 해결
Youngini e61f013
fwat(JwtConfig) : token으로 email 추출
Youngini 3dea571
feat(Entity) : 생성자 만듦
Youngini f2d5530
build(application.properties) : 디비 실행되도 생성이아니라 업데이트가 되도록 수정
Youngini ca67821
refactor(Controller) : Pageable 객체 인수를 size, page로 변경
Youngini 3678425
build(application) : RDS 연결
Youngini 85aeccb
build : RDS 연결
Youngini ab006ac
refactor : option 예약어로 변경
Youngini 237d0b5
feat(webConfig) : cors 에러 해결
Youngini cf881ae
build(appliaction) : DB를 실행될때 생성이 아닌, 업데이트 되도록 수정
Youngini 851b190
docs(README.md) : 2단계 구현할 목록 작성 완료
Youngini ddf2bab
refactore(productController) : endPoint 오류 수정
Youngini 148fca7
refactore(JwtConfig) : Bearer로 인한 토큰 인식 에러 해결
Youngini ea8ba02
docs(README.md) : API 연결 시 발생한 오류 수정
Youngini 4c966a8
docs(README.md) : 배포 스크립트 링크 첨부
Youngini a41a8f3
test(AcceptanceTest) : CORS 테스트 구현
Youngini 441e71e
docs(README.md) : 구현한 목록 정리
Youngini 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 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 |
---|---|---|
|
@@ -38,3 +38,6 @@ out/ | |
|
||
### Mac OS ### | ||
.DS_Store | ||
|
||
### secret-key 설정 | ||
src/main/resources/application-secret.properties |
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 +1,44 @@ | ||
# spring-gift-point | ||
# spring-gift-point | ||
|
||
# 0단계 | ||
|
||
## API 명세서 | ||
https://impossible-repair-22e.notion.site/57ec013f9424421eb2317b11a2b9a29c?v=f3fe7340ebae425bbfa70db78123a663 | ||
|
||
# 1단계 | ||
|
||
## 구현할 기능 목록 | ||
- [ ] 작성한 API 문서를 기반으로 팀 내에서 지금까지 만든 API를 검토하고 통일하여 변경 사항을 반영 | ||
- [x] 일반 회원가입 | ||
- [x] 일반 로그인 | ||
- [x] 모든 상품 조회 | ||
- [x] 특정 제품의 옵션 조회 | ||
- [x] 특정 카테고리별 상품 목록조회 | ||
- [x] 모든 카테고리 조회 | ||
- [x] 위시리스트에 추가 | ||
- [x] 위시리스트에서 삭제 | ||
- [x] 로그인한 회원의 위시리스트 조회 | ||
- [x] 주문 생성 | ||
|
||
# 2단계 | ||
|
||
## 구현할 기능 목록 | ||
- [x] API 오류 확인 | ||
- [x] wish | ||
- [x] product 카테고리별 상품 불러오는 api endpoint 경로 오류 수정 | ||
- [x] 배포 자동화 | ||
- [x] 배포 스크립트 작성 | ||
- [x] 웹을 서버에 배포하기 위한 셀 스크립트 작성 | ||
- [x] 스크립트는 현재 실행 중인 JAR 파일을 종료하고, 새로운 JAR 파일을 복사하여 실행하는 기능을 포함 | ||
- https://www.notion.so/18cdfba8d1e44daa978eb1c7e7ee03d9 | ||
|
||
- [x] 보안 문제 | ||
- [x] JWT를 사용한 인증에 문제가 없는지 프론트와 연결하면서 테스트 | ||
|
||
- [x] cors 에러 해결 | ||
- [x] 전역 CORS 설정 : WebConfig에서 cors에러 해결 | ||
- [ ] ~~특정 controller에서 CORS 설정~~ | ||
- [ ] ~~Spring Security에서 CORS 설정~~ | ||
- [ ] ~~application에서 CORS 설정 사용~~ | ||
|
||
- [x] CORS 테스트 구현 |
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
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package gift.config; | ||
|
||
import io.jsonwebtoken.Jwts; | ||
import io.jsonwebtoken.Claims; | ||
import io.jsonwebtoken.security.Keys; | ||
import io.jsonwebtoken.SignatureAlgorithm; | ||
import org.springframework.stereotype.Component; | ||
import gift.constant.Constants; | ||
|
||
import java.util.Date; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
@Component | ||
public class JwtConfig { | ||
|
||
public String generateToken(String email) { | ||
// Create a claims map | ||
Map<String, Object> claims = new HashMap<>(); | ||
claims.put("email", email); | ||
|
||
// Generate the JWT token | ||
return Jwts.builder() | ||
.setClaims(claims) | ||
.setSubject(email) | ||
.setIssuedAt(new Date()) | ||
.setExpiration(new Date(System.currentTimeMillis() + Constants.ONE_DAY_MILLIS)) | ||
.signWith(Keys.hmacShaKeyFor(Constants.SECRET_KEY.getBytes()), SignatureAlgorithm.HS256) | ||
.compact(); | ||
} | ||
|
||
public String extractEmail(String token) { | ||
if (token.startsWith("Bearer ")) { | ||
token = token.substring(7); | ||
} | ||
return extractAllClaims(token).getSubject(); | ||
} | ||
|
||
public Claims extractAllClaims(String token) { | ||
return Jwts.parser() | ||
.setSigningKey(Keys.hmacShaKeyFor(Constants.SECRET_KEY.getBytes())) | ||
.parseClaimsJws(token) | ||
.getBody(); | ||
} | ||
|
||
public boolean validateToken(String token, String email) { | ||
final String extractedEmail = extractEmail(token); | ||
return extractedEmail.equals(email) && !isTokenExpired(token); | ||
} | ||
|
||
private boolean isTokenExpired(String token) { | ||
return extractAllClaims(token).getExpiration().before(new Date()); | ||
} | ||
} |
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,64 @@ | ||
package gift.config; | ||
|
||
import gift.resolver.LoginMemberArgumentResolver; | ||
import gift.service.MemberService; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.converter.HttpMessageConverter; | ||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; | ||
import org.springframework.web.filter.CharacterEncodingFilter; | ||
import org.springframework.web.method.support.HandlerMethodArgumentResolver; | ||
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer; | ||
import org.springframework.web.servlet.config.annotation.CorsRegistry; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
|
||
import java.util.List; | ||
|
||
@Configuration | ||
public class WebConfig implements WebMvcConfigurer { | ||
private final MemberService memberService; | ||
|
||
public WebConfig(MemberService memberService) { | ||
this.memberService = memberService; | ||
} | ||
|
||
@Override | ||
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) { | ||
resolvers.add(new LoginMemberArgumentResolver(memberService)); | ||
} | ||
|
||
@Override | ||
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) { | ||
configurer.favorPathExtension(false) | ||
.favorParameter(true) | ||
.parameterName("mediaType") | ||
.ignoreAcceptHeader(false) | ||
.useRegisteredExtensionsOnly(false) | ||
.defaultContentType(MediaType.APPLICATION_JSON) | ||
.mediaType("json", MediaType.APPLICATION_JSON) | ||
.mediaType("xml", MediaType.APPLICATION_XML); | ||
} | ||
|
||
@Bean | ||
public CharacterEncodingFilter characterEncodingFilter() { | ||
CharacterEncodingFilter filter = new CharacterEncodingFilter(); | ||
filter.setEncoding("UTF-8"); | ||
filter.setForceEncoding(true); | ||
return filter; | ||
} | ||
|
||
@Override | ||
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) { | ||
converters.add(new MappingJackson2HttpMessageConverter()); | ||
} | ||
|
||
@Override | ||
public void addCorsMappings(CorsRegistry registry) { | ||
registry.addMapping("/**") | ||
.allowedOrigins("http://localhost:3000") | ||
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS") | ||
.allowedHeaders("*") | ||
.allowCredentials(true); | ||
} | ||
} |
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,8 @@ | ||
package gift.constant; | ||
|
||
public class Constants { | ||
public static final String SECRET_KEY = "Yn2kjibddFAWtnPJ2AFlL8WXmohJMCvigQggaEypa5E="; | ||
public static final long ONE_DAY_MILLIS = 86400000; | ||
public static final String AUTHENTICATE_HEADER = "Authenticate"; | ||
public static final String BEARER = "Bearer"; | ||
} |
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,59 @@ | ||
package gift.controller; | ||
|
||
import gift.domain.Category; | ||
import gift.dto.CategoryListDto; | ||
import gift.dto.UpdateCategoryDto; | ||
import gift.service.CategoryService; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.PageRequest; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
import java.util.List; | ||
|
||
@RestController | ||
@RequestMapping("/api/categories") | ||
public class CategoryController { | ||
private final CategoryService categoryService; | ||
|
||
@Autowired | ||
public CategoryController(CategoryService categoryService) { | ||
this.categoryService = categoryService; | ||
} | ||
|
||
@Operation(summary = "모든 카테고리 조회") | ||
@GetMapping | ||
public ResponseEntity<List<CategoryListDto>> getAllCategories(@RequestParam(defaultValue = "0") int page, | ||
@RequestParam(defaultValue = "10") int size) { | ||
Pageable pageable = PageRequest.of(page, size); | ||
Page<CategoryListDto> categories = categoryService.findAll(pageable); | ||
return ResponseEntity.ok(categories.getContent()); | ||
} | ||
|
||
/* @GetMapping("/{id}") | ||
public ResponseEntity<Category> getCategoryById(@PathVariable Long id) { | ||
Category category = categoryService.findById(id); | ||
return ResponseEntity.ok(category); | ||
} | ||
|
||
@PostMapping | ||
public ResponseEntity<Category> createCategory(@RequestParam String name) { | ||
Category category = categoryService.addCategory(name); | ||
return ResponseEntity.ok(category); | ||
} | ||
|
||
@PutMapping("/{id}") | ||
public ResponseEntity<Category> updateCategory(@PathVariable Long id, @RequestBody UpdateCategoryDto updateCategoryDto) { | ||
Category updatedCategory = categoryService.updateCategory(id, updateCategoryDto); | ||
return ResponseEntity.ok(updatedCategory); | ||
} | ||
|
||
@DeleteMapping("/{id}") | ||
public ResponseEntity<Void> deleteCategory(@PathVariable Long id) { | ||
categoryService.deleteCategory(id); | ||
return ResponseEntity.noContent().build(); | ||
}*/ | ||
|
||
} |
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,37 @@ | ||
package gift.controller; | ||
|
||
import gift.service.KakaoTokenService; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.servlet.ModelAndView; | ||
|
||
import java.io.IOException; | ||
|
||
@RestController("api/kakao") | ||
public class KakaoAuthController { | ||
/*@Value("${kakao.app.key}") | ||
private String appKey; | ||
|
||
private final KakaoTokenService kakaoTokenService; | ||
|
||
public KakaoAuthController(KakaoTokenService kakaoTokenService) { | ||
this.kakaoTokenService = kakaoTokenService; | ||
} | ||
|
||
@GetMapping("/login") | ||
public void redirectToKakao(HttpServletResponse response) throws IOException { | ||
String redirectUri = "http://localhost:8080/callback"; // 리디렉션 URI | ||
String kakaoAuthUrl = String.format("https://kauth.kakao.com/oauth/authorize?scope=talk_message&response_type=code&redirect_uri=%s&client_id=%s", redirectUri, appKey); | ||
response.sendRedirect(kakaoAuthUrl); // 카카오 인가 페이지로 리다이렉트 | ||
} | ||
|
||
@GetMapping("/callback") | ||
public String getKakaoAuthorizationCode(@RequestParam("code") String authorizationCode) { | ||
String accessToken = kakaoTokenService.getAccessToken(authorizationCode); | ||
System.out.println("Access Token: " + accessToken); | ||
return accessToken; | ||
}*/ | ||
} |
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,42 @@ | ||
package gift.controller; | ||
|
||
import gift.constant.Constants; | ||
import gift.dto.LoginRequest; | ||
import gift.dto.LoginResponse; | ||
import gift.dto.MemberRequest; | ||
import gift.dto.JoinResponse; | ||
import gift.service.MemberService; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
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("api/members") | ||
public class MemberController { | ||
|
||
private final MemberService memberService; | ||
|
||
public MemberController(MemberService memberService) { | ||
this.memberService = memberService; | ||
} | ||
|
||
@Operation(summary = "일반 회원가입") | ||
@PostMapping("/register") | ||
public ResponseEntity<JoinResponse> registerMember(@RequestBody MemberRequest requestDto) { | ||
JoinResponse responseDto = memberService.registerMember(requestDto); | ||
return ResponseEntity.status(HttpStatus.CREATED).body(responseDto); | ||
} | ||
|
||
@Operation(summary = "일반 로그인") | ||
@PostMapping("/login") | ||
public ResponseEntity<LoginResponse> login(@RequestBody LoginRequest loginRequest) { | ||
LoginResponse loginResponse = memberService.login(loginRequest); | ||
return ResponseEntity.status(loginResponse.getAccess_token() != null ? HttpStatus.OK : HttpStatus.UNAUTHORIZED) | ||
.header(Constants.AUTHENTICATE_HEADER, Constants.BEARER) | ||
.body(loginResponse); | ||
} | ||
} |
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.
시큐리티 사용을 하지 않기에 이 설정만 하면 되네요 👍🏼