Skip to content

Commit

Permalink
Merge pull request #184 from nhnacademy-be5-T3Team/feature/coupon
Browse files Browse the repository at this point in the history
마이페이지, 관리자페이지, 상세보기 쿠폰 개발
  • Loading branch information
joohyun1996 authored May 16, 2024
2 parents c5d79fa + b6ecc76 commit 1410958
Show file tree
Hide file tree
Showing 27 changed files with 468 additions and 14 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/feature-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: feature-test
on:
push:
branches:
- 'feature/**'
- ' feature/**'
jobs:
build:
runs-on: ubuntu-latest
Expand All @@ -21,6 +21,6 @@ jobs:
java-version: '11'
distribution: 'temurin'
cache: maven

- name: test with Maven
run: mvn test ${{ secrets.MAVEN_PACKAGE_OPTIONS }}
8 changes: 8 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,14 @@
<artifactId>dooray-hook-sender</artifactId>
<version>1.2.0-RELEASE</version>
</dependency>
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-okhttp</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
import com.t3t.bookstoreapi.book.model.dto.ParticipantMapDto;
import com.t3t.bookstoreapi.book.model.request.BookRegisterRequest;
import com.t3t.bookstoreapi.book.model.request.ModifyBookDetailRequest;
import com.t3t.bookstoreapi.book.model.response.BookCouponResponse;
import com.t3t.bookstoreapi.book.model.response.BookDetailResponse;
import com.t3t.bookstoreapi.book.model.response.BookListResponse;
import com.t3t.bookstoreapi.book.service.BookService;
import com.t3t.bookstoreapi.model.response.BaseResponse;
import com.t3t.bookstoreapi.model.response.PageResponse;
import lombok.RequiredArgsConstructor;

import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
Expand Down Expand Up @@ -224,4 +224,22 @@ public ResponseEntity<BaseResponse<Void>> deleteBook(@PathVariable Long bookId)
return ResponseEntity.status(HttpStatus.OK).body(
new BaseResponse<Void>().message("도서 삭제 요청이 정상적으로 처리되었습니다."));
}

/**
* 현재 BookList의 Id를 조회
* @author joohyun1996(이주현)
*/
@GetMapping("/books/coupons")
public ResponseEntity<BaseResponse<List<BookCouponResponse>>> getAllBookId(){
return ResponseEntity.status(HttpStatus.OK).body(new BaseResponse<List<BookCouponResponse>>().data(bookService.getAllBooksId()));
}

/**
* 특정 책의 id값 조회
* @author joohyun1996(이주현)
*/
@GetMapping("/books/{bookId}/coupons")
public ResponseEntity<BaseResponse<BookCouponResponse>> getBookId(@PathVariable("bookId") Long bookId){
return ResponseEntity.status(HttpStatus.OK).body(new BaseResponse<BookCouponResponse>().data(bookService.getBookId(bookId)));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.t3t.bookstoreapi.book.model.response;

import lombok.*;

@Builder@Getter
@EqualsAndHashCode
@NoArgsConstructor
@AllArgsConstructor
public class BookCouponResponse {
private long bookId;
}
34 changes: 33 additions & 1 deletion src/main/java/com/t3t/bookstoreapi/book/service/BookService.java
Original file line number Diff line number Diff line change
Expand Up @@ -403,4 +403,36 @@ public void deleteBook(Long bookId) {
}
book.updateIsDeleted(TableStatus.TRUE);
}
}
/**
* 업로드할 파일의 이름을 생성
*
* @param file 업로드할 파일
* @return 생성된 파일 이름
* @author Yujin-nKim(김유진)
*/
public String generateUploadFileName(MultipartFile file) {
UUID uuid = UUID.randomUUID(); // UUID 생성
String originalFilename = file.getOriginalFilename(); // 파일의 원본 이름 가져오기
String fileExtension = originalFilename.substring(originalFilename.lastIndexOf(".")); // 파일 확장자 가져오기
return uuid.toString() + fileExtension; // 생성된 UUID와 확장자를 결합하여 파일 이름 반환
}

/**
* 책 목록 전체의 id 값 조회
* @author joohyun1996(이주현)
*/
public List<BookCouponResponse> getAllBooksId(){
List<Book> bookList = bookRepository.findAll();
return bookList.stream()
.map(book -> new BookCouponResponse(book.getBookId()))
.collect(Collectors.toList());
}
/**
* 특정 책의 Id값 조회
* @author joohyun1996(이주현)
*/
public BookCouponResponse getBookId(Long bookId){
Book book = bookRepository.findByBookId(bookId).orElseThrow(() -> new BookNotFoundException());
return BookCouponResponse.builder().bookId(book.getBookId()).build();
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package com.t3t.bookstoreapi.category.controller;

import com.t3t.bookstoreapi.category.model.response.CategoryIdResponse;
import com.t3t.bookstoreapi.category.model.response.CategoryTreeResponse;
import com.t3t.bookstoreapi.category.service.CategoryService;
import com.t3t.bookstoreapi.model.response.BaseResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.Min;
import java.util.List;
Expand Down Expand Up @@ -45,4 +49,13 @@ public ResponseEntity<BaseResponse<List<CategoryTreeResponse>>> getCategoryTreeB
return ResponseEntity.status(HttpStatus.OK).body(
new BaseResponse<List<CategoryTreeResponse>>().data(categoryList));
}

/**
* 카테고리 리스트의 id값을 조회
* @author joohyun1996(이주현)
*/
@GetMapping("/categories/{categoryId}/coupons")
public ResponseEntity<BaseResponse<CategoryIdResponse>> getGategoryId(@PathVariable("categoryId") Integer id){
return ResponseEntity.status(HttpStatus.OK).body(new BaseResponse<CategoryIdResponse>().data(categoryService.getCategoryId(id)));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.t3t.bookstoreapi.category.model.response;

import lombok.*;

@Builder
@Getter@ToString
@EqualsAndHashCode
@NoArgsConstructor
@AllArgsConstructor
public class CategoryIdResponse {
private Integer categoryId;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.t3t.bookstoreapi.category.service;

import com.t3t.bookstoreapi.category.exception.CategoryNotFoundException;
import com.t3t.bookstoreapi.category.model.entity.Category;
import com.t3t.bookstoreapi.category.model.response.CategoryIdResponse;
import com.t3t.bookstoreapi.category.model.response.CategoryTreeResponse;
import com.t3t.bookstoreapi.category.repository.CategoryRepository;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -80,4 +82,13 @@ private void buildTree(CategoryTreeResponse parentCategory, List<CategoryTreeRes
}
}
}

/**
* category Id를 조회하는 메소드
* @author joohyun1996(이주현)
*/
public CategoryIdResponse getCategoryId(Integer id){
Category category = categoryRepository.findById(id).orElseThrow(() -> new CategoryNotFoundException());
return CategoryIdResponse.builder().categoryId(category.getCategoryId()).build();
}
}
9 changes: 9 additions & 0 deletions src/main/java/com/t3t/bookstoreapi/config/FeignConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.t3t.bookstoreapi.config;

import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableFeignClients(basePackages ="com.t3t.bookstoreapi")
public class FeignConfig {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.t3t.bookstoreapi.coupon.adapter;

import com.t3t.bookstoreapi.coupon.client.CouponApiClient;
import com.t3t.bookstoreapi.coupon.exception.CouponApiClientException;
import com.t3t.bookstoreapi.coupon.model.request.CouponIdRequest;
import com.t3t.bookstoreapi.coupon.model.response.CouponResponse;
import com.t3t.bookstoreapi.model.response.BaseResponse;
import feign.FeignException;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.Optional;

@Component
@RequiredArgsConstructor
public class CouponAdapter {
private final CouponApiClient couponApiClient;

public CouponResponse getGeneralCoupon(){
try{
return Optional.ofNullable(couponApiClient.getGeneralCoupon().getBody())
.map(BaseResponse::getData)
.orElseThrow(CouponApiClientException::new);
}catch (FeignException e){
throw new CouponApiClientException();
}
}

public CouponResponse getBookCoupon(){
try{
return Optional.ofNullable(couponApiClient.getBookCoupon().getBody())
.map(BaseResponse::getData)
.orElseThrow(CouponApiClientException::new);
}catch (FeignException e){
throw new CouponApiClientException();
}
}

public CouponResponse getCategoryCoupon(){
try{
return Optional.ofNullable(couponApiClient.getCategoryCoupon().getBody())
.map(BaseResponse::getData)
.orElseThrow(CouponApiClientException::new);
}catch (FeignException e){
throw new CouponApiClientException();
}
}

public void deleteBookCouponServer(CouponIdRequest request){
try{
couponApiClient.deleteBookCoupon(request);
}catch (FeignException e){
throw new CouponApiClientException();
}
}

public void deleteCategoryCouponServer(CouponIdRequest request){
try{
couponApiClient.deleteCategoryCoupon(request);
}catch (FeignException e){
throw new CouponApiClientException();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.t3t.bookstoreapi.coupon.client;

import com.t3t.bookstoreapi.coupon.model.request.CouponIdRequest;
import com.t3t.bookstoreapi.coupon.model.response.CouponResponse;
import com.t3t.bookstoreapi.model.response.BaseResponse;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;

@FeignClient(name = "CouponApiClient", url = "${t3t.feignClient.url}")
public interface CouponApiClient {
@GetMapping("/t3t/coupon/coupons/book")
ResponseEntity<BaseResponse<CouponResponse>> getBookCoupon();

@GetMapping("/t3t/coupon/coupons/category")
ResponseEntity<BaseResponse<CouponResponse>> getCategoryCoupon();

@GetMapping("/t3t/coupon/coupons/general")
ResponseEntity<BaseResponse<CouponResponse>> getGeneralCoupon();

@PutMapping("/t3t/coupon/coupons/book")
ResponseEntity<BaseResponse<Void>> deleteBookCoupon(@RequestBody CouponIdRequest request);

@PutMapping("/t3t/coupon/coupons/category")
ResponseEntity<BaseResponse<Void>> deleteCategoryCoupon(@RequestBody CouponIdRequest request);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.t3t.bookstoreapi.coupon.exception;

public class CouponApiClientException extends RuntimeException{
private static final String DEFAULT_MESSAGES = "쿠폰을 가져오지 못했습니다";
public CouponApiClientException(String message) {
super(message);
}
public CouponApiClientException(){
super(DEFAULT_MESSAGES);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.t3t.bookstoreapi.coupon.model.request;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data@Builder
@NoArgsConstructor
@AllArgsConstructor
public class CouponIdRequest {
private String couponId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.t3t.bookstoreapi.coupon.model.response;

import lombok.*;

@Builder
@Getter@ToString
@EqualsAndHashCode
@NoArgsConstructor
@AllArgsConstructor
public class CouponResponse {
private String couponId;
}
Loading

0 comments on commit 1410958

Please sign in to comment.