Java Code Examples for org.springframework.http.ResponseEntity#of()
The following examples show how to use
org.springframework.http.ResponseEntity#of() .
These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: cerberus File: SecureDataController.java License: Apache License 2.0 | 6 votes |
@PrincipalHasReadPermsForPath @RequestMapping(params = "versionId", value = "/**", method = GET) public ResponseEntity<?> readSecureDataVersion( @RequestParam(value = "versionId") String versionId) { Optional<SecureDataVersion> secureDataVersionOpt = secureDataVersionService.getSecureDataVersionById( sdbAccessRequest.getSdbId(), versionId, sdbAccessRequest.getCategory(), sdbAccessRequest.getPath()); return ResponseEntity.of( secureDataVersionOpt.map( secureDataVersion -> { var data = secureDataVersion.getData(); var metadata = secureDataVersionService.parseVersionMetadata(secureDataVersion); return generateSecureDataResponse(data, metadata); })); }
Example 2
Source Project: alf.io File: EventApiController.java License: GNU General Public License v3.0 | 6 votes |
@GetMapping("/events/{eventName}/ticket-sold-statistics") public ResponseEntity<TicketsStatistics> getTicketsStatistics(@PathVariable("eventName") String eventName, @RequestParam(value = "from", required = false) String f, @RequestParam(value = "to", required = false) String t, Principal principal) { return ResponseEntity.of(eventManager.getOptionalByName(eventName, principal.getName()).map(event -> { var eventId = event.getId(); var zoneId = event.getZoneId(); var from = parseDate(f, zoneId, () -> eventStatisticsManager.getFirstReservationConfirmedTimestamp(event.getId()), () -> ZonedDateTime.now(zoneId).minusDays(1)); var reservedFrom = parseDate(f, zoneId, () -> eventStatisticsManager.getFirstReservationCreatedTimestamp(event.getId()), () -> ZonedDateTime.now(zoneId).minusDays(1)); var to = parseDate(t, zoneId, Optional::empty, () -> ZonedDateTime.now(zoneId)).plusDays(1L); var granularity = getGranularity(reservedFrom, to); var ticketSoldStatistics = eventStatisticsManager.getTicketSoldStatistics(eventId, from, to, granularity); var ticketReservedStatistics = eventStatisticsManager.getTicketReservedStatistics(eventId, reservedFrom, to, granularity); return new TicketsStatistics(granularity, ticketSoldStatistics, ticketReservedStatistics); })); }
Example 3
Source Project: cerberus File: SecureDataController.java License: Apache License 2.0 | 5 votes |
@PrincipalHasReadPermsForPath @RequestMapping(value = "/**", method = GET) public ResponseEntity<?> readSecureData() { Optional<SecureData> secureDataOpt = secureDataService.readSecret(sdbAccessRequest.getSdbId(), sdbAccessRequest.getPath()); return ResponseEntity.of( secureDataOpt.map( secureData -> { var data = secureData.getData(); var metadata = secureDataService.parseSecretMetadata(secureData); return generateSecureDataResponse(data, metadata); })); }
Example 4
Source Project: cerberus File: SecureDataController.java License: Apache License 2.0 | 5 votes |
@PrincipalHasReadPermsForPath @RequestMapping(params = "list", value = "/**", method = GET) public ResponseEntity<?> listKeys(@RequestParam(value = "list") String list) { if (!Boolean.parseBoolean(list)) { return readSecureData(); // TODO } Set<String> keys = secureDataService.listKeys(sdbAccessRequest.getSdbId(), sdbAccessRequest.getPath()); return ResponseEntity.of( Optional.of(SecureDataResponse.builder().data(Map.of("keys", keys)).build())); }
Example 5
Source Project: POC File: PostController.java License: Apache License 2.0 | 5 votes |
@GetMapping("/{user_name}/posts") public ResponseEntity<PostsDTO> getPostsByUserName(@PathVariable("user_name") String userName) { List<PostDTO> posts = this.postService.fetchAllPostsByUserName(userName).stream() .map(postDTO -> this.addLinkToPostBiFunction.apply(userName, postDTO)).collect(Collectors.toList()); return ResponseEntity.of(Optional.of(new PostsDTO(posts))); }
Example 6
Source Project: POC File: PostController.java License: Apache License 2.0 | 5 votes |
@GetMapping("/{user_name}/posts/{title}") public ResponseEntity<PostDTO> getPostByUserNameAndTitle(@PathVariable("user_name") String userName, @PathVariable("title") String title) { PostDTO postDTO = this.addLinkToPostBiFunction.apply(userName, this.postService.fetchPostByUserNameAndTitle(userName, title)); Link getAllPostsLink = WebMvcLinkBuilder .linkTo(WebMvcLinkBuilder.methodOn(this.getClass()).getPostsByUserName(userName)) .withRel("get-all-posts-by-username"); postDTO.add(getAllPostsLink); return ResponseEntity.of(Optional.of(postDTO)); }
Example 7
Source Project: alf.io File: TicketApiV2Controller.java License: GNU General Public License v3.0 | 5 votes |
@GetMapping("/api/v2/public/event/{eventName}/ticket/{ticketIdentifier}/full") public ResponseEntity<ReservationInfo.TicketsByTicketCategory> getTicket(@PathVariable("eventName") String eventName, @PathVariable("ticketIdentifier") String ticketIdentifier) { var optionalTicket = ticketReservationManager.fetchCompleteAndAssigned(eventName, ticketIdentifier) .map(complete -> { var ticket = complete.getRight(); var event = complete.getLeft(); var categoryName = ticketCategoryRepository.getByIdAndActive(ticket.getCategoryId(), event.getId()).getName(); return new ReservationInfo.TicketsByTicketCategory(categoryName, List.of(bookingInfoTicketLoader.toBookingInfoTicket(ticket, event))); }); return ResponseEntity.of(optionalTicket); }
Example 8
Source Project: alf.io File: EventApiController.java License: GNU General Public License v3.0 | 5 votes |
@PutMapping("/events/{eventName}/category/{categoryId}/metadata") public ResponseEntity<Boolean> updateCategoryMetadata(@PathVariable("eventName") String eventName, @PathVariable("categoryId") int categoryId, @RequestBody MetadataModification metadataModification, Principal principal) { if(!metadataModification.isValid()) { return ResponseEntity.badRequest().build(); } return ResponseEntity.of(eventManager.getOptionalEventAndOrganizationIdByName(eventName, principal.getName()) .map(event -> eventManager.updateCategoryMetadata(event, categoryId, metadataModification.toMetadataObj()))); }
Example 9
Source Project: alf.io File: EventApiController.java License: GNU General Public License v3.0 | 5 votes |
@GetMapping("/events/{eventName}/category/{categoryId}/metadata") public ResponseEntity<AlfioMetadata> loadCategoryMetadata(@PathVariable("eventName") String eventName, @PathVariable("categoryId") int categoryId, Principal principal) { return ResponseEntity.of(eventManager.getOptionalEventAndOrganizationIdByName(eventName, principal.getName()) .map(event -> eventManager.getMetadataForCategory(event, categoryId))); }
Example 10
Source Project: spring-examples File: ProductApi.java License: GNU General Public License v3.0 | 4 votes |
@GetMapping(value = "/v1/product") public ResponseEntity<ProductV1> pathVersioningProductV1() { return ResponseEntity.of(Optional.of(new ProductV1("HP Laptop"))); }
Example 11
Source Project: spring-examples File: ProductApi.java License: GNU General Public License v3.0 | 4 votes |
@GetMapping(value = "/v2/product") public ResponseEntity<ProductV2> pathVersioningProductV2() { return ResponseEntity.of(Optional.of(new ProductV2("HP Laptop", BigDecimal.TEN))); }
Example 12
Source Project: spring-examples File: ProductApi.java License: GNU General Public License v3.0 | 4 votes |
@GetMapping(value = "/param/product", params = "apiVersion=1") public ResponseEntity<ProductV1> paramVersioningProductV1() { return ResponseEntity.of(Optional.of(new ProductV1("HP Laptop"))); }
Example 13
Source Project: spring-examples File: ProductApi.java License: GNU General Public License v3.0 | 4 votes |
@GetMapping(value = "/param/product", params = "apiVersion=2") public ResponseEntity<ProductV2> paramVersioningProductV2() { return ResponseEntity.of(Optional.of(new ProductV2("HP Laptop", BigDecimal.TEN))); }
Example 14
Source Project: alf.io File: ConfigurationApiController.java License: GNU General Public License v3.0 | 4 votes |
@GetMapping(value = "/event/{eventId}/invoice-first-date") public ResponseEntity<ZonedDateTime> getFirstInvoiceDate(@PathVariable("eventId") Integer eventId, Principal principal) { return ResponseEntity.of(optionally(() -> eventManager.getSingleEventById(eventId, principal.getName())) .map(event -> billingDocumentManager.findFirstInvoiceDate(event.getId()).orElseGet(() -> ZonedDateTime.now(event.getZoneId())))); }
Example 15
Source Project: spring-examples File: ProductApi.java License: GNU General Public License v3.0 | 4 votes |
@GetMapping(value = "/header/product", headers = "X-API-VERSION=2") public ResponseEntity<ProductV2> headerVersioningProductV2() { return ResponseEntity.of(Optional.of(new ProductV2("HP Laptop", BigDecimal.TEN))); }
Example 16
Source Project: sfg-blog-posts File: EmployeeRestController.java License: GNU General Public License v3.0 | 4 votes |
@GetMapping(path = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<Employee> get(@PathVariable long id) { Optional<Employee> employee = Optional.ofNullable(employees.get(id)); return ResponseEntity.of(employee); }
Example 17
Source Project: code-examples File: UserController.java License: MIT License | 4 votes |
@GetMapping("/{id}") public ResponseEntity<User> getUser(@PathVariable("id") Long userId) { return ResponseEntity.of(userRepository.findById(userId)); }
Example 18
Source Project: cerberus File: CategoryController.java License: Apache License 2.0 | 4 votes |
@RolesAllowed(ROLE_USER) @RequestMapping(value = "/{categoryId:.+}", method = GET) public ResponseEntity<Category> getCategory(@PathVariable String categoryId) { return ResponseEntity.of(categoryService.getCategory(categoryId)); }
Example 19
Source Project: cerberus File: RoleController.java License: Apache License 2.0 | 4 votes |
@RolesAllowed(ROLE_USER) @RequestMapping(value = "/{roleId:.+}", method = GET) public ResponseEntity<Role> getCategory(@PathVariable String roleId) { return ResponseEntity.of(roleService.getRoleById(roleId)); }
Example 20
Source Project: alf.io File: EventApiController.java License: GNU General Public License v3.0 | 4 votes |
@GetMapping("/events/{eventName}/metadata") public ResponseEntity<AlfioMetadata> loadMetadata(@PathVariable("eventName") String eventName, Principal principal) { return ResponseEntity.of(eventManager.getOptionalEventAndOrganizationIdByName(eventName, principal.getName()) .map(eventManager::getMetadataForEvent)); }