- Notifications
You must be signed in to change notification settings - Fork439
# Changed the server-port config#6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Open
ChillSpike-zz wants to merge1 commit intocallicoder:masterChoose a base branch fromChillSpike-zz:master
base:master
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
Uh oh!
There was an error while loading.Please reload this page.
Open
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
34 changes: 18 additions & 16 deletionssrc/main/java/com/example/easynotes/controller/IndexController.java
This file contains hidden or 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 |
---|---|---|
@@ -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 "<h4>Hello Everyone, Good Morning ...!!</h4>" | ||
+ "<h3>Welcome to Infusing Security tools within Software Development.</h3><br/>" | ||
+ "<li>You could create a new Note by making a POST request to /api/notes endpoint using <a href='https://www.getpostman.com/apps' target='_blank'>POSTMAN</a>.</li>"; | ||
} | ||
} |
121 changes: 59 additions & 62 deletionssrc/main/java/com/example/easynotes/controller/NoteController.java
This file contains hidden or 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 |
---|---|---|
@@ -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; | ||
@RestController | ||
@RequestMapping("/api") | ||
public class NoteController { | ||
@Autowired | ||
NoteRepository noteRepository; | ||
@GetMapping("/notes") | ||
public List<Note> 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(); | ||
} | ||
} |
160 changes: 79 additions & 81 deletionssrc/main/java/com/example/easynotes/model/Note.java
This file contains hidden or 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 |
---|---|---|
@@ -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; | ||
@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; | ||
} | ||
} |
25 changes: 11 additions & 14 deletionssrc/main/java/com/example/easynotes/repository/NoteRepository.java
This file contains hidden or 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 |
---|---|---|
@@ -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; | ||
@Repository | ||
public interface NoteRepository extends JpaRepository<Note, Long> { | ||
} |
26 changes: 14 additions & 12 deletionssrc/main/resources/application.properties
This file contains hidden or 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 |
---|---|---|
@@ -1,13 +1,15 @@ | ||
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 |
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.