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
public boolean deleteNote(String userId, int noteId) { | |
NoteUser dbUser = this.noteRepository.findById(userId).orElse(null); | |
Note dbNote = null; | |
if(dbUser != null) { | |
dbNote = this.findNote(noteId, dbUser.getNotes()); | |
if(dbNote != null) { | |
dbUser.getNotes().remove(dbNote); | |
dbUser = this.noteRepository.save(dbUser); | |
} |
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
import io.jsonwebtoken.Claims; | |
import io.jsonwebtoken.Jwts; | |
final HttpServletRequest req = (HttpServletRequest) request; | |
final String authHeader = req.getHeader("authorization"); | |
if (authHeader == null || !authHeader.startsWith("Bearer ")) { | |
throw new ServletException("Missing or invalid Authorization header"); | |
} |
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
import io.jsonwebtoken.Jwts; | |
import io.jsonwebtoken.SignatureAlgorithm; | |
@RestController | |
public class AuthenticationController { ... | |
@ApiOperation(value = "Validate the user login") | |
@PostMapping("/api/authentication/login") | |
public ResponseEntity<?> userLogin(@RequestBody User user) { | |
String jwtToken = ""; |
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
server.port=8889 | |
hello.greeting= nice to meet you | |
hello.version= 2.0 |
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
package demo; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.web.bind.annotation.RequestMapping; | |
import org.springframework.web.bind.annotation.RequestParam; | |
import org.springframework.web.bind.annotation.RestController; | |
@RestController | |
public class HelloController { | |
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
--- | |
applications: | |
- name: hello-boot | |
instances: 1 | |
host: hello-boot-${random-word} | |
path: target/hello-boot-1.0.jar |
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
// Sort an array using a simple but inefficient quicksort. | |
public int[] quicksortSimple(int[] data) { | |
if (data.length < 2) { | |
return data; | |
} | |
int pivotIndex = data.length / 2; | |
int pivotValue = data[pivotIndex]; | |
int leftCount = 0; | |
// Count how many are less than the pivot |
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
/* Mentioning all the swagger changes made on top of | |
Spring REST app: https://gist.github.com/codinko/79986dbed38d0f2b2d1b */ | |
--------------------------------------- | |
Modified File: pom.xml | |
--------------------------------------- | |
<properties> | |
<swagger.version>1.0.2</swagger.version> | |
</properties> | |
<dependencies> | |
<dependency> |
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
package com.codinko.springrestapi.vo; | |
import org.joda.time.DateTime; | |
import org.joda.time.DateTimeZone; | |
// Generic class that can have data of generic type. See it's usage when an instance of this class is created | |
public class APIContract<T> { | |
private boolean success; | |
private String message; |
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
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
<modelVersion>4.0.0</modelVersion> | |
<groupId>com.codinko.restapi</groupId> | |
<artifactId>restapi</artifactId> | |
<version>0.0.1-SNAPSHOT</version> | |
<packaging>war</packaging> | |
<build> | |
<sourceDirectory>src</sourceDirectory> | |
<plugins> | |
<plugin> |