Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
DBMS inventory manager
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
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
Shrey Patel
DBMS inventory manager
Commits
9c97d89e
Commit
9c97d89e
authored
1 year ago
by
Shrey Patel
Browse files
Options
Downloads
Patches
Plain Diff
half done w update improvement
parent
59fde02e
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/com/example/accessingdatamysql/MainController.java
+39
-2
39 additions, 2 deletions
...n/java/com/example/accessingdatamysql/MainController.java
with
39 additions
and
2 deletions
src/main/java/com/example/accessingdatamysql/MainController.java
+
39
−
2
View file @
9c97d89e
...
@@ -14,19 +14,56 @@ public class MainController {
...
@@ -14,19 +14,56 @@ public class MainController {
private
UserRepository
userRepository
;
private
UserRepository
userRepository
;
@PostMapping
(
path
=
"/add"
)
// Map ONLY POST Requests
@PostMapping
(
path
=
"/add"
)
// Map ONLY POST Requests
@ResponseBody
@ResponseBody
public
User
addJsonUser
(
@RequestBody
User
usr
)
{
public
User
addJsonUser
(
@RequestBody
User
usr
)
{
// @ResponseBody means the returned String is the response, not a view name
// @ResponseBody means the returned String is the response, not a view name
// @RequestParam means it is a parameter from the GET or POST request
// @RequestParam means it is a parameter from the GET or POST request
userRepository
.
save
(
usr
);
userRepository
.
save
(
usr
);
return
usr
;
return
usr
;
}
}
@PutMapping
(
path
=
"/update"
)
@ResponseBody
public
User
updateUser
(
@RequestBody
User
usr
)
{
userRepository
.
save
(
usr
);
return
usr
;
}
@PutMapping
(
path
=
"/changepass"
)
@ResponseBody
public
User
updateUser
(
@RequestBody
Map
<
String
,
String
>
json
)
{
if
(
json
.
get
(
"email"
))
{
User
user
=
userRepository
.
findById
(
json
.
get
(
"email"
));
user
.
setPassword
(
json
.
get
(
"password"
));
userRepository
.
save
(
user
);
return
user
;
}
return
null
;
}
@GetMapping
(
path
=
"/all"
)
@GetMapping
(
path
=
"/all"
)
public
@ResponseBody
Iterable
<
User
>
getAllUsers
()
{
public
@ResponseBody
Iterable
<
User
>
getAllUsers
()
{
// This returns a JSON or XML with the users
// This returns a JSON or XML with the users
return
userRepository
.
findAll
();
return
userRepository
.
findAll
();
}
}
@GetMapping
(
path
=
"/user"
)
public
@ResponseBody
Optional
<
User
>
getUser
(
@RequestBody
String
email
)
{
return
userRepository
.
findById
(
email
);
}
@DeleteMapping
(
path
=
"/delete"
)
public
@ResponseBody
User
deleteUser
(
@RequestBody
String
email
)
{
User
found
=
null
;
found
=
userRepository
.
findById
(
email
).
get
();
if
(
found
!=
null
)
userRepository
.
deleteById
(
email
);
return
found
;
}
}
}
\ 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