🔄Update: 实现观影记录的增加
This commit is contained in:
@@ -7,4 +7,6 @@ import java.util.List;
|
||||
public interface MovieClient {
|
||||
|
||||
List<MovieDTO> listMovies();
|
||||
|
||||
void addMovie(MovieDTO movieDTO);
|
||||
}
|
||||
|
||||
@@ -15,4 +15,9 @@ public class MovieClientImpl implements MovieClient {
|
||||
String ans = HttpUtil.get("http://localhost:8081/movie");
|
||||
return JSONUtil.parseArray(ans).toList(MovieDTO.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addMovie(MovieDTO movieDTO) {
|
||||
HttpUtil.post("http://localhost:8081/movie", JSONUtil.toJsonStr(movieDTO));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,12 +67,13 @@ public class EventListener {
|
||||
String input = event.getEvent().getAction().getFormValue().get("movie_name").toString();
|
||||
System.out.println(input);
|
||||
|
||||
// TODO: 添加用户输入的电影
|
||||
MovieService movieService = BeanUtil.getBean(MovieService.class);
|
||||
movieService.addMovie(input);
|
||||
|
||||
P2CardActionTriggerResponse response = new P2CardActionTriggerResponse();
|
||||
CallBackToast toast = new CallBackToast();
|
||||
toast.setType("success");
|
||||
toast.setContent("Operation success!!!");
|
||||
toast.setContent("Successful Operation!!!");
|
||||
response.setToast(toast);
|
||||
return response;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@@ -27,4 +28,12 @@ public class MovieService {
|
||||
}
|
||||
return movieVOS;
|
||||
}
|
||||
|
||||
public void addMovie(String movie_name) {
|
||||
MovieDTO movieDTO = new MovieDTO();
|
||||
movieDTO.setName(movie_name);
|
||||
movieDTO.setDay(new Date());
|
||||
System.out.println("movieDTO: " + movieDTO);
|
||||
movieClient.addMovie(movieDTO);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,11 +2,10 @@ package cn.hezhaohui.movie.controller;
|
||||
|
||||
import cn.hezhaohui.movie.entity.Movie;
|
||||
import cn.hezhaohui.movie.service.MovieService;
|
||||
import cn.hezhaohui.pojo.dto.MovieDTO;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -22,4 +21,12 @@ public class MovieController {
|
||||
return movieService.list(new QueryWrapper<Movie>().orderByDesc("id"));
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public void addMovie(@RequestBody MovieDTO movieDTO){
|
||||
Movie movie = new Movie();
|
||||
movie.setName(movieDTO.getName());
|
||||
movie.setDay(movieDTO.getDay());
|
||||
movieService.save(movie);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user