Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.example.accounts.repository.AccountRepository;
import com.example.accounts.repository.JournalRepository;
import java.util.List;
import com.example.accounts.model.Account;
import com.example.accounts.model.Journal;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.http.HttpStatus;
Expand All @@ -25,14 +27,16 @@
public class AccountController {

final AccountRepository accountRepository;
final JournalRepository journalRepository;

@GetMapping("/hello")
public String ping() {
return "Hello from Spring Boot";
}

public AccountController(AccountRepository accountRepository) {
public AccountController(AccountRepository accountRepository, JournalRepository journalRepository) {
this.accountRepository = accountRepository;
this.journalRepository = journalRepository;
}

@GetMapping("/accounts")
Expand Down Expand Up @@ -85,4 +89,18 @@ public ResponseEntity<HttpStatus> deleteAccount(@PathVariable("accountId") long
}
}

@GetMapping("/account/{accountId}/transactions")
public ResponseEntity<List<Journal>> getTransactions(@PathVariable("accountId") long accountId) {
try {
List<Journal> transactions = new ArrayList<Journal>();
transactions.addAll(journalRepository.findByAccountId(accountId));
if (transactions.isEmpty()) {
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
return new ResponseEntity<>(transactions, HttpStatus.OK);
} catch (Exception e) {
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@

public interface JournalRepository extends JpaRepository<Journal, Long> {
Journal findJournalByLraIdAndJournalType(String lraId, String journalType);
List<Journal> findByAccountId(long accountId);
}