Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
student-personal-details-spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
student-details-microservice
student-personal-details-spring-boot
Commits
acfd1df3
Commit
acfd1df3
authored
Apr 12, 2021
by
Darrick Yong
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feat/config-server' into 'master'
Feat/config server See merge request
!2
parents
cbf770ae
7bdabdfd
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
58 additions
and
8 deletions
+58
-8
build.gradle
build.gradle
+2
-1
DetailsController.java
...va/com/student/details/controllers/DetailsController.java
+8
-1
APIService.java
src/main/java/com/student/details/services/APIService.java
+44
-0
StudentService.java
...ain/java/com/student/details/services/StudentService.java
+4
-6
No files found.
build.gradle
View file @
acfd1df3
...
@@ -33,7 +33,8 @@ dependencies {
...
@@ -33,7 +33,8 @@ dependencies {
implementation
'org.springframework.cloud:spring-cloud-starter-config'
implementation
'org.springframework.cloud:spring-cloud-starter-config'
implementation
'org.springframework.cloud:spring-cloud-starter-bootstrap:3.0.2'
implementation
'org.springframework.cloud:spring-cloud-starter-bootstrap:3.0.2'
implementation
"io.springfox:springfox-boot-starter:3.0.0"
implementation
'io.springfox:springfox-boot-starter:3.0.0'
implementation
group:
'com.googlecode.json-simple'
,
name:
'json-simple'
,
version:
'1.1.1'
compile
'org.json:json:20210307'
compile
'org.json:json:20210307'
annotationProcessor
'org.projectlombok:lombok'
annotationProcessor
'org.projectlombok:lombok'
compileOnly
'org.projectlombok:lombok:1.18.16'
compileOnly
'org.projectlombok:lombok:1.18.16'
...
...
src/main/java/com/student/details/controllers/DetailsController.java
View file @
acfd1df3
...
@@ -2,11 +2,12 @@ package com.student.details.controllers;
...
@@ -2,11 +2,12 @@ package com.student.details.controllers;
import
com.student.details.exceptions.ResourceNotFoundException
;
import
com.student.details.exceptions.ResourceNotFoundException
;
import
com.student.details.models.Student
;
import
com.student.details.models.Student
;
import
com.student.details.services.APIService
;
import
com.student.details.services.StudentService
;
import
com.student.details.services.StudentService
;
import
org.json.simple.JSONObject
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
...
@@ -18,6 +19,12 @@ public class DetailsController {
...
@@ -18,6 +19,12 @@ public class DetailsController {
@Autowired
@Autowired
StudentService
studentService
;
StudentService
studentService
;
@GetMapping
(
"/students/demo"
)
public
JSONObject
fetchDemo
()
{
return
APIService
.
get
(
"https://opentdb.com/api.php?amount=10"
);
}
@GetMapping
(
"/students"
)
@GetMapping
(
"/students"
)
public
List
<
Student
>
getAllStudents
()
{
public
List
<
Student
>
getAllStudents
()
{
// System.out.println("This is the students index route.");
// System.out.println("This is the students index route.");
...
...
src/main/java/com/student/details/services/APIService.java
0 → 100644
View file @
acfd1df3
package
com
.
student
.
details
.
services
;
import
org.json.simple.JSONObject
;
import
org.json.simple.parser.JSONParser
;
import
java.net.HttpURLConnection
;
import
java.net.URL
;
import
java.util.Scanner
;
public
class
APIService
{
public
static
JSONObject
get
(
String
stringUrl
)
{
try
{
URL
url
=
new
URL
(
stringUrl
);
HttpURLConnection
conn
=
(
HttpURLConnection
)
url
.
openConnection
();
conn
.
setRequestMethod
(
"GET"
);
conn
.
connect
();
int
responseCode
=
conn
.
getResponseCode
();
if
(
responseCode
!=
200
)
{
throw
new
RuntimeException
(
""
+
responseCode
);
}
else
{
String
res
=
""
;
Scanner
scanner
=
new
Scanner
(
url
.
openStream
());
while
(
scanner
.
hasNext
())
{
String
nextVal
=
scanner
.
nextLine
();
res
+=
nextVal
;
}
JSONParser
parser
=
new
JSONParser
();
JSONObject
json
=
(
JSONObject
)
parser
.
parse
(
res
);
return
json
;
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
new
JSONObject
();
}
}
src/main/java/com/student/details/services/StudentService.java
View file @
acfd1df3
...
@@ -2,22 +2,21 @@ package com.student.details.services;
...
@@ -2,22 +2,21 @@ package com.student.details.services;
import
com.student.details.exceptions.ResourceNotFoundException
;
import
com.student.details.exceptions.ResourceNotFoundException
;
import
com.student.details.models.Student
;
import
com.student.details.models.Student
;
import
com.student.details.repositories.StudentRepository
;
import
com.student.details.repositories.StudentRepository
;
import
org.json.JSONObject
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
java.net.HttpURLConnection
;
import
java.net.URL
;
import
org.json.JSONObject
;
import
java.io.BufferedReader
;
import
java.io.BufferedReader
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.InputStreamReader
;
import
java.io.InputStreamReader
;
import
java.lang.reflect.MalformedParameterizedTypeException
;
import
java.net.HttpURLConnection
;
import
java.net.MalformedURLException
;
import
java.net.MalformedURLException
;
import
java.net.URL
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.Optional
;
import
java.util.Optional
;
@Service
@Service
public
class
StudentService
{
public
class
StudentService
{
...
@@ -28,7 +27,6 @@ public class StudentService {
...
@@ -28,7 +27,6 @@ public class StudentService {
return
studentRepository
.
findAll
();
return
studentRepository
.
findAll
();
}
}
public
Student
addStudent
(
Student
student
)
{
public
Student
addStudent
(
Student
student
)
{
return
studentRepository
.
save
(
student
);
return
studentRepository
.
save
(
student
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment