Skip to content

Commit

Permalink
Merge pull request #1 from Crio-Winter-of-Doing-2021/RFCT/change_db_t…
Browse files Browse the repository at this point in the history
…o_postgres

Rfct/change db to postgres
  • Loading branch information
saksham2599 authored Apr 14, 2021
2 parents a7cc018 + cd8faf2 commit 1aaa5e9
Show file tree
Hide file tree
Showing 33 changed files with 4,981 additions and 8,351 deletions.
3 changes: 3 additions & 0 deletions cashflow/.idea/.gitignore

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

9 changes: 9 additions & 0 deletions cashflow/.idea/cashflow.iml

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

8 changes: 8 additions & 0 deletions cashflow/.idea/modules.xml

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

6 changes: 6 additions & 0 deletions cashflow/.idea/vcs.xml

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

12,494 changes: 4,331 additions & 8,163 deletions cashflow/cashflow-backend/cashFlowApp_logfile.log

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
36 changes: 32 additions & 4 deletions cashflow/cashflow-backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
Expand All @@ -34,6 +30,16 @@
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.19</version>
</dependency>

<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
Expand Down Expand Up @@ -87,6 +93,28 @@
<version>RELEASE</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.jumbotail</groupId>
<artifactId>cashflow</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.4.2.Final</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

<dependency>
<groupId>jakarta.persistence</groupId>
<artifactId>jakarta.persistence-api</artifactId>
<version>2.2.3</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ public static void main(String[] args) {
SpringApplication.run(CashflowApplication.class, args);
}


}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.jumbotail.cashflow.controller;

import com.jumbotail.cashflow.dto.Entity;
import com.jumbotail.cashflow.dto.Transaction;
import com.jumbotail.cashflow.dto.EntityDto;
import com.jumbotail.cashflow.dto.TransactionDto;
import com.jumbotail.cashflow.exchanges.*;
import com.jumbotail.cashflow.services.MyUserDetailsService;
import com.jumbotail.cashflow.services.UserService;
Expand All @@ -11,11 +11,15 @@
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Controller;
import org.springframework.util.ReflectionUtils;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.lang.reflect.Field;
import java.util.Map;

@Controller
public class CashflowController {
Expand All @@ -32,6 +36,13 @@ public class CashflowController {
@Autowired
private MyUserDetailsService userDetailsService;

private String getUserName() {
UserDetails userDetails = (UserDetails) SecurityContextHolder.getContext().getAuthentication()
.getPrincipal();
String username = userDetails.getUsername();
return username;
}

@PostMapping("/authenticate")
public ResponseEntity<?> createAuthenticationToken(@RequestBody AuthenticationRequest authenticationRequest) throws Exception {

Expand All @@ -44,7 +55,6 @@ public ResponseEntity<?> createAuthenticationToken(@RequestBody AuthenticationRe
throw new Exception("Incorrect username or password", e);
}


final UserDetails userDetails = userDetailsService
.loadUserByUsername(authenticationRequest.getUsername());

Expand All @@ -54,46 +64,101 @@ public ResponseEntity<?> createAuthenticationToken(@RequestBody AuthenticationRe
}

@PostMapping("/register")
ResponseEntity<?> registerUser(@Valid @RequestBody UserRegistrationRequest userRegistrationRequest) throws Exception {
public ResponseEntity<?> registerUser(@Valid @RequestBody UserRegistrationRequest userRegistrationRequest) {

UserRegistrationResponse userRegistrationResponse = userService.registerUser(userRegistrationRequest);

return ResponseEntity.ok(userRegistrationResponse);
}


@PostMapping("/entity/{email}")
ResponseEntity<?> addEntity(@RequestBody @Valid Entity entity , @PathVariable String email ) {
@PostMapping("/entity")
ResponseEntity<?> addEntity(@RequestBody @Valid AddEntityRequest addEntityRequest ) {

AddEntityResponse addEntityResponse = userService.addEntity(entity, email);
AddEntityResponse addEntityResponse = userService.addEntity(addEntityRequest, getUserName());

return ResponseEntity.ok(addEntityResponse);
}

@GetMapping("/entity/{email}")
ResponseEntity<?> getEntities(@PathVariable String email ) {
@GetMapping("/entity")
public ResponseEntity<?> getEntities( ) {

GetEntitiesResponse getEntitiesResponse = userService.getEntities(email);
GetEntitiesResponse getEntitiesResponse = userService.getEntities(getUserName());

return ResponseEntity.ok(getEntitiesResponse);
}

@GetMapping("/transaction/{email}")
ResponseEntity<?> getTransactions(@PathVariable String email ) {
@GetMapping("/entity/{entityId}")
public ResponseEntity<?> getEntities(@PathVariable Long entityId ) {

EntityDto entity = userService.getEntity(getUserName(), entityId);

return ResponseEntity.ok(entity);
}

@GetMapping("/transaction")
public ResponseEntity<?> getTransactions( ) {

GetTransactionsResponse getTransactionsResponse = userService.getTransactions(getUserName());

return ResponseEntity.ok(getTransactionsResponse);
}

@GetMapping("/transaction/entity/{entityId}")
public ResponseEntity<?> getTransactions( @PathVariable Long entityId) {

GetTransactionsResponse getTransactionsResponse = userService.getTransactions(email);
GetTransactionsResponse getTransactionsResponse = userService.getTransactions(getUserName(), entityId);

return ResponseEntity.ok(getTransactionsResponse);
}

@PostMapping("/transaction/{email}")
ResponseEntity<?> addTransaction(@RequestBody @Valid Transaction transaction , @PathVariable String email ) {
@GetMapping("/transaction/{txnId}/entity/{entityId}")
public ResponseEntity<?> getTransaction( @PathVariable Long txnId, @PathVariable Long entityId) {

TransactionDto txn = userService.getTransaction(getUserName(), txnId, entityId);

return ResponseEntity.ok(txn);
}

@PostMapping("/transaction")
public ResponseEntity<?> addTransaction(@RequestBody @Valid AddTransactionRequest addTransactionRequest) {

AddTransactionResponse addTransactionResponse = userService.addTransaction(transaction, email);
AddTransactionResponse addTransactionResponse = userService.addTransaction(addTransactionRequest, getUserName());

return ResponseEntity.ok(addTransactionResponse);
}

@PatchMapping("/entity/{entityId}")
public ResponseEntity<?> updateEntity(@PathVariable Long entityId, @RequestBody Map<Object, Object> fields) {
EntityDto entity = userService.getEntity(getUserName(), entityId);
fields.forEach((k, v) -> {
Field field = ReflectionUtils.findField(EntityDto.class, (String) k);
field.setAccessible(true);
ReflectionUtils.setField(field, entity, v);
});
userService.updateEntity(getUserName(), entity);
return ResponseEntity.ok("Successful");
}

@PatchMapping("/transaction/{txnId}/entity/{entityId}")
public ResponseEntity<?> updateEntity(@PathVariable(name="txnId",required=true) Long txnId, @PathVariable(name="entityId",required=true) Long entityId, @RequestBody Map<Object, Object> fields) {
TransactionDto txn = userService.getTransaction(getUserName(), txnId, entityId);
fields.forEach((k, v) -> {
Field field = ReflectionUtils.findField(TransactionDto.class, (String) k);
field.setAccessible(true);
if(k.equals("amount") || k.equals("entityId")) {
ReflectionUtils.setField(field, txn, Long.valueOf("" + v));
}
else {
ReflectionUtils.setField(field, txn, v);
}
});
userService.updateTransaction(getUserName(), txn);
return ResponseEntity.ok("Successful");
}





}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Entity {
@NotBlank
public class EntityDto {
@NotNull
private Long id;
@NotBlank
private String type;
@NotBlank
@NotNull
private String name;
private String contactNo;
private String address;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@
public class MyUserDetails implements UserDetails {
private String userName;
private String password;
private boolean isActive;
private String email;
private List<GrantedAuthority> authorities;

public MyUserDetails(UserEntity userEntity) {
this.userName = userEntity.getUsername();
this.userName = userEntity.getUserName();
this.password = userEntity.getPassword();
this.isActive = userEntity.isActive();
this.email = userEntity.getEmail();
this.authorities = getAuthoritiesFromUserEntity(userEntity);
}
Expand Down Expand Up @@ -74,6 +72,6 @@ public boolean isCredentialsNonExpired() {

@Override
public boolean isEnabled() {
return isActive;
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,21 @@
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotNull;
import java.util.Date;
import java.sql.Timestamp;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Transaction {
public class TransactionDto {
@NotNull
private Long id;
@NotNull
private Long amount;
private String type;
private String modeOfPayment;
@NotNull
private Date timestamp;
private Entity entity;
private Timestamp timestamp;
private Long entityId;
private String remarks;
private String status;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.jumbotail.cashflow.exchanges;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotBlank;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class AddEntityRequest {

@NotBlank
private String type;
@NotBlank
private String name;
private String contactNo;
private String address;
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package com.jumbotail.cashflow.exchanges;

import com.jumbotail.cashflow.dto.Entity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.jumbotail.cashflow.exchanges;


import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotNull;
import java.sql.Timestamp;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class AddTransactionRequest {
@NotNull
private Long amount;
private String type;
private String modeOfPayment;
@NotNull
private Timestamp timestamp;
private Long entityId;
private String remarks;
private String status;
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package com.jumbotail.cashflow.exchanges;

import com.jumbotail.cashflow.dto.Transaction;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
Expand Down
Loading

0 comments on commit 1aaa5e9

Please sign in to comment.