Skip to content

Instantly share code, notes, and snippets.

package ch.codify.springbootgae.movie;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Optional;
@Service
public class MovieService {
package ch.codify.springbootgae.movie;
import org.springframework.data.repository.CrudRepository;
import java.util.List;
import java.util.Optional;
public interface MovieRepository extends CrudRepository<Movie,Long> {
List<Movie> findAll();
package ch.codify.springbootgae.movie;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.*;
@Data
@AllArgsConstructor
package ch.codify.springbootgae.movie;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Optional;
import { Module } from '@nestjs/common';
import { LightsaberController } from './lightsaber.controller';
import { LightsaberService } from './lightsaber.service';
import { Lightsaber } from './lightsaber.entity';
import { TypeOrmModule } from '@nestjs/typeorm';
@Module({
controllers: [LightsaberController],
providers: [LightsaberService],
imports: [
import { Entity, PrimaryGeneratedColumn, Column } from 'typeorm';
@Entity()
export class Lightsaber {
@PrimaryGeneratedColumn()
id: number;
@Column()
name: string;
@Column()
color: string;
import { Controller, Get, Post, Body, Param, Put, Delete } from '@nestjs/common';
import { LightsaberService } from './lightsaber.service';
import { Lightsaber } from './lightsaber.entity';
@Controller('light-saber')
export class LightsaberController {
constructor(private lightsaberService: LightsaberService) { }
@Get()
getAll() {
return this.lightsaberService.getAll();
import { Injectable } from '@nestjs/common';
import { Lightsaber } from './lightsaber.entity';
import { Repository, DeleteResult } from 'typeorm';
import { InjectRepository } from '@nestjs/typeorm';
@Injectable()
export class LightsaberService {
constructor(
@InjectRepository(Lightsaber)
private lightsaberRepository: Repository<Lightsaber>,
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
const HOST = '0.0.0.0';
const PORT = Number(process.env.PORT) || 8080;
async function bootstrap() {
const app = await NestFactory.create(AppModule);
// app.enableCors();
await app.listen(PORT, HOST).then(() => {
// tslint:disable-next-line:no-console
{
"name": "star-wars-backend",
"version": "0.0.1",
"description": "",
"author": "Nils Weiser",
"license": "MIT",
"main": "dist/main.js",
"scripts": {
"prepare": "npm run build",
"pretest": "npm run build",