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 kucharzyk/dev
version 1.8.0
- Loading branch information
Showing
105 changed files
with
1,533 additions
and
769 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
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
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
19 changes: 19 additions & 0 deletions
19
shardis-api/src/main/java/com/shardis/api/config/JpaConfig.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,19 @@ | ||
package com.shardis.api.config; | ||
|
||
import com.shardis.api.domain.user.User; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.data.domain.AuditorAware; | ||
import org.springframework.data.jpa.repository.config.EnableJpaAuditing; | ||
|
||
/** | ||
* Created by Tomasz Kucharzyk | ||
*/ | ||
@Configuration | ||
@EnableJpaAuditing(auditorAwareRef = "auditorProvider") | ||
public class JpaConfig { | ||
@Bean(name = "auditorProvider" ) | ||
public AuditorAware<User> auditorProvider() { | ||
return () -> null; | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
shardis-api/src/main/java/com/shardis/api/controllers/rest/BlogPostRestController.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,61 @@ | ||
package com.shardis.api.controllers.rest; | ||
|
||
|
||
import com.google.common.collect.Lists; | ||
import com.shardis.api.domain.blog.BlogPost; | ||
import com.shardis.api.domain.blog.BlogPostRepository; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.security.access.prepost.PreAuthorize; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import javax.annotation.PostConstruct; | ||
import java.util.List; | ||
|
||
/** | ||
* Created by Tomasz Kucharzyk | ||
*/ | ||
|
||
@Transactional | ||
@RestController | ||
@RequestMapping("/posts") | ||
@PreAuthorize(value = "hasRole('ROLE_USER')") | ||
@Slf4j | ||
public class BlogPostRestController { | ||
|
||
@Autowired | ||
private BlogPostRepository blogPostRepository; | ||
|
||
@PostConstruct | ||
public void fillData() { | ||
List<BlogPost> posts = this.getPosts(); | ||
if (posts.isEmpty()) { | ||
for (int i = 1; i <= 10; i++) { | ||
BlogPost post = new BlogPost("Sample blog post title #" + i, "Sample blog post content #" + i); | ||
blogPostRepository.save(post); | ||
log.warn(post.toString()); | ||
} | ||
} | ||
} | ||
|
||
@RequestMapping(value = "/", method = RequestMethod.GET) | ||
public List<BlogPost> getPosts() { | ||
return Lists.newArrayList(blogPostRepository.findAll()); | ||
} | ||
|
||
@RequestMapping(value = "/", method = RequestMethod.POST) | ||
public BlogPost savePost(@RequestBody BlogPost blogPost) { | ||
return blogPostRepository.save(blogPost); | ||
} | ||
|
||
@RequestMapping(value = "/{postId}", method = RequestMethod.DELETE) | ||
public BlogPost deletePost(@PathVariable("postId") Long postId) { | ||
BlogPost blogPost = blogPostRepository.findOne(postId); | ||
if (blogPost != null) { | ||
blogPostRepository.delete(blogPost); | ||
} | ||
return blogPost; | ||
} | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
shardis-api/src/main/java/com/shardis/api/domain/base/AuditedEntity.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,46 @@ | ||
package com.shardis.api.domain.base; | ||
|
||
import com.shardis.api.domain.user.User; | ||
import lombok.Data; | ||
import lombok.EqualsAndHashCode; | ||
import org.hibernate.envers.Audited; | ||
import org.springframework.data.annotation.CreatedBy; | ||
import org.springframework.data.annotation.CreatedDate; | ||
import org.springframework.data.annotation.LastModifiedBy; | ||
import org.springframework.data.annotation.LastModifiedDate; | ||
import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
|
||
import javax.persistence.EntityListeners; | ||
import javax.persistence.ManyToOne; | ||
import javax.persistence.MappedSuperclass; | ||
import javax.persistence.Version; | ||
import java.time.LocalDateTime; | ||
|
||
/** | ||
* Created by Tomasz Kucharzyk | ||
*/ | ||
@Audited | ||
@Data | ||
@EqualsAndHashCode(callSuper = true) | ||
@EntityListeners(AuditingEntityListener.class) | ||
@MappedSuperclass | ||
public class AuditedEntity extends BaseEntity { | ||
|
||
@CreatedDate | ||
protected LocalDateTime createdDate; | ||
|
||
@CreatedBy | ||
@ManyToOne | ||
protected User createdBy; | ||
|
||
@LastModifiedDate | ||
protected LocalDateTime updatedDate; | ||
|
||
@LastModifiedBy | ||
@ManyToOne | ||
protected User updatedBy; | ||
|
||
@Version | ||
protected Long version; | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
shardis-api/src/main/java/com/shardis/api/domain/base/BaseEntity.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,21 @@ | ||
package com.shardis.api.domain.base; | ||
|
||
import lombok.Data; | ||
|
||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
import javax.persistence.MappedSuperclass; | ||
|
||
/** | ||
* Created by Tomasz Kucharzyk | ||
*/ | ||
@Data | ||
@MappedSuperclass | ||
public class BaseEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.AUTO) | ||
protected Long id; | ||
|
||
} |
44 changes: 44 additions & 0 deletions
44
shardis-api/src/main/java/com/shardis/api/domain/blog/BlogPost.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,44 @@ | ||
package com.shardis.api.domain.blog; | ||
|
||
import com.shardis.api.domain.base.AuditedEntity; | ||
import lombok.Data; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.NoArgsConstructor; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.Table; | ||
|
||
/** | ||
* Created by Tomasz Kucharzyk | ||
*/ | ||
|
||
@Entity | ||
@Table(name = "BLOG_POST") | ||
@Data | ||
@EqualsAndHashCode(callSuper = true) | ||
@NoArgsConstructor | ||
public class BlogPost extends AuditedEntity { | ||
|
||
|
||
private String title; | ||
private String content; | ||
|
||
public BlogPost(String title, String content) { | ||
this.title = title; | ||
this.content = content; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "BlogPost{" + | ||
"id=" + id + | ||
", createdDate=" + createdDate + | ||
", createdBy=" + createdBy + | ||
", updatedDate=" + updatedDate + | ||
", updatedBy=" + updatedBy + | ||
", version=" + version + | ||
", title='" + title + '\'' + | ||
", content='" + content + '\'' + | ||
'}'; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
shardis-api/src/main/java/com/shardis/api/domain/blog/BlogPostRepository.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,11 @@ | ||
package com.shardis.api.domain.blog; | ||
|
||
import org.springframework.data.repository.CrudRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
/** | ||
* Created by Tomasz Kucharzyk | ||
*/ | ||
@Repository | ||
public interface BlogPostRepository extends CrudRepository<BlogPost, Long> { | ||
} |
Oops, something went wrong.