API.Registration.java Source code

Java tutorial

Introduction

Here is the source code for API.Registration.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package API;

import Model.LoginTable;
import Model.PatientDetail;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.QueryParam;
import org.hibernate.Session;
import org.hibernate.Transaction;

/**
 *
 * @author sonav
 */
@Path("Signup")
public class Registration {
    @Path("Add")
    @GET
    public void addUser(@QueryParam("uname") String Username, @QueryParam("FirstName") String FirstName,
            @QueryParam("LastName") String LastName, @QueryParam("password") String password,
            @QueryParam("email") String email, @QueryParam("mobile") String mobile) {
        try {
            Session se = NewHibernateUtil.getSessionFactory().openSession();
            Transaction t = se.beginTransaction();
            LoginTable lt = new LoginTable();
            lt.setPassword(password);
            lt.setUsername(Username);
            lt.setRole("patient");

            se.save(lt);

            PatientDetail pd = new PatientDetail();

            pd.setFirstName(FirstName);
            pd.setLastName(LastName);
            pd.setEmail(email);
            pd.setMobile(mobile);
            pd.setUid(lt);

            se.save(pd);
            t.commit();

        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }
}