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

Backend unit test #111

Open
wants to merge 4 commits into
base: draft
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -55,12 +55,13 @@ public class Product extends BaseTimeEntity implements Serializable {
private Integer giftPrice;


public Product(long productId, Mart martName, String productName, Integer originalPrice, SaleCategory saleCategory) {
public Product(long productId, Mart martName, String productName, Integer originalPrice, SaleCategory saleCategory, Integer salePrice) {
this.productId = productId;
this.martName = martName;
this.productName = productName;
this.originalPrice = originalPrice;
this.saleCategory = saleCategory;
this.salePrice = salePrice;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@ public interface MybagRepository extends JpaRepository<Mybag, Long> {
Optional<Mybag> findByMybagId(Long mybagId);

Optional<Mybag> findByUserAndProductIdAndStatus(User user, Long productId, int i);

Object findaByUser(User user);

Object deleteByMybagId(String accessToken, long l);

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import com.modimoa.backend.repository.MybagRepository;
import com.modimoa.backend.repository.ProductRepository;
import com.modimoa.backend.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -21,14 +20,16 @@
@Transactional
public class MybagService {

@Autowired
private MybagRepository mybagRepository;

@Autowired
private UserRepository userRepository;
private final MybagRepository mybagRepository;
private final UserRepository userRepository;
private final ProductRepository productRepository;

@Autowired
private ProductRepository productRepository;
public MybagService(MybagRepository mybagRepository, UserRepository userRepository, ProductRepository productRepository){
this.mybagRepository = mybagRepository;
this.userRepository = userRepository;
this.productRepository = productRepository;
}

// 전체 물품 가져와서 반환
public List<MybagProduct> findAll(String accessToken) {
Expand All @@ -41,6 +42,7 @@ public List<MybagProduct> findAll(String accessToken) {
.id(mybag.getMybagId())
.count(mybag.getCount())
.status(mybag.getStatus()).build();

productList.add(mybagProduct);
}
return productList;
Expand Down Expand Up @@ -102,6 +104,7 @@ public Map<String, Integer> getPrice(String accessToken) {
Optional<User> user = userRepository.findByAccessToken(accessToken);
user.orElseThrow(() -> new CustomException(OBJECT_NOTFOUND_ERROR));


int originalPriceBeforeBuy = 0;
int salePriceBeforeBuy = 0;
int originalPriceAfterBuy = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.modimoa.backend.errorhandling.CustomException;
import com.modimoa.backend.repository.MybagRepository;
import com.modimoa.backend.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
Expand All @@ -24,7 +25,7 @@
public class UserService {

private final UserRepository userRepository;

@Autowired
private MybagRepository mybagRepository;

Expand Down
Loading