Skip to content

Commit

Permalink
Dev (#4)
Browse files Browse the repository at this point in the history
* Added file upload to add modal

* Add PWA manifest
Added more filter options for data table
Minor padding issues for jobid page

* Added status update to main job table

* Dynamic height for edit modal

* Dynamic height for edit modal

* Dynamic height for edit modal

* Dynamic height for edit modal

* Added stats endpoint

* Added stats page
Fixed extension not scrolling to top when capturing

* Added alert for invalid captures
Added pre-filled url to extension add page

* Added remove fixed classes on screenshot
Added token renewal to extension on visibility change

* Updated stat logic

* Refactored project structure

* Updated actions to work with new structure

* Upped pnpm github action version
  • Loading branch information
ncpleslie authored May 9, 2024
1 parent a26fa15 commit ea1801d
Show file tree
Hide file tree
Showing 32 changed files with 368 additions and 157 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ jobs:
go-version: 1.22.0

- name: Test
run: go test -v .
run: go test ./tests -v
working-directory: backend
12 changes: 6 additions & 6 deletions .github/workflows/extension.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ jobs:
- name: Use Node.js
uses: actions/setup-node@v2
with:
node-version: "16"
node-version: "20"

- name: Setup pnpm
uses: pnpm/action-setup@v2.0.1
uses: pnpm/action-setup@v4
with:
version: latest

Expand All @@ -48,7 +48,7 @@ jobs:
- uses: actions/checkout@v2

- name: Setup pnpm
uses: pnpm/action-setup@v2.0.1
uses: pnpm/action-setup@v4
with:
version: latest

Expand All @@ -68,7 +68,7 @@ jobs:
- uses: actions/checkout@v2

- name: Setup pnpm
uses: pnpm/action-setup@v2.0.1
uses: pnpm/action-setup@v4
with:
version: latest

Expand All @@ -95,7 +95,7 @@ jobs:
- uses: actions/checkout@v2

- name: Setup pnpm
uses: pnpm/action-setup@v2.0.1
uses: pnpm/action-setup@v4
with:
version: latest

Expand Down Expand Up @@ -134,7 +134,7 @@ jobs:
- uses: actions/checkout@v2

- name: Setup pnpm
uses: pnpm/action-setup@v2.0.1
uses: pnpm/action-setup@v4
with:
version: latest

Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/frontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ jobs:
- name: Use Node.js
uses: actions/setup-node@v2
with:
node-version: "16"
node-version: "20"
- name: Setup pnpm
uses: pnpm/action-setup@v2.0.1
uses: pnpm/action-setup@v4
with:
version: latest
- name: Cache .pnpm-store
Expand All @@ -34,7 +34,7 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Setup pnpm
uses: pnpm/action-setup@v2.0.1
uses: pnpm/action-setup@v4
with:
version: latest
- name: Install Dependencies
Expand All @@ -49,7 +49,7 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Setup pnpm
uses: pnpm/action-setup@v2.0.1
uses: pnpm/action-setup@v4
with:
version: latest
- name: Install Dependencies
Expand Down
46 changes: 46 additions & 0 deletions backend/.air.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
root = "."
testdata_dir = "testdata"
tmp_dir = "tmp"

[build]
args_bin = []
bin = "./main"
cmd = "make build"
delay = 1000
exclude_dir = ["assets", "tmp", "vendor", "testdata"]
exclude_file = []
exclude_regex = ["_test.go"]
exclude_unchanged = false
follow_symlink = false
full_bin = ""
include_dir = []
include_ext = ["go", "tpl", "tmpl", "html"]
include_file = []
kill_delay = "0s"
log = "build-errors.log"
poll = false
poll_interval = 0
post_cmd = []
pre_cmd = []
rerun = false
rerun_delay = 500
send_interrupt = false
stop_on_error = false

[color]
app = ""
build = "yellow"
main = "magenta"
runner = "green"
watcher = "cyan"

[log]
main_only = false
time = false

[misc]
clean_on_exit = false

[screen]
clear_on_rebuild = false
keep_scroll = true
3 changes: 2 additions & 1 deletion backend/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
screenshot.png
fb-admin-service-account-key.json
.env
main
main
tmp
2 changes: 1 addition & 1 deletion backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=1 GOOS=linux go build -ldflags="-s -w" -a -installsuffix cgo -o main .
RUN CGO_ENABLED=1 GOOS=linux go build -ldflags="-s -w" -a -installsuffix cgo -o main cmd/api/main.go
RUN chmod +x main

FROM golang:1.22.0
Expand Down
63 changes: 63 additions & 0 deletions backend/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Simple Makefile for a Go project

# Build the application
all: build

build:
@echo "Building..."

@go build -o main cmd/api/main.go

# Run the application
run:
@go run cmd/api/main.go

lint:
@golangci-lint run

# # Create DB container
# docker-run:
# @if docker compose up 2>/dev/null; then \
# : ; \
# else \
# echo "Falling back to Docker Compose V1"; \
# docker-compose up; \
# fi

# # Shutdown DB container
# docker-down:
# @if docker compose down 2>/dev/null; then \
# : ; \
# else \
# echo "Falling back to Docker Compose V1"; \
# docker-compose down; \
# fi

# Test the application
test:
@echo "Testing..."
@go test ./tests -v

# Clean the binary
clean:
@echo "Cleaning..."
@rm -f main

# Live Reload
watch:
@if command -v air > /dev/null; then \
air; \
echo "Watching...";\
else \
read -p "Go's 'air' is not installed on your machine. Do you want to install it? [Y/n] " choice; \
if [ "$$choice" != "n" ] && [ "$$choice" != "N" ]; then \
go install github.com/cosmtrek/air@latest; \
air; \
echo "Watching...";\
else \
echo "You chose not to install air. Exiting..."; \
exit 1; \
fi; \
fi

.PHONY: all build run test clean
22 changes: 8 additions & 14 deletions backend/main.go → backend/cmd/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@ package main

import (
"log"
"net"
"net/http"
"os"

firebase "github.com/ncpleslie/job-down/clients"
db "github.com/ncpleslie/job-down/clients/db"
storage "github.com/ncpleslie/job-down/clients/storage"
cfg "github.com/ncpleslie/job-down/config"
server "github.com/ncpleslie/job-down/server"
"github.com/ncpleslie/job-down/services"
cfg "github.com/ncpleslie/job-down/internal/config"
db "github.com/ncpleslie/job-down/internal/db"
firebase "github.com/ncpleslie/job-down/internal/firebase"
server "github.com/ncpleslie/job-down/internal/server"
services "github.com/ncpleslie/job-down/internal/services"
storage "github.com/ncpleslie/job-down/internal/storage"
)

func main() {
Expand All @@ -28,13 +26,9 @@ func main() {
jobService := services.NewJobService(storage, db, log)

srv := server.NewServer(config.Server, authService, jobService)
httpServer := &http.Server{
Addr: net.JoinHostPort(config.Server.Host, config.Server.Port),
Handler: srv,
}

log.Printf("Application listening on %s\n", httpServer.Addr)
if err := httpServer.ListenAndServe(); err != nil {
log.Printf("Application listening on %s\n", srv.Addr)
if err := srv.ListenAndServe(); err != nil {
log.Printf("An error occurred. %s\n", err.Error())
}
}
File renamed without changes.
2 changes: 1 addition & 1 deletion backend/clients/db/db.go → backend/internal/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"cloud.google.com/go/firestore"
firebase "firebase.google.com/go/v4"
"github.com/ncpleslie/job-down/models/entities"
"github.com/ncpleslie/job-down/internal/models/entities"
"google.golang.org/api/iterator"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
b64 "encoding/base64"

firebase "firebase.google.com/go/v4"
"github.com/ncpleslie/job-down/config"
"github.com/ncpleslie/job-down/internal/config"
"google.golang.org/api/option"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package entities
import (
"time"

"github.com/ncpleslie/job-down/models/requests"
"github.com/ncpleslie/job-down/models/responses"
"github.com/ncpleslie/job-down/internal/models/requests"
"github.com/ncpleslie/job-down/internal/models/responses"
)

type Job struct {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package responses

type Stats struct {
Total int `json:"total"`
Current Stat `json:"current"`
Historical Stat `json:"historical"`
Total int `json:"total"`
Current *Stat `json:"current"`
Historical *Stat `json:"historical"`
}

type Stat struct {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"fmt"
"net/http"

"github.com/ncpleslie/job-down/models/requests"
"github.com/ncpleslie/job-down/models/responses"
"github.com/ncpleslie/job-down/services"
"github.com/ncpleslie/job-down/internal/models/requests"
"github.com/ncpleslie/job-down/internal/models/responses"
"github.com/ncpleslie/job-down/internal/services"
)

// Returns a handler function for the GET /jobs/{jobId} route.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"net/http"
"strings"

"github.com/ncpleslie/job-down/services"
"github.com/ncpleslie/job-down/internal/services"
)

func cors(clientAddress string, next http.Handler) http.Handler {
Expand Down
50 changes: 50 additions & 0 deletions backend/internal/server/routes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package server

import (
"net/http"
)

// RegisterRouters sets up the routes and middleware for the server.
// It returns an http.Handler that can be used with http.Server.
func (s *Server) RegisterRouters() http.Handler {
mux := http.NewServeMux()
// Unauthenticated routes
mux.Handle("/healthz/", http.StripPrefix("/healthz", s.addHealthRoutes()))

// Job routes. Require authentication.
mux.Handle("/jobs/", http.StripPrefix("/jobs", s.addJobRoutes()))

var handler http.Handler = mux
handler = cors(s.config.ClientAddress, handler)

return handler
}

// AddHealthRoutes adds the health routes to the provided http.ServeMux.
// All health routes are prefixed with "/healthz".
// TODO: Make this more useful by pinging db, etc.
func (s *Server) addHealthRoutes() http.Handler {
mux := http.NewServeMux()
mux.HandleFunc("GET /", func(w http.ResponseWriter, r *http.Request) {
encode(w, r, http.StatusOK, "ok")
})

return mux
}

// AddJobRoutes adds the job routes to the provided http.ServeMux.
// All job routes are prefixed with "/jobs".
func (s *Server) addJobRoutes() http.Handler {
mux := http.NewServeMux()
mux.Handle("GET /", handleAllJobsGet(s.jobService))
mux.Handle("GET /{jobId}", handleJobGet(s.jobService))
mux.Handle("POST /", handleJobPost(s.jobService))
mux.Handle("PATCH /{jobId}", handleJobPatch(s.jobService))
mux.Handle("DELETE /{jobId}", handleJobDelete(s.jobService))
mux.Handle("GET /stats", handleStatsGet(s.jobService))

var handler http.Handler = mux
handler = userContext(s.authService, handler)

return handler
}
Loading

0 comments on commit ea1801d

Please sign in to comment.