-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from Onlineberatung/feat/VIC-826_consultant_CRUD
Feat/vic 826 consultant crud
- Loading branch information
Showing
8 changed files
with
464 additions
and
115 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
268 changes: 171 additions & 97 deletions
268
src/main/java/com/vi/appointmentservice/controller/ConsultantController.java
Large diffs are not rendered by default.
Oops, something went wrong.
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
73 changes: 73 additions & 0 deletions
73
src/main/java/com/vi/appointmentservice/service/CalComAvailabilityService.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,73 @@ | ||
package com.vi.appointmentservice.service; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.core.type.TypeReference; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.vi.appointmentservice.api.model.CalcomAvailability; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import lombok.NonNull; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.json.JSONObject; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.http.HttpEntity; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.HttpMethod; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
@Service | ||
@Slf4j | ||
public class CalComAvailabilityService extends CalComService { | ||
|
||
public CalComAvailabilityService(@NonNull RestTemplate restTemplate, | ||
@Value("${calcom.apiUrl}") String calcomApiUrl, | ||
@Value("${calcom.apiKey}") String calcomApiKey, @NonNull ObjectMapper objectMapper) { | ||
super(restTemplate, calcomApiUrl, calcomApiKey); | ||
} | ||
|
||
public List<CalcomAvailability> getAllAvailabilities() throws JsonProcessingException { | ||
String response = this.restTemplate.getForObject(this.buildUri("/v1/availabilities"), | ||
String.class); | ||
JSONObject jsonObject = new JSONObject(response); | ||
response = jsonObject.getJSONArray("availabilities").toString(); | ||
ObjectMapper mapper = new ObjectMapper(); | ||
List<CalcomAvailability> result = mapper.readValue(response, | ||
new TypeReference<List<CalcomAvailability>>() { | ||
}); | ||
return result; | ||
} | ||
|
||
public CalcomAvailability getAvailabilityById(Long availabilityId) | ||
throws JsonProcessingException { | ||
List<CalcomAvailability> result = this.getAllAvailabilities(); | ||
return new ArrayList<>(result).stream() | ||
.filter(availability -> availability.getId() == availabilityId.intValue()) | ||
.collect(Collectors.toList()).get(0); | ||
} | ||
|
||
public CalcomAvailability createAvailability(JSONObject availability) { | ||
HttpHeaders headers = new HttpHeaders(); | ||
headers.setContentType(MediaType.APPLICATION_JSON); | ||
HttpEntity<String> request = new HttpEntity<>(availability.toString(), headers); | ||
return restTemplate.postForEntity(this.buildUri("/v1/availabilities"), request, | ||
CalcomAvailability.class).getBody(); | ||
} | ||
|
||
public CalcomAvailability editAvailability(JSONObject availability) { | ||
HttpHeaders headers = new HttpHeaders(); | ||
headers.setContentType(MediaType.APPLICATION_JSON); | ||
HttpEntity<String> request = new HttpEntity<>(availability.toString(), headers); | ||
return restTemplate.postForEntity(this.buildUri( | ||
"/v1/availabilities/" + availability.get("userId") + "_" + availability.get("teamId")), | ||
request, CalcomAvailability.class).getBody(); | ||
} | ||
|
||
public void deleteAvailability(Integer availabilityId) { | ||
restTemplate.exchange(this.buildUri("/v1/availabilities/" + availabilityId), | ||
HttpMethod.DELETE, null, String.class).getStatusCode(); | ||
} | ||
|
||
} |
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
85 changes: 85 additions & 0 deletions
85
src/main/java/com/vi/appointmentservice/service/CalComMembershipService.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,85 @@ | ||
package com.vi.appointmentservice.service; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.core.type.TypeReference; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.vi.appointmentservice.api.model.CalcomMembership; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import lombok.NonNull; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.json.JSONObject; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.http.HttpEntity; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.HttpMethod; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
@Service | ||
@Slf4j | ||
public class CalComMembershipService extends CalComService { | ||
|
||
public CalComMembershipService(@NonNull RestTemplate restTemplate, | ||
@Value("${calcom.apiUrl}") String calcomApiUrl, | ||
@Value("${calcom.apiKey}") String calcomApiKey, @NonNull ObjectMapper objectMapper) { | ||
super(restTemplate, calcomApiUrl, calcomApiKey); | ||
} | ||
|
||
public List<CalcomMembership> getAllMemberships() throws JsonProcessingException { | ||
String response = this.restTemplate.getForObject(this.buildUri("/v1/memberships"), | ||
String.class); | ||
JSONObject jsonObject = new JSONObject(response); | ||
response = jsonObject.getJSONArray("memberships").toString(); | ||
ObjectMapper mapper = new ObjectMapper(); | ||
List<CalcomMembership> result = mapper.readValue(response, | ||
new TypeReference<List<CalcomMembership>>() { | ||
}); | ||
return result; | ||
} | ||
|
||
public void deleteAllMembershipsOfUser(Long userId) throws JsonProcessingException { | ||
List<CalcomMembership> membershipsOfUser = new ArrayList<>(this.getAllMemberships()).stream() | ||
.filter(membership -> membership.getUserId() != null | ||
&& membership.getUserId() == userId.intValue()) | ||
.collect(Collectors.toList()); | ||
for (CalcomMembership membership : membershipsOfUser) { | ||
this.deleteMembership(membership.getUserId(), membership.getTeamId()); | ||
} | ||
} | ||
|
||
public List<CalcomMembership> getAllMembershipsOfUser(Long userId) | ||
throws JsonProcessingException { | ||
List<CalcomMembership> result = this.getAllMemberships(); | ||
return new ArrayList<>(result).stream() | ||
.filter(membership -> membership.getUserId() != null | ||
&& membership.getUserId() == userId.intValue()) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
|
||
public CalcomMembership createMembership(JSONObject membership) { | ||
HttpHeaders headers = new HttpHeaders(); | ||
headers.setContentType(MediaType.APPLICATION_JSON); | ||
HttpEntity<String> request = new HttpEntity<>(membership.toString(), headers); | ||
return restTemplate.postForEntity(this.buildUri("/v1/memberships"), request, | ||
CalcomMembership.class).getBody(); | ||
} | ||
|
||
public CalcomMembership editMembership(JSONObject membership) { | ||
HttpHeaders headers = new HttpHeaders(); | ||
headers.setContentType(MediaType.APPLICATION_JSON); | ||
HttpEntity<String> request = new HttpEntity<>(membership.toString(), headers); | ||
return restTemplate.postForEntity(this.buildUri( | ||
"/v1/memberships/" + membership.get("userId") + "_" + membership.get("teamId")), request, | ||
CalcomMembership.class).getBody(); | ||
} | ||
|
||
public void deleteMembership(Long userId, Long teamId) { | ||
restTemplate.exchange(this.buildUri("/v1/memberships/" + userId + "_" + teamId), | ||
HttpMethod.DELETE, null, String.class).getStatusCode(); | ||
} | ||
|
||
} |
85 changes: 85 additions & 0 deletions
85
src/main/java/com/vi/appointmentservice/service/CalComScheduleService.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,85 @@ | ||
package com.vi.appointmentservice.service; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.core.type.TypeReference; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.vi.appointmentservice.api.model.CalcomSchedule; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import lombok.NonNull; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.json.JSONObject; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.http.HttpEntity; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.HttpMethod; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
@Service | ||
@Slf4j | ||
public class CalComScheduleService extends CalComService { | ||
|
||
public CalComScheduleService(@NonNull RestTemplate restTemplate, | ||
@Value("${calcom.apiUrl}") String calcomApiUrl, | ||
@Value("${calcom.apiKey}") String calcomApiKey, @NonNull ObjectMapper objectMapper) { | ||
super(restTemplate, calcomApiUrl, calcomApiKey); | ||
} | ||
|
||
public List<CalcomSchedule> getAllSchedules() throws JsonProcessingException { | ||
String response = this.restTemplate.getForObject(this.buildUri("/v1/schedules"), String.class); | ||
JSONObject jsonObject = new JSONObject(response); | ||
response = jsonObject.getJSONArray("schedules").toString(); | ||
ObjectMapper mapper = new ObjectMapper(); | ||
List<CalcomSchedule> result = mapper.readValue(response, | ||
new TypeReference<List<CalcomSchedule>>() { | ||
}); | ||
return result; | ||
} | ||
|
||
public List<Integer> deleteAllSchedulesOfUser(Long userId) throws JsonProcessingException { | ||
ArrayList<Integer> scheduleList = new ArrayList<>(); | ||
List<CalcomSchedule> schedulesOfUser = new ArrayList<>(this.getAllSchedules()).stream() | ||
.filter( | ||
schedule -> schedule.getUserId() != null && schedule.getUserId() == userId.intValue()) | ||
.collect(Collectors.toList()); | ||
for (CalcomSchedule schedule : schedulesOfUser) { | ||
this.deleteSchedule(schedule.getId()); | ||
scheduleList.add(schedule.getId()); | ||
} | ||
return scheduleList; | ||
} | ||
|
||
public List<CalcomSchedule> getAllSchedulesOfUser(Long userId) throws JsonProcessingException { | ||
List<CalcomSchedule> result = this.getAllSchedules(); | ||
return new ArrayList<>(result).stream() | ||
.filter( | ||
schedule -> schedule.getUserId() != null && schedule.getUserId() == userId.intValue()) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
|
||
public CalcomSchedule createSchedule(JSONObject schedule) { | ||
HttpHeaders headers = new HttpHeaders(); | ||
headers.setContentType(MediaType.APPLICATION_JSON); | ||
HttpEntity<String> request = new HttpEntity<>(schedule.toString(), headers); | ||
return restTemplate.postForEntity(this.buildUri("/v1/schedules"), request, CalcomSchedule.class) | ||
.getBody(); | ||
} | ||
|
||
public CalcomSchedule editSchedule(JSONObject schedule) { | ||
HttpHeaders headers = new HttpHeaders(); | ||
headers.setContentType(MediaType.APPLICATION_JSON); | ||
HttpEntity<String> request = new HttpEntity<>(schedule.toString(), headers); | ||
return restTemplate.postForEntity(this.buildUri("/v1/schedules/" + schedule.get("id")), request, | ||
CalcomSchedule.class).getBody(); | ||
} | ||
|
||
public void deleteSchedule(int scheduleId) { | ||
restTemplate.exchange(this.buildUri("/v1/schedules/" + scheduleId), | ||
HttpMethod.DELETE, null, String.class).getStatusCode(); | ||
} | ||
|
||
} |