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

Step3 #434

Open
wants to merge 38 commits into
base: main
Choose a base branch
from
Open

Step3 #434

Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
774bbff
Update README.md
eunsoni Jul 25, 2024
5d1bd22
step0
eunsoni Jul 25, 2024
419033c
Merge pull request #1 from eunsoni/step0
eunsoni Jul 26, 2024
8a612db
Update README.md
eunsoni Jul 26, 2024
f341b84
경북대 BE_김은선 5주차 과제 (0단계) (#235)
eunsoni Jul 26, 2024
24ea912
카카오 로그인 api 테스트 및 시크릿키 관리
eunsoni Jul 27, 2024
2532a37
feat: Add Kakao login button
eunsoni Jul 27, 2024
f8ce4ba
feat: Add Kakao login Controller
eunsoni Jul 27, 2024
819fb3b
feat: Implement function to get token using authorization code
eunsoni Jul 27, 2024
25c0f52
feat: Implement function to go to home page after successful e-mail e…
eunsoni Jul 27, 2024
bd31dcd
Merge pull request #2 from eunsoni/step1
eunsoni Jul 27, 2024
a7b13b9
test: Add KakaoControllerTest
eunsoni Jul 27, 2024
24fb815
Merge pull request #3 from eunsoni/step1
eunsoni Jul 27, 2024
357eba9
테스트 코드에 주석메세지 추가
eunsoni Jul 27, 2024
f14fe59
Merge pull request #4 from eunsoni/step1
eunsoni Jul 27, 2024
7b8d9eb
Merge branch 'eunsoni' into main
eunsoni Jul 27, 2024
41355da
Update README.md
eunsoni Jul 27, 2024
a72e171
feat: Implement function to order item and Reduce the quantity
eunsoni Jul 27, 2024
13fc9b4
fix: 위시리스트 옵션 필드 삭제 및 서비스, 클라이언트 수정
eunsoni Jul 27, 2024
8759dec
feat: Implement fuction to remove the product from the wishlist when …
eunsoni Jul 27, 2024
525c1c5
feat: Implement function to send message when odering a product
eunsoni Jul 27, 2024
f22343c
경북대 BE_김은선 5주차 과제 (1단계) (#339)
eunsoni Jul 27, 2024
45adeff
Merge pull request #5 from eunsoni/step2
eunsoni Jul 29, 2024
161085f
fix: reflect feedback(to save refresh token)
eunsoni Jul 29, 2024
2343d2f
feat: Implement to send a kakaotalk
eunsoni Jul 29, 2024
432d91c
fix: add Transactional annotation
eunsoni Jul 29, 2024
92a2595
fix: Reflect Feedback(add function to test db)
eunsoni Jul 29, 2024
710c5f3
fix: set prefix path
eunsoni Jul 29, 2024
571ebd4
fix: add code, url to application-secret.properties
eunsoni Jul 29, 2024
f4707ae
fix: url을 properties에서 받도록 수정
eunsoni Jul 29, 2024
2b3f08d
Merge branch 'eunsoni' into step2
eunsoni Jul 29, 2024
7826bb8
Update README.md
eunsoni Jul 30, 2024
7e879af
Merge pull request #6 from eunsoni/step2
eunsoni Jul 30, 2024
df297ef
fix: 상품 목록 페이지 반환 객체 map에서 dto로 변환
eunsoni Jul 30, 2024
9c86ee9
fix: 위시리스트 목록 페이지 컨트롤러 반환 객체 map에서 dto로 변환 및 위시리스트 삭제기능 에러 해결
eunsoni Jul 30, 2024
b3cb64e
fix: API 명세(Swagger UI)를 위한 컨트롤러 수정
eunsoni Jul 30, 2024
70c216d
feat: api 명세 문서(.yaml)로 작성
eunsoni Jul 30, 2024
209f58c
fix: Reflect Feedback
eunsoni Aug 1, 2024
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
Prev Previous commit
Next Next commit
경북대 BE_김은선 5주차 과제 (0단계) (#235)
* Update README.md

* step0
eunsoni authored Jul 26, 2024
commit f341b84912de035ae78de37b500247877b26e323
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
# spring-gift-order
# spring-gift-order
### 0단계
* import.sql id 명시적으로 작성
* 예외처리 메세지 추가 및 테스트 코드 적용
* Code Pruning
6 changes: 6 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -21,6 +21,12 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-jdbc'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.security:spring-security-crypto'
implementation 'io.jsonwebtoken:jjwt-api:0.11.2'
runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.2'
runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.11.2'
runtimeOnly 'com.h2database:h2'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
31 changes: 31 additions & 0 deletions src/main/java/gift/config/WebConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package gift.config;

import gift.filter.JwtTokenFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

import jakarta.servlet.Filter;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;

@Configuration
public class WebConfig {

private final JwtTokenFilter jwtTokenFilter;

@Autowired
public WebConfig(JwtTokenFilter jwtTokenFilter) {
this.jwtTokenFilter = jwtTokenFilter;
}

@Bean
public FilterRegistrationBean<Filter> jwtFilter() {
FilterRegistrationBean<Filter> registrationBean = new FilterRegistrationBean<>();
registrationBean.setFilter(jwtTokenFilter);


registrationBean.addUrlPatterns("/api/products/delete/*");
return registrationBean;
}
}
43 changes: 43 additions & 0 deletions src/main/java/gift/controller/AdminController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package gift.controller;

import gift.dto.Role;
import gift.entity.Member;
import gift.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import jakarta.servlet.http.HttpSession;

import java.util.List;

@Controller
@RequestMapping("/admin")
public class AdminController {

@Autowired
private MemberService memberService;

@GetMapping
public String adminPage(HttpSession session, Model model) {
String email = (String) session.getAttribute("user");
Member member = memberService.getMember(email);
if (member.getRole() == Role.ADMIN) {
List<Member> members = memberService.getAllMembers();
model.addAttribute("members", members);
return "admin";
} else {
return "redirect:/home";
}
}

@RequestMapping(value = "/members/{id}", method = RequestMethod.DELETE)
public String deleteMember(@PathVariable Long id) {
memberService.deleteMember(id);
return "redirect:/admin";
}
}
129 changes: 129 additions & 0 deletions src/main/java/gift/controller/HomeController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
package gift.controller;

import gift.dto.ProductDto;
import gift.entity.Product;
import gift.service.CategoryService;
import gift.service.OptionService;
import gift.service.ProductService;
import gift.service.WishlistService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/view")
public class HomeController {

private final ProductService productService;
private final CategoryService categoryService;
private final OptionService optionService;
private final WishlistService wishlistService;

public HomeController(ProductService productService, CategoryService categoryService, OptionService optionService, WishlistService wishlistService) {
this.productService = productService;
this.categoryService = categoryService;
this.optionService = optionService;
this.wishlistService= wishlistService;
}

@GetMapping("/home")
public String showHomeForm() {
return "home";
}


@GetMapping("/products")
public String showProductsPage() {
return "products";
}

@GetMapping("/products/data")
@ResponseBody
public Map<String, Object> getProducts(Pageable pageable) {
Page<Product> productPage = productService.getProducts(pageable);
Map<String, Object> response = new HashMap<>();

List<ProductDto> productDtoList = new ArrayList<>();

for (Product product : productPage.getContent()) {
ProductDto dto = new ProductDto(product);
productDtoList.add(dto);
}

response.put("content", productDtoList);

response.put("currentPage", productPage.getNumber());
response.put("totalPages", productPage.getTotalPages());
response.put("hasNext", productPage.hasNext());
response.put("hasPrevious", productPage.hasPrevious());
return response;
}

@GetMapping("/products/add")
public String showAddProductForm(Model model) {
model.addAttribute("product", new ProductDto());
model.addAttribute("categories", categoryService.getAllCategories());
return "add-product";
}
@GetMapping("/products/edit/{id}")
public String showEditProductForm(@PathVariable Long id, Model model) {
Product product = productService.getProductById(id);
if (product == null) {
return "redirect:/view/products";
}

model.addAttribute("categories", categoryService.getAllCategories());
model.addAttribute("options", optionService.getAllOptions());

model.addAttribute("product", new ProductDto(product));
return "edit-product";
}

@GetMapping("/products/delete/{id}")
public String deleteProduct(@PathVariable Long id) {
productService.deleteProduct(id);
return "redirect:/view/products";
}

@GetMapping("/productlist")
public String showProductListsPage() {
return "user-products";
}


@GetMapping("/wishlist/data")
public ResponseEntity<Map<String, Object>> getWishlistItems(
@RequestParam("email") String email,
Pageable pageable) {
Page<Product> productPage = wishlistService.getWishlistByEmail(email, pageable);
Map<String, Object> response = new HashMap<>();
List<ProductDto> productDtoList = new ArrayList<>();

for (Product product : productPage.getContent()) {
ProductDto dto = new ProductDto(product);
productDtoList.add(dto);
}

response.put("content", productDtoList);
response.put("currentPage", productPage.getNumber() + 1);
response.put("totalPages", productPage.getTotalPages());
response.put("hasNext", productPage.hasNext());
response.put("hasPrevious", productPage.hasPrevious());
return ResponseEntity.ok(response);
}

@GetMapping("/wishlist")
public String wishlistForm() {
return "wishlist";
}


}
70 changes: 70 additions & 0 deletions src/main/java/gift/controller/MemberController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package gift.controller;

import gift.dto.MemberDto;
import gift.entity.Member;
import gift.service.MemberService;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/members")
public class MemberController {

private final MemberService memberService;

@Autowired
public MemberController(MemberService memberService) {
this.memberService = memberService;
}

@GetMapping("/register")
public String showRegistrationForm(Model model) {
model.addAttribute("member", new Member());
return "register";
}

@PostMapping("/register")
public String register(@ModelAttribute("member") MemberDto memberDto, HttpServletResponse response) {
String token = memberService.registerMember(memberDto);
response.setHeader("Authorization", "Bearer " + token);
return "redirect:/members/login";
}

@GetMapping("/login")
public String showLoginForm() {
return "login";
}

@PostMapping("/login")
@ResponseBody
public Map<String, String> login(@RequestParam String email, @RequestParam String password, HttpSession session) {
Map<String, String> response = new HashMap<>();
try {
String token = memberService.login(email, password);
if ("admin@kakao.com".equals(email) && "admin".equals(password)) {
session.setAttribute("user", email);
response.put("token", token);
response.put("role", "ADMIN");
} else{ // 유효한 일반 사용자 검사
session.setAttribute("user", email);
response.put("token", token);
response.put("role", "USER");
}
return response;
} catch (RuntimeException e) {
response.put("error", "Invalid email or password");
return response;
}
}




}
48 changes: 48 additions & 0 deletions src/main/java/gift/controller/OptionController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package gift.controller;

import gift.entity.Option;
import gift.service.OptionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Set;

@RestController
@RequestMapping("/api/options")
public class OptionController {

@Autowired
private OptionService optionService;

@GetMapping
public Set<Option> getAllOptions() {
return optionService.getAllOptions();
}

@GetMapping("/{id}")
public ResponseEntity<Option> getOptionById(@PathVariable Long id) {
try {
Option option = optionService.getOptionById(id);
return ResponseEntity.ok(option);
} catch (RuntimeException e) {
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
}
}

@PostMapping
public Option createOption(@RequestBody Option option) {
return optionService.saveOption(option);
}

@PutMapping("/{id}")
public Option updateOption(@PathVariable Long id, @RequestBody Option optionDetails) {
return optionService.updateOption(id, optionDetails);
}

@DeleteMapping("/{id}")
public void deleteOption(@PathVariable Long id) {
optionService.deleteOption(id);
}
}
Loading