Skip to content

Commit 6f915dd

Browse files
Update UserRestControler
1 parent 8bcb970 commit 6f915dd

File tree

222 files changed

+196
-76202
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

222 files changed

+196
-76202
lines changed

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

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,4 +337,200 @@ public ResponseEntity<Object> uploadImageProfile( @Parameter(description="id of
337337
}
338338
}
339339

340+
@Operation(summary = "create a profile image theme user by id")
341+
@ApiResponses(value = {
342+
@ApiResponse(
343+
responseCode = "201",
344+
description = "Create the ImageProfile Theme",
345+
content = {@Content(
346+
mediaType = "application/json"
347+
)}
348+
),
349+
@ApiResponse(
350+
responseCode = "204",
351+
description = "Image not found",
352+
content = @Content
353+
),
354+
@ApiResponse(
355+
responseCode = "404",
356+
description = "User not found",
357+
content = @Content
358+
)
359+
})
360+
@PostMapping("/{id}/imageThemeProfile")
361+
public ResponseEntity<Object> uploadImageThemeProfile( @Parameter(description="id of user to be searched") @PathVariable int id, @Parameter(description="user theme page picture") @RequestParam MultipartFile image) throws SQLException, IOException{
362+
Optional<Users> user = userService.getUserId(id);
363+
if(user.isPresent()) {
364+
if(image != null) {
365+
user.get().setImageprofile(BlobProxy.generateProxy(image.getInputStream(), image.getSize()));
366+
userService.saveUser(user.get());
367+
URI location = fromCurrentRequest().build().toUri();
368+
return ResponseEntity.created(location).build();
369+
}else {
370+
return ResponseEntity.noContent().build();
371+
}
372+
}else {
373+
return ResponseEntity.notFound().build();
374+
}
375+
}
376+
377+
@Operation(summary = "get all posts by user")
378+
@ApiResponses(value = {
379+
@ApiResponse(
380+
responseCode = "200",
381+
description = "found all posts by user id",
382+
content = {@Content(
383+
mediaType = "application/json"
384+
)}
385+
),
386+
@ApiResponse(
387+
responseCode = "404",
388+
description = "User not found",
389+
content = @Content
390+
)
391+
})
392+
@JsonView(Post.PostDetails.class)
393+
@GetMapping("/{id}/posts")
394+
public ResponseEntity<List<Post>> getAllPost( @Parameter(description="id of user to be searched") @PathVariable int id, @Parameter(description="page") @RequestParam(required = false) String page){
395+
Optional<Users> user = userService.getUserId(id);
396+
if(!user.isPresent()) {
397+
return ResponseEntity.notFound().build();
398+
}
399+
if(page != null) {
400+
return ResponseEntity.ok(postsService.getPostsByUser(id,page,5).getContent());
401+
}else {
402+
return ResponseEntity.ok(postsService.getAllPostsByUser(id));
403+
}
404+
}
405+
406+
@Operation(summary = "get all Products by user")
407+
@ApiResponses(value = {
408+
@ApiResponse(
409+
responseCode = "200",
410+
description = "found all products by user id",
411+
content = {@Content(
412+
mediaType = "application/json"
413+
)}
414+
),
415+
@ApiResponse(
416+
responseCode = "404",
417+
description = "User not found",
418+
content = @Content
419+
)
420+
})
421+
@JsonView(Product.Simple.class)
422+
@GetMapping("/{id}/products")
423+
public ResponseEntity<List<Product>> getAllProducts( @Parameter(description="id of user to be searched") @PathVariable int id, @Parameter(description="page") @RequestParam(required = false) String page){
424+
Optional<Users> user = userService.getUserId(id);
425+
if(!user.isPresent()) {
426+
return ResponseEntity.notFound().build();
427+
}
428+
if(page != null) {
429+
return ResponseEntity.ok( productsService.getProductsByUser(id,page,5).getContent() );
430+
}else {
431+
return ResponseEntity.ok(productsService.getAllProductsByUser(id));
432+
}
433+
}
434+
435+
@Operation(summary = "Get a followings by id users")
436+
@ApiResponses(value = {
437+
@ApiResponse(
438+
responseCode = "200",
439+
description = "Found the followings",
440+
content = {@Content(
441+
mediaType = "application/json"
442+
)}
443+
),
444+
@ApiResponse(
445+
responseCode = "404",
446+
description = "User not found",
447+
content = @Content
448+
)
449+
})
450+
@JsonView(UsersRelations.Basic.class)
451+
@GetMapping("/{id}/followings")
452+
public ResponseEntity<List<UsersRelations>> getUserRelations( @Parameter(description="id of relation to be searched") @PathVariable int id){
453+
Optional<Users> user = userService.getUserId(id);
454+
if(user.isPresent()) {
455+
return ResponseEntity.ok(userService.getFollowing(user.get().getUsername()));
456+
}else {
457+
return ResponseEntity.notFound().build();
458+
}
459+
}
460+
461+
@Operation(summary = "Get a followers by id users")
462+
@ApiResponses(value = {
463+
@ApiResponse(
464+
responseCode = "200",
465+
description = "Found the followers",
466+
content = {@Content(
467+
mediaType = "application/json"
468+
)}
469+
),
470+
@ApiResponse(
471+
responseCode = "404",
472+
description = "User not found",
473+
content = @Content
474+
)
475+
})
476+
@JsonView(UsersRelations.Basic.class)
477+
@GetMapping("/{id}/followers")
478+
public ResponseEntity<List<UsersRelations>> getRelationsUser( @Parameter(description="id of relation to be searched") @PathVariable int id){
479+
Optional<Users> user = userService.getUserId(id);
480+
if(user.isPresent()) {
481+
return ResponseEntity.ok(userService.getFollowers(user.get().getUsername()));
482+
}else {
483+
return ResponseEntity.notFound().build();
484+
}
485+
}
486+
487+
@Operation(summary = "Get a Bookmarks by id users")
488+
@ApiResponses(value = {
489+
@ApiResponse(
490+
responseCode = "200",
491+
description = "Found the bookmarks",
492+
content = {@Content(
493+
mediaType = "application/json"
494+
)}
495+
),
496+
@ApiResponse(
497+
responseCode = "404",
498+
description = "User not found",
499+
content = @Content
500+
)
501+
})
502+
@GetMapping("/{id}/bookmarks")
503+
public ResponseEntity<List<ListProducts>> getBookmarks(@Parameter(description="id of user to be searched") @PathVariable int id){
504+
Optional<Users> user = userService.getUserId(id);
505+
if(!user.isPresent()) {
506+
return ResponseEntity.notFound().build();
507+
}
508+
return ResponseEntity.ok(productsService.getBookmarksByUser(id));
509+
}
510+
511+
@Operation(summary = "Get a Likes by id users")
512+
@ApiResponses(value = {
513+
@ApiResponse(
514+
responseCode = "200",
515+
description = "Found the likes",
516+
content = {@Content(
517+
mediaType = "application/json"
518+
)}
519+
),
520+
@ApiResponse(
521+
responseCode = "404",
522+
description = "User not found",
523+
content = @Content
524+
)
525+
})
526+
@GetMapping("/{id}/likes")
527+
public ResponseEntity<List<LikeAPost>> getLike(@Parameter(description="id of user to be searched") @PathVariable int id){
528+
Optional<Users> user = userService.getUserId(id);
529+
if(!user.isPresent()) {
530+
return ResponseEntity.notFound().build();
531+
}
532+
return ResponseEntity.ok(postsService.getLikesByUser(id));
533+
}
534+
535+
340536
}

0 commit comments

Comments
 (0)