Skip to content

Commit

Permalink
Merge pull request #11 from Malloc72P/controller
Browse files Browse the repository at this point in the history
feat : controller 추가
  • Loading branch information
ChoiGiSung committed Apr 22, 2021
2 parents e609791 + ddb006f commit d20b021
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.codesquad.sidedish.category.controller;

import com.codesquad.sidedish.category.domain.dto.SidedishItemDetailListDTO;
import com.codesquad.sidedish.category.domain.dto.SidedishItemPreviewDTO;
import com.codesquad.sidedish.category.domain.dto.SidedishItemPreviewListDTO;
import com.codesquad.sidedish.category.service.SidedishItemService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class SidedishCategoryController {

private final SidedishItemService itemService;

public SidedishCategoryController(SidedishItemService itemService) {
this.itemService = itemService;
}

@GetMapping("/{category}")
public ResponseEntity<SidedishItemPreviewListDTO> previewDish(@PathVariable String category) {
List<SidedishItemPreviewDTO> previewDTOs = itemService.showItemList(category);
SidedishItemPreviewListDTO previewListDTO = new SidedishItemPreviewListDTO(previewDTOs);
return new ResponseEntity(previewListDTO, HttpStatus.OK);
}

@GetMapping("/{category}/{id}")
public ResponseEntity<SidedishItemDetailDTO> previewDish(@PathVariable String category, @PathVariable Long id) {
SidedishItemDetailDTO detailDTOs = itemService.showItem(category, id);
SidedishItemDetailListDTO detailListDTO =new SidedishItemDetailListDTO(detailDTOs);
return new ResponseEntity(detailListDTO, HttpStatus.OK);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.codesquad.sidedish.category.domain.dto;

import java.util.ArrayList;
import java.util.List;

public class SidedishItemDetailListDTO {

private SidedishItemDetailDTO item;

public SidedishItemDetailListDTO(SidedishItemDetailDTO item) {
this.item = item;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.codesquad.sidedish.category.domain;
package com.codesquad.sidedish.category.domain.dto;

import com.codesquad.sidedish.category.domain.SidedishItem;
import com.codesquad.sidedish.event.domain.SidedishEvent;
import com.codesquad.sidedish.event.domain.SidedishEventDTO;
import com.codesquad.sidedish.image.domain.SidedishImage;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.codesquad.sidedish.category.domain.dto;

import java.util.ArrayList;
import java.util.List;

public class SidedishItemPreviewListDTO {

private List<SidedishItemPreviewDTO> items;

public SidedishItemPreviewListDTO(List<SidedishItemPreviewDTO> previewDTOs) {
this.items = new ArrayList<>();
addDTO(previewDTOs);
}

private void addDTO(List<SidedishItemPreviewDTO> previewDTOs){
for (SidedishItemPreviewDTO previewDTO : previewDTOs) {
items.add(previewDTO);
}
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.codesquad.sidedish.category.domain;

import com.codesquad.sidedish.category.domain.dto.SidedishItemPreviewDTO;
import com.codesquad.sidedish.category.service.SidedishItemService;
import com.codesquad.sidedish.event.domain.SidedishEvent;
import com.codesquad.sidedish.event.domain.SidedishEventRepository;
Expand Down

0 comments on commit d20b021

Please sign in to comment.