-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from likelion-backendschool/3_week_mission_dev
3_week_mission
- Loading branch information
Showing
48 changed files
with
1,965 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
2_Week_Mission/multbooks/src/main/java/com/ebook/multbooks/MultbooksApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,13 @@ | ||
package com.ebook.multbooks.app.base; | ||
|
||
import com.ebook.multbooks.app.cart.entity.CartItem; | ||
import com.ebook.multbooks.app.cart.service.CartService; | ||
import com.ebook.multbooks.app.cash.event.EventType; | ||
import com.ebook.multbooks.app.member.entity.Member; | ||
import com.ebook.multbooks.app.member.service.MemberService; | ||
import com.ebook.multbooks.app.order.entity.Order; | ||
import com.ebook.multbooks.app.order.service.OrderService; | ||
import com.ebook.multbooks.app.order.service.PayService; | ||
import com.ebook.multbooks.app.post.dto.PostWriteForm; | ||
import com.ebook.multbooks.app.post.entity.Post; | ||
import com.ebook.multbooks.app.post.service.PostService; | ||
|
@@ -17,21 +22,27 @@ | |
@Configuration | ||
@Profile("dev") | ||
public class DevInitData { | ||
private boolean initDataDone=false; | ||
@Bean | ||
CommandLineRunner init(MemberService memberService, PasswordEncoder passwordEncoder, PostService postService, ProductService productService){ | ||
CommandLineRunner initData(MemberService memberService, PasswordEncoder passwordEncoder, PostService postService, ProductService productService, CartService cartService, OrderService orderService, PayService payService){ | ||
return args -> { | ||
//initData가 1번만 사용될수 있도록 설정 | ||
if(initDataDone)return; | ||
initDataDone=true; | ||
|
||
String password=passwordEncoder.encode("1234"); | ||
//3명회원가입=>2명작가,1명그냥회원 | ||
Member member1=memberService.join("user1",password,"[email protected]","author1"); | ||
Member member2=memberService.join("user2",password,"[email protected]","author2"); | ||
Member member3=memberService.join("user3",password,"[email protected]",""); | ||
Member member4=memberService.join("admin",password,"[email protected]","admin"); | ||
|
||
//회원 3명 예치금 10만원 충전 | ||
memberService.addCash(member1,100000, EventType.CHARGE_FOR_PAYMENT); | ||
memberService.addCash(member2,100000, EventType.CHARGE_FOR_PAYMENT); | ||
memberService.addCash(member3,100000, EventType.CHARGE_FOR_PAYMENT); | ||
|
||
//작가 회원들이 1개씩 글쓰기 | ||
//2명의작가 회원들이 1개씩 글쓰기 | ||
Post post1=postService.writePost(member1.getUsername(),new PostWriteForm("글제목1","글내용1","글내용1","#마법 #기사")); | ||
Post post2=postService.writePost(member2.getUsername(),new PostWriteForm("글제목2","글내용2","글내용2","#로맨스 #판타지")); | ||
|
||
|
@@ -41,6 +52,21 @@ CommandLineRunner init(MemberService memberService, PasswordEncoder passwordEnco | |
Product product3=productService.createProduct(member2,"도서3",3000,3L);//자신의 글의 키워드 중 로맨스 키워드를 가지는 도서 생성 | ||
Product product4=productService.createProduct(member2,"도서4",4000,4L);//자신의 글의 키워드 중 판타지 키워드를 가지는 도서 생성 | ||
|
||
//장바구니에 다른사람 상품 담기 | ||
CartItem cartItem1=cartService.addItem(member1,product3); | ||
CartItem cartItem2=cartService.addItem(member1,product4); | ||
CartItem cartItem3=cartService.addItem(member2,product1); | ||
CartItem cartItem4=cartService.addItem(member2,product2); | ||
|
||
//장바구니로 주문 | ||
Order order1=orderService.createOrderFromCart(member1); | ||
Order order2=orderService.createOrderFromCart(member2); | ||
|
||
// 주문1,2 결제 | ||
payService.payByRestCash(order1); | ||
payService.payByRestCash(order2); | ||
//주문1 환불 | ||
payService.refund(order2); | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
.../multbooks/src/main/java/com/ebook/multbooks/app/member/controller/AdmHomeController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.ebook.multbooks.app.member.controller; | ||
|
||
import org.springframework.security.access.prepost.PreAuthorize; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
|
||
@Controller | ||
@RequestMapping("/adm") | ||
public class AdmHomeController { | ||
|
||
@GetMapping("") | ||
@PreAuthorize("hasAuthority('ADMIN')") | ||
public String showIndex(){ | ||
return "redirect:/adm/home/main"; | ||
} | ||
|
||
@GetMapping("/home/main") | ||
public String showMain(){ | ||
return "adm/home/main"; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
...books/src/main/java/com/ebook/multbooks/app/orderItem/repository/OrderItemRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,15 @@ | ||
package com.ebook.multbooks.app.orderItem.repository; | ||
|
||
import com.ebook.multbooks.app.orderItem.entity.OrderItem; | ||
import com.ebook.multbooks.app.rebate.entity.RebateOrderItem; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
|
||
public interface OrderItemRepository extends JpaRepository<OrderItem,Long> { | ||
List<OrderItem> findAllByPayDateBetween(LocalDateTime fromDate, LocalDateTime toDate); | ||
Page<OrderItem> findAllByPayDateBetween(LocalDateTime fromDate, LocalDateTime toDate, Pageable pageable); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
...ultbooks/src/main/java/com/ebook/multbooks/app/rebate/controller/AdmRebateController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package com.ebook.multbooks.app.rebate.controller; | ||
|
||
import com.ebook.multbooks.app.rebate.entity.RebateOrderItem; | ||
import com.ebook.multbooks.app.rebate.service.RebateService; | ||
import com.ebook.multbooks.global.util.Util; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.beans.factory.annotation.Required; | ||
import org.springframework.security.access.prepost.PreAuthorize; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.ui.Model; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import javax.persistence.EntityNotFoundException; | ||
import javax.servlet.http.HttpServletRequest; | ||
import java.time.LocalDateTime; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
@Controller | ||
@RequiredArgsConstructor | ||
@RequestMapping("/adm/rebate") | ||
public class AdmRebateController { | ||
private final RebateService rebateService; | ||
@GetMapping("/makeData") | ||
@PreAuthorize("hasAuthority('ADMIN')") | ||
public String showMakeData(String msg,Model model) { | ||
|
||
model.addAttribute("msg",msg); | ||
return "adm/rebate/makeData"; | ||
} | ||
|
||
@PostMapping("/makeData") | ||
@PreAuthorize("hasAuthority('ADMIN')") | ||
public String makeData(String yearMonth){ | ||
|
||
rebateService.makeData(yearMonth); | ||
|
||
return "redirect:/adm/rebate/rebateOrderItemList?yearMonth="+yearMonth+"&msg="+Util.url.encode("정산데이터가 성공적으로 생성되었습니다."); | ||
} | ||
@GetMapping("/rebateOrderItemList") | ||
@PreAuthorize("hasAuthority('ADMIN')") | ||
public String showRebateOrderItemList(String yearMonth, String msg,Model model){ | ||
List<RebateOrderItem> items=rebateService.findRebateOrderItemsByPayDateInOrderByIdAsc(yearMonth); | ||
model.addAttribute("items",items); | ||
model.addAttribute("msg",msg); | ||
return "adm/rebate/rebateOrderItemList"; | ||
} | ||
|
||
@PostMapping("/rebateOne/{orderItemId}") | ||
@PreAuthorize("hasAuthority('ADMIN')") | ||
public String rebateOne(@PathVariable long orderItemId, HttpServletRequest req) { | ||
String resultMsg=null; | ||
try{ | ||
resultMsg=rebateService.rebate(orderItemId); | ||
}catch (Exception exception){ | ||
return "redirect:/adm/rebate/makeData?msg="+Util.url.encode(exception.getMessage()); | ||
} | ||
String refer=req.getHeader("Referer"); | ||
String yearMonth=Util.url.getQueryParamValue(refer,"yearMonth",""); | ||
String redirect="redirect:/adm/rebate/rebateOrderItemList?yearMonth="+yearMonth; | ||
|
||
return redirect+"&msg="+Util.url.encode(resultMsg); | ||
} | ||
@PostMapping("/rebate") | ||
@PreAuthorize("hasAuthority('ADMIN')") | ||
public String rebate(String ids, HttpServletRequest req) { | ||
|
||
String[] idsArr = ids.split(","); | ||
|
||
Arrays.stream(idsArr) | ||
.mapToLong(Long::parseLong) | ||
.forEach(id -> { | ||
rebateService.rebate(id); | ||
}); | ||
|
||
String referer = req.getHeader("Referer"); | ||
String yearMonth = Util.url.getQueryParamValue(referer, "yearMonth", ""); | ||
|
||
String redirect = "redirect:/adm/rebate/rebateOrderItemList?yearMonth=" + yearMonth; | ||
redirect += "&msg=" + Util.url.encode("%d건의 정산품목을 정산처리하였습니다.".formatted(idsArr.length)); | ||
|
||
return redirect; | ||
} | ||
} |
Oops, something went wrong.