Skip to content

Commit

Permalink
category complete
Browse files Browse the repository at this point in the history
  • Loading branch information
pasanchamikara99 committed Jul 12, 2024
1 parent 1533dd6 commit 358af02
Show file tree
Hide file tree
Showing 14 changed files with 338 additions and 1 deletion.
19 changes: 19 additions & 0 deletions .idea/dataSources.xml

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

124 changes: 124 additions & 0 deletions .idea/uiDesigner.xml

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

22 changes: 22 additions & 0 deletions backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,28 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.12.6</version>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-impl</artifactId>
<version>0.12.6</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-jackson</artifactId>
<version>0.12.6</version>
<scope>runtime</scope>
</dependency>

</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public ResponseEntity<List<CategoryDTO>> getAllCategory() {
@ResponseBody
public ResponseEntity<String> deteleCategory(@PathVariable("id") Long id) {
log.info(this.getClass().getName() + "Delete Category");
log.info(this.getClass().getName() + "Get Category");

String message = "";

message = categoryService.deleteCategory(id);
Expand All @@ -98,4 +98,19 @@ public ResponseEntity<String> deteleCategory(@PathVariable("id") Long id) {

}

@GetMapping("/getCategoryByType/{type}")
@ResponseBody
public ResponseEntity<List<CategoryDTO>> deteleCategory(@PathVariable("type") String type) {
log.info(this.getClass().getName() + "Get Category by types");
List<CategoryDTO> category = null;

category = categoryService.getCategoryByType(type);
if (!category.isEmpty()) {
return new ResponseEntity<>(category, HttpStatus.OK);
} else {
return new ResponseEntity<>(category, HttpStatus.BAD_REQUEST);
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.fianancetracker.backend.controllers;

import lombok.extern.slf4j.Slf4j;
import org.fianancetracker.backend.dto.ExpenseDTO;
import org.fianancetracker.backend.service.ExpenseService;
import org.fianancetracker.backend.util.Validation;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/expense")
@Slf4j
public class ExpenseController {

private final ExpenseService expenseService;

public ExpenseController(ExpenseService expenseService) {
this.expenseService = expenseService;
}

@PostMapping("/addExpense")
public ResponseEntity<String> addExpense(@RequestBody ExpenseDTO expenseDTO) {
log.info(this.getClass().getName() + "addExpense");
String message = Validation.expenseValidation(expenseDTO);
if (!message.isEmpty()) {
return new ResponseEntity<>(message, HttpStatus.BAD_REQUEST);
}
message = expenseService.addExpense(expenseDTO);
if (message.isEmpty()) {
return new ResponseEntity<>("Expense Added Successfully", HttpStatus.CREATED);
} else {
return new ResponseEntity<>(message, HttpStatus.INTERNAL_SERVER_ERROR);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.fianancetracker.backend.dto;

import lombok.Data;
import org.springframework.stereotype.Component;

import java.sql.Date;

@Data
@Component
public class ExpenseDTO {

private Long id;
private Long userId;
private String description;
private Long amount;
private String type;
private Date date;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.fianancetracker.backend.models;

import jakarta.persistence.*;
import lombok.Data;

import java.sql.Date;

@Entity
@Table(name = "Expense")
@Data
public class Expense {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(name = "description")
private String description;

@Column(name = "type")
private String type;

@Column(name = "amount")
private Long amount;

@Column(name = "create_date")
private Date date;

@ManyToOne
@JoinColumn(name = "user_id", nullable = false)
private User user;

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@

import org.fianancetracker.backend.models.Category;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface CategoryRepository extends JpaRepository<Category,Long> {

@Query("SELECT C FROM Category as C WHERE C.type = :type ")
List<Category> findByType(@Param("type") String type);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ public interface CategoryService {
List<CategoryDTO> getAllCategories();

String deleteCategory(Long id);

List<CategoryDTO> getCategoryByType(String type);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.fianancetracker.backend.service;

import org.fianancetracker.backend.dto.ExpenseDTO;
import org.springframework.stereotype.Service;

@Service
public interface ExpenseService {

String addExpense(ExpenseDTO expenseDTO);

}
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,20 @@ public String deleteCategory(Long id) {
}
return message;
}

@Override
public List<CategoryDTO> getCategoryByType(String type) {
List<Category> categories = categoryRepository.findByType(type);

if (!categories.isEmpty()) {
return categories.stream()
.map(category -> new CategoryDTO(
category.getId(),
category.getDescription(),
category.getType()))
.collect(Collectors.toList());
}

return new ArrayList<>();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.fianancetracker.backend.service.Impl;

import org.fianancetracker.backend.dto.ExpenseDTO;
import org.fianancetracker.backend.service.ExpenseService;
import org.springframework.stereotype.Service;

@Service
public class ExpenseServiceImpl implements ExpenseService {
@Override
public String addExpense(ExpenseDTO expenseDTO) {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ public class MessageVarList {
public static final String VALID_lOGIN = "valid Login";
public static final String EMPTY_CATEGORY = "Category Description Cannot be Empty";
public static final String EMPTY_CATEGORY_TYPE = "Category Type Cannot be Empty";
public static final String EMPTY_EXPENSE_DESCRIPTION = "Expense Description Cannot be Empty";
public static final String EMPTY_EXPENSE_TYPE = "Expense Type Cannot be Empty";
public static final String EMPTY_EXPENSE_AMOUNT = "Expense Amount Cannot be Empty";
}
Loading

0 comments on commit 358af02

Please sign in to comment.