Skip to content

Instantly share code, notes, and snippets.

@PramodDutta
Created August 20, 2025 04:34
Show Gist options
  • Select an option

  • Save PramodDutta/8b714375ad3499b16487a12bf28aafb3 to your computer and use it in GitHub Desktop.

Select an option

Save PramodDutta/8b714375ad3499b16487a12bf28aafb3 to your computer and use it in GitHub Desktop.

package com.example.api.models;

import java.io.File; import java.util.Objects;

public class DriverUploadRequest {

// text fields
private String id;
private String licenseNo;
private String aadhaarNo; // optional

// file fields
private File profilePhoto;
private File licensePhoto;
private File aadhaarPhoto; // optional

public DriverUploadRequest() {}

public DriverUploadRequest(String id,
                           String licenseNo,
                           File profilePhoto,
                           File licensePhoto,
                           String aadhaarNo,
                           File aadhaarPhoto) {
    this.id = id;
    this.licenseNo = licenseNo;
    this.profilePhoto = profilePhoto;
    this.licensePhoto = licensePhoto;
    this.aadhaarNo = aadhaarNo;
    this.aadhaarPhoto = aadhaarPhoto;
}

// Getters and setters
public String getId() { return id; }
public void setId(String id) { this.id = id; }

public String getLicenseNo() { return licenseNo; }
public void setLicenseNo(String licenseNo) { this.licenseNo = licenseNo; }

public String getAadhaarNo() { return aadhaarNo; }
public void setAadhaarNo(String aadhaarNo) { this.aadhaarNo = aadhaarNo; }

public File getProfilePhoto() { return profilePhoto; }
public void setProfilePhoto(File profilePhoto) { this.profilePhoto = profilePhoto; }

public File getLicensePhoto() { return licensePhoto; }
public void setLicensePhoto(File licensePhoto) { this.licensePhoto = licensePhoto; }

public File getAadhaarPhoto() { return aadhaarPhoto; }
public void setAadhaarPhoto(File aadhaarPhoto) { this.aadhaarPhoto = aadhaarPhoto; }

// Fluent builder for convenience
public static Builder builder() { return new Builder(); }
public static class Builder {
    private final DriverUploadRequest r = new DriverUploadRequest();
    public Builder id(String v) { r.setId(v); return this; }
    public Builder licenseNo(String v) { r.setLicenseNo(v); return this; }
    public Builder profilePhoto(File v) { r.setProfilePhoto(v); return this; }
    public Builder licensePhoto(File v) { r.setLicensePhoto(v); return this; }
    public Builder aadhaarNo(String v) { r.setAadhaarNo(v); return this; }
    public Builder aadhaarPhoto(File v) { r.setAadhaarPhoto(v); return this; }
    public DriverUploadRequest build() { return r; }
}

// Optional: equals/hashCode/toString
@Override public boolean equals(Object o) {
    if (this == o) return true;
    if (!(o instanceof DriverUploadRequest)) return false;
    DriverUploadRequest that = (DriverUploadRequest) o;
    return Objects.equals(id, that.id) &&
           Objects.equals(licenseNo, that.licenseNo) &&
           Objects.equals(aadhaarNo, that.aadhaarNo) &&
           Objects.equals(profilePhoto, that.profilePhoto) &&
           Objects.equals(licensePhoto, that.licensePhoto) &&
           Objects.equals(aadhaarPhoto, that.aadhaarPhoto);
}
@Override public int hashCode() {
    return Objects.hash(id, licenseNo, aadhaarNo, profilePhoto, licensePhoto, aadhaarPhoto);
}
@Override public String toString() {
    return "DriverUploadRequest{id='" + id + "', licenseNo='" + licenseNo + "', aadhaarNo='" + aadhaarNo + "', " +
           "profilePhoto=" + fileName(profilePhoto) + ", licensePhoto=" + fileName(licensePhoto) +
           ", aadhaarPhoto=" + fileName(aadhaarPhoto) + "}";
}
private static String fileName(File f) { return f == null ? "null" : f.getName(); }

}

Usage - DriverUploadRequest req = DriverUploadRequest.builder() .id("9") .licenseNo("2345 6789 0123") .profilePhoto(new File("src/test/resources/profile2.jpg")) .licensePhoto(new File("src/test/resources/licence.jpg")) .aadhaarNo("6789 0123") .aadhaarPhoto(new File("src/test/resources/aadhaar-card.jpg")) .build();

given() .baseUri("http://146.190.9.136:8080") .basePath("/api/v1/portal/staff/upload-files") .multiPart("id", req.getId()) .multiPart("licenseNo", req.getLicenseNo()) .multiPart("profilePhoto", req.getProfilePhoto(), "image/jpeg") .multiPart("licensePhoto", req.getLicensePhoto(), "image/jpeg") .multiPart("aadhaarNo", req.getAadhaarNo()) .multiPart("aadhaarPhoto", req.getAadhaarPhoto(), "image/jpeg") .when() .post() .then() .statusCode(200);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment