Skip to content

Commit 73597b1

Browse files
Update UserRestControler
1 parent 71f9a7e commit 73597b1

File tree

1 file changed

+109
-0
lines changed

1 file changed

+109
-0
lines changed

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

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,5 +172,114 @@ public ResponseEntity<Users> replaceUser(@Parameter(description="id of user to b
172172
content = @Content
173173
)
174174
})
175+
@JsonView(Users.Detailed.class)
176+
@DeleteMapping("/{id}")
177+
public ResponseEntity<Users> deleteUser(@Parameter(description="id of user to be searched") @PathVariable int id){
178+
Optional<Users> s = userService.getUserId(id);
179+
if(s.isPresent()){
180+
userService.deleteUserById(id);
181+
return ResponseEntity.ok(s.get());
182+
}else {
183+
return ResponseEntity.notFound().build();
184+
}
185+
}
186+
187+
@Operation(summary = "Get a all users type customers")
188+
@ApiResponses(value = {
189+
@ApiResponse(
190+
responseCode = "200",
191+
description = "Found the Users type customers",
192+
content = {@Content(
193+
mediaType = "application/json"
194+
)}
195+
)
196+
})
197+
@JsonView(Users.Detailed.class)
198+
@GetMapping("/customers")
199+
public List<Users> getUsers( @Parameter(description="page") @RequestParam(required = false) String page){
200+
if(page != null) {
201+
return userService.getCustomers(PageRequest.of(Integer.parseInt(page), 5)).getContent();
202+
}else {
203+
return userService.getAllUsers();
204+
}
205+
}
206+
207+
@Operation(summary = "Get a all users type companies")
208+
@ApiResponses(value = {
209+
@ApiResponse(
210+
responseCode = "200",
211+
description = "Found the Users type companies",
212+
content = {@Content(
213+
mediaType = "application/json"
214+
)}
215+
)
216+
})
217+
@JsonView(Users.Detailed.class)
218+
@GetMapping("/companies")
219+
public List<Users> getCompanies( @Parameter(description="page") @RequestParam(required = false) String page){
220+
if(page != null) {
221+
return userService.getCompanies(PageRequest.of(Integer.parseInt(page), 5)).getContent();
222+
}else {
223+
return userService.getAllCompanies();
224+
}
225+
}
226+
227+
@Operation(summary = "Get a profile image user by id")
228+
@ApiResponses(value = {
229+
@ApiResponse(
230+
responseCode = "200",
231+
description = "Found the Image Profile",
232+
content = {@Content(
233+
mediaType = "application/json"
234+
)}
235+
),
236+
@ApiResponse(
237+
responseCode = "204",
238+
description = "Image not found",
239+
content = @Content
240+
),
241+
@ApiResponse(
242+
responseCode = "404",
243+
description = "User not found",
244+
content = @Content
245+
)
246+
})
247+
@GetMapping("/{id}/imageProfile")
248+
public ResponseEntity<Object> getImageProfile(@Parameter(description="id of user to be searched") @PathVariable int id) throws SQLException{
249+
Optional<Users> s = userService.getUserId(id);
250+
if(s.isPresent()) {
251+
if(s.get().getUserimg() != null) {
252+
Resource file = new InputStreamResource(s.get().getUserimg().getBinaryStream());
253+
return ResponseEntity.ok()
254+
.header(HttpHeaders.CONTENT_TYPE, "image/jpeg")
255+
.contentLength(s.get().getUserimg().length())
256+
.body(file);
257+
}else {
258+
return ResponseEntity.noContent().build();
259+
}
260+
}else {
261+
return ResponseEntity.notFound().build();
262+
}
263+
}
175264

265+
@Operation(summary = "Get a profile theme image user by id")
266+
@ApiResponses(value = {
267+
@ApiResponse(
268+
responseCode = "200",
269+
description = "Found the Image Profile Theme",
270+
content = {@Content(
271+
mediaType = "application/json"
272+
)}
273+
),
274+
@ApiResponse(
275+
responseCode = "204",
276+
description = "Image not found",
277+
content = @Content
278+
),
279+
@ApiResponse(
280+
responseCode = "404",
281+
description = "User not found",
282+
content = @Content
283+
)
284+
})
176285
}

0 commit comments

Comments
 (0)