Skip to content

Commit af74023

Browse files
2 parents 702c7a4 + f3c5d57 commit af74023

File tree

10 files changed

+249
-280
lines changed

10 files changed

+249
-280
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import graphene
2+
from student.schema import Query as student_query
3+
4+
class Query(student_query):
5+
pass
6+
7+
schema=graphene.Schema(query=Query)

backend/family_tree/family_tree/settings.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
# Application definition
3232

3333
INSTALLED_APPS = [
34+
"student",
3435
"graphene_django",
3536
'django.contrib.admin',
3637
'django.contrib.auth',
@@ -126,5 +127,5 @@
126127
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
127128

128129
GRAPHENE = {
129-
"SCHEMA": "django_root.schema.schema"
130+
"SCHEMA": "family_tree.schema.schema"
130131
}

backend/family_tree/student/admin.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
from django.contrib import admin
22

3-
# Register your models here.
3+
from .models import Student
4+
5+
admin.site.register(Student)

backend/family_tree/student/models.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
11
from django.db import models
22

33
class Student(models.Model):
4-
id= models.CharField(max_length=9)
4+
roll_no= models.CharField(max_length=9)
55
name= models.CharField(max_length=50)
66
branch= models.CharField(max_length=50)
77
year= models.CharField(max_length=4)
88
picture= models.URLField(max_length=200)
99
homeTown= models.CharField(max_length=200)
10+
<<<<<<< HEAD
1011
extraCurriculars= models.CharField(max_length=2000)
1112
socialMedia= models.ForeignKey('SocialMedia')
1213
linkedIn= models.URLField(max_length=200)
1314
email= models.EmailField(max_length=254)
1415
parentId= models.CharField(max_length=9)
16+
=======
17+
extraCurriculars= models.CharField(max_length=400)
18+
socialMedia= models.URLField()
19+
linkedIn= models.URLField(max_length=200)
20+
email= models.EmailField(max_length=254)
21+
parentId= models.CharField(max_length=400)
22+
23+
>>>>>>> f3c5d575314c25efa18736f1f5355e7c052ec9a5
1524

1625
class SocialMedia(models.Model):
1726
facebook = models.URLField(max_length=255)

backend/family_tree/student/schema.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import graphene
2+
from graphene_django import DjangoObjectType
3+
from student.models import Student
4+
5+
class StudentType(DjangoObjectType):
6+
class Meta:
7+
model= Student
8+
fields= ("id","name","branch","year","picture","homeTown","extraCurriculars","socialMedia", "linkedIn","email","parentId","roll_no")
9+
filter_fields=["id","name","branch","year","email","parentId","roll_no"]
10+
11+
class Query(graphene.ObjectType):
12+
students=graphene.List(StudentType)
13+
14+
schema=graphene.Schema(query=Query)

frontend/family_tree/src/App.css

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
display: flex;
55
align-items: center;
66
flex-direction: column;
7-
/* background-image: linear-gradient(90deg, #8820dd, orange); */
87
}
98

109
.help {
@@ -47,4 +46,4 @@
4746
margin-right: 10px;
4847
width: 150px;
4948
height: 170px;
50-
}
49+
}

frontend/family_tree/src/App.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import StudentData from "./Data.json";
77
function App() {
88
return (
99
<div className="App">
10-
<SearchBar placeholder="Enter the Name or Roll Number..." data={StudentData} />
10+
<SearchBar placeholder="Enter the Name or Roll Number..." studentData={StudentData} />
1111
<div className="help">
1212
<Help />
1313
</div>

frontend/family_tree/src/Components/SearchBar.js

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
11
import React, { useState } from "react";
2-
import "./SearchBar.css";
2+
import "../Styles/SearchBar.css";
33
import SearchIcon from "@material-ui/icons/Search";
44
import CloseIcon from "@material-ui/icons/Close"
55

6-
function SearchBar({ placeholder, data }) {
6+
function SearchBar({ placeholder, studentData }) {
77
const [filteredData, setFilteredData] = useState([]);
88
const [wordEntered, setWordEntered] = useState("");
99

1010
const handleFilter = (event) => {
1111
const searchWord = event.target.value;
1212
setWordEntered(searchWord);
13-
const newFilter = data.filter((value) => {
14-
return value.title.toLowerCase().includes(searchWord.toLowerCase());
15-
});
16-
1713
if (searchWord.length < 3) {
1814
setFilteredData([]);
1915
} else {
20-
setFilteredData(newFilter);
16+
const filteredResults = studentData.filter((query) => {
17+
return query.student.name.toLowerCase().includes(searchWord.toLowerCase()) + query.student.id.toLowerCase().includes(searchWord.toLowerCase());
18+
});
19+
setFilteredData(filteredResults);
2120
}
2221
};
2322

24-
const clearInput = () => {
23+
const clearState = () => {
2524
setFilteredData([]);
2625
setWordEntered("");
2726
};
@@ -36,20 +35,18 @@ function SearchBar({ placeholder, data }) {
3635
onChange={handleFilter}
3736
/>
3837
<div className="searchIcon">
39-
{filteredData.length === 0 ? (
38+
{wordEntered.length === 0 ? (
4039
<SearchIcon />
4140
) : (
42-
<CloseIcon id="clearBtn" onClick={clearInput} />
41+
<CloseIcon id="clearBtn" onClick={clearState} />
4342
)}
4443
</div>
4544
</div>
46-
{filteredData.length != 0 && (
45+
{filteredData.length !== 0 && (
4746
<div className="dataResult">
48-
{filteredData.slice(0, 5).map((value, key) => {
47+
{filteredData.slice(0, 5).map((value) => {
4948
return (
50-
<a className="dataItem" href={value.link} target="_blank">
51-
<p>{value.title} </p>
52-
</a>
49+
<p className="dataItem">{`${value.student.name} (${value.student.id})`} </p>
5350
);
5451
})}
5552
</div>

0 commit comments

Comments
 (0)