UCO-PRE-PRODUCTION-2026-NAEEM
Naeem Ullah 3 days ago
parent 0fa9899121
commit ff93cba476

@ -15,6 +15,7 @@ import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.util.ArrayList; import java.util.ArrayList;
@ -162,8 +163,11 @@ public class UserController {
} }
@PostMapping(UCOURI.UPDATE_CUSTOMER_PROFILE) @PostMapping(UCOURI.UPDATE_CUSTOMER_PROFILE)
public ResponseEntity<HttpStatus> updateCustomerProfile(@RequestBody UpdateProfileRequestPayload updateProfileRequestPayload) { public ResponseEntity<HttpStatus> updateCustomerProfile(
customerProfileService.updateCustomerProfile(updateProfileRequestPayload); @RequestParam("porOrgacode") String porOrgacode,
@RequestParam("cmpCustcode") String cmpCustcode,
@RequestParam("image") MultipartFile image) {
customerProfileService.updateCustomerProfile(porOrgacode, cmpCustcode, image);
return ResponseEntity.ok(HttpStatus.OK); return ResponseEntity.ok(HttpStatus.OK);
} }
@PostMapping(UCOURI.ADD_BENEFICIARY) @PostMapping(UCOURI.ADD_BENEFICIARY)

@ -4,6 +4,7 @@ import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import org.springframework.web.multipart.MultipartFile;
@Data @Data
@Builder @Builder
@ -12,5 +13,5 @@ import lombok.NoArgsConstructor;
public class UpdateProfileRequestPayload { public class UpdateProfileRequestPayload {
private String porOrgacode; private String porOrgacode;
private String cmpCustcode; private String cmpCustcode;
private String cmpCustImage; private MultipartFile image;
} }

@ -55,9 +55,7 @@ public class CustomerProfile {
@Column(name = "CMP_ADDRESS", nullable = true, columnDefinition = FieldNameLength.DESCRIPTION_LONG) @Column(name = "CMP_ADDRESS", nullable = true, columnDefinition = FieldNameLength.DESCRIPTION_LONG)
private String cmpAddress; private String cmpAddress;
@Lob @Column(name = "CMP_CUSTIMG", nullable = true, columnDefinition = "VARCHAR(500)")
@JsonIgnore
@Column(name = "CMP_CUSTIMG", nullable = true, columnDefinition = "LONGTEXT")
private String cmpCustImage; private String cmpCustImage;
} }

@ -1,5 +1,6 @@
package com.mfsys.uco.service; package com.mfsys.uco.service;
import com.mfsys.comm.exception.ApplicationException;
import com.mfsys.uco.dto.UpdateProfileRequestPayload; import com.mfsys.uco.dto.UpdateProfileRequestPayload;
import com.mfsys.uco.exception.BenificiaryAlreadyExistsException; import com.mfsys.uco.exception.BenificiaryAlreadyExistsException;
import com.mfsys.uco.model.Beneficiary; import com.mfsys.uco.model.Beneficiary;
@ -9,6 +10,7 @@ import com.mfsys.uco.repository.BeneficiaryRepository;
import com.mfsys.uco.repository.CustomerProfileRepository; import com.mfsys.uco.repository.CustomerProfileRepository;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
@ -18,6 +20,7 @@ import java.util.Optional;
public class CustomerProfileService { public class CustomerProfileService {
private final CustomerProfileRepository customerProfileRepository; private final CustomerProfileRepository customerProfileRepository;
private final BeneficiaryRepository beneficiaryRepository; private final BeneficiaryRepository beneficiaryRepository;
private final FileStorageService fileStorageService;
public void deleteBeneficiary(String porOrgacode, String email, String mbmBkmsnumberRef) { public void deleteBeneficiary(String porOrgacode, String email, String mbmBkmsnumberRef) {
beneficiaryRepository.deleteByMbmBkmsnumberRefAndPorOrgacodeAndEmail(mbmBkmsnumberRef, porOrgacode, email); beneficiaryRepository.deleteByMbmBkmsnumberRefAndPorOrgacodeAndEmail(mbmBkmsnumberRef, porOrgacode, email);
@ -27,12 +30,21 @@ public class CustomerProfileService {
return customerProfileRepository.findbyEmail(porOrgacode, email); return customerProfileRepository.findbyEmail(porOrgacode, email);
} }
public void updateCustomerProfile(UpdateProfileRequestPayload updateProfileRequestPayload) { public void updateCustomerProfile(String porOrgacode, String cmpCustcode, MultipartFile image) {
customerProfileRepository.findById(new CustomerProfileId(updateProfileRequestPayload.getPorOrgacode(), updateProfileRequestPayload.getCmpCustcode())) CustomerProfile customerProfile = customerProfileRepository
.ifPresent(customerProfile -> { .findById(new CustomerProfileId(porOrgacode, cmpCustcode))
customerProfile.setCmpCustImage(updateProfileRequestPayload.getCmpCustImage()); .orElseThrow(() -> new ApplicationException(
porOrgacode,
"ERR_CUSTOMER_NOT_FOUND",
new Object[]{cmpCustcode}));
// delete old image from disk if exists
fileStorageService.deleteImage(customerProfile.getCmpCustImage());
// save new image and store path
String imagePath = fileStorageService.saveImage(cmpCustcode, image);
customerProfile.setCmpCustImage(imagePath);
customerProfileRepository.save(customerProfile); customerProfileRepository.save(customerProfile);
});
} }
public void addBeneficiary(Beneficiary beneficiary) { public void addBeneficiary(Beneficiary beneficiary) {

@ -0,0 +1,54 @@
package com.mfsys.uco.service;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.UUID;
@Service
public class FileStorageService {
@Value("${file.upload-dir}")
private String uploadDir;
public String saveImage(String custcode, MultipartFile file) {
try {
Path uploadPath = Paths.get(uploadDir).toAbsolutePath().normalize();
Files.createDirectories(uploadPath);
String extension = getExtension(file.getOriginalFilename());
String filename = custcode + "_" + UUID.randomUUID() + "." + extension;
Path targetPath = uploadPath.resolve(filename);
Files.copy(file.getInputStream(), targetPath, StandardCopyOption.REPLACE_EXISTING);
return uploadDir + "/" + filename;
} catch (IOException e) {
throw new RuntimeException("Failed to store image for custcode: " + custcode, e);
}
}
public void deleteImage(String imagePath) {
try {
if (imagePath != null) {
Path path = Paths.get(imagePath).toAbsolutePath().normalize();
Files.deleteIfExists(path);
}
} catch (IOException e) {
// log and continue — don't fail the update if old file delete fails
}
}
private String getExtension(String filename) {
if (filename != null && filename.contains(".")) {
return filename.substring(filename.lastIndexOf(".") + 1).toLowerCase();
}
return "jpg";
}
}

@ -1,17 +1,17 @@
server: server:
port: 8082 port: 8082
tomcat:
max-http-form-post-size: -1
max-swallow-size: -1
spring: spring:
application: application:
name: UCO-SERVICE name: UCO-SERVICE
datasource: datasource:
driver-class-name: com.mysql.cj.jdbc.Driver driver-class-name: com.mysql.cj.jdbc.Driver
# url: jdbc:mysql://localhost:3306/uco url: jdbc:mysql://${UCO_SQL_DB_MACHINE_IP:localhost}/uco
# username: root username: ${UCO_SQL_DB_USER:root}
# password: root password: ${UCO_SQL_DB_PASSWORD:root}
url: jdbc:mysql://${UCO_SQL_DB_MACHINE_IP}/uco
username: ${UCO_SQL_DB_USER}
password: ${UCO_SQL_DB_PASSWORD}
jpa: jpa:
show-sql: true show-sql: true
hibernate: hibernate:
@ -19,6 +19,13 @@ spring:
properties: properties:
hibernate: hibernate:
dialect: org.hibernate.dialect.MySQLDialect dialect: org.hibernate.dialect.MySQLDialect
servlet:
multipart:
max-file-size: 5MB
max-request-size: 5MB
file:
upload-dir: uploads/profiles
eureka: eureka:
instance: instance:
@ -35,4 +42,4 @@ application:
secret-key: 404E635266556A586E3272357538782F413F4428472B4B6250645367566B5970 secret-key: 404E635266556A586E3272357538782F413F4428472B4B6250645367566B5970
expiration: 86400000 expiration: 86400000
refresh-token: refresh-token:
expiration: 604800000 # 7 days expiration: 604800000
Loading…
Cancel
Save