Subversion Repositories SmartDukaan

Rev

Rev 35487 | Rev 35525 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 35487 Rev 35523
Line 122... Line 122...
122
				+ LocalDateTime.now().toEpochSecond(ZoneOffset.ofHoursMinutes(5, 30));
122
				+ LocalDateTime.now().toEpochSecond(ZoneOffset.ofHoursMinutes(5, 30));
123
		return imageString + "." + extension;
123
		return imageString + "." + extension;
124
	}
124
	}
125
 
125
 
126
	@PostMapping(value = "/content/upload")
126
	@PostMapping(value = "/content/upload")
127
	public String uploadContent(HttpServletRequest request, @RequestPart("file") MultipartFile file, Model model)
127
	public String uploadContent(HttpServletRequest request, @RequestPart("file") MultipartFile file, Model model) {
-
 
128
		try {
-
 
129
			// 1. Validation
-
 
130
			if (file.isEmpty()) {
-
 
131
				model.addAttribute("error", "Please select a file to upload.");
-
 
132
				return "response";
-
 
133
			}
-
 
134
 
128
			throws Exception {
135
			// 2. Processing
129
		List<ContentPojo> contentPojos = readFile(file);
136
			List<ContentPojo> contentPojos = readFile(file);
-
 
137
 
-
 
138
			// 3. Persistence
130
		for (ContentPojo contentPojo : contentPojos) {
139
			for (ContentPojo contentPojo : contentPojos) {
131
			mongoClient.persistEntity(contentPojo);
140
				mongoClient.persistEntity(contentPojo);
-
 
141
			}
-
 
142
 
-
 
143
			// 4. Success
-
 
144
			model.addAttribute("response1", mvcResponseSender.createResponseString(true));
-
 
145
			model.addAttribute("message", "Upload successful!");
-
 
146
 
-
 
147
		} catch (ProfitMandiBusinessException e) {
-
 
148
			// Catch your custom business exceptions (e.g., "No records found")
-
 
149
			LOGGER.error("Business error: {}", e.getMessage());
-
 
150
			model.addAttribute("error", e.getMessage());
-
 
151
		} catch (Exception e) {
-
 
152
			// Catch technical errors (IO, DB, Parsing)
-
 
153
			LOGGER.error("System error during upload: ", e);
-
 
154
			model.addAttribute("error", "An internal error occurred: " + e.getMessage());
132
		}
155
		}
133
		//List<SuperCatalog> superCatalog = superCatalogRepository.selectAll();
-
 
134
 
156
 
135
		model.addAttribute("response1", mvcResponseSender.createResponseString(true));
157
		// This return is now reachable even if an error occurs
136
		return "response";
158
		return "response";
137
	}
159
	}
138
 
160
 
139
	@Autowired
161
	@Autowired
140
	ItemLoaderService itemLoaderService;
162
	ItemLoaderService itemLoaderService;