From 5ecff0cc38f9b8a9f81554a81961e330770f9069 Mon Sep 17 00:00:00 2001 From: ricardolopezb Date: Thu, 13 Jul 2023 15:52:09 -0300 Subject: [PATCH 1/3] refactored put --- .github/workflows/dev-cd.yml | 1 + .../domains/snippet/dto/UpdateSnippetDTO.kt | 17 +---------------- .../snippet/service/SnippetServiceImpl.kt | 4 +--- 3 files changed, 3 insertions(+), 19 deletions(-) diff --git a/.github/workflows/dev-cd.yml b/.github/workflows/dev-cd.yml index b599230..8b2063c 100644 --- a/.github/workflows/dev-cd.yml +++ b/.github/workflows/dev-cd.yml @@ -4,6 +4,7 @@ on: branches: - develop - dev + - refactor_put jobs: push_to_registry: name: Push Docker image to GitHub Packages diff --git a/src/main/kotlin/ingsis/snippetmanager/domains/snippet/dto/UpdateSnippetDTO.kt b/src/main/kotlin/ingsis/snippetmanager/domains/snippet/dto/UpdateSnippetDTO.kt index 888cca1..1de2daf 100644 --- a/src/main/kotlin/ingsis/snippetmanager/domains/snippet/dto/UpdateSnippetDTO.kt +++ b/src/main/kotlin/ingsis/snippetmanager/domains/snippet/dto/UpdateSnippetDTO.kt @@ -5,32 +5,17 @@ import java.util.* class UpdateSnippetDTO { var id: UUID? = null - var name: String? = null - var type: String? = null var content: String? = null - var ownerId: String? = null - var createdAt: Date? = null constructor( - name: String?, - type: String?, + id: UUID?, content: String?, - ownerId: String?, - createdAt: Date? ) { - this.name = name - this.type = type this.content = content - this.ownerId = ownerId - this.createdAt = createdAt } constructor(snippet: Snippet){ - this.name = snippet.name - this.type = snippet.type this.content = snippet.content - this.ownerId = snippet.ownerId - this.createdAt = snippet.createdAt this.id = snippet.id } } \ No newline at end of file diff --git a/src/main/kotlin/ingsis/snippetmanager/domains/snippet/service/SnippetServiceImpl.kt b/src/main/kotlin/ingsis/snippetmanager/domains/snippet/service/SnippetServiceImpl.kt index 063c3c1..4346596 100644 --- a/src/main/kotlin/ingsis/snippetmanager/domains/snippet/service/SnippetServiceImpl.kt +++ b/src/main/kotlin/ingsis/snippetmanager/domains/snippet/service/SnippetServiceImpl.kt @@ -39,11 +39,9 @@ class SnippetServiceImpl: SnippetService { override fun updateSnippet(snippet: UpdateSnippetDTO, userId: String): SnippetDTO { val snippetToSave = this.snippetRepository.findById(snippet.id!!).get() - snippetToSave.name = snippet.name - snippetToSave.type = snippet.type snippetToSave.content = snippet.content snippetToSave.updatedAt = Date() - if (snippet.ownerId == userId) return SnippetDTO(this.snippetRepository.save(snippetToSave)) + if (snippetToSave.ownerId == userId) return SnippetDTO(this.snippetRepository.save(snippetToSave)) throw HTTPError("User must own the snippet to edit it", HttpStatus.FORBIDDEN) } From 34a942845ba89d3d8eb29a9c145624b051781f3f Mon Sep 17 00:00:00 2001 From: ricardolopezb Date: Thu, 13 Jul 2023 16:01:33 -0300 Subject: [PATCH 2/3] refactored put --- .../domains/snippet/controller/SnippetController.kt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/kotlin/ingsis/snippetmanager/domains/snippet/controller/SnippetController.kt b/src/main/kotlin/ingsis/snippetmanager/domains/snippet/controller/SnippetController.kt index fd73507..7fe5a38 100644 --- a/src/main/kotlin/ingsis/snippetmanager/domains/snippet/controller/SnippetController.kt +++ b/src/main/kotlin/ingsis/snippetmanager/domains/snippet/controller/SnippetController.kt @@ -50,6 +50,12 @@ class SnippetController { return ResponseEntity(snippetService.updateSnippet(snippet, userId), HttpStatus.OK) } + @GetMapping("/snippet/me") + @ResponseBody + fun mySnippets(@RequestHeader("Authorization") token: String, principal: Principal): ResponseEntity { + return ResponseEntity(snippetService.getSnippetsByUserId(principal.name), HttpStatus.OK) + } + @DeleteMapping("/snippet/{id}") @ResponseBody fun deleteSnippet(@RequestHeader("Authorization") token: String, principal: Principal, @PathVariable id: UUID): ResponseEntity { From eabfdbe976f99f976e552c3b13e62e16bde78d6f Mon Sep 17 00:00:00 2001 From: ricardolopezb Date: Thu, 13 Jul 2023 16:48:35 -0300 Subject: [PATCH 3/3] refactored put --- .../snippetmanager/domains/snippet/dto/UpdateSnippetDTO.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/kotlin/ingsis/snippetmanager/domains/snippet/dto/UpdateSnippetDTO.kt b/src/main/kotlin/ingsis/snippetmanager/domains/snippet/dto/UpdateSnippetDTO.kt index 1de2daf..6d83871 100644 --- a/src/main/kotlin/ingsis/snippetmanager/domains/snippet/dto/UpdateSnippetDTO.kt +++ b/src/main/kotlin/ingsis/snippetmanager/domains/snippet/dto/UpdateSnippetDTO.kt @@ -11,6 +11,7 @@ class UpdateSnippetDTO { id: UUID?, content: String?, ) { + this.id = id this.content = content }