-
Notifications
You must be signed in to change notification settings - Fork 5
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
마이페이지, 메인페이지 CRUD 페이지 추가 #59
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.kernel360.main.controller; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
|
||
@RestController | ||
public class MainContoller { | ||
@GetMapping("") | ||
ResponseEntity<String> mainPage(){ | ||
return ResponseEntity.status(HttpStatus.OK).body("main page입니다."); | ||
} | ||
|
||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Controller에서 ResponseEntity 사용 시, ApiResponse을 사용한 방식으로 처리하기로 얘기되었으니, 리팩토링 때는 그 방식으로 적용해주시면 좋을 것 같아요~! 예시 코드는 #56 PR 내용 참고해주시면 됩니다~! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 다음번 커밋에 리팩토링 하겠습니다. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.kernel360.mypage.controller; | ||
|
||
import com.kernel360.member.dto.MemberDto; | ||
import com.kernel360.member.service.MemberService; | ||
import com.kernel360.product.dto.ProductDto; | ||
import com.kernel360.product.service.ProductService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.ui.Model; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@RestController | ||
@RequestMapping("/mypage") | ||
@RequiredArgsConstructor | ||
public class MyPageController { | ||
private final MemberService memberService; | ||
private final ProductService productService; | ||
@GetMapping("/main") | ||
ResponseEntity<Model> main(Model model) { | ||
List<ProductDto> productDtoList = productService.getProductListOrderByViewCount(); | ||
String bannerImageUrl = "http://localhost:8080/bannersample.png"; | ||
String suggestImageUrl = "http://localhost:8080/suggestsample.png"; | ||
Comment on lines
+25
to
+26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍🏻 |
||
|
||
model.addAllAttributes(Map.of("Banner" , bannerImageUrl, | ||
"Suggest", suggestImageUrl, | ||
"Product", productDtoList)); | ||
|
||
return ResponseEntity.status(HttpStatus.OK).body(model); | ||
} | ||
|
||
@GetMapping("/member") | ||
ResponseEntity<String> myInfo() { | ||
return ResponseEntity.status(HttpStatus.OK).body("mypage 내정보 page입니다."); | ||
} | ||
|
||
@GetMapping("/car") | ||
ResponseEntity<String> myCar() { | ||
return ResponseEntity.status(HttpStatus.OK).body("mypage 차량정보 page입니다."); | ||
} | ||
|
||
@DeleteMapping("/member") | ||
ResponseEntity<String> memberDelete(@RequestBody MemberDto memberDto) { | ||
return ResponseEntity.status(HttpStatus.OK).body(memberDto.id() + " 회원이 탈퇴되었습니다."); | ||
} | ||
|
||
@PostMapping("/member") | ||
ResponseEntity<String> memberInfoAdd(@RequestBody MemberDto memberDto) { | ||
return ResponseEntity.status(HttpStatus.OK).body(memberDto.id() + "회원의 회원정보가 추가되었습니다."); | ||
} | ||
|
||
@PatchMapping("/member") | ||
ResponseEntity<String> changePassword(@RequestBody MemberDto memberDto) { | ||
return ResponseEntity.status(HttpStatus.OK).body(memberDto.id() + "회원의 비밀번호가 변경 되었습니다."); | ||
} | ||
|
||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package com.kernel360.mypage.controller; | ||
|
||
import com.kernel360.member.service.MemberService; | ||
import com.kernel360.product.dto.ProductDto; | ||
import com.kernel360.product.service.ProductService; | ||
import com.navercorp.fixturemonkey.FixtureMonkey; | ||
import com.navercorp.fixturemonkey.api.introspector.*; | ||
import com.navercorp.fixturemonkey.api.type.TypeReference; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import org.springframework.test.web.servlet.setup.MockMvcBuilders; | ||
import org.springframework.ui.Model; | ||
import org.springframework.web.context.WebApplicationContext; | ||
import org.springframework.web.filter.CharacterEncodingFilter; | ||
|
||
import java.util.Arrays; | ||
import java.util.LinkedHashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static org.hamcrest.collection.IsCollectionWithSize.hasSize; | ||
import static org.mockito.Mockito.*; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; | ||
|
||
@WebMvcTest(MyPageController.class) | ||
class MyPageControllerTest { | ||
|
||
private MockMvc mockMvc; | ||
|
||
@Autowired | ||
private WebApplicationContext context; | ||
|
||
@MockBean | ||
private MemberService memberService; | ||
|
||
@MockBean | ||
private ProductService productService; | ||
|
||
@MockBean | ||
private Model model; | ||
private FixtureMonkey fixtureMonkey; | ||
|
||
@BeforeEach | ||
void 준비(WebApplicationContext webApplicationContext) { | ||
fixtureMonkey = FixtureMonkey.builder() | ||
.objectIntrospector(new FailoverIntrospector( | ||
Arrays.asList( | ||
BuilderArbitraryIntrospector.INSTANCE, | ||
FieldReflectionArbitraryIntrospector.INSTANCE, | ||
ConstructorPropertiesArbitraryIntrospector.INSTANCE, | ||
BeanArbitraryIntrospector.INSTANCE | ||
) | ||
)) | ||
.build(); | ||
|
||
mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext) | ||
.build(); | ||
} | ||
|
||
@Test | ||
void 마이페이지_메인요청이왔을때_200요청과_응답이_잘반환되는지() throws Exception { | ||
//given | ||
List<ProductDto> productDtoList = fixtureMonkey.giveMeBuilder(ProductDto.class).sampleList(5); | ||
|
||
//when | ||
when(productService.getProductListOrderByViewCount()).thenReturn(productDtoList); | ||
|
||
//then | ||
mockMvc.perform(get("/mypage/main")) | ||
.andExpect(status().isOk()) | ||
.andExpect(content().contentType(MediaType.APPLICATION_JSON)) | ||
.andExpect(jsonPath("$.Banner").value("http://localhost:8080/bannersample.png")) | ||
.andExpect(jsonPath("$.Suggest").value("http://localhost:8080/suggestsample.png")) | ||
.andExpect(jsonPath("$.Product", hasSize(5))); | ||
|
||
verify(productService, times(1)).getProductListOrderByViewCount(); | ||
} | ||
|
||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
package com.kernel360.brand.entity; | ||
|
||
import com.kernel360.base.BaseEntity; | ||
import com.kernel360.product.entity.Product; | ||
import jakarta.persistence.*; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import java.util.List; | ||
|
||
@Getter | ||
@Setter | ||
@Entity | ||
@Table(name = "brand") | ||
public class Brand extends BaseEntity { | ||
|
@@ -18,6 +19,9 @@ public class Brand extends BaseEntity { | |
@Column(name = "brand_name", nullable = false, length = Integer.MAX_VALUE) | ||
private String brandName; | ||
|
||
@OneToMany(fetch = FetchType.LAZY, mappedBy = "brand") | ||
private List<Product> productList; | ||
|
||
@Column(name = "description", length = Integer.MAX_VALUE) | ||
private String description; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Overall, the code appears to be fine with a few minor suggestions for improvement:
Here's an updated version of the code with the suggested improvements: package com.kernel360.brand.entity;
import com.kernel360.base.BaseEntity;
import com.kernel360.product.entity.Product;
import javax.persistence.*;
import java.util.List;
@Entity
@Table(name = "brand")
public class Brand extends BaseEntity {
@Column(name = "brand_name", nullable = false)
private String brandName;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "brand")
private List<Product> productList;
@Column(name = "description", length = Integer.MAX_VALUE)
private String description;
// Constructors, getters, and setters
} Remember to review the changes carefully and adapt them to your specific requirements. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @OnetoOne 기본은 Eager 로 되어 있습니다. null 관련 사항은 jpa프로그래밍 책 298쪽 내용 참고로 첨부하겠습니다. 저도 정확히 이해를 못했는데, 혹시 이해가 되시면 저도 설명 좀 부탁드리겠습니다. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. #59 (comment) 이쪽에 제 생각을 적어두었습니다 |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.kernel360.carinfo.repository; | ||
|
||
import com.kernel360.carinfo.entity.CarInfo; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface CarInfoRepository extends JpaRepository<CarInfo, Long> { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.kernel360.washinfo.repository; | ||
|
||
import com.kernel360.washinfo.entity.WashInfo; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface WashInfoRepository extends JpaRepository<WashInfo, Long> { | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
커밋 새로해서 push 한 것에 반영되었습니다. pull 받는걸 깜빡하고 바로 올렸나 봅니다~ ㅠㅠ