Skip to content

Commit 5e101b9

Browse files
authored
Merge pull request #135 from VRGuild/127-ds-tile-info-entity
[DS-tile-info-entity] TileInfo CRUD API 생성
2 parents b69e380 + 35928e1 commit 5e101b9

3 files changed

Lines changed: 93 additions & 3 deletions

File tree

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package com.mtvs.devlinkbackend.channel.controller;
2+
3+
import com.mtvs.devlinkbackend.channel.dto.request.TileInfoRegistDTO;
4+
import com.mtvs.devlinkbackend.channel.dto.response.TileInfoListResponseDTO;
5+
import com.mtvs.devlinkbackend.channel.service.TileInfoService;
6+
import com.mtvs.devlinkbackend.channel.service.TileInfoViewService;
7+
import io.swagger.v3.oas.annotations.Operation;
8+
import io.swagger.v3.oas.annotations.media.Content;
9+
import io.swagger.v3.oas.annotations.media.Schema;
10+
import io.swagger.v3.oas.annotations.responses.ApiResponse;
11+
import io.swagger.v3.oas.annotations.responses.ApiResponses;
12+
import org.springframework.http.HttpStatus;
13+
import org.springframework.http.ResponseEntity;
14+
import org.springframework.web.bind.annotation.*;
15+
16+
@RestController
17+
@RequestMapping("/api/tile/zone")
18+
public class TileInfoController {
19+
20+
private final TileInfoService tileInfoService;
21+
private final TileInfoViewService tileInfoViewService;
22+
23+
public TileInfoController(TileInfoService tileInfoService, TileInfoViewService tileInfoViewService) {
24+
this.tileInfoService = tileInfoService;
25+
this.tileInfoViewService = tileInfoViewService;
26+
}
27+
28+
@Operation(summary = "채널 ID로 TileInfo 리스트 조회", description = "특정 채널 ID와 연관된 모든 TileInfo 엔티티를 조회합니다.")
29+
@ApiResponses(value = {
30+
@ApiResponse(responseCode = "200", description = "TileInfo 리스트를 성공적으로 조회했습니다.",
31+
content = @Content(schema = @Schema(implementation = TileInfoListResponseDTO.class))),
32+
@ApiResponse(responseCode = "404", description = "채널 ID를 찾을 수 없습니다.", content = @Content)
33+
})
34+
@GetMapping("/{channelId}")
35+
public ResponseEntity<TileInfoListResponseDTO> getTileInfoListByChannelId(@PathVariable String channelId) {
36+
TileInfoListResponseDTO responseDTO = tileInfoViewService.findTileInfoListByChannelId(channelId);
37+
return ResponseEntity.ok(responseDTO);
38+
}
39+
40+
@Operation(summary = "TileInfo 생성", description = "특정 채널에 TileInfo를 생성합니다.")
41+
@ApiResponses(value = {
42+
@ApiResponse(responseCode = "201", description = "TileInfo가 성공적으로 생성되었습니다.",
43+
content = @Content(schema = @Schema(implementation = TileInfoRegistDTO.class))),
44+
@ApiResponse(responseCode = "400", description = "입력 데이터가 유효하지 않습니다.", content = @Content)
45+
})
46+
@PostMapping("/{channelId}")
47+
public ResponseEntity<TileInfoRegistDTO> insertTileInfo(
48+
@PathVariable String channelId,
49+
@RequestBody TileInfoRegistDTO tileInfoRegistDTO) {
50+
TileInfoRegistDTO responseDTO = tileInfoService.insertTileInfoByChannelId(tileInfoRegistDTO, channelId);
51+
return ResponseEntity.status(HttpStatus.CREATED).body(responseDTO);
52+
}
53+
54+
@Operation(summary = "TileInfo 업데이트", description = "특정 채널에 존재하는 TileInfo를 업데이트합니다.")
55+
@ApiResponses(value = {
56+
@ApiResponse(responseCode = "200", description = "TileInfo가 성공적으로 업데이트되었습니다.",
57+
content = @Content(schema = @Schema(implementation = TileInfoRegistDTO.class))),
58+
@ApiResponse(responseCode = "404", description = "TileInfo 또는 채널 ID를 찾을 수 없습니다.", content = @Content)
59+
})
60+
@PutMapping("/{channelId}/{tileId}")
61+
public ResponseEntity<TileInfoRegistDTO> updateTileInfo(
62+
@PathVariable String channelId,
63+
@PathVariable String tileId,
64+
@RequestBody TileInfoRegistDTO tileInfoRegistDTO) {
65+
TileInfoRegistDTO responseDTO = tileInfoService.updateTileInfoByChannelId(tileInfoRegistDTO, channelId, tileId);
66+
return ResponseEntity.ok(responseDTO);
67+
}
68+
69+
@Operation(summary = "TileInfo 삭제", description = "특정 채널에 연관된 모든 TileInfo를 삭제합니다.")
70+
@ApiResponses(value = {
71+
@ApiResponse(responseCode = "204", description = "TileInfo가 성공적으로 삭제되었습니다."),
72+
@ApiResponse(responseCode = "404", description = "채널 ID를 찾을 수 없습니다.", content = @Content)
73+
})
74+
@DeleteMapping("/{channelId}/{tileId}")
75+
public ResponseEntity<Void> deleteTileInfoByChannelId(@PathVariable String channelId, @PathVariable String tileId) {
76+
tileInfoService.deleteTileInfoByChannelId(channelId, tileId);
77+
return ResponseEntity.noContent().build();
78+
}
79+
}

src/main/java/com/mtvs/devlinkbackend/channel/service/TileInfoService.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,18 @@ public TileInfoRegistDTO insertTileInfoByChannelId(TileInfoRegistDTO tileInfoReg
2727
}
2828

2929
@Transactional
30-
public void deleteTileInfoByChannelId(String channelId) {
31-
tileInfoRepository.deleteAllByChannelId(channelId);
30+
public TileInfoRegistDTO updateTileInfoByChannelId(TileInfoRegistDTO tileInfoRegistDTO, String channelId, String tileId) {
31+
TileInfo tileInfo = tileInfoRepository.findById(tileId).orElse(null);
32+
33+
if(tileInfo != null) {
34+
tileInfo.setPosition(tileInfoRegistDTO.getPosition());
35+
return tileInfoRegistDTO;
36+
}
37+
else throw new IllegalArgumentException("잘못된 channelId로의 조회");
38+
}
39+
40+
@Transactional
41+
public void deleteTileInfoByChannelId(String channelId, String tileId) {
42+
tileInfoRepository.deleteById(tileId);
3243
}
3344
}

src/test/java/com/mtvs/devlinkbackend/crud/TileInfoCRDTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ void testDeleteTileInfoByChannelId() {
7575
TileInfo tileInfo = tileInfoRepository.save(new TileInfo(channelId, new Position(15, 25, 35)));
7676

7777
// When
78-
tileInfoService.deleteTileInfoByChannelId(channelId);
78+
tileInfoService.deleteTileInfoByChannelId(channelId, tileInfo.getTileId());
7979

8080
// Then
8181
boolean exists = tileInfoViewRepository.findAllByChannelId(channelId).isEmpty();

0 commit comments

Comments
 (0)