Skip to content

Commit

Permalink
refactored put
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardolopezb committed Jul 13, 2023
1 parent 504697b commit 5ecff0c
Show file tree
Hide file tree
Showing 3 changed files with 3 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 @@ -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
}
}
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 5ecff0c

Please sign in to comment.