Skip to content

Commit

Permalink
Working before joins
Browse files Browse the repository at this point in the history
  • Loading branch information
bh5k committed Mar 15, 2021
1 parent 9f25c24 commit 40e847d
Show file tree
Hide file tree
Showing 15 changed files with 260 additions and 30 deletions.
102 changes: 77 additions & 25 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion conference.iml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
<configuration>
<setting name="validation-enabled" value="true" />
<setting name="provider-name" value="Hibernate" />
<datasource-mapping />
<datasource-mapping>
<factory-entry name="entityManagerFactory" />
</datasource-mapping>
<naming-strategy-map />
</configuration>
</facet>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.pluralsight.conference.controller;

import com.pluralsight.conference.model.Registration;
import com.pluralsight.conference.service.RegistrationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -12,6 +14,9 @@
@Controller
public class RegistrationController {

@Autowired
private RegistrationService registrationService;

@GetMapping("registration")
public String getRegistration(@ModelAttribute ("registration")Registration registration) {
return "registration";
Expand All @@ -25,6 +30,8 @@ public String addRegistration(@Valid @ModelAttribute ("registration")
if(result.hasErrors()) {
System.out.println("There were errors");
return "registration";
} else {
registrationService.addRegistration(registration);
}

System.out.println("Registration: " + registration.getName());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
package com.pluralsight.conference.controller;

import com.pluralsight.conference.model.User;
import com.pluralsight.conference.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

@RestController
public class UserController {

@Autowired
private UserService userService;

@GetMapping("/user")
public User getUser(@RequestParam(value = "firstname", defaultValue = "Bryan") String firstname,
@RequestParam(value = "lastname", defaultValue = "Hansen") String lastname,
@RequestParam(value = "age", defaultValue = "43") int age) {
public User getUser(@RequestParam(value = "firstname") String firstname,
@RequestParam(value = "lastname") String lastname,
@RequestParam(value = "age") int age) {
User user = new User();

user.setFirstname(firstname);
Expand All @@ -26,6 +34,8 @@ public User getUser(@RequestParam(value = "firstname", defaultValue = "Bryan") S
public User postUser(User user) {
System.out.println("User firstname:" + user.getFirstname());

userService.save(user);

return user;
}

Expand Down
18 changes: 18 additions & 0 deletions src/main/java/com/pluralsight/conference/model/Registration.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
package com.pluralsight.conference.model;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.validation.constraints.NotEmpty;

@Entity
@Table(name = "REGISTRATION")
public class Registration {

@Id
@GeneratedValue
private Long id;

@NotEmpty
private String name;

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public String getName() {
return name;
}
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/com/pluralsight/conference/model/User.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
package com.pluralsight.conference.model;

import javax.persistence.*;

@Entity
@Table(name = "CONF_USERS")
public class User {

@Id
@GeneratedValue
private Long id;
@Column(name = "FIRST_NAME")
private String firstname;
@Column(name = "LAST_NAME")
private String lastname;
private int age;

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public String getFirstname() {
return firstname;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.pluralsight.conference.repository;

import com.pluralsight.conference.model.Registration;

public interface RegistrationRepository {
Registration save(Registration registration);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.pluralsight.conference.repository;

import com.pluralsight.conference.model.Registration;
import org.springframework.stereotype.Repository;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

@Repository
public class RegistrationRepositoryImpl implements RegistrationRepository {

@PersistenceContext
private EntityManager entityManager;

@Override
public Registration save(Registration registration) {
entityManager.persist(registration);
return registration;
}

}
Loading

0 comments on commit 40e847d

Please sign in to comment.