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

Working example

parent 7d099076
package com.RESTAPI.RESTAPI.Controllers;
import com.RESTAPI.RESTAPI.Entities.Compte;
import com.RESTAPI.RESTAPI.Entities.User;
import com.RESTAPI.RESTAPI.Repositories.CompteRepository;
import com.RESTAPI.RESTAPI.Repositories.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
......@@ -14,10 +14,14 @@ import org.springframework.web.bind.annotation.*;
public class UserController {
@Autowired
private UserRepository userRepository;
@Autowired
private CompteRepository compteRepository;
@PutMapping(path="/")
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);
return user;
}
......
package com.RESTAPI.RESTAPI.Entities;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import lombok.*;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
......@@ -14,6 +12,8 @@ import java.util.Date;
@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Compte {
@Id
@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