Skip to content

Commit

Permalink
fix: cctv device 정보 api 토큰 사용에 따른 url 변경 및 로직 수정 (#254)
Browse files Browse the repository at this point in the history
  • Loading branch information
seok019283501 committed Dec 6, 2024
1 parent 5f85dff commit 7f7a51b
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.ioteatime.meonghanyangserver.cctv.dto.request.UpdateCctvNickname;
import org.ioteatime.meonghanyangserver.cctv.dto.response.CctvInfoListResponse;
import org.ioteatime.meonghanyangserver.cctv.dto.response.CctvInfoResponse;
import org.ioteatime.meonghanyangserver.cctv.dto.response.CctvNodeInfoResponse;
import org.ioteatime.meonghanyangserver.common.api.Api;
import org.ioteatime.meonghanyangserver.common.utils.LoginMember;
import org.springframework.web.bind.annotation.PathVariable;
Expand All @@ -24,5 +23,5 @@ Api<CctvInfoResponse> updateNickName(
@LoginMember Long memberId, @RequestBody UpdateCctvNickname request);

@Operation(summary = "CCTV 정보", description = "담당자: 양원채")
Api<CctvNodeInfoResponse> cctvInfo(@PathVariable("cctvId") Long cctvId);
Api<CctvInfoResponse> cctvInfo(@PathVariable("cctvId") Long cctvId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import org.ioteatime.meonghanyangserver.cctv.dto.request.UpdateCctvNickname;
import org.ioteatime.meonghanyangserver.cctv.dto.response.CctvInfoListResponse;
import org.ioteatime.meonghanyangserver.cctv.dto.response.CctvInfoResponse;
import org.ioteatime.meonghanyangserver.cctv.dto.response.CctvNodeInfoResponse;
import org.ioteatime.meonghanyangserver.cctv.service.CctvService;
import org.ioteatime.meonghanyangserver.common.api.Api;
import org.ioteatime.meonghanyangserver.common.type.CctvSuccessType;
Expand Down Expand Up @@ -38,8 +37,8 @@ public Api<CctvInfoResponse> updateNickName(
}

@GetMapping("/{cctvId}")
public Api<CctvNodeInfoResponse> cctvInfo(@PathVariable("cctvId") Long cctvId) {
CctvNodeInfoResponse cctvNodeInfoResponse = cctvService.cctvInfo(cctvId);
return Api.success(CctvSuccessType.GET_CCTV_DETAIL, cctvNodeInfoResponse);
public Api<CctvInfoResponse> cctvInfo(@PathVariable("cctvId") Long cctvId) {
CctvInfoResponse cctvInfoResponse = cctvService.cctvInfo(cctvId);
return Api.success(CctvSuccessType.GET_CCTV_DETAIL, cctvInfoResponse);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.ioteatime.meonghanyangserver.cctv.dto.request.CreateCctvRequest;
import org.ioteatime.meonghanyangserver.cctv.dto.response.CctvNodeInfoResponse;
import org.ioteatime.meonghanyangserver.cctv.dto.response.CctvSelfInfoResponse;
import org.ioteatime.meonghanyangserver.cctv.dto.response.CreateCctvResponse;
import org.ioteatime.meonghanyangserver.common.api.Api;
import org.springframework.web.bind.annotation.PathVariable;
import org.ioteatime.meonghanyangserver.common.utils.LoginMember;
import org.springframework.web.bind.annotation.RequestBody;

@Tag(name = "CCTV Device Api", description = "CCTV 기기에서 요청할 수 있는 API 목록입니다.")
Expand All @@ -16,5 +16,5 @@ public interface CctvDeviceApi {
Api<CreateCctvResponse> createCctv(@RequestBody CreateCctvRequest createCctvRequest);

@Operation(summary = "CCTV 정보", description = "담당자: 최민석")
Api<CctvNodeInfoResponse> cctvInfo(@PathVariable("cctvId") Long cctvId);
Api<CctvSelfInfoResponse> cctvInfo(@LoginMember Long cctvId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

import lombok.RequiredArgsConstructor;
import org.ioteatime.meonghanyangserver.cctv.dto.request.CreateCctvRequest;
import org.ioteatime.meonghanyangserver.cctv.dto.response.CctvNodeInfoResponse;
import org.ioteatime.meonghanyangserver.cctv.dto.response.CctvSelfInfoResponse;
import org.ioteatime.meonghanyangserver.cctv.dto.response.CreateCctvResponse;
import org.ioteatime.meonghanyangserver.cctv.service.CctvService;
import org.ioteatime.meonghanyangserver.common.api.Api;
import org.ioteatime.meonghanyangserver.common.type.CctvSuccessType;
import org.ioteatime.meonghanyangserver.common.utils.LoginMember;
import org.springframework.web.bind.annotation.*;

@RestController
Expand All @@ -21,9 +22,9 @@ public Api<CreateCctvResponse> createCctv(@RequestBody CreateCctvRequest createC
return Api.success(CctvSuccessType.CREATE_CCTV, createCctvResponse);
}

@GetMapping("/{cctvId}")
public Api<CctvNodeInfoResponse> cctvInfo(@PathVariable("cctvId") Long cctvId) {
CctvNodeInfoResponse cctvNodeInfoResponse = cctvService.cctvInfo(cctvId);
return Api.success(CctvSuccessType.GET_CCTV_DETAIL, cctvNodeInfoResponse);
@GetMapping
public Api<CctvSelfInfoResponse> cctvInfo(@LoginMember Long cctvId) {
CctvSelfInfoResponse cctvSelfInfoResponse = cctvService.cctvSelfInfo(cctvId);
return Api.success(CctvSuccessType.GET_CCTV_DETAIL, cctvSelfInfoResponse);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import jakarta.validation.constraints.NotBlank;

@Schema(description = "CCTV 단일 기기 정보 응답")
public record CctvNodeInfoResponse(
public record CctvSelfInfoResponse(
@NotBlank @Schema(description = "Group ID", example = "1") Long groupId,
@NotBlank @Schema(description = "CCTV ID", example = "1") Long cctvId,
@NotBlank @Schema(description = "CCTV 닉네임", example = "거실") String cctvNickname,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.ioteatime.meonghanyangserver.cctv.dto.db.CctvWithGroupId;
import org.ioteatime.meonghanyangserver.cctv.dto.response.CctvInfoListResponse;
import org.ioteatime.meonghanyangserver.cctv.dto.response.CctvInfoResponse;
import org.ioteatime.meonghanyangserver.cctv.dto.response.CctvNodeInfoResponse;
import org.ioteatime.meonghanyangserver.cctv.dto.response.CctvSelfInfoResponse;
import org.ioteatime.meonghanyangserver.cctv.dto.response.CreateCctvResponse;

public class CctvResponseMapper {
Expand All @@ -17,8 +17,8 @@ public static CctvInfoResponse from(CctvEntity cctvEntity) {
cctvEntity.getKvsChannelName());
}

public static CctvNodeInfoResponse CctvSelfInfoFrom(CctvWithGroupId cctvWithGroupId) {
return new CctvNodeInfoResponse(
public static CctvSelfInfoResponse CctvSelfInfoFrom(CctvWithGroupId cctvWithGroupId) {
return new CctvSelfInfoResponse(
cctvWithGroupId.groupId(),
cctvWithGroupId.cctvId(),
cctvWithGroupId.cctvNickname(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ public interface CctvRepository {

void deleteByGroupId(Long groupId);

Optional<CctvWithGroupId> findByCctvId(Long cctvId);
Optional<CctvEntity> findByCctvId(Long cctvId);

List<CctvEntity> findByGroupId(Long groupId);

Optional<CctvWithGroupId> findCctvWithGroupIdByCctvId(Long cctvId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,12 @@ public void deleteByGroupId(Long groupId) {
}

@Override
public Optional<CctvWithGroupId> findByCctvId(Long cctvId) {
CctvWithGroupId result =
public Optional<CctvEntity> findByCctvId(Long cctvId) {
CctvEntity result =
jpaQueryFactory
.select(
Projections.constructor(
CctvWithGroupId.class,
cctvEntity.group.id,
CctvEntity.class,
cctvEntity.id,
cctvEntity.cctvNickname,
cctvEntity.thingId,
Expand Down Expand Up @@ -85,4 +84,22 @@ public List<CctvEntity> findByGroupId(Long groupId) {

return result;
}

@Override
public Optional<CctvWithGroupId> findCctvWithGroupIdByCctvId(Long cctvId) {
CctvWithGroupId result =
jpaQueryFactory
.select(
Projections.constructor(
CctvWithGroupId.class,
cctvEntity.group.id,
cctvEntity.id,
cctvEntity.cctvNickname,
cctvEntity.thingId,
cctvEntity.kvsChannelName))
.from(cctvEntity)
.where(cctvEntity.id.eq(cctvId))
.fetchOne();
return Optional.ofNullable(result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.ioteatime.meonghanyangserver.cctv.dto.request.UpdateCctvNickname;
import org.ioteatime.meonghanyangserver.cctv.dto.response.CctvInfoListResponse;
import org.ioteatime.meonghanyangserver.cctv.dto.response.CctvInfoResponse;
import org.ioteatime.meonghanyangserver.cctv.dto.response.CctvNodeInfoResponse;
import org.ioteatime.meonghanyangserver.cctv.dto.response.CctvSelfInfoResponse;
import org.ioteatime.meonghanyangserver.cctv.dto.response.CreateCctvResponse;
import org.ioteatime.meonghanyangserver.cctv.mapper.CctvResponseMapper;
import org.ioteatime.meonghanyangserver.cctv.repository.CctvRepository;
Expand Down Expand Up @@ -88,12 +88,20 @@ public void outById(Long memberId, Long cctvId) {
cctvRepository.deleteById(cctvId);
}

public CctvNodeInfoResponse cctvInfo(Long cctvId) {
CctvWithGroupId cctvEntity =
public CctvInfoResponse cctvInfo(Long cctvId) {
CctvEntity cctvEntity =
cctvRepository
.findByCctvId(cctvId)
.orElseThrow(() -> new NotFoundException(CctvErrorType.NOT_FOUND));
return CctvResponseMapper.CctvSelfInfoFrom(cctvEntity);
return CctvResponseMapper.from(cctvEntity);
}

public CctvSelfInfoResponse cctvSelfInfo(Long cctvId) {
CctvWithGroupId cctvWithGroupId =
cctvRepository
.findCctvWithGroupIdByCctvId(cctvId)
.orElseThrow(() -> new NotFoundException(CctvErrorType.NOT_FOUND));
return CctvResponseMapper.CctvSelfInfoFrom(cctvWithGroupId);
}

public CctvInfoListResponse cctvInfoList(Long memberId, Long groupId) {
Expand Down

0 comments on commit 7f7a51b

Please sign in to comment.