Skip to content

Commit

Permalink
πŸš€ [Deploy] - Choco API μ˜ˆμ™Έμ²˜λ¦¬λ₯Ό μ„œλ²„μ— λ°˜μ˜ν•œλ‹€ (#27)
Browse files Browse the repository at this point in the history
* Refactor: 디렉토리 이름 μˆ˜μ •

* ✨ [Feature] - Choco APIλ₯Ό κ΅¬ν˜„ν•œλ‹€ (#8)

* Refactor: 디렉토리 이름 μˆ˜μ •

* Feat: Choco API 생성 μ™„λ£Œ

* Chore: Redis credential μˆ˜μ • (#11)

* Chore: CI/CD 진행 μ‹œμ—λ§Œ λ°”μŠ€ν‹°μ˜¨ 호슀트의 ingress 22번 포트λ₯Ό λš«μ„ 수 μžˆλ„λ‘ ν•œλ‹€ (#14)

* Chore: Github actions IP 였λ₯˜λ₯Ό ν•΄κ²°ν•œλ‹€ (#17)

* πŸ–ŠοΈ [Chore] - AWS 접속 μ‹œ, λ°œμƒν•˜λŠ” 였λ₯˜λ₯Ό ν•΄κ²°ν•œλ‹€ (#19)

* Chore: Github actions IP 였λ₯˜λ₯Ό ν•΄κ²°ν•œλ‹€

* Chore: Github actions IP 였λ₯˜λ₯Ό ν•΄κ²°ν•œλ‹€

* Chore: CD 진행 쀑 μ—λŸ¬ λ°œμƒ νŠΈλŸ¬λΈ” μŠˆνŒ…

* Chore/#16 (#22)

* Chore: Github actions IP 였λ₯˜λ₯Ό ν•΄κ²°ν•œλ‹€

* Chore: Github actions IP 였λ₯˜λ₯Ό ν•΄κ²°ν•œλ‹€

* Chore: Redisμ—μ„œ Session을 μ‚¬μš©ν•œλ‹€

* Feat: Choco API μ˜ˆμ™Έμ²˜λ¦¬ κ΅¬ν˜„

* Fix: Choco API μ˜ˆμ™Έμ²˜λ¦¬ 버그 μˆ˜μ •

---------

Co-authored-by: JeongHeumChoi <[email protected]>
Co-authored-by: JeongHeumChoi <[email protected]>
  • Loading branch information
3 people authored Sep 24, 2024
1 parent 28bbc46 commit dbd89df
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Choco-Express-BE-Properties
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ dependencies {

// redis
implementation 'org.springframework.boot:spring-boot-starter-data-redis'
implementation 'org.springframework.session:spring-session-data-redis'

// spring security
implementation 'org.springframework.boot:spring-boot-starter-security'
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/dgu/choco_express/constant/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class Constants {
"/api/health-check",
"/api/auth/sign-up",
"/api/auth/sign-in",
"/oauth2/authorization/kakao"
"/oauth2/authorization/kakao",
"/login/oauth2/code/kakao"
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ public ResponseEntity<?> deleteChoco(
@UserId Long userId,
@PathVariable Long chocoId
) {
return ResponseEntity.ok(chocoService.deleteChoco(userId, chocoId));
chocoService.deleteChoco(userId, chocoId);

return ResponseEntity.noContent()
.build();
}
}
8 changes: 6 additions & 2 deletions src/main/java/dgu/choco_express/exception/ChocoErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ public enum ChocoErrorCode implements ErrorCode {
INVALID_CHOCO_TYPE(HttpStatus.BAD_REQUEST, "CHOCO_001", "μ΄ˆμ½” νƒ€μž…μ΄ μœ νš¨ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€."),
NOT_FOUND_CHOCO(HttpStatus.NOT_FOUND, "CHOCO_002", "ν•΄λ‹Ή μ΄ˆμ½”κ°€ μ‘΄μž¬ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€."),
INVALID_CHOCO_NAME(HttpStatus.BAD_REQUEST, "CHOCO_003", "μ΄ˆμ½” μž‘μ„±μž 이름이 λΉ„μ–΄μžˆμŠ΅λ‹ˆλ‹€."),
CANT_CHOCO_RECURSIVE(HttpStatus.BAD_REQUEST, "CHOCO_004", "자기 μžμ‹ μ—κ²Œ μ΄ˆμ½”λ₯Ό 보낼 수 μ—†μŠ΅λ‹ˆλ‹€."),
INVALID_PAGE_CHOCO(HttpStatus.BAD_REQUEST, "CHOCO_005", "μœ νš¨ν•˜μ§€ μ•Šμ€ νŽ˜μ΄μ§€ λ„˜λ²„μž…λ‹ˆλ‹€."),
INVALID_CHOCO_CONTENT(HttpStatus.BAD_REQUEST, "CHOCO_004", "μ΄ˆμ½” λ‚΄μš©μ΄ λΉ„μ–΄μžˆμŠ΅λ‹ˆλ‹€."),
CANT_CHOCO_RECURSIVE(HttpStatus.BAD_REQUEST, "CHOCO_005", "자기 μžμ‹ μ—κ²Œ μ΄ˆμ½”λ₯Ό 보낼 수 μ—†μŠ΅λ‹ˆλ‹€."),
INVALID_PAGE_CHOCO(HttpStatus.BAD_REQUEST, "CHOCO_006", "μœ νš¨ν•˜μ§€ μ•Šμ€ νŽ˜μ΄μ§€ λ„˜λ²„μž…λ‹ˆλ‹€."),
CANT_READ_CHOCO(HttpStatus.BAD_REQUEST, "CHOCO_007", "읽을 κΆŒν•œμ΄ μ—†λŠ” μ΄ˆμ½”μž…λ‹ˆλ‹€."),
CANT_READ_BOX(HttpStatus.BAD_REQUEST, "CHOCO_008", "μ—Ώλ³Ό 수 μ—†λŠ” λ°•μŠ€μž…λ‹ˆλ‹€."),
CANT_DELETE_CHOCO(HttpStatus.BAD_REQUEST, "CHOCO_009", "μ‚­μ œν•  κΆŒν•œμ΄ μ—†λŠ” μ΄ˆμ½”μž…λ‹ˆλ‹€."),
;

private final HttpStatus status;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.core.Authentication;
Expand All @@ -25,6 +26,8 @@ public class Oauth2SuccessHandler implements AuthenticationSuccessHandler {
private String domain;
private final JwtUtil jwtUtil;
private final JwtService jwtService;
private final HttpSession session;


@Override
@Transactional
Expand All @@ -40,6 +43,13 @@ public void onAuthenticationSuccess(

AuthenticationResponse.makeLoginSuccessResponse(response, domain, jwtDto, jwtUtil.getRefreshExpiration());

response.sendRedirect("https://" + domain);
String redirectUrl = (String) session.getAttribute("redirectUrl");

if (redirectUrl != null) {
session.removeAttribute("redirectUrl"); // μ‚¬μš© ν›„ μ„Έμ…˜μ—μ„œ 제거
response.sendRedirect(redirectUrl);
} else {
response.sendRedirect("https://" + domain);
}
}
}
15 changes: 13 additions & 2 deletions src/main/java/dgu/choco_express/service/choco/ChocoService.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,19 @@ public URI createChoco(
ChocoCreateRequestDto chocoCreateRequestDto
) {
User currentUser = userRetriever.findById(userId);

Short chocoType = chocoCreateRequestDto.chocoType();
String chocoNickname = chocoCreateRequestDto.nickname();
String chocoContents = chocoCreateRequestDto.contents();
Box currentBox = boxRetriever.findById(boxId);


if (chocoType < 1 || chocoType > 6)
throw CommonException.type(ChocoErrorCode.INVALID_CHOCO_TYPE);
if (chocoNickname.isEmpty())
throw CommonException.type(ChocoErrorCode.INVALID_CHOCO_NAME);
if (chocoContents.isEmpty())
throw CommonException.type(ChocoErrorCode.INVALID_CHOCO_CONTENT);
if (currentUser.equals(currentBox.getUser()))
throw CommonException.type(ChocoErrorCode.CANT_CHOCO_RECURSIVE);

Choco createdChoco = chocoSaver.saveChoco(
Choco.from(chocoType, chocoNickname, chocoContents, currentBox)
Expand Down Expand Up @@ -91,6 +93,9 @@ public ChocoDetailsResponseDto getChocoDetails(
User currentUser = userRetriever.findById(userId);
Choco choco = chocoRetriever.findById(chocoId);

if (!currentUser.equals(choco.getBox().getUser()))
throw CommonException.type(ChocoErrorCode.CANT_READ_CHOCO);

return ChocoDetailsResponseDto.of(choco);
}

Expand All @@ -100,6 +105,9 @@ public ChocoPeekResponseDto getChocoPeek(
User currentUser = userRetriever.findById(userId);
Box currentBox = boxRetriever.findByUser(currentUser);

if (!currentUser.equals(currentBox.getUser()))
throw CommonException.type(ChocoErrorCode.CANT_READ_BOX);

return ChocoPeekResponseDto.builder()
.count(chocoRetriever.findChocoCountByBox(currentBox))
.build();
Expand All @@ -112,6 +120,9 @@ public Void deleteChoco(
User currentUser = userRetriever.findById(userId);
Choco choco = chocoRetriever.findById(chocoId);

if(!currentUser.equals(choco.getBox().getUser()))
throw CommonException.type(ChocoErrorCode.CANT_DELETE_CHOCO);

chocoRemover.deleteChoco(choco);

return null;
Expand Down

0 comments on commit dbd89df

Please sign in to comment.