Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added link to devpost on view judged project page #114

Merged
merged 1 commit into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions client/src/pages/judge/project.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ import Ratings from '../../components/judge/Ratings';

const Project = () => {
const { id } = useParams();
const [project, setProject] = useState<null | JudgedProject>(null);
const [project, setProject] = useState<null | JudgedProjectWithUrl>(null);

useEffect(() => {
async function fetchData() {
const projRes = await getRequest<JudgedProject>(`/judge/project/${id}`, 'judge');
const projRes = await getRequest<JudgedProjectWithUrl>(`/judge/project/${id}`, 'judge');
if (projRes.status !== 200) {
errorAlert(projRes);
return;
}
const proj = projRes.data as JudgedProject;
const proj = projRes.data as JudgedProjectWithUrl;
setProject(proj);
}

Expand All @@ -33,9 +33,27 @@ const Project = () => {
<JuryHeader withLogout />
<Container noCenter={true} className="px-2">
<Back location="/judge" />
<h1 className="text-3xl mb-1">{project.name}</h1>
<h1 className="text-3xl mb-1 font-bold">
<a
href={project.url}
target="_blank"
rel="noopener noreferrer"
className="hover:text-primary duration-200"
>
{project.name}
</a>
</h1>
<h2 className="text-xl font-bold text-light mb-2">Table {project.location}</h2>
<Ratings callback={() => {alert('Ratings submitted!' )}} prior={project.categories} project={project} small submitText="Update" update />
<Ratings
callback={() => {
alert('Ratings submitted!');
}}
prior={project.categories}
project={project}
small
submitText="Update"
update
/>
<Paragraph text={project.description} className="text-light" />
</Container>
</>
Expand Down
4 changes: 4 additions & 0 deletions client/src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ interface JudgedProject {
description: string;
}

type JudgedProjectWithUrl = {
url: string;
} & JudgedProject;

type SortableJudgedProject = {
id: number;
} & JudgedProject;
Expand Down
33 changes: 32 additions & 1 deletion server/router/judge.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,18 +348,49 @@ func GetJudgeProjects(ctx *gin.Context) {
ctx.JSON(http.StatusOK, judge.SeenProjects)
}

type JudgedProjectWithUrl struct {
models.JudgedProject
Url string `bson:"url" json:"url"`
}

func addUrlToJudgedProject(project *models.JudgedProject, url string) *JudgedProjectWithUrl {
return &JudgedProjectWithUrl{
JudgedProject: models.JudgedProject{
ProjectId: project.ProjectId,
Categories: project.Categories,
Name: project.Name,
Location: project.Location,
Description: project.Description,
Notes: project.Notes,
},
Url: url,
}
}

// GET /judge/project/:id - Gets a project that's been judged by ID
func GetJudgedProject(ctx *gin.Context) {
// Get the judge from the context
judge := ctx.MustGet("judge").(*models.Judge)

// Get the database from the context
db := ctx.MustGet("db").(*mongo.Database)

// Get the project ID from the URL
projectId := ctx.Param("id")

// Search through the judge seen projects for the project ID
for _, p := range judge.SeenProjects {
if p.ProjectId.Hex() == projectId {
ctx.JSON(http.StatusOK, p)
// Add URL to judged project
proj, err := database.FindProjectById(db, &p.ProjectId)
if err != nil {
ctx.JSON(http.StatusInternalServerError, gin.H{"error": "error getting project url: " + err.Error()})
return
}
jpWithUrl := addUrlToJudgedProject(&p, proj.Url)

// Parse and send JSON
ctx.JSON(http.StatusOK, jpWithUrl)
return
}
}
Expand Down