Skip to content

Commit

Permalink
Merge pull request #169 from YAPP-19th/feature/#132-공유
Browse files Browse the repository at this point in the history
[#132] 공유
  • Loading branch information
Ji-Ha authored Jul 15, 2022
2 parents 927f4bd + b981ecb commit 8014b1d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ interface BookmarkRepository : MongoRepository<Bookmark, String> {
fun findAllBookmarkByFcmToken(fcmToken: String): List<Bookmark>

@Query(value = "{\$and: [{folderId: {\$in: ?1}}, {deleted: false}, {remindList: {\$elemMatch: {userId : ?0}}}]}")
fun findRemindBookmarkInFolder(userId: Long, folderIdList: List<Long>): List<Bookmark>
fun findRemindBookmarkInFolder(userId: Long, folderIdList: List<Long>, pageable: Pageable): Page<Bookmark>

@Query(value = "{\$or: [{folderId: {\$in: ?1}}, {userId: ?0}]}")
fun findAllBookmark(userId: Long, folderIdList: List<Long>): List<Bookmark>
fun findAllBookmark(userId: Long, folderIdList: List<Long>, pageable: Pageable): Page<Bookmark>

@Query(value = "{\$and: [{remindList: {\$elemMatch: {userId: ?0}}}, {remindList: {\$elemMatch: {remindTime: ?1}}}]}")
fun findTodayRemindBookmark(userId: Long, today: String): List<Bookmark>

@Query(value = "{ 'remindList': { \$elemMatch: { 'userId' : ?0 } } }")
fun findRemindBookmark(userId: Long): List<Bookmark>
fun findRemindBookmark(userId: Long, pageable: Pageable): Page<Bookmark>
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import com.yapp.web2.domain.bookmark.repository.BookmarkRepository
import com.yapp.web2.domain.folder.entity.Folder
import com.yapp.web2.security.jwt.JwtProvider
import org.springframework.data.domain.Page
import org.springframework.data.domain.PageImpl
import org.springframework.data.domain.Pageable
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
Expand All @@ -28,11 +27,7 @@ class BookmarkPageService(
val userId = jwtProvider.getIdFromToken(token)

return when (remind) {
true -> {
val bookmarkList =
bookmarkRepository.findRemindBookmarkInFolder(userId, folderIdList = mutableListOf(folderId))
PageImpl(bookmarkList, pageable, bookmarkList.size.toLong())
}
true -> bookmarkRepository.findRemindBookmarkInFolder(userId, folderIdList = mutableListOf(folderId), pageable)
false -> bookmarkRepository.findAllByFolderIdAndDeletedIsFalse(folderId, pageable)
}
}
Expand All @@ -52,19 +47,15 @@ class BookmarkPageService(
val account = jwtProvider.getAccountFromToken(token)

return when (remind) {
true -> {
val bookmarkList =
bookmarkRepository.findRemindBookmark(account.id!!)
PageImpl(bookmarkList, pageable, bookmarkList.size.toLong())
}
true -> bookmarkRepository.findRemindBookmark(account.id!!, pageable)

false -> {
val folderIdList = mutableListOf<Long>()

for (af in account.accountFolderList)
folderIdList.addAll(getAllLowerFolderId(af.folder))

val bookmarkList = bookmarkRepository.findAllBookmark(account.id!!, folderIdList)
PageImpl(bookmarkList, pageable, bookmarkList.size.toLong())
bookmarkRepository.findAllBookmark(account.id!!, folderIdList, pageable)
}
}
}
Expand All @@ -88,6 +79,4 @@ class BookmarkPageService(
bookmarkRepository.findTodayRemindBookmark(idFromToken, yesterday)
)
}


}
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
package com.yapp.web2.domain.folder.entity

import com.yapp.web2.domain.account.entity.Account
import javax.persistence.Entity
import javax.persistence.GeneratedValue
import javax.persistence.Id
import javax.persistence.JoinColumn
import javax.persistence.ManyToOne
import javax.persistence.FetchType
import javax.persistence.GenerationType
import javax.persistence.*

@Entity
class AccountFolder(
Expand All @@ -29,5 +23,6 @@ class AccountFolder(
@GeneratedValue(strategy = GenerationType.IDENTITY)
var id: Long? = null

@Enumerated(EnumType.STRING)
var authority: Authority = Authority.NONE
}

0 comments on commit 8014b1d

Please sign in to comment.