-
Notifications
You must be signed in to change notification settings - Fork 5
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 #59 from HyunJunSon/feature/mypage_CRUD
마이페이지, 메인페이지 CRUD 페이지 추가
- Loading branch information
Showing
12 changed files
with
235 additions
and
17 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
module-api/src/main/java/com/kernel360/main/controller/MainContoller.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,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입니다."); | ||
} | ||
|
||
} |
61 changes: 61 additions & 0 deletions
61
module-api/src/main/java/com/kernel360/mypage/controller/MyPageController.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,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"; | ||
|
||
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() + "회원의 비밀번호가 변경 되었습니다."); | ||
} | ||
|
||
|
||
} |
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
86 changes: 86 additions & 0 deletions
86
module-api/src/test/java/com/kernel360/mypage/controller/MyPageControllerTest.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,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(); | ||
} | ||
|
||
|
||
} |
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
7 changes: 7 additions & 0 deletions
7
module-domain/src/main/java/com/kernel360/carinfo/repository/CarInfoRepository.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,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> { | ||
} |
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
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
7 changes: 7 additions & 0 deletions
7
module-domain/src/main/java/com/kernel360/washinfo/repository/WashInfoRepository.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,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> { | ||
} |