Skip to content
Closed

Dev #168

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
15 changes: 12 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module github.com/nbtca/saturday

go 1.22
go 1.22.0

toolchain go1.23.4
toolchain go1.24.0

require (
github.com/Masterminds/squirrel v1.5.4
Expand All @@ -12,11 +12,15 @@ require (
github.com/gin-contrib/cors v1.6.0
github.com/gin-gonic/gin v1.10.0
github.com/go-playground/validator/v10 v10.22.1
github.com/go-playground/webhooks/v6 v6.4.0
github.com/go-sql-driver/mysql v1.7.1
github.com/golang-jwt/jwt/v4 v4.5.1
github.com/golang-jwt/jwt/v4 v4.5.0
github.com/google/go-github/v69 v69.1.0
github.com/jmoiron/sqlx v1.3.5
github.com/joho/godotenv v1.5.1
github.com/lib/pq v1.10.9
github.com/mostafa/go-api-client v0.1.2
github.com/nao1215/markdown v0.7.0
github.com/nsqio/go-nsq v1.1.0
github.com/ory/dockertest/v3 v3.10.0
github.com/qustavo/sqlhooks/v2 v2.1.0
Expand All @@ -32,10 +36,15 @@ require (
github.com/distribution/reference v0.6.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.5 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/karrick/godirwalk v1.17.0 // indirect
github.com/klauspost/cpuid/v2 v2.2.8 // indirect
github.com/kr/text v0.1.0 // indirect
github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.51.0 // indirect
go.opentelemetry.io/otel/trace v1.26.0 // indirect
Expand Down
25 changes: 23 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJn
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
github.com/go-playground/validator/v10 v10.22.1 h1:40JcKH+bBNGFczGuoBYgX4I6m/i27HYW8P9FDk5PbgA=
github.com/go-playground/validator/v10 v10.22.1/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
github.com/go-playground/webhooks/v6 v6.4.0 h1:KLa6y7bD19N48rxJDHM0DpE3T4grV7GxMy1b/aHMWPY=
github.com/go-playground/webhooks/v6 v6.4.0/go.mod h1:5lBxopx+cAJiBI4+kyRbuHrEi+hYRDdRHuRR4Ya5Ums=
github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI=
Expand All @@ -75,16 +77,21 @@ github.com/goccy/go-json v0.10.3/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PU
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/golang-jwt/jwt/v4 v4.4.2/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
github.com/golang-jwt/jwt/v4 v4.5.1 h1:JdqV9zKUdtaa9gdPlywC3aeoEsR681PlKC+4F5gQgeo=
github.com/golang-jwt/jwt/v4 v4.5.1/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg=
github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
github.com/golang-migrate/migrate/v4 v4.17.1 h1:4zQ6iqL6t6AiItphxJctQb3cFqWiSpMnX7wLTPnnYO4=
github.com/golang-migrate/migrate/v4 v4.17.1/go.mod h1:m8hinFyWBn0SA4QKHuKh175Pm9wjmxj3S2Mia7dbXzM=
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-github/v69 v69.1.0 h1:ljzwzEsHsc4qUqyHEJCNA1dMqvoTK3YX2NAaK6iprDg=
github.com/google/go-github/v69 v69.1.0/go.mod h1:xne4jymxLR6Uj9b7J7PyTpkMYstEMMwGZa0Aehh1azM=
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4=
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=
Expand All @@ -101,6 +108,8 @@ github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/karrick/godirwalk v1.17.0 h1:b4kY7nqDdioR/6qnbHQyDvmA17u5G1cZ6J+CZXwSWoI=
github.com/karrick/godirwalk v1.17.0/go.mod h1:j4mkqPuvaLI8mp1DroR3P6ad7cyYd4c1qeJ3RV7ULlk=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
Expand All @@ -123,6 +132,9 @@ github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/mattn/go-sqlite3 v1.10.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
github.com/mattn/go-sqlite3 v1.14.6/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwpU1Y=
Expand All @@ -138,8 +150,14 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A=
github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc=
github.com/mostafa/go-api-client v0.1.2 h1:TIkkVQarZKNRc5j3cC/XOPYZ6Z8+oMu54rA0A2L4wGc=
github.com/mostafa/go-api-client v0.1.2/go.mod h1:QmHlkiEHNjh98j8wzRsXdXw/PyU8LQ9KNmjqGnU1xOQ=
github.com/nao1215/markdown v0.7.0 h1:SCQkvdQXQuKJW8KaCsvBob8Afy4T4iJUAYIefWpHojE=
github.com/nao1215/markdown v0.7.0/go.mod h1:ObBhnNduWwPN+bu4dtv4JoLRt57ONla7l//03iHIVhY=
github.com/nsqio/go-nsq v1.1.0 h1:PQg+xxiUjA7V+TLdXw7nVrJ5Jbl3sN86EhGCQj4+FYE=
github.com/nsqio/go-nsq v1.1.0/go.mod h1:vKq36oyeVXgsS5Q8YEO7WghqidAVXQlcFxzQbQTuDEY=
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
github.com/opencontainers/image-spec v1.0.2 h1:9yCKha/T5XdGtO0q9Q9a6T5NUCsTn/DrBg0D7ufOcFM=
Expand All @@ -157,6 +175,9 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/qustavo/sqlhooks/v2 v2.1.0 h1:54yBemHnGHp/7xgT+pxwmIlMSDNYKx5JW5dfRAiCZi0=
github.com/qustavo/sqlhooks/v2 v2.1.0/go.mod h1:aMREyKo7fOKTwiLuWPsaHRXEmtqG4yREztO0idF83AU=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8=
github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
Expand Down
6 changes: 3 additions & 3 deletions middleware/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func Auth(acceptableRoles ...Role) func(c *gin.Context) {
token := c.GetHeader("Authorization")
if token == "" {
c.AbortWithStatusJSON(util.MakeServiceError(http.StatusUnauthorized).
SetMessage("not authorized").
SetMessage("not authorized, missing token").
Build())
return
}
Expand All @@ -38,7 +38,7 @@ func Auth(acceptableRoles ...Role) func(c *gin.Context) {
tokenParsed, claims, err := util.ParseToken(token)
if err != nil || !tokenParsed.Valid {
c.AbortWithStatusJSON(util.MakeServiceError(http.StatusUnauthorized).
SetMessage("not authorized").
SetMessage("not authorized, token not valid.").
Build())
return
}
Expand Down Expand Up @@ -67,7 +67,7 @@ func Auth(acceptableRoles ...Role) func(c *gin.Context) {
userinfo, err := service.LogtoServiceApp.FetchUserInfo(token)
if err != nil {
c.AbortWithStatusJSON(util.MakeServiceError(http.StatusUnauthorized).
SetMessage("not authorized").
SetMessage("not authorized" + err.Error()).
Build())
return
}
Expand Down
2 changes: 1 addition & 1 deletion migrations/000001_init.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ INSERT INTO public.role (role_id,role) VALUES
(0,'member_inactive'),
(1,'admin_inactive'),
(2,'member'),
(4,'admin');
(3,'admin');

--
-- Name: client client_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
Expand Down
23 changes: 23 additions & 0 deletions migrations/000003_add_github_issue.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
ALTER TABLE public.event
DROP COLUMN github_issue_id;

ALTER TABLE public.event
DROP COLUMN github_issue_number;

DROP VIEW public.event_view;
CREATE OR REPLACE VIEW public.event_view AS
SELECT event.event_id,
event.client_id,
event.model,
event.phone,
event.qq,
event.contact_preference,
event.problem,
event.member_id,
event.closed_by,
event.gmt_create,
event.gmt_modified,
COALESCE(event_status.status, ''::character varying) AS status
FROM ((public.event
LEFT JOIN public.event_event_status_relation ON ((event.event_id = event_event_status_relation.event_id)))
LEFT JOIN public.event_status ON ((event_event_status_relation.event_status_id = event_status.event_status_id)));
24 changes: 24 additions & 0 deletions migrations/000003_add_github_issue.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
ALTER TABLE public.event
ADD COLUMN github_issue_id BIGINT;

ALTER TABLE public.event
ADD COLUMN github_issue_number BIGINT;

CREATE OR REPLACE VIEW public.event_view AS
SELECT event.event_id,
event.client_id,
event.model,
event.phone,
event.qq,
event.contact_preference,
event.problem,
event.member_id,
event.closed_by,
event.gmt_create,
event.gmt_modified,
COALESCE(event_status.status, ''::character varying) AS status,
event.github_issue_id,
event.github_issue_number
FROM ((public.event
LEFT JOIN public.event_event_status_relation ON ((event.event_id = event_event_status_relation.event_id)))
LEFT JOIN public.event_status ON ((event_event_status_relation.event_status_id = event_status.event_status_id)));
24 changes: 24 additions & 0 deletions migrations/000004_add_github_id.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
-- Remove the 'github_id' column from the 'member' table
ALTER TABLE public.member
DROP COLUMN github_id;

-- Revert the 'member_view' to exclude the 'github_id' column
DROP VIEW public.member_view;
CREATE VIEW public.member_view AS
SELECT member.member_id,
member.alias,
member.password,
member.name,
member.section,
member.profile,
member.phone,
member.qq,
member.avatar,
member.created_by,
member.gmt_create,
member.gmt_modified,
COALESCE(role.role, ''::character varying) AS role,
member.logto_id
FROM ((public.member
LEFT JOIN public.member_role_relation ON ((member.member_id = (member_role_relation.member_id)::bpchar)))
LEFT JOIN public.role ON ((member_role_relation.role_id = role.role_id)));
28 changes: 28 additions & 0 deletions migrations/000004_add_github_id.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
-- Add a new column 'github_id' to the 'member' table
ALTER TABLE public.member
ADD COLUMN github_id character varying(50) DEFAULT ''::character varying;

-- Optionally, add a comment for the new column
COMMENT ON COLUMN public.member.github_id IS 'GitHub User ID';

-- Update the 'member_view' to include the new 'github_id' column
DROP VIEW public.member_view;
CREATE VIEW public.member_view AS
SELECT member.member_id,
member.alias,
member.password,
member.name,
member.section,
member.profile,
member.phone,
member.qq,
member.avatar,
member.created_by,
member.gmt_create,
member.gmt_modified,
COALESCE(role.role, ''::character varying) AS role,
member.logto_id,
member.github_id -- Include the new column
FROM ((public.member
LEFT JOIN public.member_role_relation ON ((member.member_id = (member_role_relation.member_id)::bpchar)))
LEFT JOIN public.role ON ((member_role_relation.role_id = role.role_id)));
20 changes: 20 additions & 0 deletions model/event.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
package model

import (
"bytes"
"database/sql"
"fmt"

md "github.com/nao1215/markdown"
)

type Event struct {
EventId int64 `json:"eventId" db:"event_id"`
ClientId int64 `json:"clientId" db:"client_id"`
GithubIssueId sql.NullInt64 `json:"githubIssueId" db:"github_issue_id"`
GithubIssueNumber sql.NullInt64 `json:"githubIssueNumber" db:"github_issue_number"`
Model string `json:"model"`
Phone string `json:"phone"`
QQ string `json:"qq"`
Expand All @@ -18,6 +28,16 @@ type Event struct {
GmtModified string `json:"gmtModified" db:"gmt_modified"`
}

func (e Event) ToMarkdownString() string {
buf := new(bytes.Buffer)
markdown := md.NewMarkdown(buf).H2("Description")
markdown.PlainText(e.Problem)
if e.Model != "" {
markdown.BulletList(fmt.Sprintf("Model: %s", e.Model))
}
return markdown.String()
}

type Status struct {
StatusId int64 `json:"status_id"`
Status string `json:"status"`
Expand Down
2 changes: 2 additions & 0 deletions model/member.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type Member struct {
QQ string `json:"qq" `
Avatar string `json:"avatar"`
CreatedBy string `json:"createdBy" db:"created_by"`
GithubId string `json:"githubId" db:"github_id"`
GmtCreate string `json:"gmtCreate" db:"gmt_create"`
GmtModified string `json:"gmtModified" db:"gmt_modified"`
}
Expand All @@ -30,6 +31,7 @@ type NullMember struct {
Phone sql.NullString `json:"phone" `
QQ sql.NullString `json:"qq" `
Avatar sql.NullString `json:"avatar"`
GithubId string `json:"githubId" db:"github_id"`
CreatedBy sql.NullString `json:"createdBy" db:"created_by"`
GmtCreate sql.NullString `json:"gmtCreate" db:"gmt_create"`
GmtModified sql.NullString `json:"gmtModified" db:"gmt_modified"`
Expand Down
Loading
Loading