-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1533dd6
commit 358af02
Showing
14 changed files
with
338 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
backend/src/main/java/org/fianancetracker/backend/controllers/ExpenseController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
backend/src/main/java/org/fianancetracker/backend/dto/ExpenseDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
33 changes: 33 additions & 0 deletions
33
backend/src/main/java/org/fianancetracker/backend/models/Expense.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
backend/src/main/java/org/fianancetracker/backend/service/ExpenseService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
backend/src/main/java/org/fianancetracker/backend/service/Impl/ExpenseServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.