-
Notifications
You must be signed in to change notification settings - Fork 50
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 #11 from Malloc72P/controller
feat : controller 추가
- Loading branch information
Showing
5 changed files
with
75 additions
and
1 deletion.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
.../src/main/java/com/codesquad/sidedish/category/controller/SidedishCategoryController.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,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); | ||
} | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
...h/src/main/java/com/codesquad/sidedish/category/domain/dto/SidedishItemDetailListDTO.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,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; | ||
} | ||
} |
3 changes: 2 additions & 1 deletion
3
...tegory/domain/SidedishItemPreviewDTO.java → ...ry/domain/dto/SidedishItemPreviewDTO.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
21 changes: 21 additions & 0 deletions
21
.../src/main/java/com/codesquad/sidedish/category/domain/dto/SidedishItemPreviewListDTO.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,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); | ||
} | ||
} | ||
|
||
} |
1 change: 1 addition & 0 deletions
1
...t/java/com/codesquad/sidedish/category/domain/SidedishSidedishCategoryRepositoryTest.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