Last active
August 17, 2020 09:48
-
-
Save oltyx/0a833d35ea639ed84fd9e3f5315b48c5 to your computer and use it in GitHub Desktop.
Transaction controller for Digital Payment Assistant API
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
@RestController | |
public class TransactionController { | |
private TransactionRepository transactionRepo; | |
private CategoryRepository categoryRepo; | |
private SessionRepository sessionRepo; | |
private TransactionServiceImpl transactionServ; | |
@Autowired | |
public TransactionController(TransactionRepository transactionRepo, CategoryRepository categoryRepo, | |
SessionRepository sessionRepo, TransactionServiceImpl transactionServ) { | |
this.transactionRepo = transactionRepo; | |
this.categoryRepo = categoryRepo; | |
this.sessionRepo = sessionRepo; | |
this.transactionServ = transactionServ; | |
} | |
private static final Logger log = LoggerFactory.getLogger(TransactionController.class); | |
@RequestMapping(value = "/transactions", method = RequestMethod.GET) | |
public List<Transaction> doGetTransactions(@RequestParam(value = "offset", defaultValue = "0") int offset, | |
@RequestParam(value = "limit", defaultValue = "20") int limit, | |
@RequestParam(value = "category", required = false) Category category, | |
@RequestParam(value = "session_id", required = false) Session sessionId, | |
@RequestHeader(value = "X-session-ID", required = false) Session headerSessionID){ | |
log.info("'GET /transactions' has been requested ..."); | |
verifySessionId(sessionId, headerSessionID); | |
List<Transaction> transactions = transactionServ.findByCategoryWithOffsetAndLimit(offset, limit, category); | |
for (Transaction tr: transactions){ | |
log.info(tr.toString()); | |
} | |
log.info("The 'GET /transactions' response has been sent !"); | |
return transactions; | |
} | |
//............. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment