- 누락된 API 개발 (식당 메뉴 보기)
- 홀로 gitFlow
- 더 있으면 추가~ ㅋㅋ
(시간의 흐름에 따라 써내려갑니다.)


코드가 추가될 지점은 당연히 컨트롤러, 서비스, 리포지토리 3계층이고 추가적으로 데이터 전달을 위한 DTO클래스를 만들었다.
컨트롤러 추가 로직
@GetMapping("/api/v1/restaurants/{restaurantId}/foods")
public ResponseEntity<FoodsResponseDto> getFoods(@PathVariable Long restaurantId) {
return ResponseEntity
.ok()
.body(new FoodsResponseDto(foodService.getFoods(restaurantId)));
}
public List<FoodsDto> getFoods(Long restaurantId) {
Restaurant restaurant = getRestaurant(restaurantId);
return restaurant.getMenu().stream()
.map(FoodsDto::new)
.collect(Collectors.toList());
}
public class FoodsDto {
private Long id;
private String name;
private String price;
...
}
...
public class FoodsResponseDto {
private String code;
private String message;
private List<FoodsDto> data;
public FoodsResponseDto(List<FoodsDto> data) {
...
}
}
public class Restaurant extends Timestamped {
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "RESTAURANT_ID")
private Long id;
@OneToMany(mappedBy = "restaurant", fetch = LAZY)
List<Food> menu = new ArrayList<>();
(나머진 생략...)
}
메뉴라는 'Food'에 관한 리스트를 음식점 조회만으로 확인을 할 수 있기 때문에 손쉽게 조회가 가능하다!
('Restaurant'과 'Food'는 일대다 관계이며 그에 대한 엔티티 모델링이 되어 있다. 갸꿀~!)
- 여기까지가 메뉴 보기 API에 관한 구현 내용이다 -
git add .
git commit -m '메시지'
새로 생성된 파일이 없다면
git commit -am '메시지'
그리고 dev 브랜치로 switch 하고 feature 브랜치를 Merge 이후 리모트로 푸시! 혹시나 틀리면 bash가 힌트를 줄 것이다. 병합된 feature 브랜치는 꼭 삭제하자!
git switch dev브랜치명
git merge feature브랜치명
git push
git branch -D feature브랜치명

git switch main
git branch -D dev브랜치명
remote에도 dev브랜치를 제거한다. (물론 merge된 상태겠쥬?)

리모트의 최신 내역을 로컬로 불러들인다.
git remote update
git pull upstream develop # 이건 안돼~!
결과는 이러하다
