Skip to content

Commit 1411fbe

Browse files
allow teams to submit their project
1 parent b1920f6 commit 1411fbe

19 files changed

Lines changed: 258 additions & 4 deletions

File tree

app/models/hacker.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def to_label
3333
def team_owner? = owns_team?(team)
3434

3535
def owns_team?(team)
36-
team.id == owned_team&.id
36+
team&.id == owned_team&.id
3737
end
3838

3939
def name

config/locales/en.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,14 @@ en:
3333
hackathon/team_membership:
3434
one: "Team Member"
3535
other: "Team Members"
36+
hackathon/project_submission:
37+
one: "Project"
38+
other: "Projects"
3639
attributes:
3740
hackathon/team:
3841
hacker: "Team Owner"
3942
team_memberships: "Members"
43+
project_submission: "Project"
4044
hackathon/invitation:
4145
team_membership: "Member"
4246
hackathon/health_and_safety:

db/schema.rb

Lines changed: 11 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/admin_dashboard_portal/app/policies/admin_dashboard_portal/hackathon/team_policy.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ def qualify_team?
66
end
77

88
def invite_team?
9-
record.qualified? || record.late_qualified?
9+
record.qualified? && record.project_submission.present?
1010
end
1111

1212
def export_qualified_team_members?
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class Hackathon::ProjectSubmissionsController < Hackathon::ResourceController
2+
end
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Hackathon::ProjectSubmissionDefinition < Hackathon::ResourceDefinition
2+
field :about_project, as: :text,
3+
label: "About the Project",
4+
hint: "Describe your project: What problem does it solve? What features does it have? What makes it special?"
5+
display :about_project, wrapper: {class: "col-span-full"}
6+
7+
field :about_team, as: :text,
8+
label: "About the Team",
9+
hint: "Tell us about your team: What brought you together? What's your story? What did you learn?"
10+
display :about_team, wrapper: {class: "col-span-full"}
11+
end
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
module Hackathon
2+
module Teams
3+
class SubmitProjectInteraction < ResourceInteraction
4+
presents label: "Submit Project", icon: Phlex::TablerIcons::FileText
5+
6+
attribute :resource
7+
8+
attribute :about_project
9+
field :about_project, as: :text,
10+
label: "About the Project",
11+
hint: "Describe your project: What problem does it solve? What features does it have? What makes it special?"
12+
13+
attribute :about_team, as: :text
14+
field :about_team, as: :text,
15+
label: "About the Team",
16+
hint: "Tell us about your team: What brought you together? What's your story? What did you learn?"
17+
18+
private
19+
20+
def execute
21+
project_submission = resource.build_project_submission(
22+
about_project: about_project,
23+
about_team: about_team
24+
)
25+
26+
if project_submission.save
27+
success(resource)
28+
.with_message("Project submission for #{resource.name} has been successfully created!")
29+
else
30+
failed(project_submission.errors)
31+
end
32+
end
33+
end
34+
end
35+
end
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# == Schema Information
2+
#
3+
# Table name: hackathon_project_submissions
4+
#
5+
# id :integer not null, primary key
6+
# about_project :text not null
7+
# about_team :text not null
8+
# created_at :datetime not null
9+
# updated_at :datetime not null
10+
# team_id :integer not null
11+
#
12+
# Indexes
13+
#
14+
# index_hackathon_project_submissions_on_team_id (team_id) UNIQUE
15+
#
16+
# Foreign Keys
17+
#
18+
# team_id (team_id => hackathon_teams.id)
19+
#
20+
require_relative "../hackathon"
21+
22+
class Hackathon::ProjectSubmission < Hackathon::ResourceRecord
23+
# add concerns above.
24+
25+
# add model configurations above.
26+
27+
belongs_to :team
28+
# add belongs_to associations above.
29+
30+
# add has_one associations above.
31+
32+
# add has_many associations above.
33+
34+
# add attachments above.
35+
36+
# add scopes above.
37+
38+
validates :about_project, presence: true
39+
validates :about_team, presence: true
40+
# add validations above.
41+
42+
# add callbacks above.
43+
44+
# add delegations above.
45+
46+
# add misc attribute macros above.
47+
48+
def to_label
49+
"#{team.name} - Project Submission"
50+
end
51+
# add methods above.
52+
end

packages/hackathon/app/models/hackathon/team.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class Hackathon::Team < Hackathon::ResourceRecord
3333
has_many :hackers, through: :team_memberships
3434
has_many :invitations,
3535
class_name: "Hackathon::Invitation", dependent: :destroy
36+
has_one :project_submission, dependent: :destroy
3637

3738
enum :status, unqualified: 0, qualified: 1, late_qualified: 2, invited: 3
3839

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
class Hackathon::ProjectSubmissionPolicy < Hackathon::ResourcePolicy
2+
# Core actions
3+
4+
def create?
5+
true
6+
end
7+
8+
def read?
9+
true
10+
end
11+
12+
# Core attributes
13+
14+
def permitted_attributes_for_create
15+
[:team, :about_project, :about_team]
16+
end
17+
18+
def permitted_attributes_for_read
19+
[:team, :about_project, :about_team]
20+
end
21+
22+
# Associations
23+
24+
def permitted_associations
25+
%i[]
26+
end
27+
end

0 commit comments

Comments
 (0)