Skip to content

Commit

Permalink
Merge branch 'main' into dev/connectDB/#37
Browse files Browse the repository at this point in the history
  • Loading branch information
ahyoon99 authored Aug 20, 2024
2 parents 57d547a + f862f7a commit a415036
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,9 @@ public List<WishListDto> findAll(){
public void delete(@PathVariable int index){
wishListService.delete(index);
}

@PostMapping("/{index}")
public void addVisit(@PathVariable int index){
wishListService.addVisit(index);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,14 @@ public WishListDto findById(int index) {
}
return entityToDto(wishListEntity.get()); // wishListEntity에 값이 있으면 wishListDto로 변환하여 리턴하기
}

public void addVisit(int index) {
var restaurant = wishListRepository.findById(index);
if (restaurant.isPresent()){
var restaurnatEntity = restaurant.get();
restaurnatEntity.setVisit(true);
restaurnatEntity.setVisitCount(restaurnatEntity.getVisitCount()+1);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,20 @@ public void deleteTest(){

Assertions.assertEquals(wishList.size(), 2);
}

@Test
public void addVisitTest(){
var wishListDto = new WishListDto();
wishListDto.setTitle("전주마라탕");
wishListDto.setCategory("중식");

var saveEntity = wishListService.add(wishListDto);

wishListService.addVisit(1);

List<WishListDto> wishList = wishListService.findAll();

Assertions.assertEquals(1, wishList.get(0).getVisitCount());
Assertions.assertEquals(true, wishList.get(0).isVisit());
}
}

0 comments on commit a415036

Please sign in to comment.