Jak podejść do nauki Spring oraz SpringBoot?

Jak podejść do nauki Spring oraz SpringBoot?

Wątek przeniesiony 2023-07-03 09:30 z Java przez Riddle.

LukaszCh233
  • Rejestracja: dni
  • Ostatnio: dni
  • Postów: 180
0

Hej mam taki problem i nie wiem co jest źle. Jak chce dodać książkę w postman to wygląda tak:

Kopiuj
{
  "title": "Przykładowa książka",
  "author": "Jan Kowalski",
  "price": 29.99,
  "quantity": 10,
  "status": "AVAILABLE",
  "category": {
    "id": 1,
    "name": "Fantasy"
  }
}
{
    "timestamp": "2023-07-24T10:50:38.588+00:00",
    "status": 500,
    "error": "Internal Server Error",
    "path": "/books"
}

Może źle json jest napisany albo źle łącze tabele book z category?
https://github.com/LukaszCh233/Books_store

KamilAdam
  • Rejestracja: dni
  • Ostatnio: dni
  • Lokalizacja: Silesia/Marki
  • Postów: 5550
0

A co tam za błąd w logach masz po stronie backendu? No chyba że nic nie logujesz to dodaj najpierw logowanie błędów

LukaszCh233
  • Rejestracja: dni
  • Ostatnio: dni
  • Postów: 180
0

Hej to znowu ja, dalej sobie coś tam ćwiczę i napisałem metody logowania i rejestracji i czy takie coś ma sens? Bo bez GUI troche ciężej mi to sobie zobrazować czy takie coś by działało.

Kopiuj
@PostMapping("/customer")
public Customer registerCustomer(@RequestBody Customer customer) {

    if (customer.getCustomerLogin() == null) {
        throw new IllegalArgumentException("CustomerLogin cannot be null.");
    }
    if (customerLoginRepository.existsByEmail(customer.getCustomerLogin().getEmail())) {
        throw new IllegalArgumentException("This email is already registered.");
    }
    return customerRepository.save(customer);
}

@PostMapping("/customer/login")
public ResponseEntity<Customer> loginCustomer(@RequestBody CustomerLogin customerLogin) {
    CustomerLogin storedCustomerLogin = customerLoginRepository.findByEmailAndPassword(customerLogin.getEmail(), customerLogin.getPassword());
    if (storedCustomerLogin != null) {
        Customer customer = customerRepository.findByEmail(customerLogin.getEmail());
        if (customer != null) {

            return ResponseEntity.ok(customer);
        } else {

            return ResponseEntity.notFound().build();
        }
    } else {

        return ResponseEntity.badRequest().build();
    }
}

Zarejestruj się i dołącz do największej społeczności programistów w Polsce.

Otrzymaj wsparcie, dziel się wiedzą i rozwijaj swoje umiejętności z najlepszymi.