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
Expand Up @@ -120,4 +120,14 @@ class RestApiServerController(
serverService.updateServerHost(serverId, userInfo.userId, otherUser)
return ResponseEntity.ok().build()
}

@PatchMapping("/{serverId}/bookmark")
fun updateServerBookmarkStatus(
@PathVariable serverId: String,
@RequestHeader("Authorization") token: String,
): ResponseEntity<Any> {
val userInfo = authClient.getTokenInfo(token).data!!
val result = serverService.updateServerBookmarkStatus(serverId, userInfo.userId)
return ResponseEntity.ok().body(ApiResponse(data = result))
}
}
6 changes: 5 additions & 1 deletion server/src/main/kotlin/kpring/server/domain/ServerProfile.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class ServerProfile(
val imagePath: String,
val server: Server,
var role: ServerRole = ServerRole.MEMBER,
val bookmarked: Boolean = false,
var bookmarked: Boolean = false,
) {
/**
* @param authority 확인할 권한
Expand All @@ -30,4 +30,8 @@ class ServerProfile(
serverProfile.role = ServerRole.OWNER
}
}

fun updateBookmarkStatus(serverProfile: ServerProfile) {
serverProfile.bookmarked = !serverProfile.bookmarked
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ interface ServerProfileCustomRepository {
fun getOwnedProfiles(userId: String): List<ServerProfile>

fun getAll(serverId: String): List<ServerProfile>

fun updateBookmarkStatus(serverProfile: ServerProfile)
}
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,21 @@ class ServerProfileCustomRepositoryImpl(
}
}

override fun updateBookmarkStatus(serverProfile: ServerProfile) {
val newBookmarkStatus = !serverProfile.bookmarked
val result =
template.updateFirst(
Query.query(
Criteria.where("_id").`is`(serverProfile.id),
),
Update().set("bookmarked", newBookmarkStatus),
ServerProfileEntity::class.java,
)
println("@@@Check : ${result.matchedCount} modified ${result.modifiedCount}")

serverProfileRepository.save(ServerProfileEntity(serverProfile))
}

/**
* serverIds 목록 중에서 condition에 포함되는 serverId만 검색한다.
* 만약 condition이 없는 경우에는 serverIds 목록 전체를 검색한다.
Expand Down
5 changes: 5 additions & 0 deletions server/src/main/kotlin/kpring/server/service/ServerService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,9 @@ interface ServerService {
fun delete(serverId: String)

fun get(id: String): Server

fun updateServerBookmarkStatus(
serverId: String,
userId: String,
): Boolean
}
12 changes: 12 additions & 0 deletions server/src/main/kotlin/kpring/server/service/ServerServiceImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,16 @@ class ServerServiceImpl(

return serverEntity.toDomain()
}

override fun updateServerBookmarkStatus(
serverId: String,
userId: String,
): Boolean {
val serverProfile = serverProfileCustomRepository.get(serverId, userId)

serverProfile.updateBookmarkStatus(serverProfile)
serverProfileCustomRepository.updateBookmarkStatus(serverProfile)

return serverProfile.bookmarked
}
}
Loading