Skip to content

Commit

Permalink
Api-v1.0.2
Browse files Browse the repository at this point in the history
Api-v1.0.2
  • Loading branch information
ImNM authored Mar 5, 2023
2 parents 423f959 + f654986 commit 02db4fa
Show file tree
Hide file tree
Showing 32 changed files with 1,144 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import band.gosrock.api.auth.service.RefreshUseCase;
import band.gosrock.api.auth.service.RegisterUseCase;
import band.gosrock.api.auth.service.WithDrawUseCase;
import band.gosrock.api.auth.service.helper.CookieGenerateHelper;
import band.gosrock.api.auth.service.helper.CookieHelper;
import band.gosrock.api.config.rateLimit.UserRateLimiter;
import band.gosrock.common.annotation.ApiErrorCodeExample;
import band.gosrock.common.annotation.DevelopOnlyApi;
Expand All @@ -26,6 +26,7 @@
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
Expand All @@ -52,7 +53,7 @@ public class AuthController {
private final WithDrawUseCase withDrawUseCase;
private final LogoutUseCase logoutUseCase;

private final CookieGenerateHelper cookieGenerateHelper;
private final CookieHelper cookieHelper;

private final UserRateLimiter rateLimiter;

Expand Down Expand Up @@ -117,7 +118,7 @@ public OauthTokenResponse getCredentialFromKaKao(
public ResponseEntity<TokenAndUserResponse> developUserSign(@RequestParam("code") String code) {
TokenAndUserResponse tokenAndUserResponse = registerUseCase.upsertKakaoOauthUser(code);
return ResponseEntity.ok()
.headers(cookieGenerateHelper.getTokenCookies(tokenAndUserResponse))
.headers(cookieHelper.getTokenCookies(tokenAndUserResponse))
.body(tokenAndUserResponse);
}

Expand All @@ -138,7 +139,7 @@ public ResponseEntity<TokenAndUserResponse> kakaoAuthCheckRegisterValid(
TokenAndUserResponse tokenAndUserResponse =
registerUseCase.registerUserByOCIDToken(token, registerRequest);
return ResponseEntity.ok()
.headers(cookieGenerateHelper.getTokenCookies(tokenAndUserResponse))
.headers(cookieHelper.getTokenCookies(tokenAndUserResponse))
.body(tokenAndUserResponse);
}

Expand All @@ -150,7 +151,7 @@ public ResponseEntity<TokenAndUserResponse> kakaoOauthUserLogin(
@RequestParam("id_token") String token) {
TokenAndUserResponse tokenAndUserResponse = loginUseCase.execute(token);
return ResponseEntity.ok()
.headers(cookieGenerateHelper.getTokenCookies(tokenAndUserResponse))
.headers(cookieHelper.getTokenCookies(tokenAndUserResponse))
.body(tokenAndUserResponse);
}

Expand All @@ -164,24 +165,33 @@ public OauthUserInfoResponse kakaoOauthUserInfo(

@Operation(summary = "refreshToken 용입니다.")
@PostMapping("/token/refresh")
public ResponseEntity<TokenAndUserResponse> tokenRefresh(@RequestParam("token") String code) {
TokenAndUserResponse tokenAndUserResponse = refreshUseCase.execute(code);
public ResponseEntity<TokenAndUserResponse> tokenRefresh(
@CookieValue(value = "refreshToken", required = false) String refreshTokenCookie,
@RequestParam(value = "token", required = false, defaultValue = "")
String refreshToken) {

// 쿠키 우선시해서 리프레쉬.
TokenAndUserResponse tokenAndUserResponse =
refreshUseCase.execute(
refreshTokenCookie != null ? refreshTokenCookie : refreshToken);
return ResponseEntity.ok()
.headers(cookieGenerateHelper.getTokenCookies(tokenAndUserResponse))
.headers(cookieHelper.getTokenCookies(tokenAndUserResponse))
.body(tokenAndUserResponse);
}

@Operation(summary = "회원탈퇴를 합니다.")
@SecurityRequirement(name = "access-token")
@DeleteMapping("/me")
public void withDrawUser() {
public ResponseEntity withDrawUser() {
withDrawUseCase.execute();
return ResponseEntity.ok().headers(cookieHelper.deleteCookies()).body(null);
}

@Operation(summary = "로그아웃을 합니다.")
@SecurityRequirement(name = "access-token")
@PostMapping("/logout")
public void logoutUser() {
public ResponseEntity logoutUser() {
logoutUseCase.execute();
return ResponseEntity.ok().headers(cookieHelper.deleteCookies()).body(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

@Helper
@RequiredArgsConstructor
public class CookieGenerateHelper {
public class CookieHelper {
private final SpringEnvironmentHelper springEnvironmentHelper;

public HttpHeaders getTokenCookies(TokenAndUserResponse tokenAndUserResponse) {
Expand Down Expand Up @@ -41,4 +41,33 @@ public HttpHeaders getTokenCookies(TokenAndUserResponse tokenAndUserResponse) {
httpHeaders.add(HttpHeaders.SET_COOKIE, refreshToken.toString());
return httpHeaders;
}

public HttpHeaders deleteCookies() {
String sameSite = "None";

if (springEnvironmentHelper.isProdProfile()) {
sameSite = "Strict";
}

ResponseCookie accessToken =
ResponseCookie.from("accessToken", null)
.path("/")
.maxAge(0)
.sameSite(sameSite)
// .httpOnly(true)
.secure(true)
.build();
ResponseCookie refreshToken =
ResponseCookie.from("refreshToken", null)
.path("/")
.maxAge(0)
.sameSite(sameSite)
// .httpOnly(true)
.secure(true)
.build();
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.add(HttpHeaders.SET_COOKIE, accessToken.toString());
httpHeaders.add(HttpHeaders.SET_COOKIE, refreshToken.toString());
return httpHeaders;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.io.IOException;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
Expand All @@ -16,6 +17,7 @@
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Component;
import org.springframework.web.filter.OncePerRequestFilter;
import org.springframework.web.util.WebUtils;

@RequiredArgsConstructor
@Component
Expand All @@ -38,6 +40,12 @@ protected void doFilterInternal(
}

private String resolveToken(HttpServletRequest request) {
// 쿠키방식 지원
Cookie accessTokenCookie = WebUtils.getCookie(request, "accessToken");
if (accessTokenCookie != null) {
return accessTokenCookie.getValue();
}
// 기존 jwt 방식 지원
String rawHeader = request.getHeader(DuDoongStatic.AUTH_HEADER);

if (rawHeader != null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class RegisterUserEventHandlerTest {
// given
Profile profile = Profile.builder().build();
OauthInfo oauthInfo = OauthInfo.builder().build();
// BDDMockito.given(userRepository.save(any())).willReturn(null);
// given(registerUserEventHandler.handleRegisterUserEvent(any())).will(new Answer() {
// @Override
// public UserRegisterEvent answer(InvocationOnMock invocation) throws Throwable
Expand Down
1 change: 1 addition & 0 deletions DuDoong-Batch/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ repositories {

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-batch'

implementation project(':DuDoong-Domain')
implementation project(':DuDoong-Common')
implementation project(':DuDoong-Infrastructure')
Expand Down
23 changes: 23 additions & 0 deletions DuDoong-Batch/src/main/java/band/gosrock/dto/SettlementPDFDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package band.gosrock.dto;


import java.time.LocalDateTime;
import lombok.Builder;
import lombok.Getter;

@Builder
@Getter
public class SettlementPDFDto {
private final String eventTitle;
private final String hostName;
private final LocalDateTime settlementAt;
private final String dudoongTicketAmount;
private final String pgTicketAmount;
private final String totalAmount;
private final String dudoongFee;
private final String pgFee;
private final String totalFee;
private final String totalFeeVat;
private final String totalSettlement;
private final LocalDateTime now;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
import band.gosrock.domain.domains.event.domain.Event;
import band.gosrock.domain.domains.order.adaptor.OrderAdaptor;
import band.gosrock.domain.domains.order.domain.Order;
import band.gosrock.domain.domains.settlement.service.EventSettlementDomainService;
import band.gosrock.excel.ExcelOrderDto;
import band.gosrock.excel.ExcelOrderHelper;
import band.gosrock.infrastructure.config.s3.S3PrivateFileUploadService;
import band.gosrock.infrastructure.config.s3.S3PrivateFileService;
import band.gosrock.parameter.EventJobParameter;
import java.io.ByteArrayOutputStream;
import java.util.List;
Expand Down Expand Up @@ -40,12 +39,10 @@ public class EventOrdersToExcel {
private final EventAdaptor eventAdaptor;
private final OrderAdaptor orderAdaptor;

private final EventSettlementDomainService eventSettlementDomainService;

@Qualifier(BEAN_PREFIX + "eventJobParameter")
private final EventJobParameter eventJobParameter;

private final S3PrivateFileUploadService s3PrivateFileUploadService;
private final S3PrivateFileService s3PrivateFileUploadService;

@Bean(BEAN_PREFIX + "eventJobParameter")
@JobScope
Expand Down Expand Up @@ -86,11 +83,13 @@ public Step userStatisticStep() {
workbook.close();

String fileKey =
s3PrivateFileUploadService.excelUpload(
s3PrivateFileUploadService.eventOrdersExcelUpload(
event.getId(), outputStream);
// 이벤트 정산용 엑셀 파일 업로드 정보 저장
eventSettlementDomainService.updateEventOrderListExcelFileKey(
event.getId(), fileKey);
// 파일 키 형식 맞출꺼라서 필요없을듯.
//
// eventSettlementDomainService.updateEventOrderListExcelFileKey(
// event.getId(), fileKey);

return RepeatStatus.FINISHED;
})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package band.gosrock.job;


import band.gosrock.domain.domains.event.adaptor.EventAdaptor;
import band.gosrock.domain.domains.event.domain.Event;
import band.gosrock.domain.domains.host.adaptor.HostAdaptor;
import band.gosrock.domain.domains.host.domain.Host;
import band.gosrock.domain.domains.user.adaptor.UserAdaptor;
import band.gosrock.domain.domains.user.domain.User;
import band.gosrock.infrastructure.config.s3.S3PrivateFileService;
import band.gosrock.infrastructure.config.ses.AwsSesUtils;
import band.gosrock.infrastructure.config.ses.RawEmailAttachmentDto;
import band.gosrock.infrastructure.config.ses.SendRawEmailDto;
import band.gosrock.parameter.EventJobParameter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
import org.springframework.batch.core.configuration.annotation.JobScope;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.thymeleaf.context.Context;
import org.thymeleaf.spring5.SpringTemplateEngine;

@Slf4j
@RequiredArgsConstructor
@Configuration
public class EventSettlementEmailToAdmin {

private static final String JOB_NAME = "이벤트정산_이메일발송_어드민";
private static final String BEAN_PREFIX = JOB_NAME + "_";

private final JobBuilderFactory jobBuilderFactory;
private final StepBuilderFactory stepBuilderFactory;
private final EventAdaptor eventAdaptor;

private final HostAdaptor hostAdaptor;
private final UserAdaptor userAdaptor;

private final SpringTemplateEngine templateEngine;

private final S3PrivateFileService s3PrivateFileUploadService;

private final AwsSesUtils awsSesUtils;

@Bean(BEAN_PREFIX + "eventJobParameter")
@JobScope
public EventJobParameter eventJobParameter() {
return new EventJobParameter(eventAdaptor);
}

@Qualifier(BEAN_PREFIX + "eventJobParameter")
private final EventJobParameter eventJobParameter;

@Bean(JOB_NAME)
public Job slackUserStatisticJob() {
return jobBuilderFactory.get(JOB_NAME).preventRestart().start(userStatisticStep()).build();
}

@Bean(BEAN_PREFIX + "step")
@JobScope
public Step userStatisticStep() {
return stepBuilderFactory
.get(BEAN_PREFIX + "step")
.tasklet(
(contribution, chunkContext) -> {
Event event = eventJobParameter.getEvent();
String eventName = event.getEventBasic().getName();
Long eventId = event.getId();
Host host = hostAdaptor.findById(event.getHostId());
User masterUser = userAdaptor.queryUser(host.getMasterUserId());
byte[] eventSettlementPdf =
s3PrivateFileUploadService.downloadEventSettlementPdf(eventId);
RawEmailAttachmentDto eventSettlementPdfAttachment =
RawEmailAttachmentDto.builder()
.fileName(eventName + "_정산서.pdf")
.fileBytes(eventSettlementPdf)
.type("application/pdf")
.build();

byte[] eventOrderListExcel =
s3PrivateFileUploadService.downloadEventOrdersExcel(eventId);
RawEmailAttachmentDto eventOrderListExcelAttachment =
RawEmailAttachmentDto.builder()
.fileName(eventName + "_주문목록.xlsx")
.fileBytes(eventOrderListExcel)
.type(
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
.build();

SendRawEmailDto sendRawEmailDto =
SendRawEmailDto.builder()
.bodyHtml(
templateEngine.process(
"eventSettlement", new Context()))
.recipient("[email protected]")
.subject(eventName + "공연 정산서 어드민 발송 ( 관리자용 )")
.build();

sendRawEmailDto.addEmailAttachments(eventSettlementPdfAttachment);
sendRawEmailDto.addEmailAttachments(eventOrderListExcelAttachment);

awsSesUtils.sendRawEmails(sendRawEmailDto);
return RepeatStatus.FINISHED;
})
.build();
}
}
Loading

0 comments on commit 02db4fa

Please sign in to comment.