Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.task.task;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.*;
- import javax.validation.constraints.NotNull;
- @RestController
- @RequestMapping("repository")
- public class Controller {
- @Autowired
- RepositoryDetailsService userService;
- @GetMapping("{owner}/{repository}")
- @ResponseBody
- public RepositoryDetails getFooById(@NotNull @PathVariable String owner,
- @NotNull @PathVariable String repository) {
- return userService.details(owner, repository);
- }
- }
- package com.task.task;
- import org.springframework.stereotype.Service;
- import org.springframework.web.client.RestTemplate;
- @Service
- public class RepositoryDetailsService {
- private RestTemplate restTemplate = new RestTemplate();
- private String buildUrl(String owner, String repository) {
- return "https://api.github.com/repos/" + owner + "/" + repository + "";
- }
- RepositoryDetails details(String owner, String repository) {
- return restTemplate.getForObject(
- buildUrl(owner, repository), RepositoryDetails.class);
- }
- }
- package com.task.task;
- import com.fasterxml.jackson.annotation.JsonProperty;
- import java.time.LocalDate;
- public class RepositoryDetails {
- private String fullName;
- private String description;
- private String cloneUrl;
- private String stars;
- private LocalDate createdAt;
- @JsonProperty("fullName")
- public String getFullName() {
- return fullName;
- }
- @JsonProperty("full_name")
- public void setFullName(String fullName) {
- this.fullName = fullName;
- }
- @JsonProperty("description")
- public String getDescription() {
- return description;
- }
- @JsonProperty("description")
- public void setDescription(String description) {
- this.description = description;
- }
- @JsonProperty("cloneUrl")
- public String getCloneUrl() {
- return cloneUrl;
- }
- @JsonProperty("clone_url")
- public void setCloneUrl(String cloneUrl) {
- this.cloneUrl = cloneUrl;
- }
- @JsonProperty("stars")
- public String getStars() {
- return stars;
- }
- @JsonProperty("stargazers_count")
- public void setStars(String stars) {
- this.stars = stars;
- }
- @JsonProperty("createdAt")
- public LocalDate getCreatedAt() {
- return createdAt;
- }
- @JsonProperty("created_at")
- public void setCreatedAt(LocalDate createdAt) {
- this.createdAt = createdAt;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement