Skip to content

Commit 6c24d30

Browse files
h1divphieunguyent12AlexanderWangYhugoliu-codeSobaSkee
authored
Create event endpoint and service for core dashboard (#75)
* feat: created event api repo, service, and handler * docs: added /event route to openapi.yml * feat: added more checks for CreateEvent * fix: corrected error message * removed extraneous code * feat: added GetEventById * feat: added update route. various fixes and refactored UpdateEventById SQL queries * feat: added generic badge component, event badge component, and icon wrapper (#39) * feat: added generic badge component, event badge component, and icon wrapper * fix: updated darkmode colors and fixed incorrect icon colors * fix: small tweaks over rendering icons and eslint mutes * feat: added unplugin-icons and replaced old icons * fix: updated badge border property and storybook badge menu --------- Co-authored-by: AlexanderWangY <alexander.yisu.wang@outlook.com> * fix: removed mounting empty node_modules in docker compose file (#41) * feat: added swagger ui renderer plugin * refactor: changed referance to link to other site that renders api docs * TECH-107: Add mailing list (#40) * Sqlc code and goose * Added mailing list functionality * ref: change to event interest submissions * fix: move to pgconn for error handling * fix: change to satisfy linter --------- Co-authored-by: Alexander Wang <alexander.yisu.wang@outlook.com> * Fix/discord pfp (#56) * fix: parse discord pfp and save as avatar or default * fix: change default from svg to png * fix: fix non nestable workflows * fix: allow go sum for build (#57) * Stanley/basic bot structure (#59) * chore(env): setup development and production python venvs * feat: add message trigger command for bot * Create readme.md (#3) * chore: complete merge conflict and rebase * chore: rewrite readme * feat: add regex to identify potential scam/spam messages in antiSpam cog * refactor: organize and break up functions, add detailed comments, add remove role command * refactor: include direction in readme to select interpreter and add any pycache or venvs file types to gitignore * feat: create panel command and reusable buttons added * feat: update anti_spam to have new spam detection, add support cog with request features * add mentor role functions and rework ticket panel * feat: implement round-robin for pinging available mentors * feat: make threads archived, add limits to user inputs, clear selection options * feat: add mod command to grant user access to private vcs --------- Co-authored-by: Stanley <kestanley101@gmail.com> Co-authored-by: Phoenix <71522316+h1divp@users.noreply.github.com> Co-authored-by: Stanley Ke <stanleyke@Mac.lan> * feat: added event card (#58) * feat: added event card * fix: full round + more padding * fix: updated buttons for accepted status and event details links * fix: used Link from react-aria-component instead --------- Co-authored-by: Alexander Wang <alexander.yisu.wang@outlook.com> * feat: swamphacks infra files (#61) Co-authored-by: Alex Wang <alexander.wang@vobileinc.com> * fix: add more build images (#62) * Fix/multi platform build (#63) * fix: add more build images * feat: manual workflows * feat: new deployment for prod server (#64) * hotfix: fix script to indented * fix goose migraitons hotfix * feat: dev deployment (#65) * Feat/dev deployment api (#66) * feat: dev deployment * fix: add the rigth deployment names * hotfix: dev api * Merge and fastforward timeline (#68) * feat: dev deployment (#65) * Feat/dev deployment api (#66) * feat: dev deployment * fix: add the rigth deployment names * hotfix: dev api * Admin dashboard links (#69) * feat: added admin links * fix: make the link only appear on superuser status * Speedup git history and merge master to dev (#71) * fix: makefile points to correct env file * docs: added discord dev portal redirect uri instruction * fix: env variable name change * feat: added event object queries * removed newline * feat: added generic badge component, event badge component, and icon wrapper (#39) * feat: added generic badge component, event badge component, and icon wrapper * fix: updated darkmode colors and fixed incorrect icon colors * fix: small tweaks over rendering icons and eslint mutes * feat: added unplugin-icons and replaced old icons * fix: updated badge border property and storybook badge menu --------- Co-authored-by: AlexanderWangY <alexander.yisu.wang@outlook.com> * fix: removed mounting empty node_modules in docker compose file (#41) * feat: added openapi-typescript for type gen (#42) * feat: new pr template (#43) * ref: change openapi yaml from swagger.yaml to core-api.yaml (#44) * release: add versioning and random yaml file?? (#45) * docs: added more installation procedures * feat: added swagger ui renderer plugin * improvement: improved even queries * chore: sqlc generation * improvement: update template jira link * Add hyphen * refactor: changed referance to link to other site that renders api docs * feat: added event card button component (#49) * feat: added event card button component * feat: added hover state to buttons * fix: added className prop to event button * fix: muted fast refresh eslint * style: removed camelcase in css files * ref: change from loop to filter and map for storybook options --------- Co-authored-by: Alexander Wang <alexander.yisu.wang@outlook.com> * TECH-125: Create Application Schema (#36) * Created Goose Migration for Applications * sqlc generate * improvement: updated fields * fix: updated env path * fix: syntax * chore: sqlc generate * feat: add more columns and auto updates + withdrawn status * chore: generate sqlc types for new schema * feat: indexes and default for application body --------- Co-authored-by: h1divp <71522316+h1divp@users.noreply.github.com> Co-authored-by: Alexander Wang <alexander.yisu.wang@outlook.com> * TECH-107: Add mailing list (#40) * Sqlc code and goose * Added mailing list functionality * ref: change to event interest submissions * fix: move to pgconn for error handling * fix: change to satisfy linter --------- Co-authored-by: Alexander Wang <alexander.yisu.wang@outlook.com> * docs(swagger): updated swagger and regenerated web types for event interest (#50) * Navlink component and some page scaffolding (#51) * feat: navlink component and storyboard * feat: expandable links! * feat: polished navlink component * chore: removed unused colors and replaced colors --------- Co-authored-by: Alex Wang <alexander.wang@vobileinc.com> * [TECH 113] Navbar + Appshell beta (#52) * feat: navlink component and storyboard * feat: expandable links! * feat: polished navlink component * chore: removed unused colors and replaced colors * feat: mobile nav + Appshell * chore: clean up unused comments --------- Co-authored-by: Alex Wang <alexander.wang@vobileinc.com> * feat: admin and event page setup (#53) * Granulate CI/CD and only run on necessary files (#54) * fix: add dorny paths filter to only run on changed files * fix: added domain specific github actions * feat: Dockerfile and workflow for building and pushing to GHCR (#55) * fix: got rid of extra params * fix: syntax * feat: application queries * chore: sqlc generate * Fix: apps can now run * docs: db testing * TECH-107: Add mailing list (#40) * Sqlc code and goose * Added mailing list functionality * ref: change to event interest submissions * fix: move to pgconn for error handling * fix: change to satisfy linter --------- Co-authored-by: Alexander Wang <alexander.yisu.wang@outlook.com> * Fix/discord pfp (#56) * fix: parse discord pfp and save as avatar or default * fix: change default from svg to png * fix: fix non nestable workflows * fix: allow go sum for build (#57) * Stanley/basic bot structure (#59) * chore(env): setup development and production python venvs * feat: add message trigger command for bot * Create readme.md (#3) * chore: complete merge conflict and rebase * chore: rewrite readme * feat: add regex to identify potential scam/spam messages in antiSpam cog * refactor: organize and break up functions, add detailed comments, add remove role command * refactor: include direction in readme to select interpreter and add any pycache or venvs file types to gitignore * feat: create panel command and reusable buttons added * feat: update anti_spam to have new spam detection, add support cog with request features * add mentor role functions and rework ticket panel * feat: implement round-robin for pinging available mentors * feat: make threads archived, add limits to user inputs, clear selection options * feat: add mod command to grant user access to private vcs --------- Co-authored-by: Stanley <kestanley101@gmail.com> Co-authored-by: Phoenix <71522316+h1divp@users.noreply.github.com> Co-authored-by: Stanley Ke <stanleyke@Mac.lan> * feat: added event card (#58) * feat: added event card * fix: full round + more padding * fix: updated buttons for accepted status and event details links * fix: used Link from react-aria-component instead --------- Co-authored-by: Alexander Wang <alexander.yisu.wang@outlook.com> * feat: swamphacks infra files (#61) Co-authored-by: Alex Wang <alexander.wang@vobileinc.com> * fix: add more build images (#62) * Fix/multi platform build (#63) * fix: add more build images * feat: manual workflows * feat: new deployment for prod server (#64) * hotfix: fix script to indented * fix goose migraitons hotfix * feat: dev deployment (#65) * Feat/dev deployment api (#66) * feat: dev deployment * fix: add the rigth deployment names * hotfix: dev api * Merge and fastforward timeline (#68) * feat: dev deployment (#65) * Feat/dev deployment api (#66) * feat: dev deployment * fix: add the rigth deployment names * hotfix: dev api * Refactor: made UpdateEvent sql easier to use, renamed query. Fix: removed GetEventByLocation * feat: added saved_at param and added to UpdateEventById * chore: make generate * Revert "TECH-123: Create sql query to fetch event, user, and application information" --------- Co-authored-by: h1divp <71522316+h1divp@users.noreply.github.com> Co-authored-by: Hieu Nguyen <76720778+hieunguyent12@users.noreply.github.com> Co-authored-by: Hugo Liu <98724522+hugoliu-code@users.noreply.github.com> Co-authored-by: Alex Wang <alexander.wang@vobileinc.com> Co-authored-by: Stanley <kestanley101@gmail.com> Co-authored-by: Stanley Ke <stanleyke@Mac.lan> * Create sql query to fetch event, user, and application information (#73) * fix: makefile points to correct env file * docs: added discord dev portal redirect uri instruction * fix: env variable name change * feat: added event object queries * removed newline * feat: added generic badge component, event badge component, and icon wrapper (#39) * feat: added generic badge component, event badge component, and icon wrapper * fix: updated darkmode colors and fixed incorrect icon colors * fix: small tweaks over rendering icons and eslint mutes * feat: added unplugin-icons and replaced old icons * fix: updated badge border property and storybook badge menu --------- Co-authored-by: AlexanderWangY <alexander.yisu.wang@outlook.com> * fix: removed mounting empty node_modules in docker compose file (#41) * feat: added openapi-typescript for type gen (#42) * feat: new pr template (#43) * ref: change openapi yaml from swagger.yaml to core-api.yaml (#44) * release: add versioning and random yaml file?? (#45) * docs: added more installation procedures * feat: added swagger ui renderer plugin * improvement: improved even queries * chore: sqlc generation * improvement: update template jira link * Add hyphen * refactor: changed referance to link to other site that renders api docs * feat: added event card button component (#49) * feat: added event card button component * feat: added hover state to buttons * fix: added className prop to event button * fix: muted fast refresh eslint * style: removed camelcase in css files * ref: change from loop to filter and map for storybook options --------- Co-authored-by: Alexander Wang <alexander.yisu.wang@outlook.com> * TECH-125: Create Application Schema (#36) * Created Goose Migration for Applications * sqlc generate * improvement: updated fields * fix: updated env path * fix: syntax * chore: sqlc generate * feat: add more columns and auto updates + withdrawn status * chore: generate sqlc types for new schema * feat: indexes and default for application body --------- Co-authored-by: h1divp <71522316+h1divp@users.noreply.github.com> Co-authored-by: Alexander Wang <alexander.yisu.wang@outlook.com> * TECH-107: Add mailing list (#40) * Sqlc code and goose * Added mailing list functionality * ref: change to event interest submissions * fix: move to pgconn for error handling * fix: change to satisfy linter --------- Co-authored-by: Alexander Wang <alexander.yisu.wang@outlook.com> * docs(swagger): updated swagger and regenerated web types for event interest (#50) * Navlink component and some page scaffolding (#51) * feat: navlink component and storyboard * feat: expandable links! * feat: polished navlink component * chore: removed unused colors and replaced colors --------- Co-authored-by: Alex Wang <alexander.wang@vobileinc.com> * [TECH 113] Navbar + Appshell beta (#52) * feat: navlink component and storyboard * feat: expandable links! * feat: polished navlink component * chore: removed unused colors and replaced colors * feat: mobile nav + Appshell * chore: clean up unused comments --------- Co-authored-by: Alex Wang <alexander.wang@vobileinc.com> * feat: admin and event page setup (#53) * Granulate CI/CD and only run on necessary files (#54) * fix: add dorny paths filter to only run on changed files * fix: added domain specific github actions * feat: Dockerfile and workflow for building and pushing to GHCR (#55) * fix: got rid of extra params * fix: syntax * feat: application queries * chore: sqlc generate * Fix: apps can now run * docs: db testing * TECH-107: Add mailing list (#40) * Sqlc code and goose * Added mailing list functionality * ref: change to event interest submissions * fix: move to pgconn for error handling * fix: change to satisfy linter --------- Co-authored-by: Alexander Wang <alexander.yisu.wang@outlook.com> * Fix/discord pfp (#56) * fix: parse discord pfp and save as avatar or default * fix: change default from svg to png * fix: fix non nestable workflows * fix: allow go sum for build (#57) * Stanley/basic bot structure (#59) * chore(env): setup development and production python venvs * feat: add message trigger command for bot * Create readme.md (#3) * chore: complete merge conflict and rebase * chore: rewrite readme * feat: add regex to identify potential scam/spam messages in antiSpam cog * refactor: organize and break up functions, add detailed comments, add remove role command * refactor: include direction in readme to select interpreter and add any pycache or venvs file types to gitignore * feat: create panel command and reusable buttons added * feat: update anti_spam to have new spam detection, add support cog with request features * add mentor role functions and rework ticket panel * feat: implement round-robin for pinging available mentors * feat: make threads archived, add limits to user inputs, clear selection options * feat: add mod command to grant user access to private vcs --------- Co-authored-by: Stanley <kestanley101@gmail.com> Co-authored-by: Phoenix <71522316+h1divp@users.noreply.github.com> Co-authored-by: Stanley Ke <stanleyke@Mac.lan> * feat: added event card (#58) * feat: added event card * fix: full round + more padding * fix: updated buttons for accepted status and event details links * fix: used Link from react-aria-component instead --------- Co-authored-by: Alexander Wang <alexander.yisu.wang@outlook.com> * feat: swamphacks infra files (#61) Co-authored-by: Alex Wang <alexander.wang@vobileinc.com> * fix: add more build images (#62) * Fix/multi platform build (#63) * fix: add more build images * feat: manual workflows * feat: new deployment for prod server (#64) * hotfix: fix script to indented * fix goose migraitons hotfix * feat: dev deployment (#65) * Feat/dev deployment api (#66) * feat: dev deployment * fix: add the rigth deployment names * hotfix: dev api * Merge and fastforward timeline (#68) * feat: dev deployment (#65) * Feat/dev deployment api (#66) * feat: dev deployment * fix: add the rigth deployment names * hotfix: dev api * Refactor: made UpdateEvent sql easier to use, renamed query. Fix: removed GetEventByLocation * feat: added saved_at param and added to UpdateEventById * chore: make generate --------- Co-authored-by: Hieu Nguyen <76720778+hieunguyent12@users.noreply.github.com> Co-authored-by: AlexanderWangY <alexander.yisu.wang@outlook.com> Co-authored-by: Alexander Wang <98280966+AlexanderWangY@users.noreply.github.com> Co-authored-by: Hugo Liu <98724522+hugoliu-code@users.noreply.github.com> Co-authored-by: Alex Wang <alexander.wang@vobileinc.com> Co-authored-by: Stanley <kestanley101@gmail.com> Co-authored-by: Stanley Ke <stanleyke@Mac.lan> * feat: dev deployment (#65) * Feat/dev deployment api (#66) * feat: dev deployment * fix: add the rigth deployment names * Merge and fastforward timeline (#68) * feat: dev deployment (#65) * Feat/dev deployment api (#66) * feat: dev deployment * fix: add the rigth deployment names * hotfix: dev api * Refactor: made UpdateEvent sql easier to use, renamed query. Fix: removed GetEventByLocation * Revert "TECH-123: Create sql query to fetch event, user, and application information" * fastforward git history and changes (#74) * Admin dashboard links (#69) * feat: added admin links * fix: make the link only appear on superuser status * Speedup git history and merge master to dev (#71) * fix: makefile points to correct env file * docs: added discord dev portal redirect uri instruction * fix: env variable name change * feat: added event object queries * removed newline * feat: added generic badge component, event badge component, and icon wrapper (#39) * feat: added generic badge component, event badge component, and icon wrapper * fix: updated darkmode colors and fixed incorrect icon colors * fix: small tweaks over rendering icons and eslint mutes * feat: added unplugin-icons and replaced old icons * fix: updated badge border property and storybook badge menu --------- Co-authored-by: AlexanderWangY <alexander.yisu.wang@outlook.com> * fix: removed mounting empty node_modules in docker compose file (#41) * feat: added openapi-typescript for type gen (#42) * feat: new pr template (#43) * ref: change openapi yaml from swagger.yaml to core-api.yaml (#44) * release: add versioning and random yaml file?? (#45) * docs: added more installation procedures * feat: added swagger ui renderer plugin * improvement: improved even queries * chore: sqlc generation * improvement: update template jira link * Add hyphen * refactor: changed referance to link to other site that renders api docs * feat: added event card button component (#49) * feat: added event card button component * feat: added hover state to buttons * fix: added className prop to event button * fix: muted fast refresh eslint * style: removed camelcase in css files * ref: change from loop to filter and map for storybook options --------- Co-authored-by: Alexander Wang <alexander.yisu.wang@outlook.com> * TECH-125: Create Application Schema (#36) * Created Goose Migration for Applications * sqlc generate * improvement: updated fields * fix: updated env path * fix: syntax * chore: sqlc generate * feat: add more columns and auto updates + withdrawn status * chore: generate sqlc types for new schema * feat: indexes and default for application body --------- Co-authored-by: h1divp <71522316+h1divp@users.noreply.github.com> Co-authored-by: Alexander Wang <alexander.yisu.wang@outlook.com> * TECH-107: Add mailing list (#40) * Sqlc code and goose * Added mailing list functionality * ref: change to event interest submissions * fix: move to pgconn for error handling * fix: change to satisfy linter --------- Co-authored-by: Alexander Wang <alexander.yisu.wang@outlook.com> * docs(swagger): updated swagger and regenerated web types for event interest (#50) * Navlink component and some page scaffolding (#51) * feat: navlink component and storyboard * feat: expandable links! * feat: polished navlink component * chore: removed unused colors and replaced colors --------- Co-authored-by: Alex Wang <alexander.wang@vobileinc.com> * [TECH 113] Navbar + Appshell beta (#52) * feat: navlink component and storyboard * feat: expandable links! * feat: polished navlink component * chore: removed unused colors and replaced colors * feat: mobile nav + Appshell * chore: clean up unused comments --------- Co-authored-by: Alex Wang <alexander.wang@vobileinc.com> * feat: admin and event page setup (#53) * Granulate CI/CD and only run on necessary files (#54) * fix: add dorny paths filter to only run on changed files * fix: added domain specific github actions * feat: Dockerfile and workflow for building and pushing to GHCR (#55) * fix: got rid of extra params * fix: syntax * feat: application queries * chore: sqlc generate * Fix: apps can now run * docs: db testing * TECH-107: Add mailing list (#40) * Sqlc code and goose * Added mailing list functionality * ref: change to event interest submissions * fix: move to pgconn for error handling * fix: change to satisfy linter --------- Co-authored-by: Alexander Wang <alexander.yisu.wang@outlook.com> * Fix/discord pfp (#56) * fix: parse discord pfp and save as avatar or default * fix: change default from svg to png * fix: fix non nestable workflows * fix: allow go sum for build (#57) * Stanley/basic bot structure (#59) * chore(env): setup development and production python venvs * feat: add message trigger command for bot * Create readme.md (#3) * chore: complete merge conflict and rebase * chore: rewrite readme * feat: add regex to identify potential scam/spam messages in antiSpam cog * refactor: organize and break up functions, add detailed comments, add remove role command * refactor: include direction in readme to select interpreter and add any pycache or venvs file types to gitignore * feat: create panel command and reusable buttons added * feat: update anti_spam to have new spam detection, add support cog with request features * add mentor role functions and rework ticket panel * feat: implement round-robin for pinging available mentors * feat: make threads archived, add limits to user inputs, clear selection options * feat: add mod command to grant user access to private vcs --------- Co-authored-by: Stanley <kestanley101@gmail.com> Co-authored-by: Phoenix <71522316+h1divp@users.noreply.github.com> Co-authored-by: Stanley Ke <stanleyke@Mac.lan> * feat: added event card (#58) * feat: added event card * fix: full round + more padding * fix: updated buttons for accepted status and event details links * fix: used Link from react-aria-component instead --------- Co-authored-by: Alexander Wang <alexander.yisu.wang@outlook.com> * feat: swamphacks infra files (#61) Co-authored-by: Alex Wang <alexander.wang@vobileinc.com> * fix: add more build images (#62) * Fix/multi platform build (#63) * fix: add more build images * feat: manual workflows * feat: new deployment for prod server (#64) * hotfix: fix script to indented * fix goose migraitons hotfix * feat: dev deployment (#65) * Feat/dev deployment api (#66) * feat: dev deployment * fix: add the rigth deployment names * hotfix: dev api * Merge and fastforward timeline (#68) * feat: dev deployment (#65) * Feat/dev deployment api (#66) * feat: dev deployment * fix: add the rigth deployment names * hotfix: dev api * Refactor: made UpdateEvent sql easier to use, renamed query. Fix: removed GetEventByLocation * feat: added saved_at param and added to UpdateEventById * chore: make generate * Revert "TECH-123: Create sql query to fetch event, user, and application information" --------- Co-authored-by: h1divp <71522316+h1divp@users.noreply.github.com> Co-authored-by: Hieu Nguyen <76720778+hieunguyent12@users.noreply.github.com> Co-authored-by: Hugo Liu <98724522+hugoliu-code@users.noreply.github.com> Co-authored-by: Alex Wang <alexander.wang@vobileinc.com> Co-authored-by: Stanley <kestanley101@gmail.com> Co-authored-by: Stanley Ke <stanleyke@Mac.lan> * Create sql query to fetch event, user, and application information (#73) * fix: makefile points to correct env file * docs: added discord dev portal redirect uri instruction * fix: env variable name change * feat: added event object queries * removed newline * feat: added generic badge component, event badge component, and icon wrapper (#39) * feat: added generic badge component, event badge component, and icon wrapper * fix: updated darkmode colors and fixed incorrect icon colors * fix: small tweaks over rendering icons and eslint mutes * feat: added unplugin-icons and replaced old icons * fix: updated badge border property and storybook badge menu --------- Co-authored-by: AlexanderWangY <alexander.yisu.wang@outlook.com> * fix: removed mounting empty node_modules in docker compose file (#41) * feat: added openapi-typescript for type gen (#42) * feat: new pr template (#43) * ref: change openapi yaml from swagger.yaml to core-api.yaml (#44) * release: add versioning and random yaml file?? (#45) * docs: added more installation procedures * feat: added swagger ui renderer plugin * improvement: improved even queries * chore: sqlc generation * improvement: update template jira link * Add hyphen * refactor: changed referance to link to other site that renders api docs * feat: added event card button component (#49) * feat: added event card button component * feat: added hover state to buttons * fix: added className prop to event button * fix: muted fast refresh eslint * style: removed camelcase in css files * ref: change from loop to filter and map for storybook options --------- Co-authored-by: Alexander Wang <alexander.yisu.wang@outlook.com> * TECH-125: Create Application Schema (#36) * Created Goose Migration for Applications * sqlc generate * improvement: updated fields * fix: updated env path * fix: syntax * chore: sqlc generate * feat: add more columns and auto updates + withdrawn status * chore: generate sqlc types for new schema * feat: indexes and default for application body --------- Co-authored-by: h1divp <71522316+h1divp@users.noreply.github.com> Co-authored-by: Alexander Wang <alexander.yisu.wang@outlook.com> * TECH-107: Add mailing list (#40) * Sqlc code and goose * Added mailing list functionality * ref: change to event interest submissions * fix: move to pgconn for error handling * fix: change to satisfy linter --------- Co-authored-by: Alexander Wang <alexander.yisu.wang@outlook.com> * docs(swagger): updated swagger and regenerated web types for event interest (#50) * Navlink component and some page scaffolding (#51) * feat: navlink component and storyboard * feat: expandable links! * feat: polished navlink component * chore: removed unused colors and replaced colors --------- Co-authored-by: Alex Wang <alexander.wang@vobileinc.com> * [TECH 113] Navbar + Appshell beta (#52) * feat: navlink component and storyboard * feat: expandable links! * feat: polished navlink component * chore: removed unused colors and replaced colors * feat: mobile nav + Appshell * chore: clean up unused comments --------- Co-authored-by: Alex Wang <alexander.wang@vobileinc.com> * feat: admin and event page setup (#53) * Granulate CI/CD and only run on necessary files (#54) * fix: add dorny paths filter to only run on changed files * fix: added domain specific github actions * feat: Dockerfile and workflow for building and pushing to GHCR (#55) * fix: got rid of extra params * fix: syntax * feat: application queries * chore: sqlc generate * Fix: apps can now run * docs: db testing * TECH-107: Add mailing list (#40) * Sqlc code and goose * Added mailing list functionality * ref: change to event interest submissions * fix: move to pgconn for error handling * fix: change to satisfy linter --------- Co-authored-by: Alexander Wang <alexander.yisu.wang@outlook.com> * Fix/discord pfp (#56) * fix: parse discord pfp and save as avatar or default * fix: change default from svg to png * fix: fix non nestable workflows * fix: allow go sum for build (#57) * Stanley/basic bot structure (#59) * chore(env): setup development and production python venvs * feat: add message trigger command for bot * Create readme.md (#3) * chore: complete merge conflict and rebase * chore: rewrite readme * feat: add regex to identify potential scam/spam messages in antiSpam cog * refactor: organize and break up functions, add detailed comments, add remove role command * refactor: include direction in readme to select interpreter and add any pycache or venvs file types to gitignore * feat: create panel command and reusable buttons added * feat: update anti_spam to have new spam detection, add support cog with request features * add mentor role functions and rework ticket panel * feat: implement round-robin for pinging available mentors * feat: make threads archived, add limits to user inputs, clear selection options * feat: add mod command to grant user access to private vcs --------- Co-authored-by: Stanley <kestanley101@gmail.com> Co-authored-by: Phoenix <71522316+h1divp@users.noreply.github.com> Co-authored-by: Stanley Ke <stanleyke@Mac.lan> * feat: added event card (#58) * feat: added event card * fix: full round + more padding * fix: updated buttons for accepted status and event details links * fix: used Link from react-aria-component instead --------- Co-authored-by: Alexander Wang <alexander.yisu.wang@outlook.com> * feat: swamphacks infra files (#61) Co-authored-by: Alex Wang <alexander.wang@vobileinc.com> * fix: add more build images (#62) * Fix/multi platform build (#63) * fix: add more build images * feat: manual workflows * feat: new deployment for prod server (#64) * hotfix: fix script to indented * fix goose migraitons hotfix * feat: dev deployment (#65) * Feat/dev deployment api (#66) * feat: dev deployment * fix: add the rigth deployment names * hotfix: dev api * Merge and fastforward timeline (#68) * feat: dev deployment (#65) * Feat/dev deployment api (#66) * feat: dev deployment * fix: add the rigth deployment names * hotfix: dev api * Refactor: made UpdateEvent sql easier to use, renamed query. Fix: removed GetEventByLocation * feat: added saved_at param and added to UpdateEventById * chore: make generate --------- Co-authored-by: Hieu Nguyen <76720778+hieunguyent12@users.noreply.github.com> Co-authored-by: AlexanderWangY <alexander.yisu.wang@outlook.com> Co-authored-by: Alexander Wang <98280966+AlexanderWangY@users.noreply.github.com> Co-authored-by: Hugo Liu <98724522+hugoliu-code@users.noreply.github.com> Co-authored-by: Alex Wang <alexander.wang@vobileinc.com> Co-authored-by: Stanley <kestanley101@gmail.com> Co-authored-by: Stanley Ke <stanleyke@Mac.lan> --------- Co-authored-by: h1divp <71522316+h1divp@users.noreply.github.com> Co-authored-by: Hieu Nguyen <76720778+hieunguyent12@users.noreply.github.com> Co-authored-by: Hugo Liu <98724522+hugoliu-code@users.noreply.github.com> Co-authored-by: Alex Wang <alexander.wang@vobileinc.com> Co-authored-by: Stanley <kestanley101@gmail.com> Co-authored-by: Stanley Ke <stanleyke@Mac.lan> * fix: fixing rebase * feat: added delete route * feat: added better validation for missing/empty parameters * feat: progress in optional fields for CreateEvent * Fix: prevent SQL query default values being controlled by struct in handler * Fix: fixed default values being overridden by NULL in insert query * chore: updated comment * Feat: error throws when no events are deleted after a delete request * docs: updated openapi documentation * Fix: fixed error handling flow, events not being returned to client, wrong http status codes * Fix: protected routes * Refactor: moved time validation functions * Refactor: replaced required field function by using validator library * Fix: update query optional parameters now support null values * Feat: added middleware for checking user event role * Fix: RequireEventRole middleware now works * Chore: go mod tidy * Improvement: allow RequireRole middleware to take slices * Improvement: allow superusers whenever when any role is required --------- Co-authored-by: Hieu Nguyen <76720778+hieunguyent12@users.noreply.github.com> Co-authored-by: AlexanderWangY <alexander.yisu.wang@outlook.com> Co-authored-by: Alexander Wang <98280966+AlexanderWangY@users.noreply.github.com> Co-authored-by: Hugo Liu <98724522+hugoliu-code@users.noreply.github.com> Co-authored-by: Stanley <kestanley101@gmail.com> Co-authored-by: Stanley Ke <stanleyke@Mac.lan> Co-authored-by: Alex Wang <alexander.wang@vobileinc.com>
1 parent c3a8d65 commit 6c24d30

19 files changed

Lines changed: 936 additions & 238 deletions

File tree

apps/api/cmd/api/main.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,16 @@ func main() {
5454
accountRepo := repository.NewAccountRespository(database)
5555
sessionRepo := repository.NewSessionRepository(database)
5656
eventInterestRepo := repository.NewEventInterestRepository(database)
57+
eventRepo := repository.NewEventRespository(database)
5758

5859
// Injections into services
5960
authService := services.NewAuthService(userRepo, accountRepo, sessionRepo, txm, client, logger, &cfg.Auth)
6061
eventInterestService := services.NewEventInterestService(eventInterestRepo, logger)
62+
eventService := services.NewEventService(eventRepo, logger)
6163
emailService := services.NewEmailService(taskQueueClient, logger)
6264

6365
// Injections into handlers
64-
apiHandlers := handlers.NewHandlers(authService, eventInterestService, emailService, cfg, logger)
66+
apiHandlers := handlers.NewHandlers(authService, eventInterestService, eventService, emailService, cfg, logger)
6567

6668
api := api.NewAPI(&logger, apiHandlers, mw)
6769

apps/api/go.mod

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ require (
66
github.com/caarlos0/env/v11 v11.3.1
77
github.com/go-chi/chi/v5 v5.2.2
88
github.com/go-chi/cors v1.2.1
9+
github.com/go-playground/validator/v10 v10.27.0
910
github.com/google/uuid v1.6.0
1011
github.com/hibiken/asynq v0.25.1
1112
github.com/jackc/pgx/v5 v5.7.4
@@ -16,16 +17,21 @@ require (
1617
require (
1718
github.com/cespare/xxhash/v2 v2.2.0 // indirect
1819
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
20+
github.com/gabriel-vasile/mimetype v1.4.8 // indirect
21+
github.com/go-playground/locales v0.14.1 // indirect
22+
github.com/go-playground/universal-translator v0.18.1 // indirect
1923
github.com/jackc/pgpassfile v1.0.0 // indirect
2024
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
2125
github.com/jackc/puddle/v2 v2.2.2 // indirect
26+
github.com/leodido/go-urn v1.4.0 // indirect
2227
github.com/mattn/go-colorable v0.1.13 // indirect
2328
github.com/mattn/go-isatty v0.0.19 // indirect
2429
github.com/redis/go-redis/v9 v9.7.0 // indirect
2530
github.com/robfig/cron/v3 v3.0.1 // indirect
2631
github.com/spf13/cast v1.7.0 // indirect
2732
github.com/stretchr/testify v1.10.0 // indirect
2833
golang.org/x/crypto v0.38.0 // indirect
34+
golang.org/x/net v0.34.0 // indirect
2935
golang.org/x/sync v0.14.0 // indirect
3036
golang.org/x/sys v0.34.0 // indirect
3137
golang.org/x/text v0.25.0 // indirect

apps/api/go.sum

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,20 @@ github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/r
1414
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
1515
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
1616
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
17+
github.com/gabriel-vasile/mimetype v1.4.8 h1:FfZ3gj38NjllZIeJAmMhr+qKL8Wu+nOoI3GqacKw1NM=
18+
github.com/gabriel-vasile/mimetype v1.4.8/go.mod h1:ByKUIKGjh1ODkGM1asKUbQZOLGrPjydw3hYPU2YU9t8=
1719
github.com/go-chi/chi/v5 v5.2.2 h1:CMwsvRVTbXVytCk1Wd72Zy1LAsAh9GxMmSNWLHCG618=
1820
github.com/go-chi/chi/v5 v5.2.2/go.mod h1:L2yAIGWB3H+phAw1NxKwWM+7eUH/lU8pOMm5hHcoops=
1921
github.com/go-chi/cors v1.2.1 h1:xEC8UT3Rlp2QuWNEr4Fs/c2EAGVKBwy/1vHx3bppil4=
2022
github.com/go-chi/cors v1.2.1/go.mod h1:sSbTewc+6wYHBBCW7ytsFSn836hqM7JxpglAy2Vzc58=
23+
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
24+
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
25+
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
26+
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
27+
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
28+
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
29+
github.com/go-playground/validator/v10 v10.27.0 h1:w8+XrWVMhGkxOaaowyKH35gFydVHOvC0/uWoy2Fzwn4=
30+
github.com/go-playground/validator/v10 v10.27.0/go.mod h1:I5QpIEbmr8On7W0TktmJAumgzX4CA1XNl4ZmDuVHKKo=
2131
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
2232
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
2333
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
@@ -39,11 +49,15 @@ github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
3949
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
4050
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
4151
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
52+
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
53+
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
4254
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
4355
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
4456
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
4557
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
4658
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
59+
github.com/oapi-codegen/nullable v1.1.0 h1:eAh8JVc5430VtYVnq00Hrbpag9PFRGWLjxR1/3KntMs=
60+
github.com/oapi-codegen/nullable v1.1.0/go.mod h1:KUZ3vUzkmEKY90ksAmit2+5juDIhIZhfDl+0PwOQlFY=
4761
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
4862
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
4963
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
@@ -67,6 +81,8 @@ go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
6781
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
6882
golang.org/x/crypto v0.38.0 h1:jt+WWG8IZlBnVbomuhg2Mdq0+BBQaHbtqHEFEigjUV8=
6983
golang.org/x/crypto v0.38.0/go.mod h1:MvrbAqul58NNYPKnOra203SB9vpuZW0e+RRZV+Ggqjw=
84+
golang.org/x/net v0.34.0 h1:Mb7Mrk043xzHgnRM88suvJFwzVrRfHEHJEl5/71CKw0=
85+
golang.org/x/net v0.34.0/go.mod h1:di0qlW3YNM5oh6GqDGQr92MyTozJPmybPK4Ev/Gm31k=
7086
golang.org/x/sync v0.14.0 h1:woo0S4Yywslg6hp4eUFjTVOyKt0RookbpAHG4c1HmhQ=
7187
golang.org/x/sync v0.14.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
7288
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=

apps/api/internal/api/api.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ func NewAPI(logger *zerolog.Logger, handlers *handlers.Handlers, middleware *mw.
3434
}
3535

3636
func (api *API) setupRoutes(mw *mw.Middleware) {
37+
38+
var (
39+
// Both requireXXRole functions automatically allow superusers
40+
ensureSuperuser = mw.Auth.RequirePlatformRole([]sqlc.AuthUserRole{sqlc.AuthUserRoleSuperuser})
41+
ensureEventAdmin = mw.Event.RequireEventRole([]sqlc.EventRoleType{sqlc.EventRoleTypeAdmin})
42+
)
43+
3744
api.Router.Use(middleware.Logger)
3845
api.Router.Use(middleware.RealIP)
3946
api.Router.Use(cors.Handler(cors.Options{
@@ -68,7 +75,13 @@ func (api *API) setupRoutes(mw *mw.Middleware) {
6875

6976
// Event routes
7077
api.Router.Route("/event", func(r chi.Router) {
71-
r.Post("/{eventId}/interest", api.Handlers.EventInterest.AddEmailToEvent)
78+
r.With(mw.Auth.RequireAuth, ensureSuperuser).Post("/", api.Handlers.Event.CreateEvent)
79+
r.Route("/{eventId}", func(r chi.Router) {
80+
r.With(mw.Auth.RequireAuth, ensureEventAdmin).Patch("/", api.Handlers.Event.UpdateEventById)
81+
r.With(mw.Auth.RequireAuth, ensureSuperuser).Delete("/", api.Handlers.Event.DeleteEventById)
82+
r.Get("/", api.Handlers.Event.GetEventByID)
83+
r.Post("/interest", api.Handlers.EventInterest.AddEmailToEvent)
84+
})
7285
})
7386

7487
// Email routes
@@ -87,7 +100,7 @@ func (api *API) setupRoutes(mw *mw.Middleware) {
87100
})
88101

89102
r.Group(func(r chi.Router) {
90-
r.Use(mw.Auth.RequirePlatformRole(sqlc.AuthUserRoleUser))
103+
r.Use(mw.Auth.RequirePlatformRole([]sqlc.AuthUserRole{sqlc.AuthUserRoleUser}))
91104
r.Get("/user", func(w http.ResponseWriter, r *http.Request) {
92105
if _, err := w.Write([]byte("Welcome, user!\n")); err != nil {
93106
log.Err(err)
@@ -96,7 +109,7 @@ func (api *API) setupRoutes(mw *mw.Middleware) {
96109
})
97110

98111
r.Group(func(r chi.Router) {
99-
r.Use(mw.Auth.RequirePlatformRole(sqlc.AuthUserRoleSuperuser))
112+
r.Use(mw.Auth.RequirePlatformRole([]sqlc.AuthUserRole{sqlc.AuthUserRoleSuperuser}))
100113
r.Get("/superuser", func(w http.ResponseWriter, r *http.Request) {
101114
if _, err := w.Write([]byte("Welcome, superuser!\n")); err != nil {
102115
log.Err(err)
Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
package handlers
2+
3+
import (
4+
"encoding/json"
5+
"net/http"
6+
"reflect"
7+
"time"
8+
9+
"github.com/go-chi/chi/v5"
10+
"github.com/go-playground/validator/v10"
11+
"github.com/google/uuid"
12+
"github.com/rs/zerolog"
13+
res "github.com/swamphacks/core/apps/api/internal/api/response"
14+
"github.com/swamphacks/core/apps/api/internal/config"
15+
"github.com/swamphacks/core/apps/api/internal/db/sqlc"
16+
"github.com/swamphacks/core/apps/api/internal/services"
17+
)
18+
19+
type EventHandler struct {
20+
eventService *services.EventService
21+
cfg *config.Config
22+
logger zerolog.Logger
23+
}
24+
25+
func NewEventHandler(eventService *services.EventService, cfg *config.Config, logger zerolog.Logger) *EventHandler {
26+
return &EventHandler{
27+
eventService: eventService,
28+
cfg: cfg,
29+
logger: logger.With().Str("handler", "EventHandler").Str("component", "events").Logger(),
30+
}
31+
}
32+
33+
// Be very careful with the types in this struct. If a type is not a pointer (pointer types allow a null value), and the field is not present in the json body, its default value will be passed to the SQL query, and be a non-null value will be put into coalese(), which will then make a NULL value impossible and instead make the default value the type's zero value in Go.
34+
type CreateEventFields struct {
35+
Name string `json:"name" validate:"required,min=5,max=30"`
36+
ApplicationOpen time.Time `json:"application_open" validate:"required"`
37+
ApplicationClose time.Time `json:"application_close" validate:"required"`
38+
StartTime time.Time `json:"start_time" validate:"required"`
39+
EndTime time.Time `json:"end_time" validate:"required"`
40+
Description *string `json:"description"`
41+
Location *string `json:"location"`
42+
LocationUrl *string `json:"location_url"`
43+
MaxAttendees *int32 `json:"max_attendees"`
44+
RsvpDeadline *time.Time `json:"rsvp_deadline"`
45+
DecisionRelease *time.Time `json:"decision_release"`
46+
WebsiteUrl *string `json:"website_url"`
47+
IsPublished *bool `json:"is_published"`
48+
}
49+
50+
func (st CreateEventFields) ValidateTimeFields() bool {
51+
if st.ApplicationClose.Before(st.ApplicationOpen) || st.ApplicationClose.Equal(st.ApplicationOpen) {
52+
return false
53+
}
54+
if st.EndTime.Before(st.StartTime) || st.EndTime.Equal(st.StartTime) {
55+
return false
56+
}
57+
if st.ApplicationOpen.Before(time.Now()) ||
58+
st.ApplicationClose.Before(time.Now()) ||
59+
st.StartTime.Before(time.Now()) ||
60+
st.EndTime.Before(time.Now()) {
61+
return false
62+
}
63+
return true
64+
}
65+
66+
func (h *EventHandler) CreateEvent(w http.ResponseWriter, r *http.Request) {
67+
68+
// Parse JSON body
69+
var req CreateEventFields
70+
decoder := json.NewDecoder(r.Body)
71+
decoder.DisallowUnknownFields() // Prevents requests with extraneous fields
72+
// This will also throw an error for empty values for fields which correspond to types that cannot convert an empty string to a zero value (e.g. time.Time)
73+
if err := decoder.Decode(&req); err != nil {
74+
res.SendError(w, http.StatusBadRequest, res.NewError("invalid_request", "Could not parse request body"))
75+
return
76+
}
77+
78+
validate := validator.New()
79+
if err := validate.Struct(req); err != nil {
80+
res.SendError(w, http.StatusBadRequest, res.NewError("invalid_request", err.Error()))
81+
}
82+
83+
if !req.ValidateTimeFields() {
84+
res.SendError(w, http.StatusBadRequest, res.NewError("invalid_time", "Time fields must be sequential and not in the past."))
85+
return
86+
}
87+
88+
params := sqlc.CreateEventParams{
89+
Name: req.Name,
90+
ApplicationOpen: req.ApplicationOpen,
91+
ApplicationClose: req.ApplicationClose,
92+
StartTime: req.StartTime,
93+
EndTime: req.EndTime,
94+
Description: req.Description,
95+
Location: req.Location,
96+
LocationUrl: req.LocationUrl,
97+
MaxAttendees: req.MaxAttendees,
98+
RsvpDeadline: req.RsvpDeadline,
99+
DecisionRelease: req.DecisionRelease,
100+
WebsiteUrl: req.WebsiteUrl,
101+
IsPublished: req.IsPublished,
102+
}
103+
104+
event, err := h.eventService.CreateEvent(r.Context(), params)
105+
if err != nil {
106+
if err == services.ErrFailedToCreateEvent {
107+
res.SendError(w, http.StatusInternalServerError, res.NewError("creation_error", "Failed to create event"))
108+
} else {
109+
res.SendError(w, http.StatusInternalServerError, res.NewError("internal_err", "Something went wrong"))
110+
}
111+
}
112+
113+
res.Send(w, http.StatusCreated, event)
114+
}
115+
116+
func (h *EventHandler) GetEventByID(w http.ResponseWriter, r *http.Request) {
117+
eventIdStr := chi.URLParam(r, "eventId")
118+
if eventIdStr == "" {
119+
res.SendError(w, http.StatusBadRequest, res.NewError("missing_event_id", "The event ID is missing from the URL!"))
120+
return
121+
}
122+
eventId, err := uuid.Parse(eventIdStr)
123+
if err != nil {
124+
res.SendError(w, http.StatusBadRequest, res.NewError("invalid_event_id", "The event ID is not a valid UUID"))
125+
return
126+
}
127+
128+
event, err := h.eventService.GetEventByID(r.Context(), eventId)
129+
if err != nil {
130+
switch err {
131+
case services.ErrFailedToGetEvent:
132+
res.SendError(w, http.StatusNotFound, res.NewError("no_event", "Event not found"))
133+
default:
134+
res.SendError(w, http.StatusInternalServerError, res.NewError("internal_err", "Something went wrong"))
135+
}
136+
}
137+
138+
res.Send(w, http.StatusOK, event)
139+
}
140+
141+
func (h *EventHandler) UpdateEventById(w http.ResponseWriter, r *http.Request) {
142+
eventIdStr := chi.URLParam(r, "eventId")
143+
if eventIdStr == "" {
144+
res.SendError(w, http.StatusBadRequest, res.NewError("missing_event_id", "The event ID is missing from the URL!"))
145+
return
146+
}
147+
eventId, err := uuid.Parse(eventIdStr)
148+
if err != nil {
149+
res.SendError(w, http.StatusBadRequest, res.NewError("invalid_event_id", "The event ID is not a valid UUID"))
150+
return
151+
}
152+
153+
var req sqlc.UpdateEventByIdParams
154+
155+
decoder := json.NewDecoder(r.Body)
156+
decoder.DisallowUnknownFields() // Prevents requests with extraneous fields
157+
if err := decoder.Decode(&req); err != nil {
158+
res.SendError(w, http.StatusBadRequest, res.NewError("invalid_request", "Invalid request body"))
159+
return
160+
}
161+
162+
// Refactorme: could be improved by unmarshalling values into a generic that can include nil information
163+
// Todo: make sure that non nullable values can't be updated to null
164+
// Todo: Time validation
165+
req.NameDoUpdate = reflect.ValueOf(req.Name).IsValid()
166+
req.DescriptionDoUpdate = reflect.ValueOf(req.Description).IsValid()
167+
req.LocationDoUpdate = reflect.ValueOf(req.Location).IsValid()
168+
req.LocationUrlDoUpdate = reflect.ValueOf(req.LocationUrl).IsValid()
169+
req.MaxAttendeesDoUpdate = reflect.ValueOf(req.MaxAttendees).IsValid()
170+
req.ApplicationOpenDoUpdate = reflect.ValueOf(req.ApplicationOpen).IsValid()
171+
req.ApplicationCloseDoUpdate = reflect.ValueOf(req.ApplicationClose).IsValid()
172+
req.RsvpDeadlineDoUpdate = reflect.ValueOf(req.RsvpDeadline).IsValid()
173+
req.DecisionReleaseDoUpdate = reflect.ValueOf(req.DecisionRelease).IsValid()
174+
req.StartTimeDoUpdate = reflect.ValueOf(req.StartTime).IsValid()
175+
req.EndTimeDoUpdate = reflect.ValueOf(req.EndTime).IsValid()
176+
req.WebsiteUrlDoUpdate = reflect.ValueOf(req.WebsiteUrl).IsValid()
177+
req.IsPublishedDoUpdate = reflect.ValueOf(req.IsPublished).IsValid()
178+
req.ID = eventId
179+
180+
event, err := h.eventService.UpdateEventById(r.Context(), req)
181+
182+
if err != nil {
183+
switch err {
184+
case services.ErrFailedToUpdateEvent:
185+
res.SendError(w, http.StatusInternalServerError, res.NewError("patch_error", "Failed to update event"))
186+
default:
187+
res.SendError(w, http.StatusInternalServerError, res.NewError("internal_err", "Something went wrong"))
188+
}
189+
}
190+
191+
res.Send(w, http.StatusOK, event)
192+
}
193+
194+
func (h *EventHandler) DeleteEventById(w http.ResponseWriter, r *http.Request) {
195+
eventIdStr := chi.URLParam(r, "eventId")
196+
if eventIdStr == "" {
197+
res.SendError(w, http.StatusBadRequest, res.NewError("missing_event_id", "The event ID is missing from the URL!"))
198+
return
199+
}
200+
eventId, err := uuid.Parse(eventIdStr)
201+
if err != nil {
202+
res.SendError(w, http.StatusBadRequest, res.NewError("invalid_event_id", "The event ID is not a valid UUID"))
203+
return
204+
}
205+
err = h.eventService.DeleteEventById(r.Context(), eventId)
206+
207+
if err != nil {
208+
switch err {
209+
case services.ErrFailedToDeleteEvent:
210+
res.SendError(w, http.StatusInternalServerError, res.NewError("delete_error", "Failed to delete event"))
211+
default:
212+
res.SendError(w, http.StatusInternalServerError, res.NewError("internal_err", "Something went wrong"))
213+
}
214+
}
215+
216+
w.WriteHeader(http.StatusNoContent)
217+
}

apps/api/internal/api/handlers/handlers.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ import (
99
type Handlers struct {
1010
Auth *AuthHandler
1111
EventInterest *EventInterestHandler
12+
Event *EventHandler
1213
Email *EmailHandler
1314
}
1415

15-
func NewHandlers(authService *services.AuthService, eventInterestService *services.EventInterestService, emailService *services.EmailService, cfg *config.Config, logger zerolog.Logger) *Handlers {
16+
func NewHandlers(authService *services.AuthService, eventInterestService *services.EventInterestService, eventService *services.EventService, emailService *services.EmailService, cfg *config.Config, logger zerolog.Logger) *Handlers {
1617
return &Handlers{
1718
Auth: NewAuthHandler(authService, cfg, logger),
1819
EventInterest: NewEventInterestHandler(eventInterestService, cfg, logger),
20+
Event: NewEventHandler(eventService, cfg, logger),
1921
Email: NewEmailHandler(emailService, logger),
2022
}
2123
}

0 commit comments

Comments
 (0)