Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
DATABASE_URL="file:dev.db?cache=shared&mode=rwc"
PORT=""
TRUSTED_PROXIES=""
ALLOWED_ORIGINS=""
11 changes: 8 additions & 3 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ Don't be afraid to ask for help with anything on this project. DMs are open!
- Occasionally rebasing will create merge conflicts out of thin air - in
these cases it's fine to just merge.
- Don't forget to [link PR to issue](https://docs.github.com/en/issues/tracking-your-work-with-issues/using-issues/linking-a-pull-request-to-an-issue) if you are solving one.
- *Keep PRs small and focused*. If possible keep PRs under 300-400 lines of
changes. If you have a big change, maybe try breaking it into multiple smaller
PRs.
- Not a strict requirement, but it's well known that big PRs are harder to
review effectively and accurately.
- Please request a review from a current project maintainer or ping us on
discord when your pr is ready to merge.
- We may respond to your review with some suggestions and/or changes that
Expand All @@ -40,8 +45,8 @@ Don't be afraid to ask for help with anything on this project. DMs are open!
- The Copilot PR review is a useful feature - it often catches easy to miss
copy-paste errors, spelling/grammar mistakes, and other things. Be cautious
though - it can make mistakes, and always validate the issues it finds.
- Only *squash merging and rebase merging* into main are allowed. Don't worry
about this too much, but if you don't know which to choose:
- *squash merging* into main is preferred. Don't worry about this too much, but
if you don't know which to choose:
- Choose a squash merge if the individual commits in the PR don't matter very
much and/or the change is relatively atomic.
- Choose a rebase merge if the individual commits in the PR do matter.
- Choose a rebase merge/normal merge if the individual commits in the PR do matter.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ result
tmp/

.env
.DS_Store
28 changes: 16 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
.DEFAULT_GOAL := build

.PHONY: help
help: ## Display this help screen
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

BIN_DIR := bin
API_NAME := acmcsuf-api
CLI_NAME := acmcsuf-cli

GENERATE_DEPS := $(wildcard internal/db/sql/schemas/*.sql) $(wildcard internal/db/sql/queries/*.sql) internal/db/sqlc.yaml $(wildcard internal/api/handlers/*.go)
GENERATE_MARKER := .generate.marker

.PHONY:fmt run build vet check test check-sql fix-sql clean
.PHONY:fmt run build vet check test check-sql fix-sql clean release generate

fmt:
fmt: ## Format all go files
@go fmt ./...

VERSION := $(shell git describe --tags --always --dirty 2> /dev/null || echo "dev")
Expand All @@ -18,39 +22,39 @@ $(GENERATE_MARKER): $(GENERATE_DEPS)
go generate ./...
@touch $@

generate: fmt $(GENERATE_MARKER)
generate: fmt $(GENERATE_MARKER) ## Generate all necessary files

run: build
run: build ## Build and run the api
./$(BIN_DIR)/$(API_NAME)

build: generate
build: generate ## Build the api and cli binaries
@mkdir -p $(BIN_DIR)
go build -ldflags "-X main.Version=$(VERSION)" -o $(BIN_DIR)/$(API_NAME) ./cmd/$(API_NAME)
go build -ldflags "-X main.Version=$(VERSION)" -o $(BIN_DIR)/$(CLI_NAME) ./cmd/$(CLI_NAME)

vet:
vet: ## Vet all go files
go vet ./...

check:
check: ## Run static analysis on all go files
staticcheck ./...

test: check
test: check ## Run all tests
go test ./...

check-sql:
check-sql: ## Lint all sql files
sqlfluff lint --dialect sqlite

fix-sql:
fix-sql: ## Fix all sql files
sqlfluff fix --dialect sqlite

release:
release: ## Create a new release tag
@echo "Current version: $(VERSION)"
@read -p "Enter new version (e.g., v0.2.0): " version; \
git tag -a $$version -m "Release $$version"; \
git push origin $$version; \
echo "Tagged $$version."

clean:
clean: ## Clean up all generated files and binaries
go clean
rm -f $(GENERATE_MARKER)
rm -rf $(BIN_DIR) result
76 changes: 57 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,78 @@ ACM at CSUF club API for managing events, announcements, forms, and other servic

---

This project requires that you have Go, sqlc, GNU Make, and optionally Air installed. We recommend using the
provided Nix development environment, see below.
## Setting Up
This project requires that you have Go, sqlc, GNU Make, and optionally Air installed. We highly
recommend using the provided Nix development environment instead of installing everything manually.

### Start API server
Air will recompile the project on the fly so you don't have to restart the server when you make changes.
1. [Install nix](https://determinate.systems/nix-installer/) and [direnv](https://direnv.net/docs/installation.html) if you don't already have them

2. Run `direnv allow` at the project root
> If you don't have direnv, you can also use `nix develop` to enter the dev
> shell, but your environment variables won't get sourced automatically.

## Developing

### Compiling
Using `make` will compile both the API and CLI binaries, located at
`bin/acmcsuf-api` and `bin/acmcsuf-cli` respectively. If you installed `direnv`,
both of these binaries will be automatically added to your path. You can run
them directly like:
```sh
air
acmcsuf-api # Run API server
acmcsuf-cli # Start CLI client (start API server before using)
```

To compile and run manually, you can use one of the following:

### Start API server
Air will recompile the project on the fly so you don't have to restart the server when you make changes.
```sh
make # Compile program
./bin/api # Run program
air
```
OR
```sh
make run
make run # Compiles and runs directly (no hot-reloading)
```

### Other useful commands from the Makefile
#### Configuring the API
The API server is configurable via environment variables. See [`.env.example`](./.env.example) for
values you can override and configure in your `.env` file.

```sh
make check # Run checks
make test # Run tests (None yet)
make sql-fix # Format and fix SQL files
make clean # Removes all build artifacts
### Using the CLI
The CLI is a simple command-line client for the API server. Make sure the API
server is running before using.
Output of `acmcsuf-cli --help`:
```
A CLI tool to help manage the API of the CSUF ACM website

---
Usage:
acmcsuf-cli [command]

Available Commands:
announcements Manage ACM CSUF's Announcements
completion Generate the autocompletion script for the specified shell
events A command to manage events.
help Help about any command
officers A command to manage officers.

Flags:
-h, --help help for acmcsuf-cli
-v, --version version for acmcsuf-cli

Use "acmcsuf-cli [command] --help" for more information about a command.
```

## To use the Nix dev shell
### Other useful commands from the Makefile

1. [Install nix](https://determinate.systems/nix-installer/) and optionally [direnv](https://direnv.net/docs/installation.html) if you don't already have them
```sh
make check # Run checks
make test # Run tests (None yet)
make fix-sql # Format and fix SQL files
make clean # Removes all build artifacts
make help # Display all targets
```

2. Run `direnv allow` at the project root. If you don't want to use direnv, you can use `nix develop` to achieve the same thing, but you will need to run it every time you enter the project.
---

Developed with 💚 by [**@acmcsufoss**](https://github.com/acmcsufoss)
2 changes: 2 additions & 0 deletions cmd/acmcsuf-cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"

"github.com/acmcsufoss/api.acmcsuf.com/internal/cli/announcements"
"github.com/acmcsufoss/api.acmcsuf.com/internal/cli/boards/officers"
"github.com/acmcsufoss/api.acmcsuf.com/internal/cli/events"

"github.com/spf13/cobra"
Expand All @@ -31,6 +32,7 @@ func Execute() {
func init() {
rootCmd.AddCommand(events.CLIEvents)
rootCmd.AddCommand(announcements.CLIAnnouncements)
rootCmd.AddCommand(officers.CLIOfficers)
}

func main() {
Expand Down
68 changes: 51 additions & 17 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1337,7 +1337,9 @@ const docTemplate = `{
"models.CreateEventParams": {
"type": "object",
"properties": {
"end_at": {},
"end_at": {
"type": "integer"
},
"host": {
"type": "string"
},
Expand All @@ -1347,7 +1349,9 @@ const docTemplate = `{
"location": {
"type": "string"
},
"start_at": {},
"start_at": {
"type": "integer"
},
"uuid": {
"type": "string"
}
Expand All @@ -1368,14 +1372,20 @@ const docTemplate = `{
"picture": {
"$ref": "#/definitions/sql.NullString"
},
"uuid": {}
"uuid": {
"type": "string"
}
}
},
"models.CreatePositionParams": {
"type": "object",
"properties": {
"oid": {},
"semester": {},
"oid": {
"type": "string"
},
"semester": {
"type": "string"
},
"tier": {
"type": "integer"
}
Expand All @@ -1401,8 +1411,12 @@ const docTemplate = `{
"models.DeletePositionParams": {
"type": "object",
"properties": {
"oid": {},
"semester": {},
"oid": {
"type": "string"
},
"semester": {
"type": "string"
},
"tier": {
"type": "integer"
}
Expand All @@ -1411,7 +1425,9 @@ const docTemplate = `{
"models.Event": {
"type": "object",
"properties": {
"end_at": {},
"end_at": {
"type": "integer"
},
"host": {
"type": "string"
},
Expand All @@ -1421,7 +1437,9 @@ const docTemplate = `{
"location": {
"type": "string"
},
"start_at": {},
"start_at": {
"type": "integer"
},
"uuid": {
"type": "string"
}
Expand All @@ -1442,7 +1460,9 @@ const docTemplate = `{
"picture": {
"$ref": "#/definitions/sql.NullString"
},
"uuid": {}
"uuid": {
"type": "string"
}
}
},
"models.Position": {
Expand All @@ -1451,8 +1471,12 @@ const docTemplate = `{
"full_name": {
"type": "string"
},
"oid": {},
"semester": {},
"oid": {
"type": "string"
},
"semester": {
"type": "string"
},
"team": {
"$ref": "#/definitions/sql.NullString"
},
Expand Down Expand Up @@ -1504,7 +1528,9 @@ const docTemplate = `{
"models.UpdateEventParams": {
"type": "object",
"properties": {
"end_at": {},
"end_at": {
"$ref": "#/definitions/sql.NullInt64"
},
"host": {
"$ref": "#/definitions/sql.NullString"
},
Expand All @@ -1514,7 +1540,9 @@ const docTemplate = `{
"location": {
"$ref": "#/definitions/sql.NullString"
},
"start_at": {},
"start_at": {
"$ref": "#/definitions/sql.NullInt64"
},
"uuid": {
"type": "string"
}
Expand All @@ -1535,7 +1563,9 @@ const docTemplate = `{
"picture": {
"$ref": "#/definitions/sql.NullString"
},
"uuid": {}
"uuid": {
"type": "string"
}
}
},
"models.UpdatePositionParams": {
Expand All @@ -1544,8 +1574,12 @@ const docTemplate = `{
"full_name": {
"type": "string"
},
"oid": {},
"semester": {},
"oid": {
"type": "string"
},
"semester": {
"type": "string"
},
"team": {
"$ref": "#/definitions/sql.NullString"
},
Expand Down
Loading