-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: main
Are you sure you want to change the base?
Changes from all commits
afb7096
915c219
d30d345
6f0779f
bfed1d4
d758b9f
9b185c7
cc48dfa
1d840a3
b98374c
63b9838
fe21c25
b5feed4
d8a4c83
4e9adfe
3f08bce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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, | ||
LocalDateTime expireTime, LocalDateTime createdAt) { | ||
return new CouponResponseDto( | ||
couponId, | ||
name, | ||
percent, | ||
isUsed, | ||
expireTime, | ||
createdAt | ||
); | ||
} | ||
|
||
// ์ํฐํฐ๋ก๋ถํฐ DTO๋ฅผ ์์ฑํ๋ ๋ฉ์๋ from | ||
public static CouponResponseDto from(CouponEntity couponEntity) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
---|---|---|
|
@@ -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", "ํด๋น ์ฟ ํฐ์ ์ฐพ์ ์ ์์ต๋๋ค."), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ์๊ธฐ COUPON404 ์ด๋ค๊ฐ์ฌ? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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", "๋ก๊ทธ์ธ์ ์คํจํ์ต๋๋ค."), | ||
|
||
|
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 { | ||
|
@@ -16,7 +17,7 @@ public interface TicketService { | |
// ์์ธ ์กฐํ | ||
TicketResponseDto getTicketByEmailAndTicketId(Long ticketId); | ||
|
||
// TicketResponse createTicket(Long memberId, TicketRequest ticketRequest); | ||
TicketResponseDto registerticket(TicketRequestDto ticketRequest); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ์นด๋ฉ์ผ์ด์ค ์ ์ฉํด์ registerTicket์ผ๋ก ํ์๋๊ฒ ์ด๋ ์ ๊ฐ์??! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ๋ค์ด๋ฐ ์ค์ํ๋ค์. ์ฒดํฌ ๊ฐ์ฌํฉ๋๋ค! |
||
|
||
// TicketResponse updateTicket(Long id, TicketRequest ticketRequest); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์ด๊ฑฐ ์ ํฌ ์ปจ๋ฒค์ ์ด ํ๋๋ฅผ ๋ชจ๋ ์ฌ์ฉํด์ ์์ฑํ ๋๋ create,
2๊ฐ์ด์์ด๋ฉด of,
ํ๋์ผ๋๋ from ์๋๊ฐ์ฌ?
์ ๋ ํท๊ฐ๋ ค์ ์ฌ์ญค๋ด ๋๋ค..!