Commit 592a9cde authored by phùng văn dung's avatar phùng văn dung

update 15/06/2019

parent b805cf98
package com.itsol.quantrivanphong.manager.project.project.repository;
import com.itsol.quantrivanphong.model.Project;
import org.springframework.data.jpa.repository.JpaRepository;
public interface ProjectRepository extends JpaRepository<Project,Integer> {
Project findProjectById(Integer id);
Project findProjectByName(String nameProject);
Project findByName(String nameProject);
}
......@@ -22,7 +22,7 @@ public class IssuesComment {
private String contentIssuse;
@Column(name = "usercreate")
private int userCreate;
private String userCreate;
@Column(name = "createdate")
private Timestamp createDate;
......
package com.itsol.quantrivanphong.report.issuescomment.bussiness;
import com.itsol.quantrivanphong.report.issue.common.WrapperResult;
import com.itsol.quantrivanphong.report.issuescomment.dto.IssuesCommentDTO;
import java.util.List;
public interface IssuesCommentBussiness {
// danh sách comment của issues
List<IssuesCommentDTO> getListComment(Integer issuesId);
WrapperResult createComment(IssuesCommentDTO dto);
WrapperResult updateComment(IssuesCommentDTO dto);
WrapperResult deleteComment(IssuesCommentDTO dto);
IssuesCommentDTO findIssuesCommentById(Integer id);
}
package com.itsol.quantrivanphong.report.issuescomment.bussiness;
import com.itsol.quantrivanphong.model.IssuesComment;
import com.itsol.quantrivanphong.report.issue.common.WrapperResult;
import com.itsol.quantrivanphong.report.issue.repository.IssueRepository;
import com.itsol.quantrivanphong.report.issuescomment.dto.IssuesCommentDTO;
import com.itsol.quantrivanphong.report.issuescomment.repository.IssuesCommentRepository;
import org.apache.log4j.Logger;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
@Service
public class IssuesCommentBussinessImpl implements IssuesCommentBussiness{
Logger logger = Logger.getLogger(IssuesCommentBussinessImpl.class);
@Autowired
private IssueRepository issueRepository;
@Autowired
private IssuesCommentRepository issuesCommentRepository;
@Override
public List<IssuesCommentDTO> getListComment(Integer issuesId) {
return lstDTO(issuesCommentRepository.findIssuesCommentByIssuesId(issuesId));
}
@Override
public WrapperResult createComment(IssuesCommentDTO dto) {
String views ="";
int status = 113;
dto.setUserCreate("phungdung");
if(dto.getUserCreate()!=null){
try{
dto.setCreateDate(new Timestamp(System.currentTimeMillis()));
IssuesComment issuesComment = issuesCommentRepository.save(Models(dto));
views="tạo comment thành công!";
status = 200;
}catch (Exception e){
logger.info(" Lỗi Insert Comment "+e.getMessage());
views="Lỗi Tạo Comment";
}
}else{
views="Vui lòng đăng nhập để thực hiện chức năng này";
}
return new WrapperResult(status,views);
}
@Override
public WrapperResult updateComment(IssuesCommentDTO dto) {
return null;
}
@Override
public WrapperResult deleteComment(IssuesCommentDTO dto) {
return null;
}
@Override
public IssuesCommentDTO findIssuesCommentById(Integer id) {
return DTO(issuesCommentRepository.findIssuesCommentById(id));
}
public IssuesComment Models(IssuesCommentDTO dto){
IssuesComment issuesComment = new IssuesComment();
BeanUtils.copyProperties(dto,issuesComment);
if(dto.getIssueId()!=null){
issuesComment.setIssues(issueRepository.findIssuesById(dto.getIssueId()));
}
return issuesComment;
}
public IssuesCommentDTO DTO(IssuesComment issuesComment){
IssuesCommentDTO dto = new IssuesCommentDTO();
BeanUtils.copyProperties(issuesComment,dto);
return dto;
}
public List<IssuesCommentDTO> lstDTO(List<IssuesComment> lst){
List<IssuesCommentDTO> lstDTO = new ArrayList<IssuesCommentDTO>();
for (IssuesComment issuesComment:lst) {
lstDTO.add(DTO(issuesComment));
}
return lstDTO;
}
}
package com.itsol.quantrivanphong.report.issuescomment.controller;
import com.itsol.quantrivanphong.report.issue.common.WrapperResult;
import com.itsol.quantrivanphong.report.issuescomment.bussiness.IssuesCommentBussiness;
import com.itsol.quantrivanphong.report.issuescomment.dto.IssuesCommentDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
public class IssuesControllers {
@Autowired
private IssuesCommentBussiness issuesCommentBussiness;
@GetMapping(value = "/Comment/{IssuesId}")
public ResponseEntity getComment(@PathVariable("IssuesId") Integer issuesId){
List<IssuesCommentDTO> listComment = issuesCommentBussiness.getListComment(issuesId);
return ResponseEntity.ok(listComment);
}
@PostMapping(value = "/tao-comment")
public ResponseEntity saveComment(@RequestBody IssuesCommentDTO issuesCommentDTO){
WrapperResult wrapperResult = issuesCommentBussiness.createComment(issuesCommentDTO);
return ResponseEntity.ok(wrapperResult);
}
}
package com.itsol.quantrivanphong.report.issuescomment.dto;
import com.itsol.quantrivanphong.report.issue.dto.IssueDTO;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.sql.Timestamp;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class IssuesCommentDTO {
private Integer id;
private String contentIssuse;
private String userCreate;
private Timestamp createDate;
private Integer issueId;
private IssueDTO issue;
}
package com.itsol.quantrivanphong.report.issuescomment.repository;
import com.itsol.quantrivanphong.model.IssuesComment;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List;
public interface IssuesCommentRepository extends JpaRepository<IssuesComment,Integer> {
List<IssuesComment> findIssuesCommentByIssuesId(Integer issuesId);
IssuesComment findIssuesCommentById(Integer id);
}
......@@ -14,9 +14,9 @@
<div class="card my-4">
<h5 class="card-header">Comment:</h5>
<div class="card-body">
<form ng-submit="">
<form ng-submit="saveComment(IssuesComment)">
<div class="form-group">
<textarea ng-model="IssuesComment.content" class="form-control" rows="3"></textarea>
<textarea ng-model="IssuesComment.contentIssuse" class="form-control" rows="3"></textarea>
</div>
<button type="submit" class="btn btn-primary">Đăng Comments</button>
<input class="btn btn-primary" type="reset" value="Reset">
......@@ -26,7 +26,6 @@
<!-- Single Comment -->
<div class="media mb-4">
<img class="d-flex mr-3 rounded-circle" src="http://placehold.it/50x50" alt="">
<div class="media-body">
<h5 class="mt-0">UserName</h5><p>Thời gian đăng</p>
-<p>Nội dung comment</p>-
......
angular.module("myApp").controller('loadIssuesDetail', function ($scope,$stateParams,$http,$state) {
var app = angular.module("myApp").controller('loadIssuesDetail', function ($scope, $stateParams, $http, $state) {
$http.get('http://localhost:8081/chi-tiet-issues/' + $stateParams.IssuesId).then(successCallback, errorCallback);
function successCallback(response) {
......@@ -11,4 +12,63 @@ angular.module("myApp").controller('loadIssuesDetail', function ($scope,$statePa
function errorCallback(error) {
console.log("can't get data!!");
}
});
\ No newline at end of file
$scope.saveComment = function (IssuesComment) {
IssuesComment.issueId = $scope.loadIssues.id;
$http({
method: 'POST',
url: 'http://localhost:8081/tao-comment',
data: angular.toJson(IssuesComment),
headers: {
'Content-Type': 'application/json'
}
}).then(successCallback, errorCallback);
function successCallback(response) {
$scope.view = response.data;
if ($scope.view.status == 200) {
$state.reload();
}
}
function errorCallback(error) {
//error code
console.log("can't insert data!!");
}
}
//hiện thị danh sách comment
});
app.controller('showComment',showComment)
function showComment($scope, $http) {
//trang đang đứng trên font-end
$scope.currentPage = 1
//số item hiển thị trong 1 page
, $scope.numPerPage = 4
//tổng số page hiển thị trên thanh chọn
, $scope.maxSize = 5;
$http.get('http://localhost:8081/Comment/' + $scope.loadIssues.id).then(successCallback, errorCallback);
function successCallback(response) {
console.log(response.data);
{
$scope.CommentIssues = response.data
$scope.numPages = function () {
return Math.ceil($scope.CommentIssues.length / $scope.numPerPage);
};
$scope.$watch('currentPage + numPerPage', function () {
var begin = (($scope.currentPage - 1) * $scope.numPerPage)
, end = begin + $scope.numPerPage;
$scope.pageListCommentIssues = $scope.CommentIssues.slice(begin, end);
});
}
}
function errorCallback(error) {
console.log("can't get data!!");
}
}
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment