Skip to content

Commit

Permalink
Database
Browse files Browse the repository at this point in the history
  • Loading branch information
csmuxa committed May 24, 2019
1 parent 8507435 commit 0318562
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 0 deletions.
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);
}
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;
}
}
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);

}
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;
}
}

0 comments on commit 0318562

Please sign in to comment.