Skip to content
Snippets Groups Projects
Commit 84bc3c38 authored by Veda Hegde's avatar Veda Hegde
Browse files

added class, controller, repository for Organization

parent 010cd558
No related branches found
No related tags found
No related merge requests found
......@@ -8,6 +8,8 @@ import {
Register,
UpdatePassword,
} from "./components/user/index";
import CreateOrganization from "./components/user/CreateOrganization";
import CreateRequest from "./components/user/CreateRequest";
function App() {
return (
......@@ -19,6 +21,8 @@ function App() {
<Route path="/login" element={<Login />} />
<Route path="/deleteUser" element={<DeleteUser />} />
<Route path="/updatepassword" element={<UpdatePassword />} />
<Route path="/createorganization" element={<CreateOrganization />} />
<Route path="/createrequest" element={<CreateRequest />} />
</Routes>
</div>
);
......
......@@ -31,6 +31,12 @@ export const Navbar = () => {
<li>
<NavLink to="/updatepassword">Update Password</NavLink>
</li>
<li>
<NavLink to="/createorganization">Create Organization</NavLink>
</li>
<li>
<NavLink to="/createrequest">Create Request</NavLink>
</li>
</ul>
</nav>
);
......
import React, { useState } from "react";
import Axios from "axios";
export const CreateOrganization = (props) => {
const [name, setName] = useState("");
const [email, setEmail] = useState("");
const [ownerEmail, setOwnerEmail] = useState("");
const [desc, setDesc] = useState("");
// const [orgId, setOrgId] = useState("");
const handleSubmit = (e) => {
e.preventDefault();
Axios.post("http://localhost:8080/organization/add", {
email: email,
name: name,
ownerEmail: ownerEmail,
desc: desc,
// orgId: orgId,
}).then((response) => {
console.log(response);
});
};
return (
<div className="creation-form-container">
<h2>Create Organization</h2>
<form className="create-form" onSubmit={handleSubmit}>
<label htmlFor="name">Name</label>
<input
value={name}
onChange={(e) => setName(e.target.value)}
name="name"
id="name"
placeholder="Name"
/>
<label htmlFor="ownerEmail">Owner Email</label>
<input
value={ownerEmail}
onChange={(e) => setOwnerEmail(e.target.value)}
name="ownerEmail"
id="ownerEmail"
placeholder="owner_pid@vt.edu"
type="email"
/>
<label htmlFor="email">Email</label>
<input
value={email}
onChange={(e) => setEmail(e.target.value)}
name="email"
id="email"
placeholder="pid@vt.edu"
type="email"
/>
<label htmlFor="desc">Description</label>
<input
value={desc}
onChange={(e) => setDesc(e.target.value)}
id="desc"
name="desc"
placeholder="..."
/>
<button type="submit">Create</button>
</form>
</div>
);
};
export default CreateOrganization;
import React, { useState } from "react";
import Axios from "axios";
export const CreateRequest = (props) => {
const [reqId, setReqId] = useState("");
const [userEmail, setUserEmail] = useState("");
const [desc, setDesc] = useState("");
const [orgId, setOrgId] = useState("");
const [status, setStatus] = useState("");
const [type, setType] = useState("");
const handleSubmit = (e) => {
e.preventDefault();
Axios.post("http://localhost:8080/request/add", {
userEmail: userEmail,
reqId: reqId,
desc: desc,
orgId: orgId,
status: status,
type: type,
}).then((response) => {
console.log(response);
});
};
return (
<div className="creation-form-container">
<h2>Create Request</h2>
<form className="create-form" onSubmit={handleSubmit}>
<label htmlFor="reqId">Request ID</label>
<input
value={reqId}
onChange={(e) => setReqId(e.target.value)}
name="reqId"
id="reqId"
placeholder="Request ID"
/>
<label htmlFor="userEmail">User Email</label>
<input
value={userEmail}
onChange={(e) => setUserEmail(e.target.value)}
name="userEmail"
id="userEmail"
placeholder="user_pid@vt.edu"
type="email"
/>
{/* <label htmlFor="status">Status</label>
<input
value={status}
// onChange={(e) => setStatus(e.target.value)}
onChange={(e) => PENDING}
name="status"
id="status"
placeholder="STATUS"
/> */}
<label htmlFor="type">Type</label>
<input
value={type}
onChange={(e) => setType(e.target.value)}
name="type"
id="type"
placeholder="JOIN/ITEM"
/>
<label htmlFor="desc">Description</label>
<input
value={desc}
onChange={(e) => setDesc(e.target.value)}
id="desc"
name="desc"
placeholder="..."
/>
<label htmlFor="orgId">Organization ID</label>
<input
value={orgId}
onChange={(e) => setOrgId(e.target.value)}
id="orgId"
name="orgId"
placeholder="Organization ID"
/>
<button type="submit">Create</button>
</form>
</div>
);
};
export default CreateRequest;
DROP DATABASE IF EXISTS inventory;
CREATE DATABASE IF NOT EXISTS inventory;
USE inventory;
CREATE TABLE IF NOT EXISTS USER (
email VARCHAR(128) NOT NULL,
......
......@@ -84,4 +84,4 @@ public class MainController {
}
return null;
}
}
\ No newline at end of file
}
package com.example.accessingdatamysql;
import org.apache.coyote.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
import java.util.Optional;
@CrossOrigin
@RestController // This means that this class is a Controller
@RequestMapping(path="/organization") // This means URL's start with /demo (after Application path)
public class OrgController {
@Autowired // This means to get the bean called userRepository
// Which is auto-generated by Spring, we will use it to handle the data
private OrgRepository orgRepository;
@PostMapping(path = "/add") // Map ONLY POST Requests
@ResponseBody
public Organization addJsonOrg(@RequestBody Organization org) {
// @ResponseBody means the returned String is the response, not a view name
// @RequestParam means it is a parameter from the GET or POST request
orgRepository.save(org);
return org;
}
@GetMapping(path="/all")
public @ResponseBody Iterable<Organization> getAllOrgs() {
// This returns a JSON or XML with the users
return orgRepository.findAll();
}
}
package com.example.accessingdatamysql;
import org.springframework.data.repository.CrudRepository;
import com.example.accessingdatamysql.Organization;
// This will be AUTO IMPLEMENTED by Spring into a Bean called userRepository
// CRUD refers Create, Read, Update, Delete
public interface OrgRepository extends CrudRepository<Organization, String> {
}
\ No newline at end of file
package com.example.accessingdatamysql;
import jakarta.persistence.*;
@Entity // This tells Hibernate to make a table out of this class
@Table(name = "ORGANIZATION")
public class Organization {
private String name;
private String email;
private String ownerEmail;
private String desc;
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
public String getOwnerEmail() {
return ownerEmail;
}
public void setOwnerEmail(String ownerEmail) {
this.ownerEmail = ownerEmail;
}
@Id
@Column(nullable = false)
private int orgId;
public int getOrgId() {
return orgId;
}
public void setOrgId(int orgId) {
this.orgId = orgId;
}
}
\ No newline at end of file
package com.example.accessingdatamysql;
import jakarta.persistence.*;
@Entity // This tells Hibernate to make a table out of this class
@Table(name = "REQUEST")
public class Request {
enum Status {
PENDING,
ACCEPTED,
DECLINED
}
enum Type {
JOIN,
ITEM
}
private String userEmail;
private int orgId;
private String desc;
private Status status;
private Type type;
public Status getStatus() {
return status;
}
public void setStatus(Status status) {
this.status = status;
}
public Type getType() {
return type;
}
public void setType(Type type) {
this.type = type;
}
public String getUserEmail() {
return userEmail;
}
public void setUserEmail(String userEmail) {
this.userEmail = userEmail;
}
public int getOrgId() {
return orgId;
}
public void setOrgId(int orgId) {
this.orgId = orgId;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
@Id
@Column(nullable = false)
private int reqId;
public int getReqId() {
return reqId;
}
public void setReqId(int reqId) {
this.reqId = reqId;
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment