Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package doldol_server.doldol.rollingPaper.repository;

import java.time.LocalDate;
import java.util.Optional;

import org.springframework.data.jpa.repository.JpaRepository;
Expand All @@ -8,11 +9,15 @@

import doldol_server.doldol.rollingPaper.entity.Paper;
import doldol_server.doldol.rollingPaper.repository.custom.PaperRepositoryCustom;
import feign.Param;

@Repository
public interface PaperRepository extends JpaRepository<Paper, Long>, PaperRepositoryCustom {
Optional<Paper> findByInvitationCode(String invitationCode);

@Query("select count(p) from Participant p where p.user.id = :userId")
int countByUserId(Long userId);

@Query("SELECT p.openDate FROM Paper p WHERE p.id = :paperId")
Optional<LocalDate> findOpenDateById(@Param("paperId") Long paperId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ public MessageResponse getMessage(Long messageId, Long userId) {
public MessageListResponse getMessages(Long paperId, MessageType messageType, CursorPageRequest request,
Long userId) {

Paper paper = paperRepository.findById(paperId)
LocalDate openDate = paperRepository.findOpenDateById(paperId)
.orElseThrow(() -> new CustomException(PaperErrorCode.PAPER_NOT_FOUND));

boolean isOpened = !paper.getOpenDate().isAfter(LocalDate.now());
boolean isOpened = !openDate.isAfter(LocalDate.now());
boolean isReceiveType = messageType == MessageType.RECEIVE;

List<MessageResponse> messages = isReceiveType
Expand Down Expand Up @@ -81,7 +81,7 @@ public MessageListResponse getMessages(Long paperId, MessageType messageType, Cu
@Transactional
public void createMessage(CreateMessageRequest request, Long userId) {

User fromUser = userService.getById(userId);
User fromUser = new User(userId);
User toUser = userService.getById(request.receiverId());

Paper paper = paperRepository.findById(request.paperId())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import doldol_server.doldol.rollingPaper.entity.Paper;
import doldol_server.doldol.rollingPaper.entity.Participant;
import doldol_server.doldol.rollingPaper.repository.ParticipantRepository;
import doldol_server.doldol.user.service.UserService;
import doldol_server.doldol.user.entity.User;
import lombok.RequiredArgsConstructor;

@Service
Expand All @@ -24,12 +24,11 @@
public class ParticipantService {

private final ParticipantRepository participantRepository;
private final UserService userService;

@Transactional
public void addUser(Long userId, Paper paper, boolean isMaster) {
Participant participant = Participant.builder()
.user(userService.getById(userId))
.user(new User(userId))
.paper(paper)
.isMaster(isMaster)
.build();
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/doldol_server/doldol/user/entity/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ public User(String loginId, String name, String password, String phone,
this.socialType = socialType;
}

@Builder
public User(Long id) {
this.id = id;
}

public void updateSocialInfo(String socialId, SocialType socialType) {
this.socialId = socialId;
this.socialType = socialType;
Expand Down
Loading