-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[#132] fix : compile error fix
- Loading branch information
Showing
1 changed file
with
65 additions
and
61 deletions.
There are no files selected for viewing
126 changes: 65 additions & 61 deletions
126
src/main/kotlin/com/yapp/web2/domain/bookmark/service/BookmarkInterfaceService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,65 @@ | ||
package com.yapp.web2.domain.bookmark.service | ||
|
||
import com.yapp.web2.domain.bookmark.entity.* | ||
import com.yapp.web2.domain.bookmark.repository.BookmarkInterfaceRepository | ||
import com.yapp.web2.domain.folder.entity.Folder | ||
import com.yapp.web2.domain.folder.repository.FolderRepository | ||
import com.yapp.web2.exception.custom.ObjectNotFoundException | ||
import com.yapp.web2.exception.custom.BookmarkNotFoundException | ||
import com.yapp.web2.security.jwt.JwtProvider | ||
import org.springframework.stereotype.Service | ||
import org.springframework.transaction.annotation.Transactional | ||
|
||
@Service | ||
class BookmarkInterfaceService( | ||
private val bookmarkInterfaceRepository: BookmarkInterfaceRepository, | ||
private val folderRepository: FolderRepository, | ||
private val jwtProvider: JwtProvider | ||
) { | ||
fun moveBookmarkList(moveBookmarkDto: BookmarkDto.MoveBookmarkDto) { | ||
val bookmarkIdList = moveBookmarkDto.bookmarkIdList | ||
for (bookmarkId in bookmarkIdList) | ||
moveBookmark(bookmarkId, moveBookmarkDto) | ||
} | ||
|
||
fun moveBookmark(bookmarkId: String, moveBookmarkDto: BookmarkDto.MoveBookmarkDto) { | ||
val bookmark = getBookmarkIfPresent(bookmarkId) | ||
val nextFolder = checkFolderAbsence(moveBookmarkDto.nextFolderId) | ||
|
||
bookmark.folderId?.let { | ||
if(isSameFolder(it, moveBookmarkDto.nextFolderId)) return | ||
val beforeFolder = checkFolderAbsence(it) | ||
updateBookmarkCountByFolderId(beforeFolder, -1) | ||
} | ||
|
||
bookmark.changeFolderInfo(nextFolder) | ||
updateBookmarkCountByFolderId(nextFolder, 1) | ||
|
||
bookmarkInterfaceRepository.save(bookmark) | ||
} | ||
|
||
@Transactional | ||
protected fun updateBookmarkCountByFolderId(folder: Folder, count: Int) { | ||
folder.bookmarkCount += count | ||
} | ||
|
||
private fun isSameFolder(prevFolderId: Long, nextFolderId: Long) = prevFolderId == nextFolderId | ||
|
||
private fun getBookmarkIfPresent(bookmarkId: String): BookmarkInterface { | ||
return bookmarkInterfaceRepository.findBookmarkInterfaceById(bookmarkId) | ||
?: throw BookmarkNotFoundException() | ||
} | ||
private fun checkFolderAbsence(folderId: Long): Folder { | ||
return when (val folder = folderRepository.findFolderById(folderId)) { | ||
null -> throw ObjectNotFoundException() | ||
else -> folder | ||
} | ||
} | ||
|
||
fun remindToggleOn(token: String, bookmarkId: String) { | ||
val account = jwtProvider.getAccountFromToken(token) | ||
val bookmark = getBookmarkIfPresent(bookmarkId) | ||
//package com.yapp.web2.domain.bookmark.service | ||
// | ||
//import com.yapp.web2.domain.bookmark.BookmarkDto | ||
//import com.yapp.web2.domain.bookmark.entity.* | ||
//import com.yapp.web2.domain.bookmark.repository.BookmarkInterfaceRepository | ||
//import com.yapp.web2.domain.folder.entity.Folder | ||
//import com.yapp.web2.domain.folder.repository.FolderRepository | ||
//import com.yapp.web2.exception.custom.ObjectNotFoundException | ||
//import com.yapp.web2.exception.custom.BookmarkNotFoundException | ||
//import com.yapp.web2.security.jwt.JwtProvider | ||
//import org.springframework.stereotype.Service | ||
//import org.springframework.transaction.annotation.Transactional | ||
// | ||
//@Service | ||
//class BookmarkInterfaceService( | ||
// private val bookmarkInterfaceRepository: BookmarkInterfaceRepository, | ||
// private val folderRepository: FolderRepository, | ||
// private val jwtProvider: JwtProvider | ||
//) { | ||
// fun moveBookmarkList(moveBookmarkDto: BookmarkDto.MoveBookmarkDto) { | ||
// val bookmarkIdList = moveBookmarkDto.bookmarkIdList | ||
// for (bookmarkId in bookmarkIdList) | ||
// moveBookmark(bookmarkId, moveBookmarkDto) | ||
// } | ||
// | ||
// fun moveBookmark(bookmarkId: String, moveBookmarkDto: BookmarkDto.MoveBookmarkDto) { | ||
// val bookmark = getBookmarkIfPresent(bookmarkId) | ||
// val nextFolder = checkFolderAbsence(moveBookmarkDto.nextFolderId) | ||
// | ||
// bookmark.folderId?.let { | ||
// if (isSameFolder(it, moveBookmarkDto.nextFolderId)) return | ||
// val beforeFolder = checkFolderAbsence(it) | ||
// updateBookmarkCountByFolderId(beforeFolder, -1) | ||
// } | ||
// | ||
// bookmark.changeFolderInfo(nextFolder) | ||
// updateBookmarkCountByFolderId(nextFolder, 1) | ||
// | ||
// bookmarkInterfaceRepository.save(bookmark) | ||
// } | ||
// | ||
// @Transactional | ||
// protected fun updateBookmarkCountByFolderId(folder: Folder, count: Int) { | ||
// folder.bookmarkCount += count | ||
// } | ||
// | ||
// private fun isSameFolder(prevFolderId: Long, nextFolderId: Long) = prevFolderId == nextFolderId | ||
// | ||
// private fun getBookmarkIfPresent(bookmarkId: String): BookmarkInterface { | ||
// return bookmarkInterfaceRepository.findBookmarkInterfaceById(bookmarkId) | ||
// ?: throw BookmarkNotFoundException() | ||
// } | ||
// | ||
// private fun checkFolderAbsence(folderId: Long): Folder { | ||
// return when (val folder = folderRepository.findFolderById(folderId)) { | ||
// null -> throw ObjectNotFoundException() | ||
// else -> folder | ||
// } | ||
// } | ||
// | ||
// fun remindToggleOn(token: String, bookmarkId: String) { | ||
// val account = jwtProvider.getAccountFromToken(token) | ||
// val bookmark = getBookmarkIfPresent(bookmarkId) | ||
// } | ||
//} |