-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from softeerbootcamp4th/feat/sharelink
[Feature] 유형검사 결과 확인/제출 로직 분리 및 공유 링크 생성 api 추가
- Loading branch information
Showing
33 changed files
with
625 additions
and
106 deletions.
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
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
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
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,48 @@ | ||
package com.softeer.podo.common.utils; | ||
|
||
import jakarta.annotation.PostConstruct; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Component; | ||
|
||
import javax.crypto.Cipher; | ||
import javax.crypto.SecretKey; | ||
import javax.crypto.spec.SecretKeySpec; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.Arrays; | ||
import java.util.Base64; | ||
|
||
@Component | ||
public class AESUtils { | ||
private static final String ALGORITHM = "AES"; | ||
|
||
@Value("${secret.jwt}") | ||
private String baseSecretKey; | ||
|
||
private static String STATIC_BASE_SECRET_KEY; | ||
|
||
@PostConstruct | ||
public void init() { | ||
STATIC_BASE_SECRET_KEY = this.baseSecretKey; | ||
} | ||
|
||
public static String encrypt(String data) throws Exception { | ||
Cipher cipher = Cipher.getInstance(ALGORITHM); | ||
cipher.init(Cipher.ENCRYPT_MODE, makeSecretKeyByString(STATIC_BASE_SECRET_KEY)); | ||
byte[] encryptedData = cipher.doFinal(data.getBytes()); | ||
return Base64.getEncoder().encodeToString(encryptedData); | ||
} | ||
|
||
public static String decrypt(String encryptedData) throws Exception { | ||
Cipher cipher = Cipher.getInstance(ALGORITHM); | ||
cipher.init(Cipher.DECRYPT_MODE, makeSecretKeyByString(STATIC_BASE_SECRET_KEY)); | ||
byte[] decryptedData = cipher.doFinal(Base64.getDecoder().decode(encryptedData)); | ||
return new String(decryptedData); | ||
} | ||
|
||
// 특정 문자열을 기반으로 SecretKey 객체를 생성하는 메서드 | ||
public static SecretKey makeSecretKeyByString(String password) { | ||
byte[] keyBytes = password.getBytes(StandardCharsets.UTF_8); | ||
keyBytes = Arrays.copyOf(keyBytes, 16); // 128비트(16바이트)로 맞추기 | ||
return new SecretKeySpec(keyBytes, ALGORITHM); | ||
} | ||
} |
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 com.softeer.podo.common.utils; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
import java.io.UnsupportedEncodingException; | ||
import java.net.URLDecoder; | ||
import java.net.URLEncoder; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
@Component | ||
public class URLUtils { | ||
|
||
/** | ||
* 주어진 문자열을 URL 인코딩합니다. | ||
* | ||
* @param value 인코딩할 문자열 | ||
* @return URL 인코딩된 문자열 | ||
*/ | ||
public static String encode(String value) throws UnsupportedEncodingException { | ||
return URLEncoder.encode(value, StandardCharsets.UTF_8); | ||
} | ||
|
||
/** | ||
* 주어진 URL 인코딩된 문자열을 디코딩합니다. | ||
* | ||
* @param value 디코딩할 문자열 | ||
* @return URL 디코딩된 문자열 | ||
* @throws UnsupportedEncodingException 디코딩이 지원되지 않는 경우 발생 | ||
*/ | ||
public static String decode(String value) throws UnsupportedEncodingException { | ||
return URLDecoder.decode(value, StandardCharsets.UTF_8); | ||
} | ||
|
||
public static void main(String[] args) { | ||
try { | ||
String uniqueLink = "V1a1Vrqe1oBYCkqkXs7/Uw=="; | ||
String encodedLink = encode(uniqueLink); | ||
} catch (UnsupportedEncodingException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/com/softeer/podo/event/controller/EventLotsApiController.java
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,30 @@ | ||
package com.softeer.podo.event.controller; | ||
|
||
import com.softeer.podo.common.response.CommonResponse; | ||
import com.softeer.podo.event.model.dto.LotsTypeRequestDto; | ||
import com.softeer.podo.event.model.dto.LotsTypeResponseDto; | ||
import com.softeer.podo.event.service.EventLotsService; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
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; | ||
|
||
@RequestMapping("/lots") | ||
@RestController | ||
@RequiredArgsConstructor | ||
public class EventLotsApiController { | ||
|
||
private final EventLotsService eventLotsService; | ||
|
||
/** | ||
* 제출한 유형테스트 결과에 따라 적절한 드라이버 유형 반환 | ||
*/ | ||
@PostMapping("/type") | ||
@Operation(summary = "제출한 유형테스트 결과에 따라 적절한 드라이버 유형 반환") | ||
public CommonResponse<LotsTypeResponseDto> getDriverType(@Valid @RequestBody LotsTypeRequestDto dto) { | ||
return new CommonResponse<>(eventLotsService.getProperDriverType(dto)); | ||
} | ||
} |
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
43 changes: 43 additions & 0 deletions
43
src/main/java/com/softeer/podo/event/controller/EventLotsPageController.java
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,43 @@ | ||
package com.softeer.podo.event.controller; | ||
|
||
import com.softeer.podo.event.service.EventLotsService; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
|
||
@RequestMapping("/lots") | ||
@Controller | ||
@RequiredArgsConstructor | ||
public class EventLotsPageController { | ||
|
||
private final EventLotsService eventLotsService; | ||
|
||
/** | ||
* 고유 공유링크 클릭 | ||
* {uniqueLink}: 유저 id (암호화) | ||
*/ | ||
@GetMapping("/link/{uniqueLink}") | ||
@Operation(summary = "공유링크 클릭시 redirection하기 위함 (사용자 직접 호출용)") | ||
public String shareLinkClick( | ||
HttpServletResponse response, | ||
@PathVariable String uniqueLink | ||
) { | ||
try { | ||
// 해당 유저에 해당하는 적절한 이벤트 결과 페이지 찾기 | ||
String redirectUrl = eventLotsService.getEventUrl(uniqueLink); | ||
// 이벤트 결과 페이지 반환 | ||
// response.setStatus(HttpServletResponse.SC_FOUND); | ||
// response.setHeader("Location", "/type/"+redirectUrl); | ||
return "/type/"+redirectUrl; | ||
} catch (Exception e) { | ||
// 에러 페이지로 리다이렉션 | ||
// response.setStatus(HttpServletResponse.SC_FOUND); | ||
// response.setHeader("Location", "/error/404"); | ||
return "/error/404"; | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/softeer/podo/event/exception/AESExecutionException.java
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,11 @@ | ||
package com.softeer.podo.event.exception; | ||
|
||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public class AESExecutionException extends RuntimeException { | ||
private String message; | ||
} |
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
11 changes: 11 additions & 0 deletions
11
src/main/java/com/softeer/podo/event/exception/InvalidResultTypeException.java
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,11 @@ | ||
package com.softeer.podo.event.exception; | ||
|
||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public class InvalidResultTypeException extends RuntimeException { | ||
private String message; | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/softeer/podo/event/exception/LotsShareLinkNotExistsException.java
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,11 @@ | ||
package com.softeer.podo.event.exception; | ||
|
||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public class LotsShareLinkNotExistsException extends RuntimeException { | ||
private String message; | ||
} |
Oops, something went wrong.