Skip to content

Instantly share code, notes, and snippets.

View mesmacosta's full-sized avatar
🏠
Working from home

Marcelo Costa mesmacosta

🏠
Working from home
View GitHub Profile
{
"id": "17cdd3c6-8c8e-4d96-921f-674bbc098bb3",
"nome": "Welcome To The Jungle",
"artistaId": "8061e332-c443-4d0f-9ee1-1306030feb1f",
"artista": {
"id": "8061e332-c443-4d0f-9ee1-1306030feb1f",
"nome": "Guns 'n' Roses"
}
}
@mesmacosta
mesmacosta / repositório músicas
Created August 8, 2018 18:01
repositório músicas
package com.dojo.musicas.dao;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import com.dojo.musicas.entity.Musica;
public interface MusicaDao extends JpaRepository<Musica, String> {
@mesmacosta
mesmacosta / MusicaServiceImpl
Created August 8, 2018 18:32
Classes Services
package com.dojo.musicas.service.impl;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.dojo.musicas.dao.MusicaDao;
import com.dojo.musicas.entity.Musica;
import com.dojo.musicas.service.CacheService;
package com.dojo.springboot.rest.template.controllers;
import java.util.Arrays;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
package com.dojo.musicas.dao;
import org.springframework.data.jpa.repository.JpaRepository;
import com.dojo.musicas.entity.Playlist;
public interface PlaylistDao extends JpaRepository<Playlist, String> {
Playlist findPlaylistByUsuarioNome(String nome);
}
Method in controller:
@RequestMapping("/hi")
public String sayHi(@Size(max = 10, message = "name should at most 10 characters long") @RequestParam("name") String name) {
return "Hi " + name;
Controller Advice:
@ExceptionHandler(value = {ConstraintViolationException.class})
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
public String handleValidationFailure(ConstraintViolationException ex) {
@mesmacosta
mesmacosta / encoder
Last active September 8, 2018 23:25
Loggings springboot
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include
resource="org/springframework/boot/logging/logback/base.xml" />
<include
resource="org/springframework/boot/logging/logback/defaults.xml" />
<springProperty scope="context" name="springAppName"
source="spring.application.name" />
@mesmacosta
mesmacosta / SplunkJavaLoggingExamples.java
Created September 12, 2018 16:42
Simple examples to demonstrate using the SplunkJavaLogging framework
package com.splunk.dev.logging.examples;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.dtdsoftware.splunk.logging.SplunkLogEvent;
import com.dtdsoftware.splunk.logging.SplunkLogEventFactory;
/**
* Simple examples to demonstrate using the SplunkJavaLogging framework
@constructorproperties
@mesmacosta
mesmacosta / create_instance_function.js
Last active July 30, 2020 07:55
Example showing how to create a Compute Engine instance using Cloud Functions
const Buffer = require('safe-buffer').Buffer;
const Compute = require('@google-cloud/compute');
const compute = new Compute();
const zone = 'us-central1-a';
// We are going to add our vm configuration in the next step
// const vmConfig = ...
exports.createInstance = (event, context) => {