Skip to content

Commit

Permalink
Merge pull request #43 from How-homework-out/master
Browse files Browse the repository at this point in the history
Master
  • Loading branch information
ryulkim authored Nov 17, 2023
2 parents 9d6f523 + 5094b37 commit dc11719
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 24 deletions.
8 changes: 5 additions & 3 deletions src/main/java/inha/how/Controller/StopmController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -53,16 +55,16 @@ public void sendMsg(@Payload Map<String,Object> data){
@SendTo
public void sendStart(@Payload Map<String,Long> 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<String, Object> data, @DestinationVariable Long roomId){

RoutineDetailRes modifiedRoutine =stompService.modifyRoutine(roomId, data);
liveRoutRes modifiedRoutine =stompService.modifyRoutine(roomId, data);

simpMessagingTemplate.convertAndSend("/room/routine/"+roomId, modifiedRoutine);
}
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/inha/how/Domain/dto/live/liveExRes.java
Original file line number Diff line number Diff line change
@@ -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;

}
21 changes: 21 additions & 0 deletions src/main/java/inha/how/Domain/dto/live/liveRoutRes.java
Original file line number Diff line number Diff line change
@@ -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<String> cate;
private List<RoutinneDetailResult> routineDetails;
}
Original file line number Diff line number Diff line change
@@ -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();

}
1 change: 1 addition & 0 deletions src/main/java/inha/how/Domain/entity/BaseTimeEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
8 changes: 5 additions & 3 deletions src/main/java/inha/how/Repository/Live/LiveRoutine.java
Original file line number Diff line number Diff line change
@@ -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);
}
20 changes: 13 additions & 7 deletions src/main/java/inha/how/Repository/Live/LiveRoutineImpl.java
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -11,18 +14,18 @@
@RequiredArgsConstructor
public class LiveRoutineImpl implements LiveRoutine{

private final Map<Long, RoutineDetailRes> liveRoutine=new ConcurrentHashMap<>();
private final Map<Long, liveRoutRes> liveRoutine=new ConcurrentHashMap<>();
private final Map<Long, Integer> 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);
}
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
@Repository
public interface RoutineDetailRepository extends JpaRepository<RoutineDetails, Long> {
List<RoutineDetailMapping> findRoutineDetailsByRoutineOrderByOrderAsc(Routine routine);
Long countByRoutine(Routine routine);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
12 changes: 8 additions & 4 deletions src/main/java/inha/how/Service/LiveService.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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());
}
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/inha/how/Service/StompService.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -22,15 +24,16 @@ public class StompService {
private final LiveRepository liveRepository;
private final ParticipateRepository participateRepository;

public RoutineDetailRes modifyRoutine(Long roomId, Map<String, Object> data){
public liveRoutRes modifyRoutine(Long roomId, Map<String, Object> 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<RoutinneDetailResult> routinneDetailResultList = (List<RoutinneDetailResult>) data.get("routineDetails");
Set<String> cate=(Set<String>) 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;
}
Expand Down

0 comments on commit dc11719

Please sign in to comment.