New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Firat attempt at adding some business logic.. #8
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
api/src/main/java/com/g2/studentservice/api/mock/MockUrlPaths.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.g2.studentservice.api.mock; | ||
|
||
public class MockUrlPaths { | ||
public static final String EPOKMODUL = "/modul"; | ||
} |
11 changes: 11 additions & 0 deletions
11
api/src/main/java/com/g2/studentservice/api/mock/epok/EpokModulResource.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.g2.studentservice.api.mock.epok; | ||
|
||
import com.g2.studentservice.api.mock.MockUrlPaths; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
|
||
public interface EpokModulResource { | ||
@RequestMapping(method = RequestMethod.GET, path = MockUrlPaths.EPOKMODUL) | ||
ResponseEntity<ModulResponse> getModul(); | ||
} |
18 changes: 18 additions & 0 deletions
18
api/src/main/java/com/g2/studentservice/api/mock/epok/ModulResponse.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.g2.studentservice.api.mock.epok; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@Builder | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class ModulResponse { | ||
private String code; | ||
private String description; | ||
private ModulStatus status; | ||
} |
8 changes: 8 additions & 0 deletions
8
api/src/main/java/com/g2/studentservice/api/mock/epok/ModulStatus.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.g2.studentservice.api.mock.epok; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.NoArgsConstructor; | ||
|
||
public enum ModulStatus { | ||
aktiv, inaktiv_framtida, inaktiv_avslutad | ||
} |
15 changes: 15 additions & 0 deletions
15
api/src/main/java/com/g2/studentservice/api/mock/studentits/StudentItsResource.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.g2.studentservice.api.mock.studentits; | ||
|
||
import com.g2.studentservice.api.mock.MockUrlPaths; | ||
import com.g2.studentservice.api.mock.epok.ModulResponse; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
|
||
import java.util.List; | ||
|
||
public interface StudentItsResource { | ||
|
||
@RequestMapping(method = RequestMethod.GET, path = MockUrlPaths.EPOKMODUL) | ||
ResponseEntity<List<StudentItsResponse>> getAllStudents(); | ||
} |
20 changes: 20 additions & 0 deletions
20
api/src/main/java/com/g2/studentservice/api/mock/studentits/StudentItsResponse.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.g2.studentservice.api.mock.studentits; | ||
|
||
import com.fasterxml.jackson.annotation.JsonAlias; | ||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@Builder | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class StudentItsResponse { | ||
private String ssn; | ||
|
||
@JsonAlias("username") | ||
private String studentUser; | ||
} |
20 changes: 20 additions & 0 deletions
20
api/src/main/java/com/g2/studentservice/api/rest/CreateStudentRequest.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.g2.studentservice.api.rest; | ||
|
||
import com.fasterxml.jackson.databind.PropertyNamingStrategy; | ||
import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class) | ||
public class CreateStudentRequest { | ||
private String firstname; | ||
private String lastname; | ||
private String ssn; | ||
private String streetAdress; | ||
} |
14 changes: 14 additions & 0 deletions
14
api/src/main/java/com/g2/studentservice/api/rest/SsnAndStudentUserResponse.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.g2.studentservice.api.rest; | ||
|
||
import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
|
||
@Data | ||
@Builder | ||
@AllArgsConstructor | ||
public class SsnAndStudentUserResponse { | ||
private String ssn; | ||
private String studentUser; | ||
} |
19 changes: 19 additions & 0 deletions
19
api/src/main/java/com/g2/studentservice/api/rest/SsnFromStudentUserRequest.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.g2.studentservice.api.rest; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import com.fasterxml.jackson.databind.PropertyNamingStrategy; | ||
import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class) | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public class SsnFromStudentUserRequest { | ||
private String studentUser; | ||
} |
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
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
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
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
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
16 changes: 16 additions & 0 deletions
16
service/src/main/java/com/g2/studentservice/application/StudentService.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.g2.studentservice.application; | ||
|
||
import com.g2.studentservice.api.mock.studentits.StudentItsResponse; | ||
import com.g2.studentservice.api.rest.CreateStudentRequest; | ||
import com.g2.studentservice.domain.StudentEntity; | ||
|
||
import java.util.List; | ||
|
||
public interface StudentService { | ||
StudentEntity findStudentById(long studentId); | ||
StudentEntity create(CreateStudentRequest student); | ||
|
||
List<StudentItsResponse> getAllStudents(); | ||
|
||
StudentItsResponse getStudentItsSsn(String studentUser); | ||
} |
66 changes: 66 additions & 0 deletions
66
service/src/main/java/com/g2/studentservice/application/impl/StudentServiceImpl.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package com.g2.studentservice.application.impl; | ||
|
||
import com.g2.studentservice.api.mock.studentits.StudentItsResponse; | ||
import com.g2.studentservice.api.rest.CreateStudentRequest; | ||
import com.g2.studentservice.application.StudentService; | ||
import com.g2.studentservice.domain.StudentEntity; | ||
import com.g2.studentservice.infrastructure.StudentRepository; | ||
import com.g2.studentservice.infrastructure.rest.StudentItsClient; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import lombok.val; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
import java.util.Random; | ||
|
||
@RequiredArgsConstructor | ||
@Service | ||
@Slf4j | ||
public class StudentServiceImpl implements StudentService { | ||
|
||
@Autowired | ||
private final StudentRepository repository; | ||
|
||
|
||
private final StudentItsClient client; | ||
|
||
@Override | ||
public StudentEntity findStudentById(long studentId) { | ||
return repository.findById(studentId).get(); | ||
} | ||
|
||
@Override | ||
public StudentEntity create(CreateStudentRequest request){ | ||
String studentUser = studentUserGenerator(request.getFirstname(), request.getLastname()); | ||
val student = StudentEntity.builder() | ||
.studentUser(studentUser) | ||
.emailAddress(studentUser+"@fake.ltu.se") | ||
.firstname(request.getFirstname()) | ||
.lastname(request.getLastname()) | ||
.ssn(request.getSsn()) | ||
.streetAddress(request.getStreetAdress()).build(); | ||
return repository.save(student); | ||
} | ||
|
||
private String studentUserGenerator(String firstname, String lastname){ | ||
Random random = new Random(); | ||
int number = random.nextInt(200 - 2)+2; | ||
return firstname.substring(0,2)+ lastname.substring(0,3)+"-"+number; | ||
} | ||
|
||
@Override | ||
public List<StudentItsResponse> getAllStudents(){ | ||
val students = client.getAllStudents(); | ||
return students; | ||
} | ||
|
||
@Override | ||
public StudentItsResponse getStudentItsSsn(String studentUser){ | ||
val students = client.getAllStudents(); | ||
students.forEach(it -> {log.warn("studentuser "+it.getStudentUser()+" person "+it.getSsn());}); | ||
val student = students.stream().filter(it -> it.getStudentUser().equals(studentUser)).findFirst(); | ||
return student.get(); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
service/src/main/java/com/g2/studentservice/conf/FeignConfig.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.g2.studentservice.conf; | ||
|
||
public class FeignConfig { | ||
} |
37 changes: 37 additions & 0 deletions
37
service/src/main/java/com/g2/studentservice/domain/StudentEntity.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.g2.studentservice.domain; | ||
|
||
import lombok.Builder; | ||
import lombok.Data; | ||
import org.springframework.data.annotation.CreatedDate; | ||
|
||
import javax.persistence.*; | ||
import javax.validation.constraints.NotNull; | ||
import java.time.Instant; | ||
|
||
@Data | ||
@Builder | ||
@Entity | ||
public class StudentEntity { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.AUTO) | ||
long studentId; | ||
|
||
@Column(unique = true) | ||
String studentUser; | ||
|
||
@NotNull | ||
String firstname; | ||
|
||
@NotNull | ||
String lastname; | ||
|
||
@NotNull | ||
String ssn; | ||
|
||
String emailAddress; | ||
String streetAddress; | ||
|
||
@CreatedDate | ||
Instant createdAt; | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
service/src/main/java/com/g2/studentservice/infrastructure/StudentRepository.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.g2.studentservice.infrastructure; | ||
|
||
import com.g2.studentservice.domain.StudentEntity; | ||
import org.springframework.data.repository.CrudRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.Optional; | ||
|
||
@Repository | ||
public interface StudentRepository extends CrudRepository<StudentEntity, Long> { | ||
|
||
} | ||
|
23 changes: 23 additions & 0 deletions
23
service/src/main/java/com/g2/studentservice/infrastructure/StudentRepositoryImpl.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.g2.studentservice.infrastructure; | ||
|
||
import com.g2.studentservice.domain.StudentEntity; | ||
|
||
import java.time.Instant; | ||
import java.time.temporal.ChronoUnit; | ||
import java.util.Optional; | ||
|
||
public class StudentRepositoryImpl{ | ||
|
||
public Optional<StudentEntity> findById(long studentId) { | ||
return Optional.of(StudentEntity.builder() | ||
.studentId(studentId) | ||
.emailAddress(studentId + "@fakestudent@ltu.se") | ||
.firstname("Miranda") | ||
.lastname("Titania") | ||
.streetAddress("Uranusvägen 3") | ||
.ssn("101010A2345") | ||
.createdAt(Instant.now().minus(10, ChronoUnit.DAYS)).build()); | ||
} | ||
|
||
|
||
} |
13 changes: 13 additions & 0 deletions
13
service/src/main/java/com/g2/studentservice/infrastructure/rest/StudentItsClient.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.g2.studentservice.infrastructure.rest; | ||
|
||
import com.g2.studentservice.api.mock.studentits.StudentItsResponse; | ||
import org.springframework.cloud.openfeign.FeignClient; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
|
||
import java.util.List; | ||
|
||
@FeignClient(name = "studentits-client", url = "${integration.services.mock-service.url}") | ||
public interface StudentItsClient { | ||
@GetMapping("/students") | ||
List<StudentItsResponse> getAllStudents(); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably drop these dependencies to JPA and h2 database.