diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml new file mode 100644 index 0000000..74bf12f --- /dev/null +++ b/.github/workflows/backend.yml @@ -0,0 +1,32 @@ +# This workflow will build a golang project +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go + +name: Backend + +on: + push: + branches: ["main"] + pull_request: + branches: ["main"] + +jobs: + build: + runs-on: ubuntu-latest + + defaults: + run: + working-directory: ./backend + + steps: + - uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: "1.22" + + - name: Test + run: go test -v ./... + + - name: Build + run: go build -v ./... diff --git a/.github/workflows/frontend.yml b/.github/workflows/frontend.yml new file mode 100644 index 0000000..f2221c1 --- /dev/null +++ b/.github/workflows/frontend.yml @@ -0,0 +1,33 @@ +name: Frontend + +on: + push: + branches: ["main"] + pull_request: + branches: ["main"] + + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + + defaults: + run: + working-directory: ./frontend + + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: "latest" + - name: enable corepack + run: corepack enable + - name: set yarn version + run: corepack use yarn@stable + - name: install dependencies + run: yarn + - name: run eslint + run: yarn lint + - name: format with prettier + run: yarn format:fix diff --git a/.vscode/settings.json b/.vscode/settings.json index 5c9efa0..a55f7a2 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,6 +1,7 @@ { "cSpell.words": [ "cmds", + "corepack", "Darkspace", "healthcheck", "idnum", diff --git a/README.md b/README.md index 3728ac0..56124a6 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,26 @@ One must have installed these utilities to start development: - Go - Node +### MacOS + +If you're using MacOS, ```corepack``` is also needed. Corepack ships with Node, but zsh does not find this linkage in the shell. Therefore, since we are using brew, corepack can be installed with: + +```brew install corepack``` + +Brew may error and say that you must remove the symlink for ```yarn``` if you used brew to install yarn. Do not fret, run this command: + +```brew unlink yarn``` + +Then, rerun ```brew install corepack```. + +Now, run ```corepack enable```. This will enable corepack globally. Optionally, one can run ```corepack install --global yarn@stable``` to install the latest yarn version globally using corepack. + +To set the yarn version in the frontend directory, first ```cd frontend``` then ```corepack use yarn@v```, where ```v``` is the version you want to set. In this project, we are using stable, so the command would be ```corepack use yarn@stable```. + +#### Aside + +Corepack is used in the GitHub workflow file to make ensure yarn can install. + ## Software Below is a list of software one may use to code this project: @@ -116,4 +136,4 @@ We must implement endpoint testing. Here are software development terms that may be unfamiliar and are found during the development process. -- [Triage](https://dictionary.cambridge.org/dictionary/english/triage) \ No newline at end of file +- [Triage](https://dictionary.cambridge.org/dictionary/english/triage) diff --git a/backend/cmd/api/handlers.go b/backend/cmd/api/handlers.go index fbc2399..768cc24 100644 --- a/backend/cmd/api/handlers.go +++ b/backend/cmd/api/handlers.go @@ -23,23 +23,22 @@ func (app *application) courseHomepageHandler( w http.ResponseWriter, r *http.Request, ) { - // Retrieve that value of the {id} path in the URL using r.PathValue("id") - id := r.PathValue("id") + // id := r.PathValue("id") - var course *models.Course - var err error + // var course *models.Course + // var err error - course, err = app.models.Course.Get(id) - if err != nil { - app.serverError(w, r, err) - } + // course, err = app.models.Course.Get(id) + // if err != nil { + // app.serverError(w, r, err) + // } - res := jsonWrap{} + // res := jsonWrap{"course": course} - err = app.writeJSON(w, http.StatusOK, res, nil) - if err != nil { - app.serverError(w, r, err) - } + // err = app.writeJSON(w, http.StatusOK, res, nil) + // if err != nil { + // app.serverError(w, r, err) + // } // If the course ID exists in the database AND the user requesting this // data has the appropriate permissions, retrieve the course data requested. diff --git a/backend/internal/domain/permission_test.go b/backend/internal/domain/permission_test.go index 93c2768..a67d1e5 100644 --- a/backend/internal/domain/permission_test.go +++ b/backend/internal/domain/permission_test.go @@ -32,7 +32,7 @@ func TestPermission_String(t *testing.T) { p.update = true p.delete = true - want := "----" + want := "rwud" got := fmt.Sprintf("%s", p) diff --git a/frontend/.eslintrc.json b/frontend/.eslintrc.json index bffb357..4fbfd08 100644 --- a/frontend/.eslintrc.json +++ b/frontend/.eslintrc.json @@ -1,3 +1,8 @@ { - "extends": "next/core-web-vitals" + "extends": ["next/core-web-vitals", "prettier"], + "rules": { + "@next/next/no-html-link-for-pages": ["error"], + "@next/next/no-img-element": ["error"], + "@next/next/no-typos": ["error"] + } } diff --git a/frontend/.yarnrc.yml b/frontend/.yarnrc.yml index e11fa2c..ed8bd7f 100644 --- a/frontend/.yarnrc.yml +++ b/frontend/.yarnrc.yml @@ -1,4 +1,2 @@ -yarnPath: .yarn/releases/yarn-4.1.0.cjs - # Fix for GitHub Issue #3 nodeLinker: node-modules diff --git a/frontend/package.json b/frontend/package.json index ac39dde..0e548f3 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -6,7 +6,9 @@ "dev": "next dev", "build": "next build", "start": "next start", - "lint": "next lint" + "lint": "next lint", + "format": "prettier --check ./src", + "format:fix": "prettier --write --list-different ./src" }, "dependencies": { "next": "14.1.0", @@ -20,9 +22,11 @@ "autoprefixer": "^10.0.1", "eslint": "^8", "eslint-config-next": "14.1.0", + "eslint-config-prettier": "^9.1.0", "postcss": "^8", + "prettier": "^3.2.5", "tailwindcss": "^3.3.0", "typescript": "^5" }, - "packageManager": "yarn@4.1.0" + "packageManager": "yarn@4.1.1+sha256.f3cc0eda8e5560e529c7147565b30faa43b4e472d90e8634d7134a37c7f59781" } diff --git a/frontend/yarn.lock b/frontend/yarn.lock index 6e1d7ef..d024f88 100644 --- a/frontend/yarn.lock +++ b/frontend/yarn.lock @@ -1272,6 +1272,17 @@ __metadata: languageName: node linkType: hard +"eslint-config-prettier@npm:^9.1.0": + version: 9.1.0 + resolution: "eslint-config-prettier@npm:9.1.0" + peerDependencies: + eslint: ">=7.0.0" + bin: + eslint-config-prettier: bin/cli.js + checksum: 10c0/6d332694b36bc9ac6fdb18d3ca2f6ac42afa2ad61f0493e89226950a7091e38981b66bac2b47ba39d15b73fff2cd32c78b850a9cf9eed9ca9a96bfb2f3a2f10d + languageName: node + linkType: hard + "eslint-import-resolver-node@npm:^0.3.6, eslint-import-resolver-node@npm:^0.3.9": version: 0.3.9 resolution: "eslint-import-resolver-node@npm:0.3.9" @@ -1641,8 +1652,10 @@ __metadata: autoprefixer: "npm:^10.0.1" eslint: "npm:^8" eslint-config-next: "npm:14.1.0" + eslint-config-prettier: "npm:^9.1.0" next: "npm:14.1.0" postcss: "npm:^8" + prettier: "npm:^3.2.5" react: "npm:^18" react-dom: "npm:^18" tailwindcss: "npm:^3.3.0" @@ -3118,6 +3131,15 @@ __metadata: languageName: node linkType: hard +"prettier@npm:^3.2.5": + version: 3.2.5 + resolution: "prettier@npm:3.2.5" + bin: + prettier: bin/prettier.cjs + checksum: 10c0/ea327f37a7d46f2324a34ad35292af2ad4c4c3c3355da07313339d7e554320f66f65f91e856add8530157a733c6c4a897dc41b577056be5c24c40f739f5ee8c6 + languageName: node + linkType: hard + "proc-log@npm:^3.0.0": version: 3.0.0 resolution: "proc-log@npm:3.0.0" diff --git a/taskfiles/frontend.yml b/taskfiles/frontend.yml index 25029d5..e5a5740 100644 --- a/taskfiles/frontend.yml +++ b/taskfiles/frontend.yml @@ -16,4 +16,10 @@ tasks: install: dir: frontend cmds: - - yarn install + - corepack enable + - corepack use yarn@stable + - yarn + update: + dir: frontend + cmds: + - yarn upgrade