From 6ed9f2c5543aed03f1d006c6fb500feb6c76c756 Mon Sep 17 00:00:00 2001 From: Ryula Date: Fri, 17 Nov 2023 17:12:16 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[feat]=20socket=20=EC=9A=B4=EB=8F=99=20?= =?UTF-8?q?=EB=8F=99=EC=9E=91=20=EB=B3=B4=EB=82=B4=EA=B8=B0=20=EC=88=98?= =?UTF-8?q?=EC=A0=95(=EC=9A=B4=EB=8F=99=20=EB=8F=99=EC=9E=91=20=EA=B0=9C?= =?UTF-8?q?=EC=88=98=20=EC=B6=94=EA=B0=80)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../inha/how/Controller/StopmController.java | 8 ++++--- .../inha/how/Domain/dto/live/liveExRes.java | 18 ++++++++++++++++ .../inha/how/Domain/dto/live/liveRoutRes.java | 21 +++++++++++++++++++ .../inha/how/Repository/Live/LiveRoutine.java | 8 ++++--- .../how/Repository/Live/LiveRoutineImpl.java | 20 +++++++++++------- .../Routine/RoutineDetailRepository.java | 1 + .../Repository/Routine/RoutineRepository.java | 1 + .../java/inha/how/Service/LiveService.java | 12 +++++++---- .../java/inha/how/Service/StompService.java | 9 +++++--- 9 files changed, 78 insertions(+), 20 deletions(-) create mode 100644 src/main/java/inha/how/Domain/dto/live/liveExRes.java create mode 100644 src/main/java/inha/how/Domain/dto/live/liveRoutRes.java diff --git a/src/main/java/inha/how/Controller/StopmController.java b/src/main/java/inha/how/Controller/StopmController.java index e59216e..aac8052 100644 --- a/src/main/java/inha/how/Controller/StopmController.java +++ b/src/main/java/inha/how/Controller/StopmController.java @@ -2,6 +2,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; import inha.how.Domain.dto.live.ParticipateNicksMapping; +import inha.how.Domain.dto.live.liveExRes; +import inha.how.Domain.dto.live.liveRoutRes; import inha.how.Domain.dto.routine.RoutineDetailRes; import inha.how.Domain.entity.LiveRoom; import inha.how.Repository.Live.LiveRepository; @@ -53,16 +55,16 @@ public void sendMsg(@Payload Map data){ @SendTo public void sendStart(@Payload Map data, @DestinationVariable Long roomId){ - RoutineDetailRes routineDetailRes = liveRoutine.showRoutine(roomId); + liveRoutRes liveRoutRes = liveRoutine.showRoutine(roomId); - simpMessagingTemplate.convertAndSend("/room/routine/"+roomId, routineDetailRes); + simpMessagingTemplate.convertAndSend("/room/routine/"+roomId, liveRoutRes); } @MessageMapping("/routine/{roomId}") @SendTo public void sendRoutine(@Payload Map data, @DestinationVariable Long roomId){ - RoutineDetailRes modifiedRoutine =stompService.modifyRoutine(roomId, data); + liveRoutRes modifiedRoutine =stompService.modifyRoutine(roomId, data); simpMessagingTemplate.convertAndSend("/room/routine/"+roomId, modifiedRoutine); } diff --git a/src/main/java/inha/how/Domain/dto/live/liveExRes.java b/src/main/java/inha/how/Domain/dto/live/liveExRes.java new file mode 100644 index 0000000..bebcbd8 --- /dev/null +++ b/src/main/java/inha/how/Domain/dto/live/liveExRes.java @@ -0,0 +1,18 @@ +package inha.how.Domain.dto.live; + +import inha.how.Domain.dto.routine.RoutinneDetailResult; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.util.List; +import java.util.Set; + +@Getter +@NoArgsConstructor +@AllArgsConstructor +public class liveExRes { + private RoutinneDetailResult routinneDetailResult; + private Long ActionCnt; + +} diff --git a/src/main/java/inha/how/Domain/dto/live/liveRoutRes.java b/src/main/java/inha/how/Domain/dto/live/liveRoutRes.java new file mode 100644 index 0000000..bcd4b46 --- /dev/null +++ b/src/main/java/inha/how/Domain/dto/live/liveRoutRes.java @@ -0,0 +1,21 @@ +package inha.how.Domain.dto.live; + +import inha.how.Domain.dto.routine.RoutinneDetailResult; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.util.List; +import java.util.Set; + +@Getter +@NoArgsConstructor +@AllArgsConstructor +public class liveRoutRes { + private Long routId; + private String name; + private Integer hits; + private Long actionCnt; + private Set cate; + private List routineDetails; +} diff --git a/src/main/java/inha/how/Repository/Live/LiveRoutine.java b/src/main/java/inha/how/Repository/Live/LiveRoutine.java index f8402e7..f3102f8 100644 --- a/src/main/java/inha/how/Repository/Live/LiveRoutine.java +++ b/src/main/java/inha/how/Repository/Live/LiveRoutine.java @@ -1,15 +1,17 @@ package inha.how.Repository.Live; +import inha.how.Domain.dto.live.liveExRes; +import inha.how.Domain.dto.live.liveRoutRes; import inha.how.Domain.dto.routine.RoutineDetailRes; import lombok.NoArgsConstructor; import org.springframework.stereotype.Repository; public interface LiveRoutine { - void save(Long id, RoutineDetailRes routineDetailRes); + void save(Long id, liveRoutRes liveRoutRes); //수정 - RoutineDetailRes modifyRoutine(Long id, RoutineDetailRes routineDetailRes); + liveRoutRes modifyRoutine(Long id, liveRoutRes liveRoutRes); void deleteRoutine(); Object nextAction(Long id); - RoutineDetailRes showRoutine(Long id); + liveRoutRes showRoutine(Long id); } diff --git a/src/main/java/inha/how/Repository/Live/LiveRoutineImpl.java b/src/main/java/inha/how/Repository/Live/LiveRoutineImpl.java index 8b4ed43..4921a4d 100644 --- a/src/main/java/inha/how/Repository/Live/LiveRoutineImpl.java +++ b/src/main/java/inha/how/Repository/Live/LiveRoutineImpl.java @@ -1,6 +1,9 @@ package inha.how.Repository.Live; +import inha.how.Domain.dto.live.liveExRes; +import inha.how.Domain.dto.live.liveRoutRes; import inha.how.Domain.dto.routine.RoutineDetailRes; +import inha.how.Domain.dto.routine.RoutinneDetailResult; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Repository; @@ -11,18 +14,18 @@ @RequiredArgsConstructor public class LiveRoutineImpl implements LiveRoutine{ - private final Map liveRoutine=new ConcurrentHashMap<>(); + private final Map liveRoutine=new ConcurrentHashMap<>(); private final Map nextAction = new ConcurrentHashMap<>(); @Override - public void save(Long id, RoutineDetailRes routineDetailRes) { - liveRoutine.put(id, routineDetailRes); + public void save(Long id, liveRoutRes liveRoutRes) { + liveRoutine.put(id, liveRoutRes); nextAction.put(id, 0); } @Override - public RoutineDetailRes modifyRoutine(Long id, RoutineDetailRes routineDetailRes) { - liveRoutine.put(id, routineDetailRes); + public liveRoutRes modifyRoutine(Long id, liveRoutRes liveRoutRes) { + liveRoutine.put(id, liveRoutRes); return liveRoutine.get(id); } @@ -36,12 +39,15 @@ public void deleteRoutine() { public Object nextAction(Long id) { Integer next = nextAction.get(id); nextAction.put(id, next+1); + RoutinneDetailResult detail=liveRoutine.get(id).getRoutineDetails().get(next); + Long actionCnt=liveRoutine.get(id).getActionCnt(); + liveExRes liveExRes = new liveExRes(detail, actionCnt); - return liveRoutine.get(id).getRoutineDetails().get(next); + return liveExRes; } @Override - public RoutineDetailRes showRoutine(Long id){ + public liveRoutRes showRoutine(Long id){ return liveRoutine.get(id); } } diff --git a/src/main/java/inha/how/Repository/Routine/RoutineDetailRepository.java b/src/main/java/inha/how/Repository/Routine/RoutineDetailRepository.java index 7ed66f0..1b1ee0b 100644 --- a/src/main/java/inha/how/Repository/Routine/RoutineDetailRepository.java +++ b/src/main/java/inha/how/Repository/Routine/RoutineDetailRepository.java @@ -11,4 +11,5 @@ @Repository public interface RoutineDetailRepository extends JpaRepository { List findRoutineDetailsByRoutineOrderByOrderAsc(Routine routine); + Long countByRoutine(Routine routine); } diff --git a/src/main/java/inha/how/Repository/Routine/RoutineRepository.java b/src/main/java/inha/how/Repository/Routine/RoutineRepository.java index 8ddfd26..431494d 100644 --- a/src/main/java/inha/how/Repository/Routine/RoutineRepository.java +++ b/src/main/java/inha/how/Repository/Routine/RoutineRepository.java @@ -3,6 +3,7 @@ import inha.how.Domain.entity.Routine; import inha.how.Domain.entity.RoutineDetails; import inha.how.Domain.entity.User; +import jakarta.persistence.criteria.CriteriaBuilder; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; diff --git a/src/main/java/inha/how/Service/LiveService.java b/src/main/java/inha/how/Service/LiveService.java index cd98d86..330efd2 100644 --- a/src/main/java/inha/how/Service/LiveService.java +++ b/src/main/java/inha/how/Service/LiveService.java @@ -1,13 +1,14 @@ package inha.how.Service; -import inha.how.Domain.dto.live.liveAddRes; -import inha.how.Domain.dto.live.liveList; -import inha.how.Domain.dto.live.liveListRes; +import inha.how.Domain.dto.live.*; +import inha.how.Domain.dto.routine.RoutineDetailRes; import inha.how.Domain.entity.*; import inha.how.Domain.entity.Identify.ParticipateId; import inha.how.Repository.Live.LiveRepository; import inha.how.Repository.Live.LiveRoutine; import inha.how.Repository.Live.ParticipateRepository; +import inha.how.Repository.Routine.RoutineDetailRepository; +import inha.how.Repository.Routine.RoutineRepository; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.security.core.parameters.P; @@ -24,6 +25,7 @@ public class LiveService { private final LiveRepository liveRepository; private final ParticipateRepository participateRepository; + private final RoutineDetailRepository routineDetailRepository; private final RoutineService routineService; private final LiveRoutine liveRoutine; @@ -56,7 +58,9 @@ public liveAddRes addLive(User user, String subject, Long routId){ participateRepository.save(participate); // live방 운동 루틴 로컬 저장 - liveRoutine.save(liveRoom.getId(), routineService.findRoutineOne(routId)); + RoutineDetailRes routineDetailRes=routineService.findRoutineOne(routId); + liveRoutRes liveRoutRes = new liveRoutRes(routineDetailRes.getRoutId(), routineDetailRes.getName(), routineDetailRes.getHits(), routineDetailRepository.countByRoutine(routine), routineDetailRes.getCate(), routineDetailRes.getRoutineDetails()); + liveRoutine.save(liveRoom.getId(), liveRoutRes); return new liveAddRes(liveRoom.getId(), liveRoom.getRoomSubject()); } diff --git a/src/main/java/inha/how/Service/StompService.java b/src/main/java/inha/how/Service/StompService.java index 7aaf66f..7fdabe5 100644 --- a/src/main/java/inha/how/Service/StompService.java +++ b/src/main/java/inha/how/Service/StompService.java @@ -1,6 +1,8 @@ package inha.how.Service; import inha.how.Domain.dto.live.ParticipateNicksMapping; +import inha.how.Domain.dto.live.liveExRes; +import inha.how.Domain.dto.live.liveRoutRes; import inha.how.Domain.dto.routine.RoutineDetailRes; import inha.how.Domain.dto.routine.RoutinneDetailResult; import inha.how.Domain.entity.LiveRoom; @@ -22,15 +24,16 @@ public class StompService { private final LiveRepository liveRepository; private final ParticipateRepository participateRepository; - public RoutineDetailRes modifyRoutine(Long roomId, Map data){ + public liveRoutRes modifyRoutine(Long roomId, Map data){ Long routId=((Number) data.get("routId")).longValue(); String name=(String) data.get("name"); Integer hits=(Integer) data.get("hits"); + Long actionCnt=(Long) data.get("actionCnt"); List routinneDetailResultList = (List) data.get("routineDetails"); Set cate=(Set) data.get("cate"); - RoutineDetailRes detailRes=new RoutineDetailRes(routId, name, hits, cate, routinneDetailResultList); + liveRoutRes liveRoutRes=new liveRoutRes(routId, name, hits,actionCnt, cate, routinneDetailResultList); - RoutineDetailRes modifiedRoutine = liveRoutine.modifyRoutine(roomId, detailRes); + liveRoutRes modifiedRoutine = liveRoutine.modifyRoutine(roomId, liveRoutRes); return modifiedRoutine; } From 5094b37cb0da7fa73b1fdd574236a82e73b72c6e Mon Sep 17 00:00:00 2001 From: Ryula Date: Fri, 17 Nov 2023 18:07:30 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[feat]=20=EB=82=B4=20=EB=A3=A8=ED=8B=B4=20D?= =?UTF-8?q?atetime=20format=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../how/Domain/dto/routine/RoutineMeDetailMapping.java | 8 ++++---- src/main/java/inha/how/Domain/entity/BaseTimeEntity.java | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/inha/how/Domain/dto/routine/RoutineMeDetailMapping.java b/src/main/java/inha/how/Domain/dto/routine/RoutineMeDetailMapping.java index 4ab95c7..3f5a9eb 100644 --- a/src/main/java/inha/how/Domain/dto/routine/RoutineMeDetailMapping.java +++ b/src/main/java/inha/how/Domain/dto/routine/RoutineMeDetailMapping.java @@ -1,16 +1,16 @@ package inha.how.Domain.dto.routine; +import com.fasterxml.jackson.annotation.JsonFormat; +import org.springframework.format.annotation.DateTimeFormat; + import java.time.LocalDateTime; public interface RoutineMeDetailMapping { - //운동 id - //운동 제목 - //운동 횟수 - //내 루틴 생성 일자 Long getRoutineId(); String getRoutineSubject(); Integer getCount(); + @JsonFormat(pattern = "yyyy-MM-dd") LocalDateTime getCreateDate(); } diff --git a/src/main/java/inha/how/Domain/entity/BaseTimeEntity.java b/src/main/java/inha/how/Domain/entity/BaseTimeEntity.java index 8e96b59..10ac980 100644 --- a/src/main/java/inha/how/Domain/entity/BaseTimeEntity.java +++ b/src/main/java/inha/how/Domain/entity/BaseTimeEntity.java @@ -5,6 +5,7 @@ import lombok.Getter; import org.springframework.data.annotation.CreatedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; +import org.springframework.format.annotation.DateTimeFormat; import java.time.LocalDateTime;