Skip to content

Commit 8bcb970

Browse files
Update UserRestControler
1 parent 73597b1 commit 8bcb970

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

backend/webandtech/src/main/java/webapp8/webandtech/controller/api/users/UserRestControler.java

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,4 +282,59 @@ public ResponseEntity<Object> getImageProfile(@Parameter(description="id of user
282282
content = @Content
283283
)
284284
})
285+
@GetMapping("/{id}/imageThemeProfile")
286+
public ResponseEntity<Object> getImageThemeProfile( @Parameter(description="id of user to be searched") @PathVariable int id) throws SQLException{
287+
Optional<Users> s = userService.getUserId(id);
288+
if(s.isPresent()) {
289+
if(s.get().getImageprofile() != null) {
290+
Resource file = new InputStreamResource(s.get().getImageprofile().getBinaryStream());
291+
return ResponseEntity.ok()
292+
.header(HttpHeaders.CONTENT_TYPE, "image/jpeg")
293+
.contentLength(s.get().getImageprofile().length())
294+
.body(file);
295+
}else {
296+
return ResponseEntity.noContent().build();
297+
}
298+
}else {
299+
return ResponseEntity.notFound().build();
300+
}
301+
}
302+
303+
@Operation(summary = "create a profile image user by id")
304+
@ApiResponses(value = {
305+
@ApiResponse(
306+
responseCode = "201",
307+
description = "Create the ImageProfile",
308+
content = {@Content(
309+
mediaType = "application/json"
310+
)}
311+
),
312+
@ApiResponse(
313+
responseCode = "204",
314+
description = "Image not found",
315+
content = @Content
316+
),
317+
@ApiResponse(
318+
responseCode = "404",
319+
description = "User not found",
320+
content = @Content
321+
)
322+
})
323+
@PostMapping("/{id}/imageProfile")
324+
public ResponseEntity<Object> uploadImageProfile( @Parameter(description="id of user to be searched") @PathVariable int id, @Parameter(description="user profile picture") @RequestParam MultipartFile image) throws SQLException, IOException{
325+
Optional<Users> user = userService.getUserId(id);
326+
if(user.isPresent()) {
327+
if(image != null) {
328+
user.get().setUserimg(BlobProxy.generateProxy(image.getInputStream(), image.getSize()));
329+
userService.saveUser(user.get());
330+
URI location = fromCurrentRequest().build().toUri();
331+
return ResponseEntity.created(location).build();
332+
}else {
333+
return ResponseEntity.noContent().build();
334+
}
335+
}else {
336+
return ResponseEntity.notFound().build();
337+
}
338+
}
339+
285340
}

0 commit comments

Comments
 (0)