Skip to content

Commit

Permalink
Merge pull request #7 from ingsis-group-6/refactor_put
Browse files Browse the repository at this point in the history
Refactor put
  • Loading branch information
ricardolopezb authored Jul 13, 2023
2 parents 504697b + eabfdbe commit 5fc2507
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 19 deletions.
1 change: 1 addition & 0 deletions .github/workflows/dev-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
branches:
- develop
- dev
- refactor_put
jobs:
push_to_registry:
name: Push Docker image to GitHub Packages
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Any> {
return ResponseEntity(snippetService.getSnippetsByUserId(principal.name), HttpStatus.OK)
}

@DeleteMapping("/snippet/{id}")
@ResponseBody
fun deleteSnippet(@RequestHeader("Authorization") token: String, principal: Principal, @PathVariable id: UUID): ResponseEntity<String> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,18 @@ 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.id = id
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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down

0 comments on commit 5fc2507

Please sign in to comment.