Skip to content
Snippets Groups Projects
Commit e497e747 authored by Sarthak Shrivastava's avatar Sarthak Shrivastava
Browse files

changed schema to make OrgRoster strong. Moved files to clean back end.

parent 368f428e
No related branches found
No related tags found
No related merge requests found
......@@ -38,11 +38,13 @@ INSERT INTO ORGANIZATION (name, email, description, owner_email, category, membe
('Political Discussion Group', 'politics@example.com', 'Discussions on current political affairs', 'alicedoe@example.com', 'POLITICS', 25),
('Greek Life Association', 'greeklife@example.com', 'Promoting Greek culture and traditions', 'emilyjohnson@example.com', 'GREEKLIFE', 40);
DROP TABLE ORGANIZATION_ROSTER;
CREATE TABLE IF NOT EXISTS ORGANIZATION_ROSTER (
roster_id INT AUTO_INCREMENT NOT NULL,
user_email VARCHAR(128) NOT NULL,
organization_id INT NOT NULL,
type ENUM('MEMBER', 'MANAGER') NOT NULL,
PRIMARY KEY (user_email, organization_id),
PRIMARY KEY (roster_id),
CONSTRAINT fk_user_manager FOREIGN KEY (user_email) REFERENCES USER (email),
CONSTRAINT fk_organization_manager FOREIGN KEY (organization_id) REFERENCES ORGANIZATION (organization_id)
);
......
package com.example.accessingdatamysql.myorg;
import jakarta.persistence.Entity;
import jakarta.persistence.NamedQuery;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@CrossOrigin
@RestController // This means that this class is a Controller
@RequestMapping(path="/orgauth") // This means URL's start with /orgauth (after Application path)
public class OrgAuth {
// @NamedQuery(
// name="findAllCustomersWithName",
// query="SELECT o FROM Organization o WHERE o.name LIKE :custName"
// )
}
package com.example.accessingdatamysql.myorg;
import org.springframework.data.repository.CrudRepository;
// This will be AUTO IMPLEMENTED by Spring into a Bean called userRepository
// CRUD refers Create, Read, Update, Delete
public interface OrgRosterRepository extends CrudRepository<Organization_Roster, Integer>{
}
package com.example.accessingdatamysql.myorg;
import jakarta.persistence.*;
import java.io.Serializable;
import java.util.Objects;
@Entity
@Table(name="Organization_Roster")
public class Organization_Roster {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Integer rosterId;
private String userEmail;
private Integer organizationId;
public Integer getRosterId() {
return rosterId;
}
public void setRosterId(Integer rosterId) {
this.rosterId = rosterId;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Organization_Roster that = (Organization_Roster) o;
return getRosterId().equals(that.getRosterId()) && userEmail.equals(that.userEmail) && organizationId.equals(that.organizationId) && type == that.type;
}
@Override
public int hashCode() {
return Objects.hash(getRosterId(), userEmail, organizationId, type);
}
public Organization_Roster() {
}
enum Type {
OWNER,
MANAGER,
MEMBER
}
@Enumerated(EnumType.STRING)
private Type type;
}
package com.example.accessingdatamysql;
package com.example.accessingdatamysql.org;
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)
......
package com.example.accessingdatamysql;
package com.example.accessingdatamysql.org;
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> {
public interface OrgRepository extends CrudRepository<Organization, Integer> {
}
\ No newline at end of file
package com.example.accessingdatamysql;
package com.example.accessingdatamysql.org;
import jakarta.persistence.*;
......
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