Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. package com.task.task;
  2.  
  3. import org.springframework.beans.factory.annotation.Autowired;
  4. import org.springframework.web.bind.annotation.*;
  5.  
  6. import javax.validation.constraints.NotNull;
  7.  
  8. @RestController
  9. @RequestMapping("repository")
  10. public class Controller {
  11.  
  12. @Autowired
  13. RepositoryDetailsService userService;
  14.  
  15. @GetMapping("{owner}/{repository}")
  16. @ResponseBody
  17. public RepositoryDetails getFooById(@NotNull @PathVariable String owner,
  18. @NotNull @PathVariable String repository) {
  19.  
  20. return userService.details(owner, repository);
  21. }
  22. }
  23.  
  24.  
  25.  
  26.  
  27. package com.task.task;
  28.  
  29. import org.springframework.stereotype.Service;
  30. import org.springframework.web.client.RestTemplate;
  31.  
  32. @Service
  33. public class RepositoryDetailsService {
  34.  
  35. private RestTemplate restTemplate = new RestTemplate();
  36.  
  37. private String buildUrl(String owner, String repository) {
  38. return "https://api.github.com/repos/" + owner + "/" + repository + "";
  39. }
  40.  
  41. RepositoryDetails details(String owner, String repository) {
  42. return restTemplate.getForObject(
  43. buildUrl(owner, repository), RepositoryDetails.class);
  44. }
  45.  
  46.  
  47. }
  48.  
  49.  
  50. package com.task.task;
  51.  
  52.  
  53. import com.fasterxml.jackson.annotation.JsonProperty;
  54.  
  55. import java.time.LocalDate;
  56.  
  57. public class RepositoryDetails {
  58.  
  59. private String fullName;
  60. private String description;
  61. private String cloneUrl;
  62. private String stars;
  63. private LocalDate createdAt;
  64.  
  65. @JsonProperty("fullName")
  66. public String getFullName() {
  67. return fullName;
  68. }
  69.  
  70. @JsonProperty("full_name")
  71. public void setFullName(String fullName) {
  72. this.fullName = fullName;
  73. }
  74.  
  75. @JsonProperty("description")
  76. public String getDescription() {
  77. return description;
  78. }
  79.  
  80. @JsonProperty("description")
  81. public void setDescription(String description) {
  82. this.description = description;
  83. }
  84.  
  85. @JsonProperty("cloneUrl")
  86. public String getCloneUrl() {
  87. return cloneUrl;
  88. }
  89.  
  90. @JsonProperty("clone_url")
  91. public void setCloneUrl(String cloneUrl) {
  92. this.cloneUrl = cloneUrl;
  93. }
  94.  
  95. @JsonProperty("stars")
  96. public String getStars() {
  97. return stars;
  98. }
  99.  
  100. @JsonProperty("stargazers_count")
  101. public void setStars(String stars) {
  102. this.stars = stars;
  103. }
  104.  
  105. @JsonProperty("createdAt")
  106. public LocalDate getCreatedAt() {
  107. return createdAt;
  108. }
  109.  
  110. @JsonProperty("created_at")
  111. public void setCreatedAt(LocalDate createdAt) {
  112. this.createdAt = createdAt;
  113. }
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement