-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chat agent use same online MySQL database as other components (#52)
## Purpose Make chat agent use the same online MySQL database as other components. Currently the local DB config still exists, because some UI is using it. Will update the UI later and then we can simplify. ## Does this introduce a breaking change? <!-- Mark one with an "x". --> ``` [ ] Yes [x] No ``` ## Pull Request Type What kind of change does this Pull Request introduce? <!-- Please check the one that applies to this PR using "x". --> ``` [ ] Bugfix [ ] Feature [ ] Code style update (formatting, local variables) [ ] Refactoring (no functional changes, no api changes) [ ] Documentation content changes [ ] Other... Please describe: ``` ## How to Test * Get the code ``` git clone [repo-address] cd [repo-name] git checkout [branch-name] npm install ``` * Test the code <!-- Add steps to run the tests suite and/or manually test --> ``` ``` ## What to Check Verify that the following are valid * ... ## Other Information <!-- Add any other helpful information that may be needed here. --> --------- Co-authored-by: Hao Zhang <[email protected]>
- Loading branch information
Showing
15 changed files
with
203 additions
and
31 deletions.
There are no files selected for viewing
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
23 changes: 23 additions & 0 deletions
23
...ic-chat-agent/src/main/java/org/springframework/samples/petclinic/agent/dto/OwnerDto.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 org.springframework.samples.petclinic.agent.dto; | ||
|
||
import lombok.Data; | ||
|
||
import java.util.Set; | ||
|
||
@Data | ||
public class OwnerDto { | ||
|
||
private Integer id; | ||
|
||
private String firstName; | ||
|
||
private String lastName; | ||
|
||
private String address; | ||
|
||
private String city; | ||
|
||
private String telephone; | ||
|
||
private Set<PetDto> pets; | ||
} |
19 changes: 19 additions & 0 deletions
19
...inic-chat-agent/src/main/java/org/springframework/samples/petclinic/agent/dto/PetDto.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 org.springframework.samples.petclinic.agent.dto; | ||
|
||
import lombok.Data; | ||
|
||
import java.util.Date; | ||
|
||
@Data | ||
public class PetDto { | ||
|
||
private Integer id; | ||
|
||
private String name; | ||
|
||
private Date birthDate; | ||
|
||
private PetTypeDto type; | ||
|
||
private OwnerDto owner; | ||
} |
12 changes: 12 additions & 0 deletions
12
...-chat-agent/src/main/java/org/springframework/samples/petclinic/agent/dto/PetTypeDto.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,12 @@ | ||
package org.springframework.samples.petclinic.agent.dto; | ||
|
||
import lombok.Data; | ||
|
||
@Data | ||
public class PetTypeDto { | ||
|
||
private Integer id; | ||
|
||
private String name; | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
...hat-agent/src/main/java/org/springframework/samples/petclinic/agent/dto/SpecialtyDto.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,12 @@ | ||
package org.springframework.samples.petclinic.agent.dto; | ||
|
||
import lombok.Data; | ||
|
||
@Data | ||
public class SpecialtyDto { | ||
|
||
private Integer id; | ||
|
||
private String name; | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
...inic-chat-agent/src/main/java/org/springframework/samples/petclinic/agent/dto/VetDto.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 org.springframework.samples.petclinic.agent.dto; | ||
|
||
import lombok.Data; | ||
|
||
import java.util.Set; | ||
|
||
@Data | ||
public class VetDto { | ||
|
||
private Integer id; | ||
|
||
private String firstName; | ||
|
||
private String lastName; | ||
|
||
private Set<SpecialtyDto> specialties; | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
...agent/src/main/java/org/springframework/samples/petclinic/agent/service/OwnerService.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 org.springframework.samples.petclinic.agent.service; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.samples.petclinic.agent.dto.OwnerDto; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Service | ||
public class OwnerService { | ||
|
||
private final RestTemplate restTemplate; | ||
|
||
@Autowired | ||
public OwnerService(RestTemplate restTemplate) { | ||
this.restTemplate = restTemplate; | ||
} | ||
|
||
public List<OwnerDto> findByFirstName(String firstName) { | ||
var owners = restTemplate.getForObject("http://customers-service/owners/firstname/{firstName}", OwnerDto[].class, firstName); | ||
if (owners != null) { | ||
return List.of(owners); | ||
} else { | ||
return new ArrayList<>(); | ||
} | ||
} | ||
|
||
public OwnerDto findById(int ownerId) { | ||
return restTemplate.getForObject("http://customers-service/owners/{ownerId}", OwnerDto.class, ownerId); | ||
} | ||
|
||
public void save(OwnerDto owner) { | ||
restTemplate.postForEntity("http://customers-service/owners", owner, OwnerDto.class); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...t-agent/src/main/java/org/springframework/samples/petclinic/agent/service/VetService.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,30 @@ | ||
package org.springframework.samples.petclinic.agent.service; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.samples.petclinic.agent.dto.VetDto; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Service | ||
public class VetService { | ||
|
||
private final RestTemplate restTemplate; | ||
|
||
@Autowired | ||
public VetService(RestTemplate restTemplate) { | ||
this.restTemplate = restTemplate; | ||
} | ||
|
||
public List<VetDto> findAll() { | ||
var vets = restTemplate.getForObject("http://vets-service/vets", VetDto[].class); | ||
if (vets != null) { | ||
return List.of(vets); | ||
} else { | ||
return new ArrayList<>(); | ||
} | ||
} | ||
|
||
} |
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