Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

문서 조회 수정 #61

Merged
merged 2 commits into from
Nov 14, 2023
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,6 +1,7 @@
package com.smart.watchboard.repository;

import com.smart.watchboard.domain.Document;
import com.smart.watchboard.domain.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
Expand All @@ -9,8 +10,7 @@

public interface DocumentRepository extends JpaRepository<Document, Long> {

@Query("SELECT d FROM Document d JOIN UserDocument ud ON d.documentId = ud.document.documentId WHERE ud.user.id = :userId AND d.isDeleted = false")
List<Document> findDocumentsByUserId(@Param("userId") Long userId);
List<Document> findByUserAndIsDeletedFalse(User user);

Document findByDocumentId(Long documentId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public List<DocumentDto> findDocumentsByUserId(String accessToken) {
String extractedAccessToken = jwtService.extractAccessToken(accessToken);
Optional<Long> userId = jwtService.extractUserId(extractedAccessToken);

List<Document> documents = documentRepository.findDocumentsByUserId(userId.get());
User user = userRepository.findById(userId).orElse(null);
List<Document> documents = documentRepository.findByUserAndIsDeletedFalse(user);
List<DocumentDto> documentDtos = new ArrayList<>();
for (Document document : documents) {
documentDtos.add(new DocumentDto(document.getDocumentId(), document.getDocumentName(), document.getCreatedAt(), document.getModifiedAt()));
Expand Down