view spring-boot-playground/src/main/java/de/comline/spring/service/MovieService.java @ 6:d57d0c6a841b

Einbau von liquibase zum Erzeugen des Schemas
author Dirk Olmes <dirk.olmes@codedo.de>
date Thu, 13 Aug 2020 16:18:20 +0200
parents 92d52e4ac567
children 4594ff529ab1
line wrap: on
line source

package de.comline.spring.service;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import de.comline.spring.entity.Movie;
import de.comline.spring.repository.MovieRepository;

@Service
public class MovieService {
	@Autowired
	private MovieRepository repository;
	
	@Transactional
	public Movie createMovie(String title) {
		Movie movie = new Movie(title);
		movie = repository.save(movie);
		return movie;
	}
	
	@Transactional
	public String listAllMovies() {
		StringBuilder buf = new StringBuilder(128);
		repository.findAll().forEach(movie -> buf.append(movie.getTitle()).append(","));
		return buf.toString();
	}
}