Created
May 4, 2020 15:34
-
-
Save edwin/9f8106d7432c6f06348c767d60bcd1fd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.redhat.edwin.controller; | |
import com.redhat.edwin.annotation.Decrypt; | |
import com.redhat.edwin.annotation.Encrypt; | |
import com.redhat.edwin.model.UserProfile; | |
import com.redhat.edwin.repository.UserProfileRepository; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.web.bind.annotation.*; | |
import java.util.Date; | |
import java.util.HashMap; | |
import java.util.List; | |
/** | |
* <pre> | |
* com.redhat.edwin.controller.IndexController | |
* </pre> | |
* | |
* @author Muhammad Edwin < edwin at redhat dot com > | |
* 04 Mei 2020 11:37 | |
*/ | |
@RestController | |
public class IndexController { | |
@Autowired | |
private UserProfileRepository userProfileRepository; | |
@GetMapping("/") | |
@Decrypt(values = {"fullname", "address", "phonenumber"}) | |
public List<UserProfile> index() { | |
return userProfileRepository.findAll(); | |
} | |
@GetMapping("/{id}") | |
@Decrypt(values = {"fullname", "address", "phonenumber"}) | |
public UserProfile get(@PathVariable Integer id) { | |
return userProfileRepository.findById(id).orElse(new UserProfile()); | |
} | |
@PostMapping("/save") | |
@Encrypt(values = {"fullname", "address", "phonenumber"}) | |
public HashMap save(@RequestBody UserProfile userProfile) { | |
userProfile.setCreatedDate(new Date()); | |
userProfileRepository.save(userProfile); | |
return new HashMap() {{ | |
put("id", userProfile.getId()); | |
}}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment