|
|
|
@@ -53,6 +53,8 @@ import java.io.UnsupportedEncodingException; |
|
|
|
import jakarta.validation.Valid; |
|
|
|
import jakarta.validation.constraints.NotBlank; |
|
|
|
|
|
|
|
import com.ffii.fpsms.modules.common.internalSetup.UsersSetup; |
|
|
|
|
|
|
|
@RestController |
|
|
|
@RequestMapping("/user") |
|
|
|
public class UserController{ |
|
|
|
@@ -62,16 +64,19 @@ public class UserController{ |
|
|
|
private PasswordEncoder passwordEncoder; |
|
|
|
private SettingsService settingsService; |
|
|
|
private UserQrCodeService userQrCodeService; |
|
|
|
|
|
|
|
private UsersSetup usersSetup; |
|
|
|
|
|
|
|
public UserController( |
|
|
|
UserService userService, |
|
|
|
PasswordEncoder passwordEncoder, |
|
|
|
SettingsService settingsService, |
|
|
|
UserQrCodeService userQrCodeService) { |
|
|
|
this.userService = userService; |
|
|
|
UserQrCodeService userQrCodeService, |
|
|
|
UsersSetup usersSetup) { |
|
|
|
this.userService = userService; |
|
|
|
this.passwordEncoder = passwordEncoder; |
|
|
|
this.settingsService = settingsService; |
|
|
|
this.userQrCodeService = userQrCodeService; |
|
|
|
this.usersSetup = usersSetup; |
|
|
|
} |
|
|
|
|
|
|
|
// @Operation(summary = "list user", responses = { @ApiResponse(responseCode = "200"), |
|
|
|
@@ -293,4 +298,31 @@ public class UserController{ |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@PostMapping("/users-setup") |
|
|
|
public ResponseEntity<Map<String, Object>> importUsersFromExcel(@RequestBody Map<String, String> request) { |
|
|
|
String filePath = request.get("filePath"); |
|
|
|
|
|
|
|
if (filePath == null || filePath.isEmpty()) { |
|
|
|
Map<String, Object> errorResponse = new HashMap<>(); |
|
|
|
errorResponse.put("success", false); |
|
|
|
errorResponse.put("error", "filePath is required"); |
|
|
|
return ResponseEntity.badRequest().body(errorResponse); |
|
|
|
} |
|
|
|
|
|
|
|
try { |
|
|
|
int createdCount = usersSetup.importExcelFromLocal(filePath); |
|
|
|
Map<String, Object> response = new HashMap<>(); |
|
|
|
response.put("success", true); |
|
|
|
response.put("message", "Users imported successfully"); |
|
|
|
response.put("createdCount", createdCount); |
|
|
|
return ResponseEntity.ok(response); |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("Error importing users from Excel", e); |
|
|
|
Map<String, Object> errorResponse = new HashMap<>(); |
|
|
|
errorResponse.put("success", false); |
|
|
|
errorResponse.put("error", e.getMessage()); |
|
|
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(errorResponse); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |