Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Sprachschulsystem
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jan Pokorný
Sprachschulsystem
Commits
98089eaa
There was an error fetching the commit references. Please try again later.
Commit
98089eaa
authored
2 years ago
by
Dominika Zemanovičová
Committed by
Martin Gargalovič
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Add exercise update to ExerciseController
parent
4455ca49
No related branches found
No related tags found
3 merge requests
!31
M2
,
!28
M2 user
,
!27
Draft: M2 user
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
application/module-exercise/src/main/java/org/fuseri/moduleexercise/exercise/ExerciseController.java
+25
-0
25 additions, 0 deletions
...rg/fuseri/moduleexercise/exercise/ExerciseController.java
with
25 additions
and
0 deletions
application/module-exercise/src/main/java/org/fuseri/moduleexercise/exercise/ExerciseController.java
+
25
−
0
View file @
98089eaa
package
org.fuseri.moduleexercise.exercise
;
import
jakarta.persistence.EntityNotFoundException
;
import
org.fuseri.model.dto.common.Result
;
import
org.fuseri.model.dto.exercise.ExerciseCreateDto
;
import
org.fuseri.model.dto.exercise.ExerciseDto
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.domain.Page
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.server.ResponseStatusException
;
/**
* Represent a REST API controller for exercises
...
...
@@ -67,4 +70,26 @@ public class ExerciseController {
return
mapper
.
toResult
(
exercise
);
}
/**
* Update an existing exercise
*
* @param id the ID of the exercise to update
* @param dto the ExerciseCreateDto object containing information about the exercise to update
* @return an ExerciseDto object representing the updated exercise
*/
@PutMapping
(
"/{id}"
)
public
ExerciseDto
update
(
@PathVariable
String
id
,
@RequestBody
ExerciseCreateDto
dto
)
{
Exercise
exercise
=
mapper
.
fromCreateDto
(
dto
);
exercise
.
setId
(
id
);
try
{
Exercise
updatedExercise
=
service
.
update
(
exercise
);
return
mapper
.
toDto
(
updatedExercise
);
}
catch
(
IllegalArgumentException
e
)
{
throw
new
ResponseStatusException
(
HttpStatus
.
BAD_REQUEST
,
"Null exercise"
);
}
catch
(
EntityNotFoundException
e
)
{
throw
new
ResponseStatusException
(
HttpStatus
.
NOT_FOUND
,
"Exercise not found with id: "
+
id
);
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment