This commit is contained in:
string 2025-08-29 09:08:54 +05:30
parent bbca71f125
commit 477647da0f
2 changed files with 16 additions and 8 deletions

View File

@ -7,6 +7,7 @@ import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@ -23,9 +24,10 @@ public class GeneratetokenController {
private GeneratetokenService generatetokenService;
@PostMapping("/generateToken")
public String generatetoken(@RequestParam String token_name) throws JsonProcessingException {
public Token_registery generatetoken(@RequestBody Token_registery reg) throws JsonProcessingException {
String token = generatetokenService.generatetoken(token_name);
String token_name = reg.getToken_name();
Token_registery token = generatetokenService.generatetoken(token_name);
return token;

View File

@ -7,6 +7,7 @@ import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
@ -29,13 +30,16 @@ public class GeneratetokenService {
@Autowired
private Token_registery_Repository token_registery_Repository;
public String generatetoken(String toekn_name) throws JsonProcessingException {
@Autowired
private BCryptPasswordEncoder bcryptEncoder;
public Token_registery generatetoken(String toekn_name) throws JsonProcessingException {
AppUser loggedInUser = userServiceImpl.getLoggedInUser();
String username = loggedInUser.getUsername();
String userPassw = loggedInUser.getUserPassw();
String userPassw = loggedInUser.getChangePassw();
StringBuilder builder = new StringBuilder();
@ -56,13 +60,13 @@ public class GeneratetokenService {
HttpEntity<Object> request = new HttpEntity<Object>(builder.toString(), headers);
ResponseEntity<String> res = restTemplate.postForEntity(resourceUrl, request, String.class);
Object object = res.getBody();
String object = res.getBody();
ObjectMapper mapper = new ObjectMapper();
String str = mapper.writeValueAsString(object);
// String str = mapper.writeValueAsString(object);
JsonParser parser = new JsonParser();
JsonElement element = parser.parse(str);
JsonElement element = parser.parse(object);
JsonObject obj = element.getAsJsonObject();
JsonObject item = obj.get("item").getAsJsonObject();
@ -74,9 +78,11 @@ public class GeneratetokenService {
token_registery.setToken_name(toekn_name);
token_registery.setCreatedBy(loggedInUser.getUserId());
Token_registery save = token_registery_Repository.save(token_registery);
System.out.println("token is == " + token);
return token;
return save;
}