Merge pull request #8436 from amit2103/BAEL-17317-31

Bael 17317 31
This commit is contained in:
Josh Cummings 2019-12-27 21:56:11 -07:00 committed by GitHub
commit d295f71498
17 changed files with 94 additions and 36 deletions

View File

@ -45,6 +45,11 @@
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<!-- Spring HATEOAS -->
<dependency>
<groupId>org.springframework.boot</groupId>

View File

@ -1,9 +0,0 @@
package com.baeldung.modelmapper.service;
import com.baeldung.modelmapper.model.User;
public interface IUserService {
User getCurrentUser();
}

View File

@ -24,8 +24,8 @@ import com.google.common.base.Preconditions;
@Configuration
@EnableTransactionManagement
@PropertySource({ "classpath:persistence-${envTarget:h2}.properties" })
@ComponentScan(basePackages = { "com.baeldung.persistence", "com.baeldung.modelmapper" })
@EnableJpaRepositories(basePackages = {"com.baeldung.persistence.dao", "com.baeldung.modelmapper.repository"})
@ComponentScan(basePackages = { "com.baeldung.persistence", "com.baeldung.springpagination" })
@EnableJpaRepositories(basePackages = {"com.baeldung.persistence.dao", "com.baeldung.springpagination.repository"})
public class PersistenceConfig {
@Autowired
@ -39,7 +39,7 @@ public class PersistenceConfig {
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setDataSource(dataSource());
em.setPackagesToScan(new String[] { "com.baeldung.persistence.model", "com.baeldung.modelmapper.model" });
em.setPackagesToScan(new String[] { "com.baeldung.persistence.model", "com.baeldung.springpagination.model" });
final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
// vendorAdapter.set

View File

@ -1,9 +1,9 @@
package com.baeldung.modelmapper.controller;
package com.baeldung.springpagination.controller;
import com.baeldung.modelmapper.dto.PostDto;
import com.baeldung.modelmapper.model.Post;
import com.baeldung.modelmapper.service.IPostService;
import com.baeldung.modelmapper.service.IUserService;
import com.baeldung.springpagination.dto.PostDto;
import com.baeldung.springpagination.model.Post;
import com.baeldung.springpagination.service.IPostService;
import com.baeldung.springpagination.service.IUserService;
import org.modelmapper.ModelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;

View File

@ -1,4 +1,4 @@
package com.baeldung.modelmapper.dto;
package com.baeldung.springpagination.dto;
import java.text.ParseException;
import java.text.SimpleDateFormat;

View File

@ -1,4 +1,4 @@
package com.baeldung.modelmapper.dto;
package com.baeldung.springpagination.dto;
public class UserDto {

View File

@ -1,4 +1,4 @@
package com.baeldung.modelmapper.model;
package com.baeldung.springpagination.model;
import java.util.Date;

View File

@ -1,4 +1,4 @@
package com.baeldung.modelmapper.model;
package com.baeldung.springpagination.model;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;

View File

@ -0,0 +1,37 @@
package com.baeldung.springpagination.model;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@Entity
public class Subject {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@Column(nullable = false)
private String name;
public Subject() {
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

View File

@ -1,4 +1,4 @@
package com.baeldung.modelmapper.model;
package com.baeldung.springpagination.model;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;

View File

@ -1,4 +1,4 @@
package com.baeldung.modelmapper.repository;
package com.baeldung.springpagination.repository;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
@ -7,8 +7,8 @@ import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import com.baeldung.modelmapper.model.Post;
import com.baeldung.modelmapper.model.User;
import com.baeldung.springpagination.model.Post;
import com.baeldung.springpagination.model.User;
public interface PostRepository extends JpaRepository<Post, Long>, PagingAndSortingRepository<Post, Long> {

View File

@ -0,0 +1,16 @@
package com.baeldung.springpagination.repository;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.data.rest.core.annotation.RestResource;
import com.baeldung.springpagination.model.Subject;
public interface SubjectRepository extends PagingAndSortingRepository<Subject, Long> {
@RestResource(path = "nameContains")
public Page<Subject> findByNameContaining(@Param("name") String name, Pageable p);
}

View File

@ -1,8 +1,8 @@
package com.baeldung.modelmapper.service;
package com.baeldung.springpagination.service;
import java.util.List;
import com.baeldung.modelmapper.model.Post;
import com.baeldung.springpagination.model.Post;
public interface IPostService {

View File

@ -0,0 +1,9 @@
package com.baeldung.springpagination.service;
import com.baeldung.springpagination.model.User;
public interface IUserService {
User getCurrentUser();
}

View File

@ -1,4 +1,4 @@
package com.baeldung.modelmapper.service;
package com.baeldung.springpagination.service;
import java.util.List;
@ -8,8 +8,8 @@ import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import com.baeldung.modelmapper.model.Post;
import com.baeldung.modelmapper.repository.PostRepository;
import com.baeldung.springpagination.model.Post;
import com.baeldung.springpagination.repository.PostRepository;
@Service
public class PostService implements IPostService {

View File

@ -1,9 +1,9 @@
package com.baeldung.modelmapper.service;
package com.baeldung.springpagination.service;
import org.springframework.stereotype.Service;
import com.baeldung.modelmapper.model.Preference;
import com.baeldung.modelmapper.model.User;
import com.baeldung.springpagination.model.Preference;
import com.baeldung.springpagination.model.User;
@Service
public class UserService implements IUserService {

View File

@ -1,12 +1,12 @@
package com.baeldung.modelmapper;
package com.baeldung.springpagination;
import static org.junit.Assert.assertEquals;
import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
import org.junit.Test;
import org.modelmapper.ModelMapper;
import com.baeldung.modelmapper.dto.PostDto;
import com.baeldung.modelmapper.model.Post;
import com.baeldung.springpagination.dto.PostDto;
import com.baeldung.springpagination.model.Post;
public class PostDtoUnitTest {