-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
133 additions
and
0 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
src/main/java/com/springProject/project/io/repositories/AddressRepository.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.springProject.project.io.repositories; | ||
|
||
import com.springProject.project.io.entity.AddressEntity; | ||
import com.springProject.project.io.entity.UserEntity; | ||
import org.springframework.data.repository.CrudRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.List; | ||
@Repository | ||
public interface AddressRepository extends CrudRepository<AddressEntity,Long> { | ||
List<AddressEntity> findAllByUserDetails(UserEntity userEntity); | ||
|
||
AddressEntity findByAddressId(String addressId); | ||
} |
59 changes: 59 additions & 0 deletions
59
src/main/java/com/springProject/project/iu/model/response/AddressesRest.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,59 @@ | ||
package com.springProject.project.iu.model.response; | ||
|
||
|
||
public class AddressesRest { | ||
private String addressId; | ||
private String country; | ||
private String city; | ||
private String streetName; | ||
private String postalCode; | ||
private String type; | ||
|
||
public String getAddressId() { | ||
return addressId; | ||
} | ||
|
||
public void setAddressId(String addressId) { | ||
this.addressId = addressId; | ||
} | ||
|
||
public String getCountry() { | ||
return country; | ||
} | ||
|
||
public void setCountry(String country) { | ||
this.country = country; | ||
} | ||
|
||
public String getCity() { | ||
return city; | ||
} | ||
|
||
public void setCity(String city) { | ||
this.city = city; | ||
} | ||
|
||
public String getStreetName() { | ||
return streetName; | ||
} | ||
|
||
public void setStreetName(String streetName) { | ||
this.streetName = streetName; | ||
} | ||
|
||
public String getPostalCode() { | ||
return postalCode; | ||
} | ||
|
||
public void setPostalCode(String postalCode) { | ||
this.postalCode = postalCode; | ||
} | ||
|
||
public String getType() { | ||
return type; | ||
} | ||
|
||
public void setType(String type) { | ||
this.type = type; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/springProject/project/service/AddressService.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 com.springProject.project.service; | ||
|
||
import com.springProject.project.shared.dto.AddressDto; | ||
|
||
import java.util.List; | ||
|
||
public interface AddressService { | ||
List<AddressDto> getAddresses(String userId); | ||
|
||
AddressDto getAddress(String addressId); | ||
|
||
} |
48 changes: 48 additions & 0 deletions
48
src/main/java/com/springProject/project/service/serviceImpl/AddressServiceImpl.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,48 @@ | ||
package com.springProject.project.service.serviceImpl; | ||
|
||
import com.springProject.project.UserRepository; | ||
import com.springProject.project.io.entity.AddressEntity; | ||
import com.springProject.project.io.entity.UserEntity; | ||
import com.springProject.project.io.repositories.AddressRepository; | ||
import com.springProject.project.service.AddressService; | ||
import com.springProject.project.shared.dto.AddressDto; | ||
import org.modelmapper.ModelMapper; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
@Service | ||
public class AddressServiceImpl implements AddressService { | ||
|
||
@Autowired | ||
UserRepository userRepository; | ||
|
||
@Autowired | ||
AddressRepository addressRepository; | ||
|
||
@Override | ||
public List<AddressDto> getAddresses(String userId) { | ||
List<AddressDto> returnValue = new ArrayList<>(); | ||
ModelMapper mapper = new ModelMapper(); | ||
UserEntity userEntity = userRepository.findByUserId(userId); | ||
if (userEntity == null) | ||
return returnValue; | ||
|
||
Iterable<AddressEntity> addresses = addressRepository.findAllByUserDetails(userEntity); | ||
for (AddressEntity addressEntity : addresses) { | ||
returnValue.add(mapper.map(addressEntity, AddressDto.class)); | ||
} | ||
|
||
return returnValue; | ||
} | ||
|
||
@Override | ||
public AddressDto getAddress(String addressId) { | ||
AddressDto returnValue=new AddressDto(); | ||
AddressEntity addressEntity=addressRepository.findByAddressId(addressId); | ||
if (addressEntity!=null) | ||
returnValue=new ModelMapper().map(addressEntity,AddressDto.class); | ||
return returnValue; | ||
} | ||
} |