Skip to content
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

Feat/#36 ticket buy #50

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
afb7096
feat : coupon response record ์ถ”๊ฐ€
skfk286 Oct 1, 2024
915c219
feat : coupon entity ์ถ”๊ฐ€
skfk286 Oct 1, 2024
d30d345
Merge branch 'main' into feat/#21-CouponRead
skfk286 Oct 1, 2024
6f0779f
feat : coupon repository ์ถ”๊ฐ€
skfk286 Oct 1, 2024
bfed1d4
feat : coupon controller ์ „์ฒด ์กฐํšŒ ์ถ”๊ฐ€
skfk286 Oct 1, 2024
d758b9f
feat : coupon controller ์ „์ฒด ์กฐํšŒ ์„œ๋น„์Šค ์ถ”๊ฐ€
skfk286 Oct 1, 2024
9b185c7
feat : coupon controller ์ „์ฒด ์กฐํšŒ Query DSL ์ถ”๊ฐ€
skfk286 Oct 1, 2024
cc48dfa
refactor : member email ์— ํ•ด๋‹นํ•˜๋Š” ๋ฉค๋ฒ„ QueryDSL ์กฐํšŒ ์ถ”๊ฐ€
skfk286 Oct 1, 2024
1d840a3
test : Coupon ์ „์ฒด ์กฐํšŒ ์ถ”๊ฐ€
skfk286 Oct 2, 2024
b98374c
Merge branch 'feat/#21-CouponRead' into feat/#36-TicketBuy
skfk286 Oct 2, 2024
63b9838
refactor : ํ‹ฐ์ผ“ ๋ฐœ๊ถŒ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ์— ํ•„์š”ํ•œ ์ƒํƒœ์ฝ”๋“œ ์ถ”๊ฐ€
skfk286 Oct 2, 2024
fe21c25
refactor : ์ฟ ํฐ ์‚ฌ์šฉ ์ƒํƒœ ๋ณ€๊ฒฝ์„ ์œ„ํ•œ setter ์ถ”๊ฐ€
skfk286 Oct 2, 2024
b5feed4
feat : ํ‹ฐ์ผ“ ๋ฐœ๊ถŒ ์ž‘์—… ์ถ”๊ฐ€
skfk286 Oct 2, 2024
d8a4c83
test : ํ‹ฐ์ผ“ ๋ฐœ๊ถŒ ์ž‘์—… ์ถ”๊ฐ€์— ๋Œ€ํ•œ ํ…Œ์ŠคํŠธ ์ฝ”๋“œ ์ž‘์„ฑ
skfk286 Oct 2, 2024
4e9adfe
style : ์ตœ์ƒ์œ„ ์•ฑ ํŒจํ‚ค์ง€ ์ •๋ฆฌ
skfk286 Oct 2, 2024
3f08bce
Merge branch 'main' into feat/#36-TicketBuy
skfk286 Oct 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;

@SpringBootApplication
public class SocialCultureApplication {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.socialculture.platform.coupon.controller;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.socialculture.platform.coupon.dto.response.CouponResponseDto;
import org.socialculture.platform.coupon.service.CouponService;
import org.socialculture.platform.global.apiResponse.ApiResponse;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
* ์ฟ ํฐ ๋ฐ์ดํ„ฐ ์ปจํŠธ๋กค๋Ÿฌ
*
* @author ycjung
*/
@RestController
@RequestMapping("/api/v1/coupons")
@RequiredArgsConstructor
@Slf4j
public class CouponController {
private final CouponService couponService;

@GetMapping
public ResponseEntity<ApiResponse<List<CouponResponseDto>>> getAllCouponsByMemberEmail() {
log.info("Received request to get all coupons by member email");

return ApiResponse.onSuccess(couponService.getAllCouponsByMemberEmail());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.socialculture.platform.coupon.dto.response;

import org.socialculture.platform.coupon.entity.CouponEntity;

import java.time.LocalDateTime;

/**
* Coupon ์— ๋Œ€ํ•œ Response ์ •๋ณด ๋งคํ•‘
*
* @author ycjung
*/
public record CouponResponseDto(
Long couponId,
String name,
int percent,
boolean isUsed,
LocalDateTime expireTime,
LocalDateTime createdAt
) {
// ์ •์  ํŒฉํ† ๋ฆฌ ๋ฉ”์„œ๋“œ of
public static CouponResponseDto of(Long couponId, String name, int percent, boolean isUsed,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ด๊ฑฐ ์ €ํฌ ์ปจ๋ฒค์…˜์ด ํ•„๋“œ๋ฅผ ๋ชจ๋‘ ์‚ฌ์šฉํ•ด์„œ ์ƒ์„ฑํ• ๋•Œ๋Š” create,
2๊ฐœ์ด์ƒ์ด๋ฉด of,
ํ•˜๋‚˜์ผ๋•Œ๋Š” from ์•„๋‹Œ๊ฐ€์—ฌ?
์ €๋„ ํ—ท๊ฐˆ๋ ค์„œ ์—ฌ์ญค๋ด…๋‹ˆ๋‹ค..!

LocalDateTime expireTime, LocalDateTime createdAt) {
return new CouponResponseDto(
couponId,
name,
percent,
isUsed,
expireTime,
createdAt
);
}

// ์—”ํ‹ฐํ‹ฐ๋กœ๋ถ€ํ„ฐ DTO๋ฅผ ์ƒ์„ฑํ•˜๋Š” ๋ฉ”์„œ๋“œ from
public static CouponResponseDto from(CouponEntity couponEntity) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ํ˜น์‹œ ์—ฌ๊ธฐ์„œ request์—์„œ toEntity๋ฅผ ํ•˜๋Š”๊ฒƒ์ฒ˜๋Ÿผ fromEntity๋ผ๊ณ  ํ•˜๋Š”๊ฑด ์–ด๋– ์‹ ๊ฐ€์š”?!

return new CouponResponseDto(
couponEntity.getCouponId(),
couponEntity.getName(),
couponEntity.getPercent(),
couponEntity.isUsed(),
couponEntity.getExpireTime(),
couponEntity.getCreatedAt()
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.socialculture.platform.coupon.entity;

import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import org.socialculture.platform.global.entity.BaseEntity;
import org.socialculture.platform.member.entity.MemberEntity;

import java.time.LocalDateTime;

/**
* ์ฟ ํฐ ์—”ํ‹ฐํ‹ฐ
*
* @author ycjung
*/
@Entity
@Getter
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "coupon")
public class CouponEntity extends BaseEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "coupon_id")
private Long couponId;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member_id", nullable = false)
private MemberEntity member;

@Column(name = "name", nullable = false, length = 30)
private String name;

@Column(name = "percent", nullable = false)
private int percent;

@Column(name = "is_used", nullable = false)
private boolean isUsed;

@Column(name = "expire_time", nullable = false)
private LocalDateTime expireTime;

public void setUsed(boolean used) {
this.isUsed = used;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.socialculture.platform.coupon.repository;

import org.socialculture.platform.coupon.entity.CouponEntity;
import org.socialculture.platform.coupon.repository.querydsl.CouponRepositoryCustom;
import org.springframework.data.jpa.repository.JpaRepository;

/**
* ์ฟ ํฐ ๋ ˆํŒŒ์ง€ํ† ๋ฆฌ
*
* @author ycjung
*/
public interface CouponRepository extends JpaRepository<CouponEntity, Long>, CouponRepositoryCustom {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.socialculture.platform.coupon.repository.querydsl;

import org.socialculture.platform.coupon.dto.response.CouponResponseDto;
import org.socialculture.platform.coupon.entity.CouponEntity;

import java.util.List;

/**
* QueryDSL ์„ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•œ repo
*
* @author ycjung
*/
public interface CouponRepositoryCustom {

List<CouponEntity> getAllCouponsByMemberEmail(String email);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.socialculture.platform.coupon.repository.querydsl;

import com.querydsl.jpa.impl.JPAQueryFactory;
import lombok.RequiredArgsConstructor;
import org.socialculture.platform.coupon.entity.CouponEntity;
import org.socialculture.platform.coupon.entity.QCouponEntity;

import java.util.List;

/**
* QueryDSL ์„ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•œ repo impl
*
* @author ycjung
*/
@RequiredArgsConstructor
public class CouponRepositoryCustomImpl implements CouponRepositoryCustom{

private final JPAQueryFactory jpaQueryFactory;

@Override
public List<CouponEntity> getAllCouponsByMemberEmail(String email) {
QCouponEntity couponEntity = QCouponEntity.couponEntity;

return jpaQueryFactory.selectFrom(couponEntity)
.where(couponEntity.member.email.eq(email))
.fetch();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.socialculture.platform.coupon.service;

import org.socialculture.platform.coupon.dto.response.CouponResponseDto;

import java.util.List;

/**
* ์ฟ ํฐ ์„œ๋น„์Šค ์ธํ„ฐํŽ˜์ด์Šค
*
* @author ycjung
*/
public interface CouponService {

List<CouponResponseDto> getAllCouponsByMemberEmail();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.socialculture.platform.coupon.service;

import lombok.RequiredArgsConstructor;
import org.socialculture.platform.coupon.dto.response.CouponResponseDto;
import org.socialculture.platform.coupon.repository.CouponRepository;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
* ์ฟ ํฐ ์„œ๋น„์Šค ๊ตฌํ˜„์ฒด
*
* @author ycjung
*/
@Service
@RequiredArgsConstructor
public class CouponServiceImpl implements CouponService {

private final CouponRepository couponRepository;

private static String MEMBER_EMAIL = "[email protected]"; // ์ž„์‹œ ๋ฉ”์ผ ํ…Œ์ŠคํŠธ -> ํ† ํฐ ๋ฐœํ–‰๋˜๋ฉด ์ˆ˜์ •

@Override
public List<CouponResponseDto> getAllCouponsByMemberEmail() {

return couponRepository.getAllCouponsByMemberEmail(MEMBER_EMAIL)
.stream()
.map(CouponResponseDto::from)
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ public enum ErrorStatus implements BaseErrorCode{
_TICKET_INVALID_SORT_OPTION(HttpStatus.BAD_REQUEST, "TICKET400", "์ž˜๋ชป๋œ ์ •๋ ฌ ์˜ต์…˜์ž…๋‹ˆ๋‹ค. ํ—ˆ์šฉ๋œ ๊ฐ’์€ 'ticketId', 'price', 'expired'์ž…๋‹ˆ๋‹ค."),
_TICKET_INVALID_PAGINATION_PARAMETERS(HttpStatus.BAD_REQUEST, "TICKET400", "ํŽ˜์ด์ง€๋‚˜ ํฌ๊ธฐ ๊ฐ’์ด ์œ ํšจํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. 0 ์ด์ƒ์˜ ๊ฐ’์„ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."),

// ์ฟ ํฐ
_COUPON_NOT_FOUND(HttpStatus.NOT_FOUND, "TICKET400", "ํ•ด๋‹น ์ฟ ํฐ์„ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์š”๊ธฐ COUPON404 ์–ด๋–ค๊ฐ€์—ฌ?

Copy link
Collaborator Author

@skfk286 skfk286 Oct 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

404 ๋Š” ์‚ฌ์šฉ์ž๊ฐ€ ์กด์žฌํ•˜์ง€ ์•Š๋Š” URL ์— ์ ‘์† ํ–ˆ์„ ๋•Œ ๋‚˜๋Š” ์—๋Ÿฌ๋กœ ์•Œ๊ณ  ์žˆ๋Š”๋ฐ, 400 BadRequest ๊ฐ€ ๊ดœ์ฐฎ์ง€ ์•Š์„๊นŒ์š” ?

_COUPON_ALREADY_USED(HttpStatus.BAD_REQUEST, "COUPON400", "์ด๋ฏธ ์‚ฌ์šฉ๋œ ์ฟ ํฐ์ž…๋‹ˆ๋‹ค."),
_COUPON_EXPIRED(HttpStatus.BAD_REQUEST, "COUPON400", "๋งŒ๋ฃŒ๋œ ์ฟ ํฐ์ž…๋‹ˆ๋‹ค."),

// ์œ ์ € ๊ด€๋ จ ์—๋Ÿฌ
LOGIN_FAIL(HttpStatus.UNAUTHORIZED, "MEMBER4001", "๋กœ๊ทธ์ธ์— ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค."),

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package org.socialculture.platform.ticket.controller;

import jakarta.annotation.Nullable;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.socialculture.platform.global.apiResponse.ApiResponse;
import org.socialculture.platform.global.apiResponse.exception.ErrorStatus;
import org.socialculture.platform.global.apiResponse.exception.GeneralException;
import org.socialculture.platform.ticket.dto.request.TicketRequestDto;
import org.socialculture.platform.ticket.dto.response.TicketResponseDto;
import org.socialculture.platform.ticket.service.TicketService;
import org.springframework.http.ResponseEntity;
Expand All @@ -30,6 +28,7 @@ public class TicketController {

/**
* ๋‚˜์˜ ํ‹ฐ์ผ“ ์ „์ฒด ์กฐํšŒ - ํŽ˜์ด์ง• ์ฒ˜๋ฆฌ
*
* @param page
* @param size
* @param option
Expand All @@ -54,6 +53,7 @@ public ResponseEntity<ApiResponse<List<TicketResponseDto>>> getAllTicketsByMembe

/**
* ๋‚˜์˜ ํ‹ฐ์ผ“ ์ƒ์„ธ ์กฐํšŒ
*
* @param ticketId
* @return
*/
Expand All @@ -66,4 +66,11 @@ public ResponseEntity<ApiResponse<TicketResponseDto>> getTicketById(@PathVariabl
}
return ApiResponse.onSuccess(ticketService.getTicketByEmailAndTicketId(ticketId));
}

@PostMapping
public ResponseEntity<ApiResponse<TicketResponseDto>> buyTicket(@RequestBody TicketRequestDto ticketRequestDto) {
log.info("Buy ticket: {}", ticketRequestDto);

return ApiResponse.onSuccess(ticketService.registerticket(ticketRequestDto));
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package org.socialculture.platform.ticket.service;

import org.socialculture.platform.ticket.dto.request.TicketRequestDto;
import org.socialculture.platform.ticket.dto.response.TicketResponseDto;

import java.util.List;

/**
* ํ‹ฐ์ผ“ ์„œ๋น„์Šค ์ธํ„ฐํŽ˜์ด์Šค
*
*
* @author ycjung
*/
public interface TicketService {
Expand All @@ -16,7 +17,7 @@ public interface TicketService {
// ์ƒ์„ธ ์กฐํšŒ
TicketResponseDto getTicketByEmailAndTicketId(Long ticketId);

// TicketResponse createTicket(Long memberId, TicketRequest ticketRequest);
TicketResponseDto registerticket(TicketRequestDto ticketRequest);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์นด๋ฉœ์ผ€์ด์Šค ์ ์šฉํ•ด์„œ registerTicket์œผ๋กœ ํ•˜์‹œ๋Š”๊ฒŒ ์–ด๋– ์‹ ๊ฐ€์š”??!

Copy link
Collaborator Author

@skfk286 skfk286 Oct 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋„ค์ด๋ฐ ์‹ค์ˆ˜ํ–ˆ๋„ค์š”. ์ฒดํฌ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค!


// TicketResponse updateTicket(Long id, TicketRequest ticketRequest);

Expand Down
Loading