diff --git a/src/main/java/com/example/easynotes/controller/IndexController.java b/src/main/java/com/example/easynotes/controller/IndexController.java index f9c5ea4..9895b43 100644 --- a/src/main/java/com/example/easynotes/controller/IndexController.java +++ b/src/main/java/com/example/easynotes/controller/IndexController.java @@ -1,16 +1,18 @@ -package com.example.easynotes.controller; - - -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -@RestController -@RequestMapping("/") -public class IndexController { - - @GetMapping - public String sayHello() { - return "Hello and Welcome to the EasyNotes application. You can create a new Note by making a POST request to /api/notes endpoint."; - } -} +package com.example.easynotes.controller; + + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/") +public class IndexController { + + @GetMapping + public String sayHello() { + return "

Hello Everyone, Good Morning ...!!

" + + "

Welcome to Infusing Security tools within Software Development.


" + + "
  • You could create a new Note by making a POST request to /api/notes endpoint using POSTMAN.
  • "; + } +} diff --git a/src/main/java/com/example/easynotes/controller/NoteController.java b/src/main/java/com/example/easynotes/controller/NoteController.java index 52f2ef0..cb1be07 100644 --- a/src/main/java/com/example/easynotes/controller/NoteController.java +++ b/src/main/java/com/example/easynotes/controller/NoteController.java @@ -1,62 +1,59 @@ -package com.example.easynotes.controller; - -import com.example.easynotes.exception.ResourceNotFoundException; -import com.example.easynotes.model.Note; -import com.example.easynotes.repository.NoteRepository; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; - -import javax.validation.Valid; -import java.util.List; - -/** - * Created by rajeevkumarsingh on 27/06/17. - */ -@RestController -@RequestMapping("/api") -public class NoteController { - - @Autowired - NoteRepository noteRepository; - - @GetMapping("/notes") - public List getAllNotes() { - return noteRepository.findAll(); - } - - @PostMapping("/notes") - public Note createNote(@Valid @RequestBody Note note) { - return noteRepository.save(note); - } - - @GetMapping("/notes/{id}") - public Note getNoteById(@PathVariable(value = "id") Long noteId) { - return noteRepository.findById(noteId) - .orElseThrow(() -> new ResourceNotFoundException("Note", "id", noteId)); - } - - @PutMapping("/notes/{id}") - public Note updateNote(@PathVariable(value = "id") Long noteId, - @Valid @RequestBody Note noteDetails) { - - Note note = noteRepository.findById(noteId) - .orElseThrow(() -> new ResourceNotFoundException("Note", "id", noteId)); - - note.setTitle(noteDetails.getTitle()); - note.setContent(noteDetails.getContent()); - - Note updatedNote = noteRepository.save(note); - return updatedNote; - } - - @DeleteMapping("/notes/{id}") - public ResponseEntity deleteNote(@PathVariable(value = "id") Long noteId) { - Note note = noteRepository.findById(noteId) - .orElseThrow(() -> new ResourceNotFoundException("Note", "id", noteId)); - - noteRepository.delete(note); - - return ResponseEntity.ok().build(); - } -} +package com.example.easynotes.controller; + +import com.example.easynotes.exception.ResourceNotFoundException; +import com.example.easynotes.model.Note; +import com.example.easynotes.repository.NoteRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import javax.validation.Valid; +import java.util.List; + +@RestController +@RequestMapping("/api") +public class NoteController { + + @Autowired + NoteRepository noteRepository; + + @GetMapping("/notes") + public List getAllNotes() { + return noteRepository.findAll(); + } + + @PostMapping("/notes") + public Note createNote(@Valid @RequestBody Note note) { + return noteRepository.save(note); + } + + @GetMapping("/notes/{id}") + public Note getNoteById(@PathVariable(value = "id") Long noteId) { + return noteRepository.findById(noteId) + .orElseThrow(() -> new ResourceNotFoundException("Note", "id", noteId)); + } + + @PutMapping("/notes/{id}") + public Note updateNote(@PathVariable(value = "id") Long noteId, + @Valid @RequestBody Note noteDetails) { + + Note note = noteRepository.findById(noteId) + .orElseThrow(() -> new ResourceNotFoundException("Note", "id", noteId)); + + note.setTitle(noteDetails.getTitle()); + note.setContent(noteDetails.getContent()); + + Note updatedNote = noteRepository.save(note); + return updatedNote; + } + + @DeleteMapping("/notes/{id}") + public ResponseEntity deleteNote(@PathVariable(value = "id") Long noteId) { + Note note = noteRepository.findById(noteId) + .orElseThrow(() -> new ResourceNotFoundException("Note", "id", noteId)); + + noteRepository.delete(note); + + return ResponseEntity.ok().build(); + } +} diff --git a/src/main/java/com/example/easynotes/model/Note.java b/src/main/java/com/example/easynotes/model/Note.java index 4f8b6b1..9d9c657 100644 --- a/src/main/java/com/example/easynotes/model/Note.java +++ b/src/main/java/com/example/easynotes/model/Note.java @@ -1,81 +1,79 @@ -package com.example.easynotes.model; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import org.springframework.data.annotation.CreatedDate; -import org.springframework.data.annotation.LastModifiedDate; -import org.springframework.data.jpa.domain.support.AuditingEntityListener; - -import javax.persistence.*; -import javax.validation.constraints.NotBlank; -import java.util.Date; - -/** - * Created by rajeevkumarsingh on 27/06/17. - */ -@Entity -@Table(name = "notes") -@EntityListeners(AuditingEntityListener.class) -@JsonIgnoreProperties(value = {"createdAt", "updatedAt"}, - allowGetters = true) -public class Note { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - - @NotBlank - private String title; - - @NotBlank - private String content; - - @Column(nullable = false, updatable = false) - @Temporal(TemporalType.TIMESTAMP) - @CreatedDate - private Date createdAt; - - @Column(nullable = false) - @Temporal(TemporalType.TIMESTAMP) - @LastModifiedDate - private Date updatedAt; - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getContent() { - return content; - } - - public void setContent(String content) { - this.content = content; - } - - public Date getCreatedAt() { - return createdAt; - } - - public void setCreatedAt(Date createdAt) { - this.createdAt = createdAt; - } - - public Date getUpdatedAt() { - return updatedAt; - } - - public void setUpdatedAt(Date updatedAt) { - this.updatedAt = updatedAt; - } - -} +package com.example.easynotes.model; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.annotation.LastModifiedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +import javax.persistence.*; +import javax.validation.constraints.NotBlank; +import java.util.Date; + + +@Entity +@Table(name = "notes") +@EntityListeners(AuditingEntityListener.class) +@JsonIgnoreProperties(value = {"createdAt", "updatedAt"}, + allowGetters = true) +public class Note { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @NotBlank + private String title; + + @NotBlank + private String content; + + @Column(nullable = false, updatable = false) + @Temporal(TemporalType.TIMESTAMP) + @CreatedDate + private Date createdAt; + + @Column(nullable = false) + @Temporal(TemporalType.TIMESTAMP) + @LastModifiedDate + private Date updatedAt; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + + public Date getCreatedAt() { + return createdAt; + } + + public void setCreatedAt(Date createdAt) { + this.createdAt = createdAt; + } + + public Date getUpdatedAt() { + return updatedAt; + } + + public void setUpdatedAt(Date updatedAt) { + this.updatedAt = updatedAt; + } + +} diff --git a/src/main/java/com/example/easynotes/repository/NoteRepository.java b/src/main/java/com/example/easynotes/repository/NoteRepository.java index 4b7b8b3..190e4dc 100644 --- a/src/main/java/com/example/easynotes/repository/NoteRepository.java +++ b/src/main/java/com/example/easynotes/repository/NoteRepository.java @@ -1,14 +1,11 @@ -package com.example.easynotes.repository; - -import com.example.easynotes.model.Note; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; - -/** - * Created by rajeevkumarsingh on 27/06/17. - */ - -@Repository -public interface NoteRepository extends JpaRepository { - -} +package com.example.easynotes.repository; + +import com.example.easynotes.model.Note; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + + +@Repository +public interface NoteRepository extends JpaRepository { + +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index b0f06a8..24fdd1a 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,13 +1,15 @@ -## Spring DATASOURCE (DataSourceAutoConfiguration & DataSourceProperties) -spring.datasource.url = jdbc:mysql://localhost:3306/notes_app?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&useSSL=false -spring.datasource.username = root -spring.datasource.password = callicoder - - -## Hibernate Properties - -# The SQL dialect makes Hibernate generate better SQL for the chosen database -spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect - -# Hibernate ddl auto (create, create-drop, validate, update) +server.port=8084 + +## Spring DATASOURCE (DataSourceAutoConfiguration & DataSourceProperties) +spring.datasource.url = jdbc:mysql://localhost:3306/world?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&useSSL=false +spring.datasource.username = root +spring.datasource.password = + + +## Hibernate Properties + +# The SQL dialect makes Hibernate generate better SQL for the chosen database +spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect + +# Hibernate ddl auto (create, create-drop, validate, update) spring.jpa.hibernate.ddl-auto = update \ No newline at end of file