diff --git a/src/app/api/post/route.js b/src/app/api/post/route.js index ce171ef3cb19191f4c195133f137d0acb5e1265c..efae2e2ade4c49fb9e92e8adbf59e383502c8ca1 100644 --- a/src/app/api/post/route.js +++ b/src/app/api/post/route.js @@ -4,11 +4,13 @@ import { NextResponse } from 'next/server'; export async function GET() { const post = await prisma.post.findFirst({ select: { + id: true, name: true, applications: { select: { student: { select: { + id: true, name: true } }, @@ -18,6 +20,7 @@ export async function GET() { rating: true, requirement: { select: { + id: true, requirementText: true } } diff --git a/src/app/api/rating/route.js b/src/app/api/rating/route.js new file mode 100644 index 0000000000000000000000000000000000000000..3e7e3ba4be2156cb3ac8e42c374a48efcab44a32 --- /dev/null +++ b/src/app/api/rating/route.js @@ -0,0 +1,20 @@ +import { prisma } from '../../db/client' +import { NextResponse } from 'next/server'; + +export async function PUT(request) { + const body = await request.json() + console.log(body) + await prisma.evidence.update({ + where: { + postID_requirementID_studentID: { + postID: body.postID, + requirementID: body.requirementID, + studentID: body.studentID + } + }, + data: { + rating: body.rating + } + }) + return NextResponse.json({}) +} diff --git a/src/app/recruiterInternship/page.js b/src/app/recruiterInternship/page.js index 34149575fd5d6b0cb27ba7076062e9f60c757cf0..dcd322082ffb400e9faa4751563847f5721fb93c 100644 --- a/src/app/recruiterInternship/page.js +++ b/src/app/recruiterInternship/page.js @@ -101,7 +101,12 @@ class SkillList extends Component { <Accordion.Body> <Card><Card.Body>{skill.evidenceText}</Card.Body></Card> <Card className="ratingCard"><Card.Body style={{ alignSelf: "flex-end" }}> - <StarRating initialRating={skill.rating}/> + <StarRating + initialRating={skill.rating} + postID={this.props.post.id} + studentID={this.props.post.applications[this.props.selectedApplicant].student.id} + requirementID={skill.requirement.id} + /> </Card.Body></Card> </Accordion.Body> </Accordion.Item> @@ -113,9 +118,23 @@ class SkillList extends Component { } } -const StarRating = ({ initialRating }) => { +const StarRating = ({ initialRating, studentID, postID, requirementID }) => { const [rating, setRating] = useState(initialRating); const [hover, setHover] = useState(0); + + const selectRating = (n) => { + setRating(n); + fetch('/api/rating', { + method: 'PUT', + body: JSON.stringify({ + studentID: studentID, + postID: postID, + requirementID: requirementID, + rating: n + }) + }); + } + return ( <div className="star-rating"> {[...Array(5)].map((_, index) => { @@ -124,10 +143,9 @@ const StarRating = ({ initialRating }) => { type="button" key={index + 1} className={index + 1 <= (hover || rating) ? starStyle.on : starStyle.off} - onClick={() => setRating(index + 1)} + onClick={() => selectRating(index + 1)} onMouseEnter={() => setHover(index + 1)} onMouseLeave={() => setHover(rating)} - onDoubleClick={() => {setRating(0); setHover(0);}} > <span className="star">★</span> </button>