Skip to content

Commit

Permalink
Merge pull request #9 from ingsis-group-6/refactor_put
Browse files Browse the repository at this point in the history
Refactor put
  • Loading branch information
ricardolopezb committed Jul 14, 2023
2 parents 5fc2507 + 281bb60 commit ced86ce
Show file tree
Hide file tree
Showing 5 changed files with 20 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
@@ -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) }
}
}

0 comments on commit ced86ce

Please sign in to comment.