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

Refactor put #9

Merged
merged 2 commits into from
Jul 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
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
@@ -1,5 +1,6 @@
package ingsis.snippetmanager.domains.snippet.dto

import ingsis.snippetmanager.domains.rule.model.ComplianceState
import ingsis.snippetmanager.domains.snippet.model.Snippet
import ingsis.snippetmanager.domains.test.dto.CreateTestDTO
import ingsis.snippetmanager.domains.test.model.Test
Expand All @@ -11,6 +12,7 @@ class SnippetDTO {
var name: String? = null
var type: String? = null
var content: String? = null
var compliance: ComplianceState? = null
var tests: List<CreateTestDTO>? = null
var ownerId: String? = null
var createdAt: Date? = null
Expand All @@ -29,6 +31,7 @@ class SnippetDTO {
this.tests = tests!!.map { CreateTestDTO(it.description, parseStringToList(it.input!!), parseStringToList(it.output!!), it.snippet!!.id) }
this.ownerId = ownerId
this.createdAt = createdAt
this.compliance = ComplianceState.PENDING
}

constructor(snippet: Snippet){
Expand All @@ -39,6 +42,7 @@ class SnippetDTO {
this.ownerId = snippet.ownerId
this.createdAt = snippet.createdAt
this.id = snippet.id
this.compliance = snippet.compliance
}

private fun parseStringToList(string: String): List<String?> {
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) }
}
}
Loading