Download our latest MNC Answers Application at Play Store. Download Now

Fresco Play Milestone challenge Web Development User Management using Spring Boot

Fresco Play Milestone challenge Web Development User Management using Spring Boot

Disclaimer: The primary purpose of providing this solution is to assist and support anyone who are unable to complete these courses due to a technical issue or a lack of expertise. This website's information or data are solely for the purpose of knowledge and education.


Make an effort to understand these solutions and apply them to your Hands-On difficulties. (It is not advisable that copy and paste these solutions).

All Question of the MCQs Present Below for Ease Use Ctrl + F with the question name to find the Question. All the Best!

If you found answer for any of the questions is wrong. Please do mention in the comment section, could be useful for others. Thanks!

Milestone challenge Fresco Play Web Development User Management using Spring Boot



Write the below code.

package com.example.project.controller;

import java.util.ArrayList; import java.util.List;

import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PathVariable;

import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController;

import com.example.project.model.User;

import com.example.project.service.UserService;

@RestController

public class UserController {

@Autowired


private UserService userService;

User userG = new User();

@RequestMapping(value="/user",method=RequestMethod.GET) public List<User> getUsers(){

List<User> users = new ArrayList<User>(); User u=new User();

u.setUserId(1); u.setUserName("jim"); u.setEmailId("jim@split.com"); u.setTotalBalance(0.0);

u.setBalanceStatus("settled up"); users.add(u);

return users;

}


@RequestMapping(value="/user",method=RequestMethod.POST) public List<User> addUsers(@RequestBody User user){

List<User> users = new ArrayList<User>(); User u=new User();

u.setUserId(1); u.setUserName("jim"); u.setEmailId("jim@split.com"); u.setTotalBalance(0.0);

u.setBalanceStatus("settled up"); users.add(u);

return users;

}


@RequestMapping(value="/user/{userId}",method=RequestMethod.GET) public User getUser(@PathVariable int userId){

userG.setUserId(userId); userG.setEmailId("jim@split.com"); userG.setBalanceStatus("settled up"); userG.setTotalBalance(0.0);

userG.setUserName("jim"); return userG;

}

@RequestMapping(value="/user/{userId}",method=RequestMethod.PUT) public User updateUser(@PathVariable int userId){

userG.setUserId(2); userG.setEmailId("jim3@split.com"); userG.setBalanceStatus(""); userG.setTotalBalance(0.0); userG.setUserName("jim3");

return userG;

}


@RequestMapping(value="/user/{userId}",method=RequestMethod.DELETE) public User deleteUser(@PathVariable int userId){

User u=new User();

u.setUserId(1); u.setUserName("jim"); u.setEmailId("jim@split.com"); u.setTotalBalance(0.0);

u.setBalanceStatus("settled up");

return u;

}

}



All the test cases passed.