Skip to content

Commit

Permalink
Merge pull request #35 from stevensblueprint/feat/dto
Browse files Browse the repository at this point in the history
Split DTOs
  • Loading branch information
miguel-merlin authored Jan 31, 2025
2 parents 52b8222 + 264ccf5 commit 1a92e80
Show file tree
Hide file tree
Showing 55 changed files with 1,192 additions and 451 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.sarapis.orservice.controller;

import com.sarapis.orservice.dto.ContactDTO;
import com.sarapis.orservice.dto.upsert.UpsertContactDTO;
import com.sarapis.orservice.service.ContactService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
Expand Down Expand Up @@ -31,8 +32,8 @@ public ResponseEntity<ContactDTO> getContactById(@PathVariable String contactId)
}

@PostMapping
public ResponseEntity<ContactDTO> createContact(@RequestBody ContactDTO contactDTO) {
ContactDTO createdContact = this.contactService.createContact(contactDTO);
public ResponseEntity<ContactDTO> createContact(@RequestBody UpsertContactDTO upsertContactDTO) {
ContactDTO createdContact = this.contactService.createContact(upsertContactDTO);
return ResponseEntity.ok(createdContact);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.sarapis.orservice.dto.LocationDTO;
import com.sarapis.orservice.dto.PaginationDTO;
import com.sarapis.orservice.dto.upsert.UpsertLocationDTO;
import com.sarapis.orservice.service.LocationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
Expand Down Expand Up @@ -42,8 +43,8 @@ public ResponseEntity<LocationDTO> getLocation(@PathVariable String locationId)
}

@PostMapping
public ResponseEntity<LocationDTO> createLocation(@RequestBody LocationDTO locationDTO) {
LocationDTO createdLocation = this.locationService.createLocation(locationDTO);
public ResponseEntity<LocationDTO> createLocation(@RequestBody UpsertLocationDTO upsertLocationDTO) {
LocationDTO createdLocation = this.locationService.createLocation(upsertLocationDTO);
return ResponseEntity.ok(createdLocation);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.sarapis.orservice.dto.OrganizationDTO;
import com.sarapis.orservice.dto.PaginationDTO;
import com.sarapis.orservice.dto.upsert.UpsertOrganizationDTO;
import com.sarapis.orservice.service.OrganizationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
Expand Down Expand Up @@ -42,8 +43,8 @@ public ResponseEntity<OrganizationDTO> getOrganizationById(@PathVariable String
}

@PostMapping
public ResponseEntity<OrganizationDTO> createOrganization(@RequestBody OrganizationDTO organizationDTO) {
OrganizationDTO createdOrganization = this.organizationService.createOrganization(organizationDTO);
public ResponseEntity<OrganizationDTO> createOrganization(@RequestBody UpsertOrganizationDTO upsertOrganizationDTO) {
OrganizationDTO createdOrganization = this.organizationService.createOrganization(upsertOrganizationDTO);
return ResponseEntity.ok(createdOrganization);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.sarapis.orservice.controller;

import com.sarapis.orservice.dto.ProgramDTO;
import com.sarapis.orservice.dto.upsert.UpsertLocationDTO;
import com.sarapis.orservice.dto.upsert.UpsertProgramDTO;
import com.sarapis.orservice.service.ProgramService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
Expand Down Expand Up @@ -31,8 +33,8 @@ public ResponseEntity<ProgramDTO> getProgramById(@PathVariable String programId)
}

@PostMapping
public ResponseEntity<ProgramDTO> createProgram(@RequestBody ProgramDTO programDTO) {
ProgramDTO createdProgram = this.programService.createProgram(programDTO);
public ResponseEntity<ProgramDTO> createProgram(@RequestBody UpsertProgramDTO upsertProgramDTO) {
ProgramDTO createdProgram = this.programService.createProgram(upsertProgramDTO);
return ResponseEntity.ok(createdProgram);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.sarapis.orservice.dto.PaginationDTO;
import com.sarapis.orservice.dto.ServiceAtLocationDTO;
import com.sarapis.orservice.dto.upsert.UpsertServiceAtLocationDTO;
import com.sarapis.orservice.service.ServiceAtLocationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
Expand Down Expand Up @@ -44,9 +45,9 @@ public ResponseEntity<ServiceAtLocationDTO> getServiceAtLocationById(@PathVariab

@PostMapping
public ResponseEntity<ServiceAtLocationDTO> createServiceAtLocation(
@RequestBody ServiceAtLocationDTO serviceAtLocationDTO) {
@RequestBody UpsertServiceAtLocationDTO upsertServiceAtLocationDTO) {
ServiceAtLocationDTO createdServiceAtLocation = this.serviceAtLocationService
.createServiceAtLocation(serviceAtLocationDTO);
.createServiceAtLocation(upsertServiceAtLocationDTO);
return ResponseEntity.ok(createdServiceAtLocation);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.sarapis.orservice.dto.PaginationDTO;
import com.sarapis.orservice.dto.ServiceDTO;
import com.sarapis.orservice.dto.upsert.UpsertServiceDTO;
import com.sarapis.orservice.service.ServiceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
Expand Down Expand Up @@ -42,8 +43,8 @@ public ResponseEntity<ServiceDTO> getServiceById(@PathVariable String serviceId)
}

@PostMapping
public ResponseEntity<ServiceDTO> createService(@RequestBody ServiceDTO serviceDTO) {
ServiceDTO createdService = this.serviceService.createService(serviceDTO);
public ResponseEntity<ServiceDTO> createService(@RequestBody UpsertServiceDTO upsertServiceDTO) {
ServiceDTO createdService = this.serviceService.createService(upsertServiceDTO);
return ResponseEntity.ok(createdService);
}

Expand Down
39 changes: 7 additions & 32 deletions src/main/java/com/sarapis/orservice/dto/ContactDTO.java
Original file line number Diff line number Diff line change
@@ -1,54 +1,29 @@
package com.sarapis.orservice.dto;

import com.sarapis.orservice.entity.Contact;
import com.sarapis.orservice.entity.core.Location;
import com.sarapis.orservice.entity.core.Organization;
import com.sarapis.orservice.entity.core.Service;
import com.sarapis.orservice.entity.core.ServiceAtLocation;
import lombok.*;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

/**
* Returned response for a contact entity.
* <a href="http://docs.openreferral.org/en/v3.1.1/hsds/schema_reference.html#contact">Reference</a>
*/
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class ContactDTO {
private String id;

private String organizationId;
private String serviceId;
private String serviceAtLocationId;
private String locationId;

private String name;
private String title;
private String department;
private String email;

private List<PhoneDTO> phones = new ArrayList<>();
private List<AttributeDTO> attributes = new ArrayList<>();
private List<MetadataDTO> metadata = new ArrayList<>();

public Contact toEntity(Organization organization,
Service service,
ServiceAtLocation serviceAtLocation,
Location location) {
Contact contact = Contact.builder()
.id(this.id == null ? UUID.randomUUID().toString() : this.id)
.organization(organization)
.service(service)
.serviceAtLocation(serviceAtLocation)
.location(location)
.name(this.name)
.title(this.title)
.department(this.department)
.email(this.email)
.build();
contact.setPhones(this.phones.stream().map(e -> e.toEntity(null, null, null, contact, null)).toList());
return contact;
}
private List<PhoneDTO> phones;
private List<AttributeDTO> attributes;
private List<MetadataDTO> metadata;
}
28 changes: 6 additions & 22 deletions src/main/java/com/sarapis/orservice/dto/CostOptionDTO.java
Original file line number Diff line number Diff line change
@@ -1,44 +1,28 @@
package com.sarapis.orservice.dto;

import com.sarapis.orservice.entity.CostOption;
import com.sarapis.orservice.entity.core.Service;
import lombok.*;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

/**
* Returned response for a cost option entity.
* <a href="http://docs.openreferral.org/en/v3.1.1/hsds/schema_reference.html#cost-option">Reference</a>
*/
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class CostOptionDTO {
private String id;

private String serviceId;

private LocalDate validFrom;
private LocalDate validTo;
private String option;
private String currency;
private int amount;
private String amountDescription;

private List<AttributeDTO> attributes = new ArrayList<>();
private List<MetadataDTO> metadata = new ArrayList<>();

public CostOption toEntity(Service service) {
return CostOption.builder()
.id(this.id == null ? UUID.randomUUID().toString() : this.id)
.service(service)
.validFrom(this.validFrom)
.validTo(this.validTo)
.option(this.option)
.currency(this.currency)
.amount(this.amount)
.amountDescription(this.amountDescription)
.build();
}
private List<AttributeDTO> attributes;
private List<MetadataDTO> metadata;
}
52 changes: 13 additions & 39 deletions src/main/java/com/sarapis/orservice/dto/LocationDTO.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
package com.sarapis.orservice.dto;

import com.sarapis.orservice.entity.core.Location;
import com.sarapis.orservice.entity.core.LocationType;
import com.sarapis.orservice.entity.core.Organization;
import lombok.*;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

/**
* Returned response for a location entity.
* <a href="http://docs.openreferral.org/en/v3.1.1/hsds/schema_reference.html#location">Reference</a>
*/
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class LocationDTO {
private String id;

private String organizationId;

private LocationType locationType;
private String url;
private String organizationId;
private String name;
private String alternateName;
private String description;
Expand All @@ -29,36 +27,12 @@ public class LocationDTO {
private int longitude;
private String externalIdentifier;
private String externalIdentifierType;

private List<LanguageDTO> languages = new ArrayList<>();
private List<AddressDTO> addresses = new ArrayList<>();
private List<ContactDTO> contacts = new ArrayList<>();
private List<AccessibilityDTO> accessibility = new ArrayList<>();
private List<PhoneDTO> phones = new ArrayList<>();
private List<ScheduleDTO> schedules = new ArrayList<>();
private List<AttributeDTO> attributes = new ArrayList<>();
private List<MetadataDTO> metadata = new ArrayList<>();

public Location toEntity(Organization organization) {
Location location = Location.builder()
.id(this.id == null ? UUID.randomUUID().toString() : this.id)
.organization(organization)
.locationType(this.locationType)
.url(this.url).name(this.name)
.alternateName(this.alternateName)
.description(this.description)
.transportation(this.transportation)
.latitude(this.latitude)
.longitude(this.longitude)
.externalIdentifier(this.externalIdentifier)
.externalIdentifierType(this.externalIdentifierType)
.build();
location.setLanguages(this.languages.stream().map(e -> e.toEntity(null, location, null)).toList());
location.setAddresses(this.addresses.stream().map(e -> e.toEntity(location)).toList());
location.setContacts(this.contacts.stream().map(e -> e.toEntity(null, null, null, location)).toList());
location.setAccessibility(this.accessibility.stream().map(e -> e.toEntity(location)).toList());
location.setPhones(this.phones.stream().map(e -> e.toEntity(location, null, null, null, null)).toList());
location.setSchedules(this.schedules.stream().map(e -> e.toEntity(null, location, null)).toList());
return location;
}
private List<LanguageDTO> languages;
private List<AddressDTO> addresses;
private List<ContactDTO> contacts;
private List<AccessibilityDTO> accessibility;
private List<PhoneDTO> phones;
private List<ScheduleDTO> schedules;
private List<AttributeDTO> attributes;
private List<MetadataDTO> metadata;
}
41 changes: 7 additions & 34 deletions src/main/java/com/sarapis/orservice/dto/OrganizationDTO.java
Original file line number Diff line number Diff line change
@@ -1,35 +1,34 @@
package com.sarapis.orservice.dto;

import com.sarapis.orservice.entity.core.Organization;
import lombok.*;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

/**
* Returned response for organization entity.
* <a href="http://docs.openreferral.org/en/v3.1.1/hsds/schema_reference.html#organization">Reference</a>
*/
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class OrganizationDTO {
private String id;

private String parentOrganizationId;

private String name;
private String alternateName;
private String description;
private String email;
private String website;
private List<UrlDTO> additionalWebsites = new ArrayList<>();
private String taxStatus;
private String taxId;
private int yearIncorporated;
private String legalStatus;
private String logo;
private String uri;

private List<UrlDTO> additionalWebsites = new ArrayList<>();
private String parentOrganizationId;
private List<FundingDTO> funding = new ArrayList<>();
private List<ContactDTO> contacts = new ArrayList<>();
private List<PhoneDTO> phones = new ArrayList<>();
Expand All @@ -38,30 +37,4 @@ public class OrganizationDTO {
private List<OrganizationIdentifierDTO> organizationIdentifiers = new ArrayList<>();
private List<AttributeDTO> attributes = new ArrayList<>();
private List<MetadataDTO> metadata = new ArrayList<>();

public Organization toEntity(Organization parentOrganization) {
Organization organization = Organization.builder()
.id(this.id == null ? UUID.randomUUID().toString() : this.id)
.parentOrganization(parentOrganization)
.name(this.name)
.alternateName(this.alternateName)
.description(this.description)
.email(this.email)
.website(this.website)
.taxStatus(this.taxStatus)
.taxId(this.taxId)
.yearIncorporated(this.yearIncorporated)
.legalStatus(this.legalStatus)
.logo(this.logo)
.uri(this.uri)
.build();
organization.setAdditionalWebsites(this.additionalWebsites.stream().map(e -> e.toEntity(organization, null)).toList());
organization.setFunding(this.funding.stream().map(e -> e.toEntity(organization, null)).toList());
organization.setContacts(this.contacts.stream().map(e -> e.toEntity(organization, null, null, null)).toList());
organization.setPhones(this.phones.stream().map(e -> e.toEntity(null, null, organization, null, null)).toList());
organization.setLocations(this.locations.stream().map(e -> e.toEntity(organization)).toList());
organization.setPrograms(this.programs.stream().map(e -> e.toEntity(organization)).toList());
organization.setOrganizationIdentifiers(this.organizationIdentifiers.stream().map(e -> e.toEntity(organization)).toList());
return organization;
}
}
}
Loading

0 comments on commit 1a92e80

Please sign in to comment.