Last active
March 28, 2023 13:28
-
-
Save GerritRiesch94/265f1581d8ba60684223a55afd10ae25 to your computer and use it in GitHub Desktop.
App Controller Spring Boot Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.example.api; | |
import com.example.example.service.AppService; | |
import org.springframework.http.ResponseEntity; | |
import org.springframework.web.bind.annotation.*; | |
import java.util.List; | |
@RestController | |
@RequestMapping("/api/data") | |
public class AppController { | |
private final AppService appService; | |
public AppController(AppService appService) { | |
this.appService = appService; | |
} | |
@GetMapping("/{id}") | |
public ResponseEntity<List<String>> getData(@PathVariable String id, @RequestParam Integer skip, @RequestParam Integer top) { | |
// should represent a database service, api call, etc. | |
var data = this.appService.searchForIdAndPaginate(id, skip, top); | |
if (!data.isEmpty()) { | |
return ResponseEntity.ok(data); | |
} else { | |
return ResponseEntity.noContent().build(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment