nathan
08/13/2020, 9:10 PM@Entity
@Table(name="storypost")
class StoryPost(
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "storypost_id")
var id: Long,
var body: String,
var video_link: String,
var image_link: String,
var likes: Int,
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "userprofile_id")
@JsonBackReference
var userProfile: UserProfile?=null
)
Controller
@RestController
class StoryPostController ( val repo : StoryPostRepositories){
@GetMapping("/storypost")
fun getAllStoryPosts() = repo.findAll().toList()
@PostMapping("/storypost")
fun addStoryPost(@RequestBody userPost : StoryPost) : ResponseEntity<StoryPost>{
repo.save(userPost)
return ResponseEntity<StoryPost>(userPost, HttpStatus.CREATED)
}
}
how would I include the user id when making a storypost post request? should i just put another var user_id: Long
and then have a val repo2 : UserRepo
to find by id?Gary
08/14/2020, 1:33 AM