Skip to content

Commit

Permalink
feat: Webpush for webcam
Browse files Browse the repository at this point in the history
  • Loading branch information
okodeee committed Jun 25, 2024
1 parent 26477a8 commit 27f13c3
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 11 deletions.
7 changes: 7 additions & 0 deletions src/main/java/vom/spring/domain/webcam/domain/Webcam.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

import jakarta.persistence.*;
import lombok.*;
import vom.spring.domain.homepy.Homepy;
import vom.spring.domain.webpush.domain.Webpush;

import java.time.LocalDateTime;

import static jakarta.persistence.FetchType.LAZY;

@Entity
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor(access = AccessLevel.PRIVATE)
Expand All @@ -18,4 +22,7 @@ public class Webcam {
private LocalDateTime createdAt;
@Enumerated(EnumType.STRING)
private Status status;

@OneToOne(mappedBy = "webcam", fetch = LAZY)
private Webpush webpush;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import vom.spring.domain.webcam.dto.WebcamResponseDto;
import vom.spring.domain.webcam.repository.MemberWebcamRepository;
import vom.spring.domain.webcam.repository.WebcamRepository;
import vom.spring.domain.webpush.domain.Webpush;
import vom.spring.domain.webpush.repository.WebpushRepository;

import java.time.LocalDateTime;
import java.util.List;
Expand All @@ -24,6 +26,7 @@ public class WebcamServiceImpl implements WebcamServcie{
private final WebcamRepository webcamRepository;
private final MemberRepository memberRepository;
private final MemberWebcamRepository memberWebcamRepository;
private final WebpushRepository webpushRepository;

/**
* 화상채팅 방 생성
Expand All @@ -42,6 +45,13 @@ public WebcamResponseDto.CreateWebcamDto createWebcamRoom(WebcamRequestDto.Creat
MemberWebcam toMemberWebcam = MemberWebcam.builder().member(toMember).webcam(newWebcam).build();
memberWebcamRepository.save(fromMemberWebcam);
memberWebcamRepository.save(toMemberWebcam);
webpushRepository.save(
Webpush.builder()
.createdAt(LocalDateTime.now())
.fromMember(fromMember)
.toMember(toMember)
.webcam(newWebcam)
.build());
return WebcamResponseDto.CreateWebcamDto.builder().webcamId(newWebcam.getId()).build();
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/vom/spring/domain/webpush/domain/Webpush.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class Webpush {
@JoinColumn(referencedColumnName = "id", name = "to_member_id", nullable = false)
private Member toMember;

// @OneToOne
// @JoinColumn(referencedColumnName = "id", name = "webcam_id", nullable = false)
// private Webcam webcam;
@OneToOne
@JoinColumn(referencedColumnName = "id", name = "webcam_id", nullable = false)
private Webcam webcam;
}
6 changes: 3 additions & 3 deletions src/main/java/vom/spring/domain/webpush/dto/WebpushDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
public class WebpushDto {
private Long fromMemberId;
private LocalDateTime createdAt;
// private Long webcamId;
private Long webcamId;

public WebpushDto(Long fromMemberId, LocalDateTime createdAt) {
public WebpushDto(Long fromMemberId, LocalDateTime createdAt, Long webcamId) {
this.fromMemberId = fromMemberId;
this.createdAt = createdAt;
// this.webcamId = webcamId;
this.webcamId = webcamId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ public void save(Webpush webpush) {
em.persist(webpush);
}

public List<WebpushDto> findFromMemberIdsByToMemberId(Long toMemberId) {
public List<WebpushDto> findByToMemberId(Long toMemberId) {
return em.createQuery(
"select new WebpushDto(w.fromMember.id, w.createdAt) " +
"select new WebpushDto(w.fromMember.id, w.createdAt, w.webcam.id) " +
"from Webpush w where w.toMember.id = :toMemberId",
WebpushDto.class)
.setParameter("toMemberId", toMemberId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ public WebpushService(WebpushRepository webpushRepository, MemberRepository memb
/**
* 웹푸쉬 조회
*/
@Transactional
public List<WebpushDto> getWebpushes(Long member_id) {
return webpushRepository.findFromMemberIdsByToMemberId(member_id);
public List<WebpushDto> getWebpushes(Long toMemberId) {
return webpushRepository.findByToMemberId(toMemberId);
}

/**
Expand Down

0 comments on commit 27f13c3

Please sign in to comment.