-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added sorting by price and month in descending order, renamed and add…
…ed categories, added other logic fixes
- Loading branch information
1 parent
c203ab5
commit 4dec239
Showing
18 changed files
with
679 additions
and
57 deletions.
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.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.expensys.config; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.cors.CorsConfiguration; | ||
import org.springframework.web.cors.CorsConfigurationSource; | ||
import org.springframework.web.cors.UrlBasedCorsConfigurationSource; | ||
|
||
@Configuration | ||
public class CorsConfig { | ||
|
||
@Bean | ||
public CorsConfigurationSource corsConfigurationSource() { | ||
CorsConfiguration configuration = new CorsConfiguration(); | ||
configuration.addAllowedOrigin("http://localhost:"); // Specify your allowed origin(s) | ||
configuration.addAllowedHeader("*"); | ||
configuration.addAllowedMethod("*"); | ||
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); | ||
source.registerCorsConfiguration("/**", configuration); | ||
return source; | ||
} | ||
} | ||
|
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
26 changes: 11 additions & 15 deletions
26
src/main/java/com/expensys/controller/ExpenseManagementController.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 |
---|---|---|
@@ -1,34 +1,30 @@ | ||
package com.expensys.controller; | ||
|
||
import com.expensys.model.request.ReportRequest; | ||
import com.expensys.model.response.Report; | ||
import com.expensys.model.request.NewExpense; | ||
import com.expensys.service.main.ExpenseManagementService; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.ModelAttribute; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.List; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@RequestMapping("/report") | ||
@RequestMapping("/expense") | ||
public class ExpenseManagementController { | ||
Logger logger = LoggerFactory.getLogger(ExpenseManagementController.class); | ||
private final ExpenseManagementService expenseManagementService; | ||
|
||
@Autowired | ||
public ExpenseManagementController(ExpenseManagementService expenseManagementService) { | ||
this.expenseManagementService = expenseManagementService; | ||
} | ||
|
||
@GetMapping | ||
public ResponseEntity<List<Report>> getReport(@ModelAttribute ReportRequest reportRequest){ | ||
List<Report> reportList = expenseManagementService.getReport(reportRequest); | ||
return new ResponseEntity<>(reportList, HttpStatus.OK); | ||
@CrossOrigin | ||
@PostMapping("/save") | ||
public ResponseEntity<HttpStatus> saveExpense(@RequestBody NewExpense newExpense){ | ||
logger.info("newExpense -> {}",newExpense); | ||
// expenseManagementService.addExpense(newExpense); | ||
return new ResponseEntity<>(expenseManagementService.addExpense(newExpense) ? HttpStatus.OK : HttpStatus.INTERNAL_SERVER_ERROR); | ||
} | ||
|
||
|
||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/com/expensys/controller/ReportController.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,32 @@ | ||
package com.expensys.controller; | ||
|
||
import com.expensys.model.request.ReportRequest; | ||
import com.expensys.model.response.Report; | ||
import com.expensys.service.main.ExpenseManagementService; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequestMapping("/report") | ||
public class ReportController { | ||
Logger logger = LoggerFactory.getLogger(ReportController.class); | ||
private final ExpenseManagementService expenseManagementService; | ||
|
||
public ReportController(ExpenseManagementService expenseManagementService) { | ||
this.expenseManagementService = expenseManagementService; | ||
} | ||
|
||
@CrossOrigin | ||
@GetMapping | ||
public ResponseEntity<List<Report>> getReport(@ModelAttribute ReportRequest reportRequest){ | ||
List<Report> reportList = expenseManagementService.getReport(reportRequest); | ||
return new ResponseEntity<>(reportList, HttpStatus.OK); | ||
} | ||
|
||
|
||
} |
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
77 changes: 77 additions & 0 deletions
77
src/main/java/com/expensys/helper/WordSimilarityCalculator.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,77 @@ | ||
package com.expensys.helper; | ||
|
||
import org.apache.commons.text.similarity.CosineSimilarity; | ||
import java.util.*; | ||
|
||
public class WordSimilarityCalculator { | ||
private int wordLength; | ||
|
||
public WordSimilarityCalculator(int wordLength) { | ||
this.wordLength = wordLength; | ||
} | ||
|
||
public static void main(String[] args) { | ||
// System.out.println(calculateSimilarity("vegetable & fruits", "vegetables and fruits")); | ||
System.out.println(calculateSimilarity("fruit", "fruits")); | ||
} | ||
|
||
public static double calculateSimilarity(String word1, String word2) { | ||
// Tokenization | ||
List<String> word1List = tokenizeWord(word1); | ||
List<String> word2List = tokenizeWord(word2); | ||
|
||
// Remove stopwords | ||
List<String> word1Set = removeStopWords(word1List); | ||
List<String> word2Set = removeStopWords(word2List); | ||
|
||
// Convert the lists to maps with word frequencies | ||
Map<CharSequence, Integer> word1Map = createWordFrequencyMap(word1Set); | ||
Map<CharSequence, Integer> word2Map = createWordFrequencyMap(word2Set); | ||
|
||
// Calculate cosine similarity | ||
CosineSimilarity cosineSimilarity = new CosineSimilarity(); | ||
double similarity = cosineSimilarity.cosineSimilarity(word1Map, word2Map); | ||
|
||
return similarity; | ||
} | ||
|
||
private static List<String> tokenizeWord(String word) { | ||
List<String> tokenList = new ArrayList<>(); | ||
String[] tokens = word.split("\\s+"); // Split by whitespace | ||
for (String token : tokens) { | ||
tokenList.add(token.toLowerCase()); | ||
} | ||
return tokenList; | ||
} | ||
|
||
private static List<String> removeStopWords(List<String> tokens) { | ||
List<String> cleanedTokens = new ArrayList<>(); | ||
Set<String> stopWords = getStopWords(); // Define your set of stopwords | ||
|
||
for (String token : tokens) { | ||
if (!stopWords.contains(token)) { | ||
cleanedTokens.add(token); | ||
} | ||
} | ||
|
||
return cleanedTokens; | ||
} | ||
|
||
private static Map<CharSequence, Integer> createWordFrequencyMap(List<String> words) { | ||
Map<CharSequence, Integer> wordFrequencyMap = new HashMap<>(); | ||
for (String word : words) { | ||
wordFrequencyMap.put(word, wordFrequencyMap.getOrDefault(word, 0) + 1); | ||
} | ||
return wordFrequencyMap; | ||
} | ||
|
||
private static Set<String> getStopWords() { | ||
// Define your set of English stopwords here | ||
Set<String> stopWords = new HashSet<>(); | ||
stopWords.add("the"); | ||
stopWords.add("and"); | ||
stopWords.add("&"); | ||
// Add more stopwords as needed | ||
return stopWords; | ||
} | ||
} |
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.