Skip to content

Instantly share code, notes, and snippets.

@oltyx
Last active August 17, 2020 09:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oltyx/0a833d35ea639ed84fd9e3f5315b48c5 to your computer and use it in GitHub Desktop.
Save oltyx/0a833d35ea639ed84fd9e3f5315b48c5 to your computer and use it in GitHub Desktop.
Transaction controller for Digital Payment Assistant API
@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