Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/Orange-Co/DDANZI_Server
Browse files Browse the repository at this point in the history
…into deploy
  • Loading branch information
Kang1221 committed Sep 12, 2024
2 parents 1935e1e + fb6a6d0 commit 2c31c64
Show file tree
Hide file tree
Showing 28 changed files with 373 additions and 143 deletions.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ dependencies {
// Google Firebase Admin
implementation 'com.google.firebase:firebase-admin:9.2.0'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation group: 'org.bouncycastle', name: 'bcpkix-jdk15to18', version: '1.78.1' // 최신 버전 확인 후 사용

}

tasks.named('test') {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/co/orange/ddanzi/common/error/Error.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public enum Error {
ACCOUNT_NAME_DOES_NOT_MATCH(HttpStatus.BAD_REQUEST, "The account name does not match to user name."),
DUE_DATE_IS_INCORRECT(HttpStatus.BAD_REQUEST, "The due date is incorrect."),
ITEM_IS_NOT_ON_SALE(HttpStatus.BAD_REQUEST, "The item is not on sale."),
INVALID_ORDER_STATUS(HttpStatus.BAD_REQUEST,"잘못된 주문 상태입니다."),

//402 Payment Required
PAYMENT_REQUIRED(HttpStatus.PAYMENT_REQUIRED, "Payment is required to place the order."),
Expand Down
8 changes: 2 additions & 6 deletions src/main/java/co/orange/ddanzi/controller/AuthController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import co.orange.ddanzi.common.error.Error;
import co.orange.ddanzi.common.response.Success;
import co.orange.ddanzi.domain.user.enums.LoginType;
import co.orange.ddanzi.dto.auth.RefreshTokenRequestDto;
import co.orange.ddanzi.dto.auth.SigninRequestDto;
import co.orange.ddanzi.dto.auth.VerifyRequestDto;
Expand All @@ -22,7 +21,6 @@
@RequestMapping("/api/v1/auth")
public class AuthController {
private final AuthService authService;
private final OAuthService oAuthService;
private final JwtUtils jwtUtils;

@PostMapping("/signin/test")
Expand All @@ -32,14 +30,12 @@ ApiResponse<?> test(@RequestBody SigninRequestDto requestDto){

@PostMapping("/signin")
ApiResponse<?> signin(@RequestBody SigninRequestDto requestDto) throws JsonProcessingException {
if(requestDto.getType().equals(LoginType.KAKAO))
return oAuthService.kakaoSignIn(requestDto);
return oAuthService.kakaoSignIn(requestDto);
return authService.signin(requestDto);
}

@PostMapping("/refreshtoken")
ApiResponse<?> refreshAccessToken(@RequestBody RefreshTokenRequestDto requestDto) throws JsonProcessingException{
return oAuthService.refreshAccessToken(requestDto.getRefreshtoken());
return authService.refreshAccessToken(requestDto.getRefreshtoken());
}

@PostMapping("/logout")
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/co/orange/ddanzi/controller/FcmController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import co.orange.ddanzi.common.response.ApiResponse;
import co.orange.ddanzi.dto.fcm.FcmSendDto;
import co.orange.ddanzi.dto.fcm.ReportSendDto;
import co.orange.ddanzi.service.FcmService;
import com.google.firebase.messaging.FirebaseMessagingException;
import lombok.RequiredArgsConstructor;
Expand All @@ -21,7 +22,7 @@ ApiResponse<?> testFcm(@RequestBody FcmSendDto requestDto) throws FirebaseMessag
}

@PostMapping("/fcm/report")
ApiResponse<?> reportNotification(@RequestBody FcmSendDto requestDto) throws FirebaseMessagingException {
ApiResponse<?> reportNotification(@RequestBody ReportSendDto requestDto) throws FirebaseMessagingException {
return fcmService.reportNotification(requestDto);
}
}
5 changes: 3 additions & 2 deletions src/main/java/co/orange/ddanzi/controller/HomeController.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import co.orange.ddanzi.service.HomeService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;

@Slf4j
Expand All @@ -14,8 +15,8 @@ public class HomeController {
private final HomeService homeService;

@GetMapping
public ApiResponse<?> home() {
return homeService.getProductList();
public ApiResponse<?> home(Pageable pageable) {
return homeService.getProductList(pageable);
}

@GetMapping( "/product/{id}")
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/co/orange/ddanzi/controller/ItemController.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ ApiResponse<?> getProduct(@PathVariable("id") String id) {

@PostMapping
ApiResponse<?> saveItem(@RequestBody SaveItemRequestDto requestDto){
if(requestDto.getDueDate().isBefore(LocalDate.now()))
return ApiResponse.onFailure(Error.DUE_DATE_IS_INCORRECT, null);
return itemService.saveItem( requestDto);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package co.orange.ddanzi.domain.order.enums;

public enum PayMethod {
card("신용카드"),
naverpay_card("네이버페이 - 카드"),
card("신용/체크카드"),
naverpay_card("네이버페이"),
kakaopay("카카오페이"),
samsungpay("삼성페이"),
trans("실시간 계좌이체"),
phone("휴대폰소액결제")
// trans("실시간 계좌이체"),
phone("휴대폰 결제")
;

private String payMethod;
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/co/orange/ddanzi/dto/common/PageInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package co.orange.ddanzi.dto.common;

import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
public class PageInfo {
private Long totalElements;
private Integer numberOfElements;
}
9 changes: 9 additions & 0 deletions src/main/java/co/orange/ddanzi/dto/fcm/ReportSendDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package co.orange.ddanzi.dto.fcm;

import lombok.Getter;

@Getter
public class ReportSendDto {
private String email;
private String orderId;
}
2 changes: 2 additions & 0 deletions src/main/java/co/orange/ddanzi/dto/home/HomeResponseDto.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package co.orange.ddanzi.dto.home;

import co.orange.ddanzi.dto.common.PageInfo;
import co.orange.ddanzi.dto.common.ProductInfo;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -10,5 +11,6 @@
@Builder
public class HomeResponseDto {
private String homeImgUrl;
private PageInfo pageInfo;
private List<ProductInfo> productList;
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ public class ItemResponseDto {
private String buyerNickName;
private AddressInfo addressInfo;
private LocalDateTime paidAt;
private PayMethod paymentMethod;
private String paymentMethod;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
public class SaveItemRequestDto {
private String productId;
private String productName;
private LocalDate dueDate;
private LocalDate receivedDate;
private String registeredImage;

public Item toItem(String id, User user, Product product){
Expand All @@ -21,7 +21,7 @@ public Item toItem(String id, User user, Product product){
.product(product)
.seller(user)
.imgUrl(registeredImage)
.dueDate(dueDate)
.dueDate(receivedDate.plusDays(7))
.status(ItemStatus.ON_SALE)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package co.orange.ddanzi.dto.oauth;

import lombok.Getter;

@Getter
public class AppleIdTokenPayload {
private String subject;
private String email;
}
19 changes: 19 additions & 0 deletions src/main/java/co/orange/ddanzi/dto/oauth/AppleProperties.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package co.orange.ddanzi.dto.oauth;

import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

@Component
@ConfigurationProperties(prefix = "apple")
@Getter
@Setter
public class AppleProperties {
private String grantType;
private String clientId;
private String keyId;
private String teamId;
private String audience;
private String privateKey;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package co.orange.ddanzi.dto.oauth;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;

@Getter
public class AppleSocialTokenInfoResponse {
@JsonProperty("access_token")
private String accessToken;

@JsonProperty("token_type")
private String tokenType;

@JsonProperty("expires_in")
private Long expiresIn;

@JsonProperty("refresh_token")
private String refreshToken;

@JsonProperty("id_token")
private String idToken;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
import java.util.List;

public interface AlarmRepository extends JpaRepository<Alarm, Long> {
@Query("SELECT a FROM Alarm a WHERE a.user = :user AND a.createdAt >= :sevenDaysAgo")
@Query("SELECT a FROM Alarm a WHERE a.user = :user AND a.createdAt >= :sevenDaysAgo ORDER BY a.createdAt DESC")
List<Alarm> findRecentAlarmsByUser(@Param("user") User user, @Param("sevenDaysAgo") LocalDateTime sevenDaysAgo);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public interface ItemRepository extends JpaRepository<Item, String> {

Integer countAllBySeller(User user);

@Query("SELECT MAX(CAST(SUBSTRING(i.id, 14, 2) AS integer)) FROM Item i WHERE i.product = :product")
@Query("SELECT MAX(CAST(RIGHT(i.id, 2) AS integer)) FROM Item i WHERE i.product = :product")
Integer findMaxSequenceNumberByProduct(@Param("product") Product product);

@Query("SELECT i FROM Item i WHERE i.status = 'ON_SALE' AND i.product = :product ORDER BY i.dueDate ASC")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import co.orange.ddanzi.domain.product.Category;
import co.orange.ddanzi.domain.product.Product;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
Expand All @@ -18,7 +20,7 @@ public interface ProductRepository extends JpaRepository<Product, String> {
Product findByKakaoProductId(Long kakaoProductId);

@Query(value = "SELECT * FROM products p WHERE p.stock > :stock", nativeQuery = true)
List<Product> findAllByStock(Integer stock);
Page<Product> findAllByStock(Pageable pageable, Integer stock);

@Query(value = "SELECT * FROM products p WHERE p.stock > 0 AND p.name LIKE %:keyword% ", nativeQuery = true)
List<Product> findAllByName(@Param("keyword") String keyword);
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/co/orange/ddanzi/service/AddressService.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ public AddressSeparateInfo setAddressSeparateInfo(User user){
}

public AddressInfo setAddressInfo(User user){
Address address = addressRepository.findByUser(user);
Address address = null;
if(user != null){
address = addressRepository.findByUser(user);
}
return AddressInfo.builder()
.recipient(address != null ? address.getRecipient() : null)
.zipCode(address != null ? address.getZipCode() : null)
Expand Down
15 changes: 6 additions & 9 deletions src/main/java/co/orange/ddanzi/service/AlarmService.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,17 @@ public ApiResponse<?> getAlarms(){
for(Alarm alarm : alarmList){
Order order = alarm.getOrder();
FcmCase alarmCase = alarm.getAlarmCase();
MyAlarm.MyAlarmBuilder myAlarm = MyAlarm.builder()
MyAlarm myAlarm = MyAlarm.builder()
.alarmId(alarm.getId())
.alarmCase(alarmCase)
.title(alarmCase.getTitle())
.content(alarmCase.getBody())
.time(createAlarmTime(alarm.getCreatedAt()))
.isChecked(alarm.getIsChecked());

if(alarmCase == FcmCase.A1 || alarmCase == FcmCase.A2 || alarmCase == FcmCase.A3 || alarmCase == FcmCase.A4){
myAlarm.itemId(order.getItem().getId());
}
else
myAlarm.orderId(order.getId());
myAlarmList.add(myAlarm.build());
.isChecked(alarm.getIsChecked())
.orderId(order.getId())
.itemId(order.getItem().getId())
.build();
myAlarmList.add(myAlarm);
}
return ApiResponse.onSuccess(Success.GET_ALARM_LIST_SUCCESS, AlarmResponseDto.builder().alarmList(myAlarmList).build());
}
Expand Down
16 changes: 14 additions & 2 deletions src/main/java/co/orange/ddanzi/service/FcmService.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@
import co.orange.ddanzi.common.response.ApiResponse;
import co.orange.ddanzi.common.response.Success;
import co.orange.ddanzi.dto.fcm.FcmSendDto;
import co.orange.ddanzi.dto.fcm.ReportSendDto;
import co.orange.ddanzi.global.firebase.FirebaseUtils;
import co.orange.ddanzi.repository.OrderRepository;
import co.orange.ddanzi.repository.PushAlarmRepository;
import co.orange.ddanzi.repository.UserRepository;
import co.orange.ddanzi.service.auth.AuthService;
import com.google.firebase.messaging.FirebaseMessaging;
import com.google.firebase.messaging.FirebaseMessagingException;
import jakarta.transaction.Transactional;
Expand All @@ -26,6 +30,8 @@ public class FcmService {
private final FirebaseUtils firebaseUtils;
private final PushAlarmRepository pushAlarmRepository;
private final AlarmService alarmService;
private final UserRepository userRepository;
private final OrderRepository orderRepository;

@Transactional
public ApiResponse<?> testSendMessage(FcmSendDto requestDto) throws FirebaseMessagingException {
Expand All @@ -43,8 +49,14 @@ public ApiResponse<?> testSendMessage(FcmSendDto requestDto) throws FirebaseMess
}

@Transactional
public ApiResponse<?> reportNotification(FcmSendDto requestDto) throws FirebaseMessagingException {
firebaseUtils.sendMessage(requestDto.getFcmToken(), FcmCase.A4);
public ApiResponse<?> reportNotification(ReportSendDto requestDto) throws FirebaseMessagingException {
User user = userRepository.findByEmail(requestDto.getEmail()).get();
PushAlarm pushAlarm = pushAlarmRepository.findByUser(user).orElse(null);
Order order = orderRepository.findById(requestDto.getOrderId()).orElse(null);

firebaseUtils.sendMessage(pushAlarm.getFcmToken(), FcmCase.A4);
alarmService.createAlarm(user, FcmCase.A4, order);

return ApiResponse.onSuccess(Success.SUCCESS, Map.of("title", FcmCase.A4.getTitle()));
}

Expand Down
18 changes: 13 additions & 5 deletions src/main/java/co/orange/ddanzi/service/HomeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import co.orange.ddanzi.domain.Banner;
import co.orange.ddanzi.domain.product.*;
import co.orange.ddanzi.domain.user.User;
import co.orange.ddanzi.dto.common.PageInfo;
import co.orange.ddanzi.dto.common.ProductInfo;
import co.orange.ddanzi.dto.common.OptionDetailInfo;
import co.orange.ddanzi.dto.common.OptionInfo;
Expand All @@ -16,6 +17,8 @@
import jakarta.transaction.Transactional;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.util.Pair;
import org.springframework.stereotype.Service;

Expand All @@ -36,24 +39,29 @@ public class HomeService {
private final RedisRepository redisRepository;

@Transactional
public ApiResponse<?> getProductList(){
public ApiResponse<?> getProductList(Pageable pageable) {
User user = authUtils.getUser();
Banner banner = bannerRepository.findByIsSelected(Boolean.TRUE);
List<Product> productList = productRepository.findAllByStock(0);
Page<Product> productPage = productRepository.findAllByStock(pageable, 0);

List<ProductInfo> productInfoList = new ArrayList<>();
List<ProductInfo> productInfoList;
if(user!=null) {
log.info("User is not null");
productInfoList = setProductList(user, productList, interestProductRepository);
productInfoList = setProductList(user, productPage.getContent(), interestProductRepository);
}
else{
log.info("User is null");
productInfoList = setProductListInNotUser(productList, interestProductRepository);
productInfoList = setProductListInNotUser(productPage.getContent(), interestProductRepository);
}

PageInfo pageInfo = PageInfo.builder()
.totalElements(productPage.getTotalElements())
.numberOfElements(productPage.getNumberOfElements())
.build();

HomeResponseDto responseDto = HomeResponseDto.builder()
.homeImgUrl(banner.getImgUrl())
.pageInfo(pageInfo)
.productList(productInfoList).build();
return ApiResponse.onSuccess(Success.GET_HOME_INFO_SUCCESS, responseDto);
}
Expand Down
Loading

0 comments on commit 2c31c64

Please sign in to comment.