|
| 1 | +package webapp8.webandtech.controller.api.admins; |
| 2 | + |
| 3 | +import java.util.List; |
| 4 | + |
| 5 | +import org.springframework.beans.factory.annotation.Autowired; |
| 6 | +import org.springframework.data.domain.PageRequest; |
| 7 | +import org.springframework.data.domain.Sort; |
| 8 | +import org.springframework.web.bind.annotation.CrossOrigin; |
| 9 | +import org.springframework.web.bind.annotation.GetMapping; |
| 10 | + |
| 11 | +import org.springframework.web.bind.annotation.RequestMapping; |
| 12 | +import org.springframework.web.bind.annotation.RequestParam; |
| 13 | +import org.springframework.web.bind.annotation.RestController; |
| 14 | + |
| 15 | +import com.fasterxml.jackson.annotation.JsonView; |
| 16 | + |
| 17 | +import io.swagger.v3.oas.annotations.Operation; |
| 18 | +import io.swagger.v3.oas.annotations.Parameter; |
| 19 | +import io.swagger.v3.oas.annotations.media.Content; |
| 20 | +import io.swagger.v3.oas.annotations.responses.ApiResponses; |
| 21 | +import webapp8.webandtech.model.Order; |
| 22 | +import webapp8.webandtech.model.Statistics; |
| 23 | +import webapp8.webandtech.model.User; |
| 24 | +import webapp8.webandtech.service.AdminService; |
| 25 | +import webapp8.webandtech.service.OrderService; |
| 26 | +import webapp8.webandtech.service.UserService; |
| 27 | +import io.swagger.v3.oas.annotations.responses.ApiResponse; |
| 28 | + |
| 29 | +@RestController |
| 30 | +@CrossOrigin |
| 31 | +@RequestMapping("api/admins") |
| 32 | +public class AdminRestController { |
| 33 | + |
| 34 | + @Autowired |
| 35 | + private UserService userService; |
| 36 | + |
| 37 | + @Autowired |
| 38 | + private OrderService orderService; |
| 39 | + |
| 40 | + @Autowired |
| 41 | + private AdminService adminService; |
| 42 | + |
| 43 | + |
| 44 | + @Operation(summary = "Get a all users type customers") |
| 45 | + @ApiResponses(value = { |
| 46 | + @ApiResponse( |
| 47 | + responseCode = "200", |
| 48 | + description = "Found the Users type customers", |
| 49 | + content = {@Content( |
| 50 | + mediaType = "application/json" |
| 51 | + )} |
| 52 | + ) |
| 53 | + }) |
| 54 | + @JsonView(User.Detailed.class) |
| 55 | + @GetMapping("/customers") |
| 56 | + public List<User> getUsers( @Parameter(description="page") @RequestParam(required = false) String page){ |
| 57 | + if(page != null) { |
| 58 | + return userService.getCustomers(PageRequest.of(Integer.parseInt(page), 10,Sort.by("username").ascending())).getContent(); |
| 59 | + }else { |
| 60 | + return userService.getAll(); |
| 61 | + } |
| 62 | + } |
| 63 | + @Operation(summary = "Get a all orders") |
| 64 | + @ApiResponses(value = { |
| 65 | + @ApiResponse( |
| 66 | + responseCode = "200", |
| 67 | + description = "Found the orders", |
| 68 | + content = {@Content( |
| 69 | + mediaType = "application/json" |
| 70 | + )} |
| 71 | + ) |
| 72 | + }) |
| 73 | + @JsonView(Order.Detailed.class) |
| 74 | + @GetMapping("/orders") |
| 75 | + public List<Order> getOrders( @Parameter(description="page") @RequestParam(required = false) String page){ |
| 76 | + if(page != null) { |
| 77 | + |
| 78 | + return orderService.getMoreAllOrders(PageRequest.of(Integer.parseInt(page), 10,Sort.by("idorder").ascending())).getContent(); |
| 79 | + }else { |
| 80 | + return orderService.getAll(); |
| 81 | + } |
| 82 | + } |
| 83 | + |
| 84 | + @Operation(summary = "Get a all Statistics") |
| 85 | + @ApiResponses(value = { |
| 86 | + @ApiResponse( |
| 87 | + responseCode = "200", |
| 88 | + description = "Found the statistics", |
| 89 | + content = {@Content( |
| 90 | + mediaType = "application/json" |
| 91 | + )} |
| 92 | + ) |
| 93 | + }) |
| 94 | + @GetMapping("/statistics") |
| 95 | + public Statistics getStatistics() { |
| 96 | + return adminService.getStatics(); |
| 97 | + } |
| 98 | + |
| 99 | +} |
0 commit comments