From 29eb5f4af5568c56f822955a2ac78ae9560eb3c1 Mon Sep 17 00:00:00 2001 From: ywonchae1 Date: Fri, 22 Nov 2024 19:17:46 +0900 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20CCTV=20=EC=9D=B4=EB=A6=84=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20=EA=B5=AC=ED=98=84=20(#159)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cctv/controller/CctvApi.java | 7 +++++++ .../cctv/controller/CctvController.java | 9 +++++++++ .../cctv/domain/CctvEntity.java | 5 +++++ .../cctv/dto/request/UpdateCctvNickname.java | 9 +++++++++ .../cctv/service/CctvService.java | 17 +++++++++++++++++ .../common/type/CctvSuccessType.java | 3 ++- 6 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 src/main/java/org/ioteatime/meonghanyangserver/cctv/dto/request/UpdateCctvNickname.java diff --git a/src/main/java/org/ioteatime/meonghanyangserver/cctv/controller/CctvApi.java b/src/main/java/org/ioteatime/meonghanyangserver/cctv/controller/CctvApi.java index 85968190..e3676ce5 100644 --- a/src/main/java/org/ioteatime/meonghanyangserver/cctv/controller/CctvApi.java +++ b/src/main/java/org/ioteatime/meonghanyangserver/cctv/controller/CctvApi.java @@ -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 { @@ -14,4 +17,8 @@ public interface CctvApi { @Operation(summary = "CCTV 정보 목록 조회", description = "담당자: 최민석") Api cctvInfoList(@LoginMember Long memberId, @PathVariable Long groupId); + + @Operation(summary = "CCTV 이름 변경", description = "담당자: 양원채") + Api updateNickName( + @LoginMember Long memberId, @RequestBody UpdateCctvNickname request); } diff --git a/src/main/java/org/ioteatime/meonghanyangserver/cctv/controller/CctvController.java b/src/main/java/org/ioteatime/meonghanyangserver/cctv/controller/CctvController.java index 150e3823..0ae974b0 100644 --- a/src/main/java/org/ioteatime/meonghanyangserver/cctv/controller/CctvController.java +++ b/src/main/java/org/ioteatime/meonghanyangserver/cctv/controller/CctvController.java @@ -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; @@ -26,4 +28,11 @@ public Api cctvInfoList( CctvInfoListResponse cctvInfoListResponse = cctvService.cctvInfoList(memberId, groupId); return Api.success(CctvSuccessType.GET_CCTV_DETAIL_LIST, cctvInfoListResponse); } + + @PatchMapping + public Api updateNickName( + @LoginMember Long memberId, @RequestBody UpdateCctvNickname request) { + CctvInfoResponse response = cctvService.updateNickname(memberId, request); + return Api.success(CctvSuccessType.UPDATE_NICKNAME, response); + } } diff --git a/src/main/java/org/ioteatime/meonghanyangserver/cctv/domain/CctvEntity.java b/src/main/java/org/ioteatime/meonghanyangserver/cctv/domain/CctvEntity.java index 79e85039..41cc1a14 100644 --- a/src/main/java/org/ioteatime/meonghanyangserver/cctv/domain/CctvEntity.java +++ b/src/main/java/org/ioteatime/meonghanyangserver/cctv/domain/CctvEntity.java @@ -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; + } } diff --git a/src/main/java/org/ioteatime/meonghanyangserver/cctv/dto/request/UpdateCctvNickname.java b/src/main/java/org/ioteatime/meonghanyangserver/cctv/dto/request/UpdateCctvNickname.java new file mode 100644 index 00000000..18d16b1b --- /dev/null +++ b/src/main/java/org/ioteatime/meonghanyangserver/cctv/dto/request/UpdateCctvNickname.java @@ -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) {} diff --git a/src/main/java/org/ioteatime/meonghanyangserver/cctv/service/CctvService.java b/src/main/java/org/ioteatime/meonghanyangserver/cctv/service/CctvService.java index 80329e3d..a3527021 100644 --- a/src/main/java/org/ioteatime/meonghanyangserver/cctv/service/CctvService.java +++ b/src/main/java/org/ioteatime/meonghanyangserver/cctv/service/CctvService.java @@ -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; @@ -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); + } } diff --git a/src/main/java/org/ioteatime/meonghanyangserver/common/type/CctvSuccessType.java b/src/main/java/org/ioteatime/meonghanyangserver/common/type/CctvSuccessType.java index 2a2a3486..f9a6f586 100644 --- a/src/main/java/org/ioteatime/meonghanyangserver/common/type/CctvSuccessType.java +++ b/src/main/java/org/ioteatime/meonghanyangserver/common/type/CctvSuccessType.java @@ -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; From e7f0b535d531f8da29c0d6b4e1cf7c0cc605fcaf Mon Sep 17 00:00:00 2001 From: ywonchae1 Date: Fri, 22 Nov 2024 23:52:38 +0900 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20GroupMember=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EC=BF=BC=EB=A6=AC=20=EA=B0=9C=EC=84=A0=20(#159)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../groupmember/repository/GroupMemberRepositoryImpl.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/org/ioteatime/meonghanyangserver/groupmember/repository/GroupMemberRepositoryImpl.java b/src/main/java/org/ioteatime/meonghanyangserver/groupmember/repository/GroupMemberRepositoryImpl.java index 1af18b57..ecac9a63 100644 --- a/src/main/java/org/ioteatime/meonghanyangserver/groupmember/repository/GroupMemberRepositoryImpl.java +++ b/src/main/java/org/ioteatime/meonghanyangserver/groupmember/repository/GroupMemberRepositoryImpl.java @@ -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; @@ -97,6 +98,8 @@ public Optional findByGroupIdAndMemberId(Long groupId, Long m return Optional.ofNullable( jpaQueryFactory .selectFrom(groupMemberEntity) + .join(groupMemberEntity.member, memberEntity) + .fetchJoin() .where( groupMemberEntity .group