Skip to content
This repository has been archived by the owner on Apr 21, 2024. It is now read-only.

Commit

Permalink
feat: add comments column to club_member
Browse files Browse the repository at this point in the history
  • Loading branch information
GetPsyched committed Sep 27, 2023
1 parent 54d3941 commit 3cf48ad
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
11 changes: 7 additions & 4 deletions database/queries/club/member.sql
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
-- name: CreateClubMember :exec
INSERT INTO club_member (
club_name, roll_number, position, extra_groups
club_name, roll_number, position, extra_groups, comments
)
VALUES (
(SELECT c.name FROM club AS c WHERE c.name = @club_name_or_alias OR c.alias = @club_name_or_alias),
@roll_number,
@position,
@extra_groups
@extra_groups,
@comments
);

-- name: ReadClubMembers :many
Expand All @@ -17,7 +18,8 @@ SELECT
student.batch,
student.email,
club_member.position,
club_member.extra_groups
club_member.extra_groups,
COALESCE(club_member.comments, '')
FROM
student
JOIN club_member ON student.roll_number = club_member.roll_number
Expand All @@ -29,7 +31,8 @@ UPDATE
club_member
SET
position = @position,
extra_groups = @extra_groups
extra_groups = @extra_groups,
comments = @comments
WHERE
roll_number = @roll_number
AND club_name = (SELECT c.name FROM club AS c WHERE c.name = @club_name_or_alias OR c.alias = @club_name_or_alias);
Expand Down
1 change: 1 addition & 0 deletions database/schemas/club.sql
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ CREATE TABLE IF NOT EXISTS club_member (
roll_number VARCHAR(9) REFERENCES student(roll_number),
position VARCHAR(32) DEFAULT 'Member' NOT NULL,
extra_groups VARCHAR(32)[] NOT NULL,
comments VARCHAR,
PRIMARY KEY (club_name, roll_number)
);

Expand Down
4 changes: 4 additions & 0 deletions handlers/club.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func CreateClubMember(db *sql.DB) http.HandlerFunc {
RollNumber string `json:"roll_number"`
Position string `json:"position"`
ExtraGroups []string `json:"extra_groups"`
Comments string `json:"comments"`
}

return func(w http.ResponseWriter, r *http.Request) {
Expand All @@ -93,6 +94,7 @@ func CreateClubMember(db *sql.DB) http.HandlerFunc {
RollNumber: clubMember.RollNumber,
Position: clubMember.Position,
ExtraGroups: clubMember.ExtraGroups,
Comments: sql.NullString{String: clubMember.Comments, Valid: true},
}
err := queries.CreateClubMember(ctx, params)
if err != nil {
Expand Down Expand Up @@ -335,6 +337,7 @@ func UpdateClubMember(db *sql.DB) http.HandlerFunc {
RollNumber string `json:"roll_number"`
Position string `json:"position"`
ExtraGroups []string `json:"extra_groups"`
Comments string `json:"comments"`
}

return func(w http.ResponseWriter, r *http.Request) {
Expand All @@ -348,6 +351,7 @@ func UpdateClubMember(db *sql.DB) http.HandlerFunc {
RollNumber: clubMember.RollNumber,
Position: clubMember.Position,
ExtraGroups: clubMember.ExtraGroups,
Comments: sql.NullString{String: clubMember.Comments, Valid: true},
}
err := queries.UpdateClubMember(ctx, params)
if err != nil {
Expand Down

0 comments on commit 3cf48ad

Please sign in to comment.