Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package com.mtvs.devlinkbackend.channel.controller;

import com.mtvs.devlinkbackend.channel.dto.request.ObjectInfoRegistDTO;
import com.mtvs.devlinkbackend.channel.dto.response.ObjectInfoListResponseDTO;
import com.mtvs.devlinkbackend.channel.dto.response.ObjectInfoSingleResponseDTO;
import com.mtvs.devlinkbackend.channel.service.ObjectInfoService;
import com.mtvs.devlinkbackend.channel.service.ObjectInfoViewService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/tile/object")
public class ObjectInfoController {

private final ObjectInfoService objectInfoService;
private final ObjectInfoViewService objectInfoViewService;

public ObjectInfoController(ObjectInfoService objectInfoService, ObjectInfoViewService objectInfoViewService) {
this.objectInfoService = objectInfoService;
this.objectInfoViewService = objectInfoViewService;
}

@Operation(summary = "채널 ID로 ObjectInfo 리스트 조회", description = "특정 채널 ID와 연관된 모든 ObjectInfo 엔티티를 조회합니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "ObjectInfo 리스트를 성공적으로 조회했습니다.",
content = @Content(schema = @Schema(implementation = ObjectInfoListResponseDTO.class))),
@ApiResponse(responseCode = "404", description = "채널 ID를 찾을 수 없습니다.", content = @Content)
})
@GetMapping("/{channelId}")
public ResponseEntity<ObjectInfoListResponseDTO> getObjectInfoListByChannelId(@PathVariable String channelId) {
ObjectInfoListResponseDTO responseDTO = objectInfoViewService.findObjectInfoListByChannelId(channelId);
return ResponseEntity.ok(responseDTO);
}

@Operation(summary = "ObjectInfo 생성", description = "새로운 ObjectInfo를 생성합니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "201", description = "ObjectInfo가 성공적으로 생성되었습니다.",
content = @Content(schema = @Schema(implementation = ObjectInfoSingleResponseDTO.class))),
@ApiResponse(responseCode = "400", description = "입력 데이터가 유효하지 않습니다.", content = @Content)
})
@PostMapping("/{channelId}")
public ResponseEntity<ObjectInfoSingleResponseDTO> insertObjectInfo(
@PathVariable String channelId,
@RequestBody ObjectInfoRegistDTO objectInfoRegistDTO) {
ObjectInfoSingleResponseDTO responseDTO = objectInfoService.insertObjectInfoByChannelId(objectInfoRegistDTO, channelId);
return ResponseEntity.status(HttpStatus.CREATED).body(responseDTO);
}

@Operation(summary = "ObjectInfo 업데이트", description = "기존 ObjectInfo를 업데이트합니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "ObjectInfo가 성공적으로 업데이트되었습니다.",
content = @Content(schema = @Schema(implementation = ObjectInfoSingleResponseDTO.class))),
@ApiResponse(responseCode = "404", description = "ObjectInfo ID를 찾을 수 없습니다.", content = @Content)
})
@PutMapping("/{channelId}/{objectId}")
public ResponseEntity<ObjectInfoSingleResponseDTO> updateObjectInfo(
@PathVariable String objectId,
@PathVariable String channelId,
@RequestBody ObjectInfoRegistDTO objectInfoRegistDTO) {
ObjectInfoSingleResponseDTO responseDTO = objectInfoService.updateObjectInfoByObjectId(objectInfoRegistDTO, objectId, channelId);
return ResponseEntity.ok(responseDTO);
}

@Operation(summary = "ObjectInfo 삭제", description = "ObjectInfo를 ID로 삭제합니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "204", description = "ObjectInfo가 성공적으로 삭제되었습니다."),
@ApiResponse(responseCode = "404", description = "ObjectInfo ID를 찾을 수 없습니다.", content = @Content)
})
@DeleteMapping("/{objectId}")
public ResponseEntity<Void> deleteObjectInfo(@PathVariable String objectId) {
objectInfoService.deleteObjectInfoByObjectId(objectId);
return ResponseEntity.noContent().build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.mtvs.devlinkbackend.channel.dto.request;

import com.mtvs.devlinkbackend.channel.entity.Position;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;
import org.springframework.stereotype.Service;

@Getter
@Service
@NoArgsConstructor
@AllArgsConstructor
@ToString
public class ObjectInfoRegistDTO {
private String objectName;
private String objectClassName;
private Position position;
private Position rotator;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.mtvs.devlinkbackend.channel.dto.response;

import com.mtvs.devlinkbackend.channel.entity.ObjectInfo;
import lombok.*;

import java.util.List;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@ToString
public class ObjectInfoListResponseDTO {
private List<ObjectInfo> data;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.mtvs.devlinkbackend.channel.dto.response;

import com.mtvs.devlinkbackend.channel.entity.ObjectInfo;
import lombok.*;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@ToString
public class ObjectInfoSingleResponseDTO {
private ObjectInfo data;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.mtvs.devlinkbackend.channel.entity;

import jakarta.persistence.Id;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;

@NoArgsConstructor
@Document
@Data
public class ObjectInfo {
@Id
private String objectId;

private String objectName;

private String objectClassName;

@NotNull
private Position position;

@NotNull
private Position rotator;

@Indexed
private String channelId;

public ObjectInfo(String objectName, String objectClassName, Position position, Position rotator, String channelId) {
this.objectId = null;
this.objectName = objectName;
this.objectClassName = objectClassName;
this.position = position;
this.rotator = rotator;
this.channelId = channelId;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.mtvs.devlinkbackend.channel.repository;

import com.mtvs.devlinkbackend.channel.entity.ObjectInfo;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface ObjectInfoRepository extends MongoRepository<ObjectInfo, String> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.mtvs.devlinkbackend.channel.repository;

import com.mtvs.devlinkbackend.channel.entity.ObjectInfo;
import com.mtvs.devlinkbackend.channel.entity.TileInfo;
import org.springframework.data.mongodb.repository.MongoRepository;

import java.util.List;

public interface ObjectInfoViewRepository extends MongoRepository<ObjectInfo, String> {
List<ObjectInfo> findAllByChannelId(String channelId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.mtvs.devlinkbackend.channel.service;

import com.mtvs.devlinkbackend.channel.dto.request.ObjectInfoRegistDTO;
import com.mtvs.devlinkbackend.channel.dto.response.ObjectInfoSingleResponseDTO;
import com.mtvs.devlinkbackend.channel.entity.ObjectInfo;
import com.mtvs.devlinkbackend.channel.repository.ObjectInfoRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class ObjectInfoService {

private final ObjectInfoRepository objectInfoRepository;

public ObjectInfoService(ObjectInfoRepository objectInfoRepository) {
this.objectInfoRepository = objectInfoRepository;
}

@Transactional
public ObjectInfoSingleResponseDTO insertObjectInfoByChannelId(ObjectInfoRegistDTO objectInfoRegistDTO, String channelId) {
ObjectInfo objectInfo = objectInfoRepository.save(new ObjectInfo(
objectInfoRegistDTO.getObjectName(),
objectInfoRegistDTO.getObjectClassName(),
objectInfoRegistDTO.getPosition(),
objectInfoRegistDTO.getRotator(),
channelId
));

return new ObjectInfoSingleResponseDTO(objectInfo);
}

@Transactional
public ObjectInfoSingleResponseDTO updateObjectInfoByObjectId(
ObjectInfoRegistDTO objectInfoRegistDTO, String objectId, String channelId) {

ObjectInfo objectInfo = objectInfoRepository.findById(objectId).orElse(null);

if (objectInfo != null) {
objectInfo.setObjectName(objectInfoRegistDTO.getObjectName());
objectInfo.setObjectClassName(objectInfoRegistDTO.getObjectClassName());
objectInfo.setPosition(objectInfoRegistDTO.getPosition());
objectInfo.setRotator(objectInfoRegistDTO.getRotator());
objectInfo.setChannelId(channelId);

return new ObjectInfoSingleResponseDTO(objectInfo);
}
else throw new IllegalArgumentException("잘못된 ObjectInfoId로 수정 요청");
}

@Transactional
public void deleteObjectInfoByObjectId(String objectId) {
objectInfoRepository.deleteById(objectId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.mtvs.devlinkbackend.channel.service;

import com.mtvs.devlinkbackend.channel.dto.response.ObjectInfoListResponseDTO;
import com.mtvs.devlinkbackend.channel.entity.ObjectInfo;
import com.mtvs.devlinkbackend.channel.repository.ObjectInfoViewRepository;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ObjectInfoViewService {

private final ObjectInfoViewRepository objectInfoViewRepository;

public ObjectInfoViewService(ObjectInfoViewRepository objectInfoViewRepository) {
this.objectInfoViewRepository = objectInfoViewRepository;
}

public ObjectInfoListResponseDTO findObjectInfoListByChannelId(String channelId) {
List<ObjectInfo> objectInfoList = objectInfoViewRepository.findAllByChannelId(channelId);

return new ObjectInfoListResponseDTO(objectInfoList);
}
}
Loading