Skip to content

Commit

Permalink
feat: Get Howto [#342]
Browse files Browse the repository at this point in the history
  • Loading branch information
lowgiant committed Feb 13, 2022
1 parent fbef500 commit 40132fe
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.bancow.bancowback.domain.sub.howto.Mapper;

import org.springframework.stereotype.Component;

import com.bancow.bancowback.domain.sub.howto.entity.Howto;

@Component
public class HowtoMapper {

public Howto toHowto(Howto howto) {
return Howto.builder()
.id(howto.getId())
.movieName(howto.getMovieName())
.movieUrl("https://kr.object.ncloudstorage.com/bancowback/" + howto.getMovieUrl())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.bancow.bancowback.domain.sub.howto.controller;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.bancow.bancowback.domain.common.dto.Response;
import com.bancow.bancowback.domain.sub.howto.service.HowtoService;

import lombok.RequiredArgsConstructor;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/howto")
public class HowtoController {

private final HowtoService howtoService;

@GetMapping()
public Response<?> getHowto(){
return new Response<>(howtoService.getHowto(), HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.bancow.bancowback.domain.sub.howto.entity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Entity
public class Howto {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(name = "movie_name", nullable = false)
private String movieName;

@Column(name = "movie_url", nullable = false)
private String movieUrl;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.bancow.bancowback.domain.sub.howto.repository;

import org.springframework.data.jpa.repository.JpaRepository;

import com.bancow.bancowback.domain.sub.howto.entity.Howto;

public interface HowtoRepository extends JpaRepository<Howto, Long> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.bancow.bancowback.domain.sub.howto.service;

import java.util.List;
import java.util.stream.Collectors;

import org.springframework.stereotype.Service;

import com.bancow.bancowback.domain.sub.howto.Mapper.HowtoMapper;
import com.bancow.bancowback.domain.sub.howto.entity.Howto;
import com.bancow.bancowback.domain.sub.howto.repository.HowtoRepository;

import lombok.RequiredArgsConstructor;

@Service
@RequiredArgsConstructor
public class HowtoService {

private final HowtoRepository howtoRepository;
private final HowtoMapper howtoMapper;

public List<Howto> getHowto() {

return howtoRepository.findAll().stream()
.map(howto -> howtoMapper.toHowto(howto))
.collect(Collectors.toList());
}
}

0 comments on commit 40132fe

Please sign in to comment.