Skip to content

Commit

Permalink
Merge pull request #160 from IoTeaTime/feature/159-cctv-name-update
Browse files Browse the repository at this point in the history
feat: CCTV 이름 수정 구현
  • Loading branch information
ywonchae1 authored Nov 23, 2024
2 parents 15ff3c6 + e7f0b53 commit 1ec191f
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
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.common.api.Api;
import org.ioteatime.meonghanyangserver.common.utils.LoginMember;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;

@Tag(name = "CCTV Api", description = "CCTV 관련 API 목록입니다.")
public interface CctvApi {
Expand All @@ -14,4 +17,8 @@ public interface CctvApi {

@Operation(summary = "CCTV 정보 목록 조회", description = "담당자: 최민석")
Api<CctvInfoListResponse> cctvInfoList(@LoginMember Long memberId, @PathVariable Long groupId);

@Operation(summary = "CCTV 이름 변경", description = "담당자: 양원채")
Api<CctvInfoResponse> updateNickName(
@LoginMember Long memberId, @RequestBody UpdateCctvNickname request);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package org.ioteatime.meonghanyangserver.cctv.controller;

import lombok.RequiredArgsConstructor;
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.service.CctvService;
import org.ioteatime.meonghanyangserver.common.api.Api;
import org.ioteatime.meonghanyangserver.common.type.CctvSuccessType;
Expand All @@ -26,4 +28,11 @@ public Api<CctvInfoListResponse> cctvInfoList(
CctvInfoListResponse cctvInfoListResponse = cctvService.cctvInfoList(memberId, groupId);
return Api.success(CctvSuccessType.GET_CCTV_DETAIL_LIST, cctvInfoListResponse);
}

@PatchMapping
public Api<CctvInfoResponse> updateNickName(
@LoginMember Long memberId, @RequestBody UpdateCctvNickname request) {
CctvInfoResponse response = cctvService.updateNickname(memberId, request);
return Api.success(CctvSuccessType.UPDATE_NICKNAME, response);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,9 @@ public CctvEntity(Long id, String cctvNickname, String kvsChannelName, String th
this.kvsChannelName = kvsChannelName;
this.thingId = thingId;
}

public CctvEntity updateNickname(String nickname) {
this.cctvNickname = nickname;
return this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.ioteatime.meonghanyangserver.cctv.dto.request;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;

@Schema(description = "CCTV 이름 수정 요청")
public record UpdateCctvNickname(
@NotNull @Schema(description = "수정할 CCTV ID", example = "1") Long cctvId,
@NotNull @Schema(description = "수정할 CCTV 이름", example = "멍하냥CCTV") String cctvNickname) {}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import lombok.RequiredArgsConstructor;
import org.ioteatime.meonghanyangserver.cctv.domain.CctvEntity;
import org.ioteatime.meonghanyangserver.cctv.dto.request.CreateCctvRequest;
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.mapper.CctvResponseMapper;
Expand Down Expand Up @@ -90,4 +91,20 @@ public CctvInfoListResponse cctvInfoList(Long memberId, Long groupId) {
CctvInfoListResponse cctvInfoListResponse = new CctvInfoListResponse(cctvInfoResponseList);
return cctvInfoListResponse;
}

@Transactional
public CctvInfoResponse updateNickname(Long memberId, UpdateCctvNickname request) {
// cctvId로 cctv 객체 찾기
CctvEntity cctvEntity =
cctvRepository
.findById(request.cctvId())
.orElseThrow(() -> new NotFoundException(CctvErrorType.NOT_FOUND));
// groupId와 memberId로 groupMember가 존재하는지 확인 -> 아니면 에러
groupMemberRepository
.findByGroupIdAndMemberId(cctvEntity.getGroup().getId(), memberId)
.orElseThrow(() -> new NotFoundException(GroupErrorType.GROUP_MEMBER_NOT_FOUND));
// cctv 이름 변경
cctvEntity = cctvEntity.updateNickname(request.cctvNickname());
return CctvResponseMapper.from(cctvEntity);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ public enum CctvSuccessType implements SuccessTypeCode {
CREATE_CCTV(201, "CREATE", "CCTV 생성에 성공하였습니다."),
DELETE_CCTV(200, "OK", "CCTV 삭제(퇴출)에 성공하였습니다."),
GET_CCTV_DETAIL_LIST(200, "OK", "CCTV 정보 목록 조회에 성공하였습니다."),
GET_CCTV_DETAIL(200, "OK", "CCTV 정보 조회에 성공하였습니다.");
GET_CCTV_DETAIL(200, "OK", "CCTV 정보 조회에 성공하였습니다."),
UPDATE_NICKNAME(200, "OK", "CCTV 이름 수정에 성공하였습니다.");

private final Integer code;
private final String message;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.ioteatime.meonghanyangserver.groupmember.repository;

import static org.ioteatime.meonghanyangserver.groupmember.doamin.QGroupMemberEntity.groupMemberEntity;
import static org.ioteatime.meonghanyangserver.member.domain.QMemberEntity.memberEntity;

import com.querydsl.core.types.Projections;
import com.querydsl.jpa.impl.JPAQueryFactory;
Expand Down Expand Up @@ -97,6 +98,8 @@ public Optional<GroupMemberEntity> findByGroupIdAndMemberId(Long groupId, Long m
return Optional.ofNullable(
jpaQueryFactory
.selectFrom(groupMemberEntity)
.join(groupMemberEntity.member, memberEntity)
.fetchJoin()
.where(
groupMemberEntity
.group
Expand Down

0 comments on commit 1ec191f

Please sign in to comment.