Skip to content

Commit

Permalink
Adding delete accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
iwokonl committed Apr 18, 2024
1 parent fd53411 commit e6035bb
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,11 @@ public ResponseEntity<ForeignCurrencyAccountDto> createCurrencyAccount(
foreignCurrencyAccountDto.getBalance());
return ResponseEntity.ok(foreignCurrencyAccountDtoToSend);
}
@DeleteMapping("/deleteCurrencyAccount")
public ResponseEntity<String> deleteCurrencyAccount(
@RequestBody ForeignCurrencyAccountDto foreignCurrencyAccountDto
){
foreignCurrencyAccountService.deleteForeignCurrencyAccount(foreignCurrencyAccountDto.getId());
return ResponseEntity.ok("Account deleted");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
public interface ForeignCurrencyAccountRepo extends JpaRepository<ForeignCurrencyAccount, Long> {
List<ForeignCurrencyAccount> findAllByUserId(Long userId);
Optional<ForeignCurrencyAccount> findByCurrencyCodeAndUserId(String currencyCode, Long userId);

void deleteById(Long Id);
Optional<ForeignCurrencyAccount> findByUserIdAndCurrencyCode(Long id, String code);
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package pl.kantor.backend.MVC.service;

import lombok.RequiredArgsConstructor;
import org.apache.catalina.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.http.HttpStatus;
import org.springframework.security.core.Authentication;
Expand Down Expand Up @@ -108,4 +106,8 @@ public ForeignCurrencyAccount addAmount(Long accountId, BigDecimal amount) {
account.setBalance(account.getBalance().add(amount));
return accountRepository.save(account);
}

public void deleteForeignCurrencyAccount(Long id) {
foreignCurrencyAccountRepo.deleteById(id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ <h5 class="card-title">
<a [routerLink]="['/currency', account.curencyCode]">{{ account.curencyName + ' ' + account.curencyCode }}</a>
</h5>
<p class="card-text">Balans: {{ account.balance + ' ' + account.curencyCode + ' = ' + (account.balanceInPLN | number : '1.2-2') +' PLN' }}</p>
<button class="btn btn-outline-primary delete">Usuń konto walutowe</button>
<button class="btn btn-outline-primary delete" (click)="onDeleteAccount(account)">Usuń konto walutowe</button>
<button class="btn btn-outline-primary">Dodaj fundusze</button>
<button class="btn btn-outline-primary withdraw">Wypłać fundusze</button>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
}

.withdraw{
position: fixed;

padding: 3px 1px;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,15 @@ export class CurrencyAccountComponent implements OnInit {
this.getCurrencyAccounts();

}

onDeleteAccount(account: any) {
this.axiosService.request("DELETE",
"/api/ForeignCurrencyAccount/deleteCurrencyAccount",
{
id: account.id
}).then((response) => {
console.log(response.data);
this.getCurrencyAccounts(); // Refresh the accounts list after creating a new account
});
}
}

0 comments on commit e6035bb

Please sign in to comment.