🔄Update: 获取数据库中的 Movie
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
package cn.hezhaohui.lark.client;
|
||||
|
||||
import cn.hezhaohui.pojo.dto.MovieDTO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface MovieClient {
|
||||
|
||||
List<MovieDTO> listMovies();
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package cn.hezhaohui.lark.client;
|
||||
|
||||
|
||||
import cn.hezhaohui.entity.Weather;
|
||||
import cn.hezhaohui.pojo.entity.Weather;
|
||||
|
||||
public interface WeatherClient {
|
||||
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package cn.hezhaohui.lark.client.impl;
|
||||
|
||||
import cn.hezhaohui.pojo.dto.MovieDTO;
|
||||
import cn.hezhaohui.lark.client.MovieClient;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class MovieClientImpl implements MovieClient {
|
||||
@Override
|
||||
public List<MovieDTO> listMovies() {
|
||||
String ans = HttpUtil.get("http://localhost:8081/movie");
|
||||
return JSONUtil.parseArray(ans).toList(MovieDTO.class);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package cn.hezhaohui.lark.client.impl;
|
||||
|
||||
|
||||
import cn.hezhaohui.entity.Weather;
|
||||
import cn.hezhaohui.pojo.entity.Weather;
|
||||
import cn.hezhaohui.lark.client.WeatherClient;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
|
||||
@@ -2,7 +2,7 @@ package cn.hezhaohui.lark.handler;
|
||||
|
||||
import cn.hezhaohui.common.AppConstant;
|
||||
import cn.hezhaohui.common.CardEnum;
|
||||
import cn.hezhaohui.entity.Weather;
|
||||
import cn.hezhaohui.pojo.entity.Weather;
|
||||
import cn.hezhaohui.lark.client.WeatherClient;
|
||||
import cn.hezhaohui.lark.util.BeanUtil;
|
||||
import cn.hezhaohui.lark.util.LarkUtil;
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package cn.hezhaohui.lark.service;
|
||||
|
||||
import cn.hezhaohui.lark.client.MovieClient;
|
||||
import cn.hezhaohui.pojo.dto.MovieDTO;
|
||||
import cn.hezhaohui.pojo.vo.MovieVO;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class MovieService {
|
||||
|
||||
@Resource
|
||||
private MovieClient movieClient;
|
||||
|
||||
public List<MovieVO> listMovies() {
|
||||
List<MovieDTO> movieDTOS = movieClient.listMovies();
|
||||
List<MovieVO> movieVOS = new ArrayList<>();
|
||||
for (MovieDTO movieDTO : movieDTOS) {
|
||||
MovieVO movieVO = new MovieVO();
|
||||
movieVO.setName(movieDTO.getName());
|
||||
movieVO.setDate(new SimpleDateFormat("yyyy-MM-dd").format(movieDTO.getDay()));
|
||||
movieVOS.add(movieVO);
|
||||
}
|
||||
return movieVOS;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package cn.hezhaohui.lark.client.impl;
|
||||
|
||||
import cn.hezhaohui.pojo.dto.MovieDTO;
|
||||
import cn.hezhaohui.lark.client.MovieClient;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@SpringBootTest
|
||||
class MovieClientImplTest {
|
||||
|
||||
@Resource
|
||||
private MovieClient movieClient;
|
||||
|
||||
@Test
|
||||
void listMovies() {
|
||||
List<MovieDTO> movieDTOS = movieClient.listMovies();
|
||||
for(MovieDTO movieDTO : movieDTOS) {
|
||||
System.out.println(movieDTO);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package cn.hezhaohui.lark.client.impl;
|
||||
|
||||
import cn.hezhaohui.entity.Weather;
|
||||
import cn.hezhaohui.pojo.entity.Weather;
|
||||
import cn.hezhaohui.lark.client.WeatherClient;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package cn.hezhaohui.lark.service;
|
||||
|
||||
import cn.hezhaohui.pojo.vo.MovieVO;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@SpringBootTest
|
||||
class MovieServiceTest {
|
||||
|
||||
@Resource
|
||||
private MovieService movieService;
|
||||
|
||||
@Test
|
||||
void listMovies() {
|
||||
List<MovieVO> movies = movieService.listMovies();
|
||||
for (MovieVO movie : movies) {
|
||||
System.out.println(movie);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@ package cn.hezhaohui.lark.util;
|
||||
|
||||
import cn.hezhaohui.lark.client.WeatherClient;
|
||||
import cn.hezhaohui.common.CardEnum;
|
||||
import cn.hezhaohui.entity.Weather;
|
||||
import cn.hezhaohui.pojo.entity.Weather;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
Reference in New Issue
Block a user