Skip to content

Commit

Permalink
Added compliance to snippet dto
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardolopezb committed Jul 14, 2023
1 parent 634c42b commit 281bb60
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ class SnippetController {
return ResponseEntity(snippetService.getSnippetsByUserIdAndSnippetId(userId, ids), HttpStatus.OK)
}

@GetMapping("/snippet/shared_with_me")
@ResponseBody
fun getSharedWithMeSnippets(@RequestHeader("Authorization") token: String, principal: Principal): ResponseEntity<List<SnippetDTO>> {
val ids = ShareSnippetService.getSharedWithMeSnippetsIds(token)
val userId = principal.name
return ResponseEntity(snippetService.getSnippetsFromIdList(ids), HttpStatus.OK)
}

@GetMapping("/snippet/all")
@ResponseBody
fun getAllSnippet(@RequestHeader("Authorization") token: String, principal: Principal): ResponseEntity<List<SnippetDTO>> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ interface SnippetRepository : JpaRepository<Snippet, UUID> {

@Query("SELECT s FROM Snippet s WHERE s.ownerId = :userId OR s.id IN :snippets")
fun findAllByUserIdAndSnippetId(userId: String, snippets: List<UUID>): List<Snippet>

@Query("SELECT s FROM Snippet s WHERE s.id IN :snippets")
fun findAllInIdList(snippets: List<UUID>): List<Snippet>
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ interface SnippetService {
fun getSnippetsByUserIdAndSnippetId(userId: String, snippets: List<UUID>): List<SnippetDTO>
fun validateOwnership(userId: String, snippetId: UUID)
fun setSnippetCompliance(snippetId: UUID, compliance: ComplianceState)
fun getSnippetsFromIdList(ids: List<UUID>): List<SnippetDTO>
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,8 @@ class SnippetServiceImpl: SnippetService {
throw HTTPError("Snippet not found", HttpStatus.NOT_FOUND)
}
}

override fun getSnippetsFromIdList(ids: List<UUID>): List<SnippetDTO> {
return this.snippetRepository.findAllInIdList(ids).map { SnippetDTO(it) }
}
}

0 comments on commit 281bb60

Please sign in to comment.