Skip to content

Commit

Permalink
[#23]
Browse files Browse the repository at this point in the history
  • Loading branch information
lukehongg committed Jan 27, 2023
2 parents 80f95f0 + 3e0330e commit 3b962df
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ public class CustomerService {
@Autowired
private CustomerRepository customerRepository;




@Transactional
public Customer findById(Long id) {
// Customer ret = customerRepository.findById(id).orElseThrow(CustomerNotFoundException::new);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ public class HistoryController {
private CustomerService customerService;

@GetMapping(value = "/history/{id}")
public ResponseEntity<List<HistoryResponse>> findAllById(@PathVariable Long customerId){
List<HistoryResponse> res = historyService.findAllById(customerId);
public ResponseEntity<List<HistoryResponse>> findAllById(@PathVariable Long id){
List<HistoryResponse> res = historyService.findAllById(id);
return ResponseEntity.ok(res);
}

@PostMapping(value="/history")
public ResponseEntity<Long> addHistory(@RequestBody HistoryRequest request){
Customer customer = customerService.findById(request.getCustomerId());
Store store = storeService.findStoreById(request.getStoreId());
Store store = storeService.findById(request.getStoreId());
Long res = historyService.create(History.from(store, request), customer);
return ResponseEntity.ok(res);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import com.greenpoint.server.common.BaseEntity;
import com.greenpoint.server.customer.model.Customer;
import com.greenpoint.server.customer.service.CustomerService;
import com.greenpoint.server.store.model.Store;
import lombok.*;
import org.hibernate.annotations.SQLDelete;
Expand All @@ -29,6 +30,7 @@ public class History extends BaseEntity {
private Store store;

private int cost;
private int currentPoint;
private int savedPoint;
private int usedPoint;

Expand All @@ -43,5 +45,9 @@ public static History from(Store store, HistoryRequest request){
.build();
}

public void pointCheck(Customer customer){
this.currentPoint = customer.getPoint();
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public static HistoryResponse from(History history){
.storeName(history.getStore().getName())
.savedPoint(history.getSavedPoint())
.usedPoint(history.getUsedPoint())
.currentPoint(history.getCurrentPoint())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public Long create(History history, Customer customer){
Level level = levelService.findByGrade(newgrade);
customer.upgrade(level);
}

res.pointCheck(customer);
return res.getId();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ public ResponseEntity<List<Store>> findAll(){
List<Store> res = storeService.findAll();
return ResponseEntity.ok(res);
}
@GetMapping(value="/store/{id}")
public ResponseEntity<Store> findById(@PathVariable Long id){
Store res = storeService.findById(id);
return ResponseEntity.ok(res);
}

@GetMapping(value="/store/three/{id}")
public ResponseEntity<List<Store>> findThreeById(@PathVariable Long id){
List<Store> res = storeService.findThreeById(id);
return ResponseEntity.ok(res);
}

@PostMapping(value="/store")
public ResponseEntity<Store> create(@RequestBody StoreRequest request){
Store res = storeService.create(Store.from(request));
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/greenpoint/server/store/model/Store.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class Store extends BaseEntity {

@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST)
private StoreLevel storeLevel;

public static Store from(StoreRequest request){
return Store.builder()
.loginID(request.getLoginID())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

import com.greenpoint.server.store.model.Store;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface StoreRepository extends JpaRepository<Store, Long> {

@Query(nativeQuery = true, value ="select s from Store s where s.id = :id order by s. LIMIT 3")
List<Store> findThreeById(Long id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class StoreService {


@Transactional(readOnly = true)
public Store findStoreById(Long storeId) {
public Store findById(Long storeId) {
Store ret = storeRepository.findById(storeId).get();
return ret;
}
Expand Down Expand Up @@ -50,4 +50,10 @@ public Store update(Long id, StoreRequest request) {
private Store findOne(Long id) {
return storeRepository.findById(id).get();
}


public List<Store> findThreeById(Long id) {
List<Store> ret = storeRepository.findThreeById(id);
return ret;
}
}

0 comments on commit 3b962df

Please sign in to comment.