Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add comments #29

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

137 changes: 120 additions & 17 deletions .idea/workspace.xml

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions code/SoloSavingsApp/init-database.sql
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ FLUSH PRIVILEGES;

-- CREATE TABLES

CREATE TABLE `comments` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`content` varchar(255) DEFAULT NULL,
`user_id` int(11) DEFAULT NULL,
`transaction_id` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=306 DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS users (
user_id INT NOT NULL AUTO_INCREMENT,
username VARCHAR(255) NOT NULL,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package com.soloSavings.controller;

import com.soloSavings.model.Comments;
import com.soloSavings.service.CommentsService;
import com.soloSavings.service.SecurityContext;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("comments")
public class CommentsController {
@Autowired
CommentsService commentsService;
@Autowired
SecurityContext securityContext;

@RequestMapping(value = "/add/{transactionId}", method = RequestMethod.POST)
public ResponseEntity<?> addComments (HttpServletRequest request, @RequestBody Comments comments,
@PathVariable("transactionId") Integer transactionId){
securityContext.setContext(SecurityContextHolder.getContext());
comments.setUser_id(securityContext.getCurrentUser().getUser_id());
comments.setTransaction_id(transactionId);
commentsService.add(comments);
securityContext.dispose();
return new ResponseEntity<>(HttpStatus.OK);
}

@RequestMapping(value = "/find", method = RequestMethod.POST)
public ResponseEntity<Comments> findComments (@RequestParam Integer comments_id){
securityContext.setContext(SecurityContextHolder.getContext());
Comments foundComment = commentsService.findByCommentsId(comments_id, securityContext.getCurrentUser().getUser_id());
if (foundComment != null) {
securityContext.dispose();
return new ResponseEntity<>(foundComment, HttpStatus.OK);
} else {
securityContext.dispose();
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
}

@RequestMapping(value = "/del/{commentsId}", method = RequestMethod.POST)
public ResponseEntity<?> delComments (@PathVariable("commentsId") Integer comments_id){
securityContext.setContext(SecurityContextHolder.getContext());
commentsService.deleteByCommentsId(comments_id, securityContext.getCurrentUser().getUser_id());
securityContext.dispose();
return new ResponseEntity<>(HttpStatus.OK);
}

@GetMapping( "/list/{transactionId}")
@ResponseBody
public ResponseEntity<List<Comments>> listComments (HttpServletRequest request,
@PathVariable("transactionId") Integer transactionId){
securityContext.setContext(SecurityContextHolder.getContext());
//List<Comments> commentsList = commentsService.allList(securityContext.getCurrentUser().getUser_id());
List<Comments> commentsList = commentsService.allListByTransactionId(transactionId);
if (commentsList != null && !commentsList.isEmpty()) {
securityContext.dispose();
return new ResponseEntity<>(commentsList, HttpStatus.OK);
} else {
//securityContext.dispose();
//return new ResponseEntity<>(HttpStatus.NOT_FOUND);
return new ResponseEntity<>(commentsList, HttpStatus.OK);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.soloSavings.model;


import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Entity
@Table(name = "comments")
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class Comments {
@Id
@GeneratedValue
private Integer id;
private String content;
private Integer user_id;

private Integer transaction_id;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.soloSavings.repository;

import com.soloSavings.model.Comments;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/*
* Copyright (c) 2023 Team 2 - SoloSavings
* Boston University MET CS 673 - Software Engineering
* All rights reserved.
*
* This software is the confidential and proprietary information of
* Team 2 - SoloSavings Application
*/
@Repository
public interface CommentsRepository extends JpaRepository<Comments, Integer> {

@Query("SELECT c FROM Comments c WHERE c.id = ?1 AND c.user_id = ?2")
Comments findByCommentsId(Integer comments_id, Integer user_id);


@Query("SELECT c FROM Comments c where c.user_id=?1")
List<Comments> allList(Integer user_id);

@Query("SELECT c FROM Comments c where c.transaction_id=?1")
List<Comments> allListByTransactionId(Integer transactionId);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.soloSavings.service;

import com.soloSavings.model.Comments;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public interface CommentsService {
//Expenses
public Comments findByCommentsId(Integer user_id, Integer comments_id);
//Income
public void deleteByCommentsId(Integer user_id, Integer comments_id);

public List<Comments> allList(Integer user_id);

public void add(Comments comments);

List<Comments> allListByTransactionId(Integer transactionId);


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.soloSavings.serviceImpl;

import com.soloSavings.model.Comments;
import com.soloSavings.repository.CommentsRepository;
import com.soloSavings.service.CommentsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommentsServiceImpl implements CommentsService {
@Autowired
CommentsRepository commentsRepository;
@Override
public Comments findByCommentsId(Integer user_id, Integer comments_id) {
return commentsRepository.findByCommentsId(comments_id, user_id);
}

@Override
public void deleteByCommentsId(Integer user_id, Integer comments_id) {
Comments comments = commentsRepository.findByCommentsId(user_id, comments_id);
if(null != comments)
commentsRepository.deleteById(comments_id);
}

@Override
public List<Comments> allList(Integer user_id) {
return commentsRepository.allList(user_id);
}

@Override
public void add(Comments comments) {
commentsRepository.save(comments);
}

@Override
public List<Comments> allListByTransactionId(Integer transactionId) {
return commentsRepository.allListByTransactionId(transactionId);
}
}

This file was deleted.

18 changes: 2 additions & 16 deletions code/SoloSavingsApp/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,9 @@ spring.datasource.password=cs673
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.show-sql: true

server.port=${SPRING_SSL_PORT:8888}
server.port=8888
server.error.path=/error
logging.level.org.springframework.security=TRACE

jwt.secret=mysecretkey
jwt.expiration=86400

# Gmail SMTP Properties
spring.mail.host=aspmx.l.google.com
spring.mail.port=25
[email protected]
spring.mail.password=mlwucjcqjmggmif

# Properties
spring.mail.properties.mail.transport.protocol=smtp
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.required=true
spring.mail.properties.mail.smtp.ssl.trust=aspmx.l.google.com
spring.mail.properties.mail.smtp.auth.mechanisms=PLAIN
jwt.expiration=86400
Loading