Skip to content

Commit

Permalink
- update on author creation
Browse files Browse the repository at this point in the history
- deployable war build with servlet initializer
- datetime field in news creation form
  • Loading branch information
shg-dsi committed Oct 13, 2017
1 parent 10cb8f2 commit d129868
Show file tree
Hide file tree
Showing 14 changed files with 56 additions and 16 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
#News Story

###Requirements
- Java 8
- Gradle 4+
- Java 8.x
- Gradle 4.x
- Tomcat 8.x

###Get Started
- Run gradle task `./gradlew bootRun` in Linux or `.\gradlew.bat bootRun` in Windows
- Browse `http://localhost:8080`

###To Make it Deployable
- Run `./gradlew build`
- Deploy `build/libs/news-story-1.0.0.war` as root webapp (`ROOT.war`)
- Start tomcat

###To Change UI
- Install nodejs 8+
- Install quasar-cli `npm install -g quasar-cli`
Expand Down
6 changes: 4 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group = 'news-story'
version = '0.0.1-SNAPSHOT'
version = '1.0.0'

buildscript {
repositories {
Expand All @@ -13,6 +13,7 @@ buildscript {
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'war'

repositories {
mavenCentral()
Expand All @@ -24,8 +25,9 @@ targetCompatibility = 1.8
dependencies {
compile "org.springframework.boot:spring-boot-starter-web"
compile "org.springframework.boot:spring-boot-starter-data-jpa"
compile "org.springframework.boot:spring-boot-devtools"
compile "com.h2database:h2"

providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'

testCompile 'org.springframework.boot:spring-boot-starter-test'
}
12 changes: 12 additions & 0 deletions src/main/java/com/newsstories/ServletInitializer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.newsstories;

import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;

public class ServletInitializer extends SpringBootServletInitializer {

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(Application.class);
}
}
4 changes: 3 additions & 1 deletion src/main/java/com/newsstories/author/Author.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import com.newsstories.story.Story;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
Expand All @@ -16,6 +16,8 @@ public class Author {
@Id
@GeneratedValue
private Long id;

@Column(unique = true)
private String fullName;

@OneToMany(mappedBy = "author")
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/newsstories/author/AuthorRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@

@Repository
public interface AuthorRepository extends CrudRepository<Author, Long> {

Author findByFullName(String fullName);

}
10 changes: 9 additions & 1 deletion src/main/java/com/newsstories/story/StoryService.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.newsstories.story;

import com.newsstories.author.Author;
import com.newsstories.author.AuthorRepository;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
Expand All @@ -10,16 +12,22 @@
public class StoryService {

private StoryRepository storyRepository;
private AuthorRepository authorRepository;

public StoryService(StoryRepository storyRepository) {
public StoryService(StoryRepository storyRepository, AuthorRepository authorRepository) {
this.storyRepository = storyRepository;
this.authorRepository = authorRepository;
}

@Transactional
public Story save(Story story) {
if (story.getPublishedDate() == null) {
story.setPublishedDate(Date.from(Instant.now()));
}
Author author = authorRepository.findByFullName(story.getAuthor().getFullName());
if (author != null) {
story.setAuthor(author);
}
return storyRepository.save(story);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/static/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!DOCTYPE html><html lang=en><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge"><meta name=format-detection content="telephone=no"><meta name=msapplication-tap-highlight content=no><meta name=viewport content="width=device-width,initial-scale=1"><title>Quasar PWA App</title><link rel=icon type=image/png sizes=32x32 href=statics/icons/favicon-32x32.png><link rel=icon type=image/png sizes=16x16 href=statics/icons/favicon-16x16.png><link rel=manifest href=statics/manifest.json><meta name=apple-mobile-web-app-capable content=yes><meta name=apple-mobile-web-app-status-bar-style content=white><meta name=apple-mobile-web-app-title content="Quasar App"><link rel=apple-touch-icon href=statics/icons/apple-icon-152x152.png><meta name=msapplication-TileImage content=statics/icons/ms-icon-144x144.png><meta name=msapplication-TileColor content=#ffffff><meta name=theme-color content=#027be3><link rel=preload href=js/vendor.js as=script><link rel=preload href=js/app.js as=script><link rel=preload href=app.de52267cfe15ae8a60bdeb99cf122365.css as=style><link rel=preload href=js/manifest.js as=script><link href=app.de52267cfe15ae8a60bdeb99cf122365.css rel=stylesheet></head><body><noscript>This is your fallback content in case JavaScript fails to load.</noscript><div id=q-app></div><script>!function(){"use strict";const o=Boolean("localhost"===window.location.hostname||"[::1]"===window.location.hostname||window.location.hostname.match(/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/));window.addEventListener("load",function(){"serviceWorker"in navigator&&("https:"===window.location.protocol||o)&&navigator.serviceWorker.register("service-worker.js").then(function(o){o.onupdatefound=function(){if(navigator.serviceWorker.controller){const n=o.installing;n.onstatechange=function(){switch(n.state){case"installed":break;case"redundant":throw new Error("The installing service worker became redundant.")}}}}}).catch(function(o){console.error("Error during service worker registration:",o)})})}();</script><script type=text/javascript src=js/manifest.js></script><script type=text/javascript src=js/vendor.js></script><script type=text/javascript src=js/app.js></script></body></html>
<!DOCTYPE html><html lang=en><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge"><meta name=format-detection content="telephone=no"><meta name=msapplication-tap-highlight content=no><meta name=viewport content="width=device-width,initial-scale=1"><title>News Today</title><link rel=icon type=image/png sizes=32x32 href=statics/icons/favicon-32x32.png><link rel=icon type=image/png sizes=16x16 href=statics/icons/favicon-16x16.png><link rel=manifest href=statics/manifest.json><meta name=apple-mobile-web-app-capable content=yes><meta name=apple-mobile-web-app-status-bar-style content=white><meta name=apple-mobile-web-app-title content="Quasar App"><link rel=apple-touch-icon href=statics/icons/apple-icon-152x152.png><meta name=msapplication-TileImage content=statics/icons/ms-icon-144x144.png><meta name=msapplication-TileColor content=#ffffff><meta name=theme-color content=#027be3><link rel=preload href=js/vendor.js as=script><link rel=preload href=js/app.js as=script><link rel=preload href=app.de52267cfe15ae8a60bdeb99cf122365.css as=style><link rel=preload href=js/manifest.js as=script><link href=app.de52267cfe15ae8a60bdeb99cf122365.css rel=stylesheet></head><body><noscript>This is your fallback content in case JavaScript fails to load.</noscript><div id=q-app></div><script>!function(){"use strict";const o=Boolean("localhost"===window.location.hostname||"[::1]"===window.location.hostname||window.location.hostname.match(/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/));window.addEventListener("load",function(){"serviceWorker"in navigator&&("https:"===window.location.protocol||o)&&navigator.serviceWorker.register("service-worker.js").then(function(o){o.onupdatefound=function(){if(navigator.serviceWorker.controller){const n=o.installing;n.onstatechange=function(){switch(n.state){case"installed":break;case"redundant":throw new Error("The installing service worker became redundant.")}}}}}).catch(function(o){console.error("Error during service worker registration:",o)})})}();</script><script type=text/javascript src=js/manifest.js></script><script type=text/javascript src=js/vendor.js></script><script type=text/javascript src=js/app.js></script></body></html>
2 changes: 1 addition & 1 deletion src/main/resources/static/js/app.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/main/resources/static/js/manifest.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/main/resources/static/js/vendor.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion vueapp/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<router-view></router-view>
<q-fixed-position corner="bottom-right" :offset="[560, 16]">
<q-fab
ref="create-story"
ref="createstory"
color="primary"
direction="up"
class="animate-pop"
Expand Down
13 changes: 10 additions & 3 deletions vueapp/src/components/NewsForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@
<q-input v-model="story.title" float-label="Title" :value="story.title" />
</q-field>
<q-field>
<q-input type="textarea" v-model="story.body" float-label="Details" :value="story.body" />
<q-input v-model="story.author.fullName" float-label="Author" :value="story.author.fullName" />
</q-field>
<q-field>
<q-datetime v-model="story.publishedDate" format="ddd, DD-MMM-YYYY hh:mm:ss A" type="datetime" />
</q-field>
<q-field>
<q-input type="text" v-model="story.author.fullName" float-label="Author" :value="story.author.fullName" />
<q-input type="textarea" v-model="story.body" float-label="Details" :value="story.body" />
</q-field>
</q-card-main>
<q-card-separator />
Expand Down Expand Up @@ -41,7 +44,8 @@ import {
QChipsInput,
QRating,
QBtn,
QIcon
QIcon,
date
} from 'quasar'
export default {
Expand All @@ -66,13 +70,16 @@ export default {
data () {
return {
story: {
publishedDate: new Date(),
author: {}
}
}
},
methods: {
submit () {
/* format publishedDate according to API format */
this.story.publishedDate = date.formatDate(this.story.publishedDate, 'DD-MMM-YYYY hh:mm:ss a')
this.$http.post('/stories', this.story)
.then(resp => {
this.$router.push({name: 'feeds'})
Expand Down
2 changes: 1 addition & 1 deletion vueapp/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<meta name="msapplication-tap-highlight" content="no">
<meta name="viewport" content="width=device-width, initial-scale=1">

<title>Quasar PWA App</title>
<title>News Today</title>
<link rel="icon" type="image/png" sizes="32x32" href="<%= htmlWebpackPlugin.files.publicPath %>statics/icons/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="<%= htmlWebpackPlugin.files.publicPath %>statics/icons/favicon-16x16.png">
<link rel="manifest" href="<%= htmlWebpackPlugin.files.publicPath %>statics/manifest.json">
Expand Down
2 changes: 1 addition & 1 deletion vueapp/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Vue.config.productionTip = false
Vue.use(Quasar) // Install Quasar Framework

Vue.prototype.$http = axios.create({
baseURL: 'http://localhost:8080/api/'
baseURL: PROD ? '/api' : 'http://localhost:8080/api'
})

if (__THEME === 'mat') {
Expand Down

0 comments on commit d129868

Please sign in to comment.