Skip to content

Commit

Permalink
πŸš€ :: Api-v0.0.3-1
Browse files Browse the repository at this point in the history
πŸš€ :: Api-v0.0.3-1
  • Loading branch information
ImNM authored Jan 13, 2023
2 parents 3caeb41 + 3ee9b8c commit 393bb5c
Show file tree
Hide file tree
Showing 19 changed files with 193 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,14 @@ public OauthTokenResponse getCredentialFromKaKao(
@Tag(name = "카카였 oauth")
@DevelopOnlyApi
@GetMapping("/oauth/kakao/develop")
public ResponseEntity<TokenAndUserResponse> developUserSign(@RequestParam("code") String code) {
public ResponseEntity<TokenAndUserResponse> developUserSign(
@RequestParam("code") String code,
@RequestHeader(value = "referer", required = false, defaultValue = "localhost")
String referer,
@RequestHeader(value = "host", required = false) String host) {
TokenAndUserResponse tokenAndUserResponse = registerUseCase.upsertKakaoOauthUser(code);
return ResponseEntity.ok()
.headers(cookieGenerateHelper.getTokenCookies(tokenAndUserResponse))
.headers(cookieGenerateHelper.getTokenCookies(tokenAndUserResponse, referer, host))
.body(tokenAndUserResponse);
}

Expand All @@ -115,11 +119,13 @@ public AvailableRegisterResponse kakaoAuthCheckRegisterValid(
@PostMapping("/oauth/kakao/register")
public ResponseEntity<TokenAndUserResponse> kakaoAuthCheckRegisterValid(
@RequestParam("id_token") String token,
@Valid @RequestBody RegisterRequest registerRequest) {
@Valid @RequestBody RegisterRequest registerRequest,
@RequestHeader(value = "referer", required = false) String referer,
@RequestHeader(value = "host", required = false) String host) {
TokenAndUserResponse tokenAndUserResponse =
registerUseCase.registerUserByOCIDToken(token, registerRequest);
return ResponseEntity.ok()
.headers(cookieGenerateHelper.getTokenCookies(tokenAndUserResponse))
.headers(cookieGenerateHelper.getTokenCookies(tokenAndUserResponse, referer, host))
.body(tokenAndUserResponse);
}

Expand All @@ -128,10 +134,12 @@ public ResponseEntity<TokenAndUserResponse> kakaoAuthCheckRegisterValid(
@Tag(name = "카카였 oauth")
@PostMapping("/oauth/kakao/login")
public ResponseEntity<TokenAndUserResponse> kakaoOauthUserLogin(
@RequestParam("id_token") String token) {
@RequestParam("id_token") String token,
@RequestHeader(value = "referer", required = false) String referer,
@RequestHeader(value = "host", required = false) String host) {
TokenAndUserResponse tokenAndUserResponse = loginUseCase.execute(token);
return ResponseEntity.ok()
.headers(cookieGenerateHelper.getTokenCookies(tokenAndUserResponse))
.headers(cookieGenerateHelper.getTokenCookies(tokenAndUserResponse, referer, host))
.body(tokenAndUserResponse);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,34 @@
public class CookieGenerateHelper {
private final Environment env;

public HttpHeaders getTokenCookies(TokenAndUserResponse tokenAndUserResponse) {
public HttpHeaders getTokenCookies(
TokenAndUserResponse tokenAndUserResponse, String referer, String host) {
String[] activeProfiles = env.getActiveProfiles();
String sameSite = "None";

if (Arrays.stream(activeProfiles).toList().contains("prod")) {
sameSite = "Strict";
}
String domain = "localhost";
if (referer.contains(host)) {
domain = host;
}

ResponseCookie accessToken =
ResponseCookie.from("accessToken", tokenAndUserResponse.getAccessToken())
.path("/")
.maxAge(tokenAndUserResponse.getAccessTokenAge())
.sameSite(sameSite)
.httpOnly(true)
.domain(domain)
.secure(true)
.build();
ResponseCookie refreshToken =
ResponseCookie.from("refreshToken", tokenAndUserResponse.getRefreshToken())
.path("/")
.maxAge(tokenAndUserResponse.getRefreshTokenAge())
.sameSite(sameSite)
.domain(domain)
.httpOnly(true)
.secure(true)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public class AdminIssuedTicketController {
public RetrieveIssuedTicketListResponse getIssuedTickets(
@RequestParam Long page,
@RequestParam Long eventId,
@RequestParam(required = false) String userName) {
return readIssuedTicketsUseCase.execute(page, eventId, userName);
@RequestParam(required = false) String userName,
@RequestParam(required = false) String phoneNumber) {
return readIssuedTicketsUseCase.execute(page, eventId, userName, phoneNumber);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class RetrieveIssuedTicketDTO {
private final UserInfoVo userInfo;

public RetrieveIssuedTicketDTO(IssuedTicket issuedTicket, User user) {
this.issuedTicketInfo = new IssuedTicketInfoVo(issuedTicket);
this.userInfo = new UserInfoVo(user);
this.issuedTicketInfo = issuedTicket.toIssuedTicketInfoVo(issuedTicket);
this.userInfo = user.toUserInfoVo(user);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ public class ReadIssuedTicketsUseCase {
* 둜직이 λ„ˆλ¬΄ λ³΅μž‘ν•΄μ§ => 일단 연관관계 맀핑 걸어두고 λ‚˜μ€‘μ— QueryDsl μ„€μ • λ“€μ–΄μ˜€λ©΄ λ°”κΏ”μ•Ό ν•  λ“―
*/
@Transactional(readOnly = true)
public RetrieveIssuedTicketListResponse execute(Long page, Long eventId, String userName) {
public RetrieveIssuedTicketListResponse execute(
Long page, Long eventId, String userName, String phoneNumber) {
Long currentUserId = SecurityUtils.getCurrentUserId();
// 쑰회 μœ μ € κΆŒν•œ 인증
eventService.checkEventHost(currentUserId, eventId);
Page<IssuedTicket> issuedTickets =
issuedTicketDomainService.retrieveIssuedTickets(page, eventId, userName);
issuedTicketDomainService.retrieveIssuedTickets(
page, eventId, userName, phoneNumber);
return new RetrieveIssuedTicketListResponse(
page,
(long) issuedTickets.getTotalPages(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public enum ErrorCode implements BaseErrorCode {
ORDER_CANNOT_CANCEL(BAD_REQUEST, "Order-404-3", "주문을 μ·¨μ†Œν•  수 μ—†λŠ” μƒνƒœμž…λ‹ˆλ‹€."),
ORDER_CANNOT_REFUND(BAD_REQUEST, "Order-404-4", "주문을 ν™˜λΆˆν•  수 μ—†λŠ” μƒνƒœμž…λ‹ˆλ‹€."),
EVENT_NOT_FOUND(NOT_FOUND, "Event-404-1", "Event Not Found"),
Host_NOT_AUTH_EVENT(FORBIDDEN, "Event-403-1", "Host Not Auth Event");
HOST_NOT_AUTH_EVENT(FORBIDDEN, "Event-403-1", "Host Not Auth Event");
private int status;
private String code;
private String reason;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
import band.gosrock.domain.domains.issuedTicket.domain.IssuedTicketStatus;
import com.fasterxml.jackson.annotation.JsonFormat;
import java.time.LocalDateTime;
import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
public class IssuedTicketInfoVo {

/*
Expand Down Expand Up @@ -54,14 +56,16 @@ public class IssuedTicketInfoVo {
*/
private final Money optionPrice;

public IssuedTicketInfoVo(IssuedTicket issuedTicket) {
this.issuedTicketId = issuedTicket.getId();
this.issuedTicketNo = issuedTicket.getIssuedTicketNo();
this.uuid = issuedTicket.getUuid();
this.ticketName = issuedTicket.getTicketItem().getName();
this.ticketPrice = issuedTicket.getTicketItem().getPrice();
this.createdAt = issuedTicket.getCreatedAt();
this.issuedTicketStatus = issuedTicket.getIssuedTicketStatus();
this.optionPrice = issuedTicket.sumOptionPrice();
public static IssuedTicketInfoVo from(IssuedTicket issuedTicket) {
return IssuedTicketInfoVo.builder()
.issuedTicketId(issuedTicket.getId())
.issuedTicketNo(issuedTicket.getIssuedTicketNo())
.uuid(issuedTicket.getUuid())
.ticketName(issuedTicket.getTicketItem().getName())
.ticketPrice(issuedTicket.getPrice())
.createdAt(issuedTicket.getCreatedAt())
.issuedTicketStatus(issuedTicket.getIssuedTicketStatus())
.optionPrice(issuedTicket.sumOptionPrice())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@


import band.gosrock.domain.domains.user.domain.User;
import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
public class UserInfoVo {

private final Long userId;
Expand All @@ -15,10 +17,15 @@ public class UserInfoVo {

private final String phoneNumber;

public UserInfoVo(User user) {
this.userId = user.getId();
this.userName = user.getProfile().getName();
this.email = user.getProfile().getEmail();
this.phoneNumber = user.getProfile().getPhoneNumber();
private final String profileImage;

public static UserInfoVo from(User user) {
return UserInfoVo.builder()
.userId(user.getId())
.userName(user.getProfile().getName())
.email(user.getProfile().getEmail())
.profileImage(user.getProfile().getProfileImage())
.phoneNumber(user.getProfile().getPhoneNumber())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ public class HostNotAuthEventException extends DuDoongCodeException {
public static final DuDoongCodeException EXCEPTION = new HostNotAuthEventException();

private HostNotAuthEventException() {
super(ErrorCode.Host_NOT_AUTH_EVENT);
super(ErrorCode.HOST_NOT_AUTH_EVENT);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import band.gosrock.domain.domains.event.domain.Event;
import band.gosrock.domain.domains.event.exception.HostNotAuthEventException;
import band.gosrock.domain.domains.event.repository.EventRepository;
import java.util.Objects;
import lombok.RequiredArgsConstructor;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -19,7 +18,7 @@ public class EventService {

public void checkEventHost(Long hostId, Long eventId) {
Event event = eventAdaptor.findById(eventId);
if (!Objects.equals(event.getHostId(), hostId)) {
if (!event.getHostId().equals(hostId)) {
throw HostNotAuthEventException.EXCEPTION;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ public IssuedTicket save(IssuedTicket issuedTicket) {
return issuedTicketRepository.save(issuedTicket);
}

public void saveAll(List<IssuedTicket> issuedTickets) {
issuedTicketRepository.saveAll(issuedTickets);
}

public List<IssuedTicket> findAllByOrderLineId(Long orderLineId) {
return issuedTicketRepository.findAllByOrderLineId(orderLineId);
}
Expand All @@ -39,4 +43,10 @@ public Page<IssuedTicket> findAllByEventAndUserName(
return issuedTicketRepository.findAllByEvent_IdAndUser_Profile_NameContaining(
eventId, userName, pageRequest);
}

public Page<IssuedTicket> findAllByEventAndUserPhoneNumber(
PageRequest pageRequest, Long eventId, String phoneNumber) {
return issuedTicketRepository.findAllByEvent_IdAndUser_Profile_PhoneNumberContaining(
eventId, phoneNumber, pageRequest);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@


import band.gosrock.domain.common.model.BaseTimeEntity;
import band.gosrock.domain.common.vo.IssuedTicketInfoVo;
import band.gosrock.domain.common.vo.Money;
import band.gosrock.domain.domains.event.domain.Event;
import band.gosrock.domain.domains.issuedTicket.dto.request.CreateIssuedTicketDTO;
import band.gosrock.domain.domains.issuedTicket.dto.request.CreateIssuedTicketRequest;
import band.gosrock.domain.domains.issuedTicket.dto.response.CreateIssuedTicketResponse;
import band.gosrock.domain.domains.ticket_item.domain.TicketItem;
import band.gosrock.domain.domains.user.domain.User;
import java.util.ArrayList;
Expand Down Expand Up @@ -87,7 +90,7 @@ public void addOptionAnswers(List<IssuedTicketOptionAnswer> answers) {
/*
λ°œκΈ‰ ν‹°μΌ“ 가격
*/
private Long price;
private Money price;

/*
μƒνƒœ
Expand All @@ -105,7 +108,7 @@ public IssuedTicket(
User user,
Long orderLineId,
TicketItem ticketItem,
Long price,
Money price,
IssuedTicketStatus issuedTicketStatus,
List<IssuedTicketOptionAnswer> issuedTicketOptionAnswers) {
this.event = event;
Expand Down Expand Up @@ -139,7 +142,6 @@ public void createIssuedTicketNo() {
this.issuedTicketNo = "T" + this.id;
}

// todo: μ˜΅μ…˜ 정리
public Money sumOptionPrice() {
// issuedTicketOptionAnswers.forEach(issuedTicketOptionAnswer -> {
// this.optionPrice = this.optionPrice.plus(issuedTicketOptionAnswer.getOption()
Expand All @@ -151,4 +153,31 @@ public Money sumOptionPrice() {
issuedTicketOptionAnswer.getOption().getAdditionalPrice())
.reduce(Money.ZERO, Money::plus);
}

public IssuedTicketInfoVo toIssuedTicketInfoVo(IssuedTicket issuedTicket) {
return IssuedTicketInfoVo.from(issuedTicket);
}

public static CreateIssuedTicketResponse orderLineItemToIssuedTickets(
CreateIssuedTicketDTO dto) {
long quantity = dto.getOrderLineItem().getQuantity();
List<IssuedTicket> createIssuedTickets = new ArrayList<>();
List<IssuedTicketOptionAnswer> issuedTicketOptionAnswers =
dto.getOrderLineItem().getOrderOptionAnswer().stream()
.map(IssuedTicketOptionAnswer::orderOptionAnswerToIssuedTicketOptionAnswer)
.toList();
for (long i = 1; i <= quantity; i++) {
createIssuedTickets.add(
IssuedTicket.builder()
.event(dto.getOrderLineItem().getTicketItem().getEvent())
.orderLineId(dto.getOrderLineItem().getId())
.user(dto.getUser())
.price(dto.getOrderLineItem().getTicketItem().getPrice())
.ticketItem(dto.getOrderLineItem().getTicketItem())
.issuedTicketStatus(IssuedTicketStatus.ENTRANCE_INCOMPLETE)
.issuedTicketOptionAnswers(issuedTicketOptionAnswers)
.build());
}
return new CreateIssuedTicketResponse(createIssuedTickets, issuedTicketOptionAnswers);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package band.gosrock.domain.domains.issuedTicket.dto.request;


import band.gosrock.domain.domains.order.domain.Order;
import band.gosrock.domain.domains.order.domain.OrderLineItem;
import band.gosrock.domain.domains.user.domain.User;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
public class CreateIssuedTicketDTO {

private final Order order;

private final OrderLineItem orderLineItem;

private final User user;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package band.gosrock.domain.domains.issuedTicket.dto.request;


import band.gosrock.domain.common.vo.Money;
import band.gosrock.domain.domains.event.domain.Event;
import band.gosrock.domain.domains.order.domain.OrderOptionAnswer;
import band.gosrock.domain.domains.ticket_item.domain.TicketItem;
Expand All @@ -21,7 +22,7 @@ public class CreateIssuedTicketRequest {
/*
λ°œκΈ‰ ν‹°μΌ“μ˜ orderline id
*/
private Long orderLineId;
private final Long orderLineId;

/*
ν‹°μΌ“ λ°œκΈ‰ν•œ μœ μ € id
Expand All @@ -31,7 +32,7 @@ public class CreateIssuedTicketRequest {
/*
λ°œκΈ‰ ν‹°μΌ“ 가격
*/
private final Long price;
private final Money price;

/*
λ°œκΈ‰ ν‹°μΌ“μ˜ ν‹°μΌ“ itemId (λ°œκΈ‰ ν‹°μΌ“μ˜ μ’…λ₯˜)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
package band.gosrock.domain.domains.issuedTicket.dto.response;


import band.gosrock.domain.domains.issuedTicket.domain.IssuedTicket;
import band.gosrock.domain.domains.issuedTicket.domain.IssuedTicketOptionAnswer;
import java.util.List;
import lombok.Getter;

@Getter
public class CreateIssuedTicketResponse {

private final List<IssuedTicketDTO> issuedTickets;
private final List<IssuedTicket> issuedTickets;

public CreateIssuedTicketResponse(List<IssuedTicketDTO> issuedTickets) {
private final List<IssuedTicketOptionAnswer> issuedTicketOptionAnswers;

public CreateIssuedTicketResponse(
List<IssuedTicket> issuedTickets,
List<IssuedTicketOptionAnswer> issuedTicketOptionAnswers) {
this.issuedTickets = issuedTickets;
this.issuedTicketOptionAnswers = issuedTicketOptionAnswers;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class IssuedTicketDTO {
private final EventInfoVo eventInfo;

public IssuedTicketDTO(IssuedTicket issuedTicket) {
this.issuedTicketInfo = new IssuedTicketInfoVo(issuedTicket);
this.issuedTicketInfo = issuedTicket.toIssuedTicketInfoVo(issuedTicket);
this.eventInfo = new EventInfoVo(issuedTicket.getEvent());
}
}
Loading

0 comments on commit 393bb5c

Please sign in to comment.