22
33import com .evolvedbinary .bblValidator .dto .ValidationForm ;
44import com .evolvedbinary .bblValidator .dto .ValidationResponse ;
5+ import com .evolvedbinary .bblValidator .service .FileDownloadService ;
56import io .micronaut .http .MediaType ;
67import io .micronaut .http .annotation .Body ;
78import io .micronaut .http .annotation .Consumes ;
89import io .micronaut .http .annotation .Controller ;
910import io .micronaut .http .annotation .Post ;
1011import io .micronaut .http .annotation .QueryValue ;
12+ import org .slf4j .Logger ;
13+ import org .slf4j .LoggerFactory ;
1114
15+ import java .io .IOException ;
16+ import java .nio .file .Path ;
17+
18+ /**
19+ * Controller for handling validation requests.
20+ */
1221@ Controller ("/validate" )
1322public class ValidateController {
1423
15- // SCENARIO: Form URL Encoded
16- // Matches when Content-Type is 'application/x-www-form-urlencoded'
24+ private static final Logger LOG = LoggerFactory .getLogger (ValidateController .class );
25+ private final FileDownloadService fileDownloadService ;
26+
27+ /**
28+ * Constructor for ValidateController.
29+ *
30+ * @param fileDownloadService service for downloading files
31+ */
32+ public ValidateController (FileDownloadService fileDownloadService ) {
33+ this .fileDownloadService = fileDownloadService ;
34+ }
35+
36+ /**
37+ * Handles form URL encoded validation requests.
38+ *
39+ * @param form validation form
40+ * @return validation response
41+ */
1742 @ Post
1843 @ Consumes (MediaType .APPLICATION_FORM_URLENCODED )
1944 public ValidationResponse validateForm (@ Body ValidationForm form ) {
20- return new ValidationResponse (form .schemaId (), form .url (), true , "form handler" );
45+ try {
46+ Path downloadedFile = fileDownloadService .downloadToTemp (form .url ());
47+ LOG .info ("File downloaded to: {}" , downloadedFile );
48+ // TODO: Perform validation with downloadedFile
49+ return new ValidationResponse (form .schemaId (), form .url (), true , "form handler" );
50+ } catch (IOException e ) {
51+ LOG .error ("Failed to download file from URL: {}" , form .url (), e );
52+ return new ValidationResponse (form .schemaId (), form .url (), false , "Download failed: " + e .getMessage ());
53+ }
2154 }
2255
23- // SCENARIO: CSV Body + Query param
24- // Matches when Content-Type is 'text/csv'
56+ /**
57+ * Handles CSV body + query param validation requests.
58+ *
59+ * @param schemaId schema ID
60+ * @param csvContent CSV content
61+ * @return validation response
62+ */
2563 @ Post
2664 @ Consumes (MediaType .TEXT_CSV )
2765 public ValidationResponse validateCsv (@ QueryValue ("schema-id" ) String schemaId ,
2866 @ Body String csvContent ) {
29-
30- return new ValidationResponse (schemaId , csvContent , true , "text handler" );
67+ try {
68+ Path tempFile = fileDownloadService .saveContentToTemp (csvContent , "uploaded-content.csv" );
69+ LOG .info ("CSV content saved to: {}" , tempFile );
70+ // TODO: Perform validation with tempFile
71+ return new ValidationResponse (schemaId , "CSV content" , true , "text handler" );
72+ } catch (IOException e ) {
73+ LOG .error ("Failed to save CSV content to temp file" , e );
74+ return new ValidationResponse (schemaId , "CSV content" , false , "Failed to save content: " + e .getMessage ());
75+ }
3176 }
3277
33- // SCENARIO: Query Params Only
34- // We use ALL here as a fallback, but specific types above take precedence
78+ /**
79+ * Handles query params only validation requests.
80+ *
81+ * @param schemaId schema ID
82+ * @param url URL
83+ * @return validation response
84+ */
3585 @ Post
3686 @ Consumes (MediaType .ALL )
3787 public ValidationResponse validateParams (@ QueryValue ("schema-id" ) String schemaId ,
3888 @ QueryValue String url ) {
39- return new ValidationResponse (schemaId , url , true , "query handler" );
89+ try {
90+ Path downloadedFile = fileDownloadService .downloadToTemp (url );
91+ LOG .info ("File downloaded to: {}" , downloadedFile );
92+ // TODO: Perform validation with downloadedFile
93+ return new ValidationResponse (schemaId , url , true , "query handler" );
94+ } catch (IOException e ) {
95+ LOG .error ("Failed to download file from URL: {}" , url , e );
96+ return new ValidationResponse (schemaId , url , false , "Download failed: " + e .getMessage ());
97+ }
4098 }
4199}
0 commit comments