Commit 3f122569 authored by Alexandre Ducarne's avatar Alexandre Ducarne

Working example

parent 7d099076
package com.RESTAPI.RESTAPI.Controllers; package com.RESTAPI.RESTAPI.Controllers;
import com.RESTAPI.RESTAPI.Entities.Compte;
import com.RESTAPI.RESTAPI.Entities.User; import com.RESTAPI.RESTAPI.Entities.User;
import com.RESTAPI.RESTAPI.Repositories.CompteRepository;
import com.RESTAPI.RESTAPI.Repositories.UserRepository; import com.RESTAPI.RESTAPI.Repositories.UserRepository;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
...@@ -14,10 +14,14 @@ import org.springframework.web.bind.annotation.*; ...@@ -14,10 +14,14 @@ import org.springframework.web.bind.annotation.*;
public class UserController { public class UserController {
@Autowired @Autowired
private UserRepository userRepository; private UserRepository userRepository;
@Autowired
private CompteRepository compteRepository;
@PutMapping(path="/") @PutMapping(path="/")
public @ResponseBody public @ResponseBody
User addNewUser (@ModelAttribute User user, @ModelAttribute Compte compte) { User addNewUser (@RequestBody User user) {
compteRepository.save(user.getCompte());
user.setCompte(user.getCompte());
userRepository.save(user); userRepository.save(user);
return user; return user;
} }
......
package com.RESTAPI.RESTAPI.Entities; package com.RESTAPI.RESTAPI.Entities;
import lombok.Builder; import lombok.*;
import lombok.Getter;
import lombok.Setter;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.GeneratedValue; import javax.persistence.GeneratedValue;
...@@ -14,6 +12,8 @@ import java.util.Date; ...@@ -14,6 +12,8 @@ import java.util.Date;
@Getter @Getter
@Setter @Setter
@Builder @Builder
@NoArgsConstructor
@AllArgsConstructor
public class Compte { public class Compte {
@Id @Id
@GeneratedValue(strategy= GenerationType.IDENTITY) @GeneratedValue(strategy= GenerationType.IDENTITY)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment