From 1fd8002a8d64d1fc3f142b4428eb4818bebee78d Mon Sep 17 00:00:00 2001 From: Nam Nguyen Date: Wed, 19 Apr 2023 10:39:34 +0700 Subject: [PATCH 1/2] refactor: notion handler --- pkg/handler/audience/interface.go | 7 - pkg/handler/dfupdate/interface.go | 45 ----- pkg/handler/digest/interface.go | 7 - pkg/handler/earn/interface.go | 7 - pkg/handler/event/interface.go | 7 - pkg/handler/handler.go | 119 +++++-------- pkg/handler/hiring/interface.go | 7 - pkg/handler/issue/interface.go | 7 - pkg/handler/memo/interface.go | 7 - pkg/handler/{audience => notion}/audience.go | 46 ++---- .../{changelog => notion}/changelog.go | 18 +- pkg/handler/{digest => notion}/digest.go | 38 +---- pkg/handler/{earn => notion}/earn.go | 41 +---- pkg/handler/{event => notion}/event.go | 36 +--- pkg/handler/{hiring => notion}/hiring.go | 44 ++--- .../{changelog => notion}/interface.go | 27 +-- pkg/handler/{issue => notion}/issue.go | 52 ++---- pkg/handler/{memo => notion}/memo.go | 39 +---- .../df_update.go => notion/newsletter.go} | 27 ++- pkg/handler/notion/project_milestone.go | 156 ++++++++++++++++++ .../staffing_demand.go | 40 +---- .../{techradar => notion}/tech_radar.go | 47 ++---- pkg/handler/{update => notion}/update.go | 40 +---- pkg/handler/project/interface.go | 1 - pkg/handler/project/project.go | 145 ---------------- pkg/handler/staffingdemand/interface.go | 7 - pkg/handler/techradar/interface.go | 8 - pkg/handler/update/interface.go | 7 - pkg/model/audience.go | 11 -- pkg/model/digest.go | 9 - pkg/model/earn.go | 16 -- pkg/model/hiring.go | 19 --- pkg/model/hiring_position.go | 13 -- pkg/model/issue.go | 20 --- pkg/model/memo.go | 11 -- pkg/model/notion.go | 115 +++++++++++++ pkg/model/project_milestone.go | 15 -- pkg/model/staffing_demand.go | 7 - pkg/model/tech_radar.go | 11 -- pkg/model/update.go | 10 -- pkg/routes/v1.go | 50 +++--- pkg/routes/v1_test.go | 36 ++-- pkg/view/hiring.go | 2 +- 43 files changed, 502 insertions(+), 875 deletions(-) delete mode 100644 pkg/handler/audience/interface.go delete mode 100644 pkg/handler/dfupdate/interface.go delete mode 100644 pkg/handler/digest/interface.go delete mode 100644 pkg/handler/earn/interface.go delete mode 100644 pkg/handler/event/interface.go delete mode 100644 pkg/handler/hiring/interface.go delete mode 100644 pkg/handler/issue/interface.go delete mode 100644 pkg/handler/memo/interface.go rename pkg/handler/{audience => notion}/audience.go (64%) rename pkg/handler/{changelog => notion}/changelog.go (94%) rename pkg/handler/{digest => notion}/digest.go (60%) rename pkg/handler/{earn => notion}/earn.go (69%) rename pkg/handler/{event => notion}/event.go (75%) rename pkg/handler/{hiring => notion}/hiring.go (69%) rename pkg/handler/{changelog => notion}/interface.go (63%) rename pkg/handler/{issue => notion}/issue.go (73%) rename pkg/handler/{memo => notion}/memo.go (62%) rename pkg/handler/{dfupdate/df_update.go => notion/newsletter.go} (86%) create mode 100644 pkg/handler/notion/project_milestone.go rename pkg/handler/{staffingdemand => notion}/staffing_demand.go (57%) rename pkg/handler/{techradar => notion}/tech_radar.go (82%) rename pkg/handler/{update => notion}/update.go (61%) delete mode 100644 pkg/handler/staffingdemand/interface.go delete mode 100644 pkg/handler/techradar/interface.go delete mode 100644 pkg/handler/update/interface.go delete mode 100644 pkg/model/audience.go delete mode 100644 pkg/model/digest.go delete mode 100644 pkg/model/earn.go delete mode 100644 pkg/model/hiring.go delete mode 100644 pkg/model/hiring_position.go delete mode 100644 pkg/model/issue.go delete mode 100644 pkg/model/memo.go delete mode 100644 pkg/model/project_milestone.go delete mode 100644 pkg/model/staffing_demand.go delete mode 100644 pkg/model/tech_radar.go delete mode 100644 pkg/model/update.go diff --git a/pkg/handler/audience/interface.go b/pkg/handler/audience/interface.go deleted file mode 100644 index 7eeb3b4a8..000000000 --- a/pkg/handler/audience/interface.go +++ /dev/null @@ -1,7 +0,0 @@ -package audience - -import "github.com/gin-gonic/gin" - -type IHandler interface { - List(c *gin.Context) -} diff --git a/pkg/handler/dfupdate/interface.go b/pkg/handler/dfupdate/interface.go deleted file mode 100644 index 3920b76c3..000000000 --- a/pkg/handler/dfupdate/interface.go +++ /dev/null @@ -1,45 +0,0 @@ -package dfupdate - -import ( - "github.com/gin-gonic/gin" - - "github.com/dwarvesf/fortress-api/pkg/config" - "github.com/dwarvesf/fortress-api/pkg/logger" - "github.com/dwarvesf/fortress-api/pkg/service" - "github.com/dwarvesf/fortress-api/pkg/store" -) - -type From struct { - Email string `json:"email,omitempty"` - Name string `json:"name,omitempty"` -} - -type ProjectChangelog struct { - ProjectPageID string `json:"project_page_id,omitempty"` - IsPreview bool `json:"is_preview"` - From From `json:"from,omitempty"` -} - -// IHandler functions of dfupdate handler interface -type IHandler interface { - Send(c *gin.Context) -} - -type handler struct { - store *store.Store - service *service.Service - logger logger.Logger - repo store.DBRepo - config *config.Config -} - -// New returns a handler -func New(store *store.Store, repo store.DBRepo, service *service.Service, logger logger.Logger, cfg *config.Config) IHandler { - return &handler{ - store: store, - repo: repo, - service: service, - logger: logger, - config: cfg, - } -} diff --git a/pkg/handler/digest/interface.go b/pkg/handler/digest/interface.go deleted file mode 100644 index 9a7ff6cdb..000000000 --- a/pkg/handler/digest/interface.go +++ /dev/null @@ -1,7 +0,0 @@ -package digest - -import "github.com/gin-gonic/gin" - -type IHandler interface { - List(c *gin.Context) -} diff --git a/pkg/handler/earn/interface.go b/pkg/handler/earn/interface.go deleted file mode 100644 index aa58e72b5..000000000 --- a/pkg/handler/earn/interface.go +++ /dev/null @@ -1,7 +0,0 @@ -package earn - -import "github.com/gin-gonic/gin" - -type IHandler interface { - List(c *gin.Context) -} diff --git a/pkg/handler/event/interface.go b/pkg/handler/event/interface.go deleted file mode 100644 index f953c69c4..000000000 --- a/pkg/handler/event/interface.go +++ /dev/null @@ -1,7 +0,0 @@ -package event - -import "github.com/gin-gonic/gin" - -type IHandler interface { - List(c *gin.Context) -} diff --git a/pkg/handler/handler.go b/pkg/handler/handler.go index a29b66249..67c310f7d 100644 --- a/pkg/handler/handler.go +++ b/pkg/handler/handler.go @@ -5,35 +5,24 @@ import ( "github.com/dwarvesf/fortress-api/pkg/controller" "github.com/dwarvesf/fortress-api/pkg/handler/accounting" "github.com/dwarvesf/fortress-api/pkg/handler/asset" - "github.com/dwarvesf/fortress-api/pkg/handler/audience" "github.com/dwarvesf/fortress-api/pkg/handler/audit" "github.com/dwarvesf/fortress-api/pkg/handler/auth" "github.com/dwarvesf/fortress-api/pkg/handler/bankaccount" "github.com/dwarvesf/fortress-api/pkg/handler/birthday" - "github.com/dwarvesf/fortress-api/pkg/handler/changelog" "github.com/dwarvesf/fortress-api/pkg/handler/client" "github.com/dwarvesf/fortress-api/pkg/handler/dashboard" "github.com/dwarvesf/fortress-api/pkg/handler/dashboard/util" - "github.com/dwarvesf/fortress-api/pkg/handler/dfupdate" - "github.com/dwarvesf/fortress-api/pkg/handler/digest" "github.com/dwarvesf/fortress-api/pkg/handler/discord" - "github.com/dwarvesf/fortress-api/pkg/handler/earn" "github.com/dwarvesf/fortress-api/pkg/handler/employee" - "github.com/dwarvesf/fortress-api/pkg/handler/event" "github.com/dwarvesf/fortress-api/pkg/handler/feedback" "github.com/dwarvesf/fortress-api/pkg/handler/healthz" - "github.com/dwarvesf/fortress-api/pkg/handler/hiring" "github.com/dwarvesf/fortress-api/pkg/handler/invoice" - "github.com/dwarvesf/fortress-api/pkg/handler/issue" - "github.com/dwarvesf/fortress-api/pkg/handler/memo" "github.com/dwarvesf/fortress-api/pkg/handler/metadata" + "github.com/dwarvesf/fortress-api/pkg/handler/notion" "github.com/dwarvesf/fortress-api/pkg/handler/payroll" "github.com/dwarvesf/fortress-api/pkg/handler/profile" "github.com/dwarvesf/fortress-api/pkg/handler/project" - "github.com/dwarvesf/fortress-api/pkg/handler/staffingdemand" "github.com/dwarvesf/fortress-api/pkg/handler/survey" - "github.com/dwarvesf/fortress-api/pkg/handler/techradar" - "github.com/dwarvesf/fortress-api/pkg/handler/update" "github.com/dwarvesf/fortress-api/pkg/handler/valuation" "github.com/dwarvesf/fortress-api/pkg/handler/webhook" "github.com/dwarvesf/fortress-api/pkg/logger" @@ -43,73 +32,51 @@ import ( ) type Handler struct { - Healthcheck healthz.IHandler - Employee employee.IHandler - Metadata metadata.IHandler - Auth auth.IHandler - Project project.IHandler - Profile profile.IHandler - Feedback feedback.IHandler - Survey survey.IHandler - Dashboard dashboard.IHandler - Valuation valuation.IHandler - Earn earn.IHandler - TechRadar techradar.IHandler - Issue issue.IHandler - Audience audience.IHandler - Event event.IHandler - Hiring hiring.IHandler - StaffingDemand staffingdemand.IHandler - Audit audit.IHandler - Digest digest.IHandler - Update update.IHandler - Memo memo.IHandler - BankAccount bankaccount.IHandler - Birthday birthday.IHandler - Invoice invoice.IHandler - Webhook webhook.IHandler - Discord discord.IHandler - Client client.IHandler - Asset asset.IHandler - Changelog changelog.IHandler - DFUpdate dfupdate.IHandler - Payroll payroll.IHandler - Accounting accounting.IHandler + Accounting accounting.IHandler + Asset asset.IHandler + Audit audit.IHandler + Auth auth.IHandler + BankAccount bankaccount.IHandler + Birthday birthday.IHandler + Client client.IHandler + Dashboard dashboard.IHandler + Discord discord.IHandler + Employee employee.IHandler + Feedback feedback.IHandler + Healthcheck healthz.IHandler + Invoice invoice.IHandler + Metadata metadata.IHandler + Notion notion.IHandler + Payroll payroll.IHandler + Profile profile.IHandler + Project project.IHandler + Survey survey.IHandler + Valuation valuation.IHandler + Webhook webhook.IHandler } func New(store *store.Store, repo store.DBRepo, service *service.Service, ctrl *controller.Controller, worker *worker.Worker, logger logger.Logger, cfg *config.Config) *Handler { return &Handler{ - Healthcheck: healthz.New(), - Employee: employee.New(ctrl, store, repo, service, logger, cfg), - Metadata: metadata.New(store, repo, service, logger, cfg), - Auth: auth.New(ctrl, logger, cfg), - Project: project.New(store, repo, service, logger, cfg), - Profile: profile.New(store, repo, service, logger, cfg), - Feedback: feedback.New(store, repo, service, logger, cfg), - Survey: survey.New(store, repo, service, logger, cfg), - Dashboard: dashboard.New(store, repo, service, logger, cfg, util.New()), - Valuation: valuation.New(store, repo, service, logger, cfg), - Earn: earn.New(store, repo, service, logger, cfg), - TechRadar: techradar.New(store, repo, service, logger, cfg), - Issue: issue.New(store, repo, service, logger, cfg), - Audience: audience.New(store, repo, service, logger, cfg), - Event: event.New(store, repo, service, logger, cfg), - Hiring: hiring.New(store, repo, service, logger, cfg), - StaffingDemand: staffingdemand.New(store, repo, service, logger, cfg), - Audit: audit.New(store, repo, service, logger, cfg), - Digest: digest.New(store, repo, service, logger, cfg), - Update: update.New(store, repo, service, logger, cfg), - Memo: memo.New(store, repo, service, logger, cfg), - BankAccount: bankaccount.New(store, repo, service, logger, cfg), - Birthday: birthday.New(store, repo, service, logger, cfg), - Invoice: invoice.New(ctrl, store, repo, service, worker, logger, cfg), - Webhook: webhook.New(ctrl, store, repo, service, logger, cfg), - Discord: discord.New(store, repo, service, logger, cfg), - Client: client.New(ctrl, store, repo, service, logger, cfg), - Asset: asset.New(store, repo, service, logger, cfg), - Changelog: changelog.New(store, repo, service, logger, cfg), - DFUpdate: dfupdate.New(store, repo, service, logger, cfg), - Payroll: payroll.New(store, repo, service, worker, logger, cfg), - Accounting: accounting.New(store, repo, service, logger, cfg), + Accounting: accounting.New(store, repo, service, logger, cfg), + Asset: asset.New(store, repo, service, logger, cfg), + Audit: audit.New(store, repo, service, logger, cfg), + Auth: auth.New(ctrl, logger, cfg), + BankAccount: bankaccount.New(store, repo, service, logger, cfg), + Birthday: birthday.New(store, repo, service, logger, cfg), + Client: client.New(ctrl, store, repo, service, logger, cfg), + Dashboard: dashboard.New(store, repo, service, logger, cfg, util.New()), + Discord: discord.New(store, repo, service, logger, cfg), + Employee: employee.New(ctrl, store, repo, service, logger, cfg), + Feedback: feedback.New(store, repo, service, logger, cfg), + Healthcheck: healthz.New(), + Invoice: invoice.New(ctrl, store, repo, service, worker, logger, cfg), + Metadata: metadata.New(store, repo, service, logger, cfg), + Notion: notion.New(store, repo, service, logger, cfg), + Payroll: payroll.New(store, repo, service, worker, logger, cfg), + Profile: profile.New(store, repo, service, logger, cfg), + Project: project.New(store, repo, service, logger, cfg), + Survey: survey.New(store, repo, service, logger, cfg), + Valuation: valuation.New(store, repo, service, logger, cfg), + Webhook: webhook.New(ctrl, store, repo, service, logger, cfg), } } diff --git a/pkg/handler/hiring/interface.go b/pkg/handler/hiring/interface.go deleted file mode 100644 index d1c70adbc..000000000 --- a/pkg/handler/hiring/interface.go +++ /dev/null @@ -1,7 +0,0 @@ -package hiring - -import "github.com/gin-gonic/gin" - -type IHandler interface { - List(c *gin.Context) -} diff --git a/pkg/handler/issue/interface.go b/pkg/handler/issue/interface.go deleted file mode 100644 index d47b93514..000000000 --- a/pkg/handler/issue/interface.go +++ /dev/null @@ -1,7 +0,0 @@ -package issue - -import "github.com/gin-gonic/gin" - -type IHandler interface { - List(c *gin.Context) -} diff --git a/pkg/handler/memo/interface.go b/pkg/handler/memo/interface.go deleted file mode 100644 index 95a4f53c2..000000000 --- a/pkg/handler/memo/interface.go +++ /dev/null @@ -1,7 +0,0 @@ -package memo - -import "github.com/gin-gonic/gin" - -type IHandler interface { - List(c *gin.Context) -} diff --git a/pkg/handler/audience/audience.go b/pkg/handler/notion/audience.go similarity index 64% rename from pkg/handler/audience/audience.go rename to pkg/handler/notion/audience.go index 35fa7d189..9fc8867e8 100644 --- a/pkg/handler/audience/audience.go +++ b/pkg/handler/notion/audience.go @@ -1,39 +1,17 @@ -// please edit this file only with approval from hnh -package audience +// Package notion please edit this file only with approval from hnh +package notion import ( "net/http" "github.com/dstotijn/go-notion" - "github.com/dwarvesf/fortress-api/pkg/config" - "github.com/dwarvesf/fortress-api/pkg/logger" + "github.com/gin-gonic/gin" + "github.com/dwarvesf/fortress-api/pkg/model" - "github.com/dwarvesf/fortress-api/pkg/service" - "github.com/dwarvesf/fortress-api/pkg/store" "github.com/dwarvesf/fortress-api/pkg/view" - "github.com/gin-gonic/gin" ) -type handler struct { - store *store.Store - service *service.Service - logger logger.Logger - repo store.DBRepo - config *config.Config -} - -// New returns a handler -func New(store *store.Store, repo store.DBRepo, service *service.Service, logger logger.Logger, cfg *config.Config) IHandler { - return &handler{ - store: store, - repo: repo, - service: service, - logger: logger, - config: cfg, - } -} - -// List godoc +// ListAudiences godoc // @Summary Get list audiences from DF Audience // @Description Get list audiences from DF Audience // @Tags Audience @@ -41,7 +19,7 @@ func New(store *store.Store, repo store.DBRepo, service *service.Service, logger // @Produce json // @Success 200 {object} []model.Audience // @Failure 400 {object} view.ErrorResponse -func (h *handler) List(c *gin.Context) { +func (h *handler) ListAudiences(c *gin.Context) { filter := ¬ion.DatabaseQueryFilter{} filterNewSubscriber := true @@ -69,15 +47,15 @@ func (h *handler) List(c *gin.Context) { return } - var audiences = []model.Audience{} + var audiences []model.NotionAudience for _, r := range resp.Results { props := r.Properties.(notion.DatabasePageProperties) - fullname := "" + fullName := "" if len(props["Full Name"].Title) > 0 { - fullname = props["Full Name"].Title[0].Text.Content + fullName = props["Full Name"].Title[0].Text.Content } - sources := []string{} + var sources []string for _, c := range props["Source"].MultiSelect { sources = append(sources, c.Name) } @@ -86,9 +64,9 @@ func (h *handler) List(c *gin.Context) { email = *props["Email"].Email } - audiences = append(audiences, model.Audience{ + audiences = append(audiences, model.NotionAudience{ ID: r.ID, - FullName: fullname, + FullName: fullName, Email: email, CreatedAt: r.CreatedTime, Sources: sources, diff --git a/pkg/handler/changelog/changelog.go b/pkg/handler/notion/changelog.go similarity index 94% rename from pkg/handler/changelog/changelog.go rename to pkg/handler/notion/changelog.go index ac81dc2ae..82915d310 100644 --- a/pkg/handler/changelog/changelog.go +++ b/pkg/handler/notion/changelog.go @@ -1,4 +1,4 @@ -package changelog +package notion import ( "context" @@ -42,7 +42,7 @@ func (e singleChangelogError) Error() string { func parseProjectChangelogNotionMessageFromCtx(c *gin.Context) (ProjectChangelog, error) { msg := ProjectChangelog{} - err := c.ShouldBindJSON((&msg)) + err := c.ShouldBindJSON(&msg) if err != nil { return msg, err } @@ -62,7 +62,7 @@ func (h *handler) GetAvailableProjectsChangelog(c *gin.Context) { func (h *handler) SendProjectChangelog(c *gin.Context) { msg, err := parseProjectChangelogNotionMessageFromCtx(c) if err != nil { - h.logger.Error(err, "can not parse change log") + h.logger.Error(err, "failed to parse project changelog message") c.JSON(http.StatusInternalServerError, view.CreateResponse[any](nil, nil, err, nil, "")) return } @@ -83,7 +83,7 @@ func (h *handler) sendProjectChangelog(changelog ProjectChangelog) error { categories := []string{key, changelog.ProjectPageID} values, err := h.service.Notion.GetProjectInDB(changelog.ProjectPageID) if err != nil { - h.logger.Error(err, "download page") + h.logger.Errorf(err, "failed to get project in db", "project", changelog.ProjectPageID) return err } return h.sendSingleProjectChangelog(changelog.ProjectPageID, *values, &mail.Email{ @@ -122,7 +122,7 @@ func (h *handler) generateEmailChangelog( isPreview bool, ) (*model.Email, *model.ProjectChangelogPage, error) { m := model.Email{From: from, Categories: categories} - changelogBlocks := []nt.Block{} + var changelogBlocks []nt.Block projectName := "" archiveURL := "" p := model.ProjectChangelogPage{RowID: id} @@ -160,7 +160,7 @@ func (h *handler) generateEmailChangelog( for _, c := range v.Relation { clientPage, err := h.service.Notion.FindClientPageForChangelog(c.ID) if err != nil { - h.logger.Error(err, "download page") + h.logger.Errorf(err, "failed to find client page for changelog", "clientPage", c.ID) return nil, nil, singleChangelogError{ProjectName: projectName, Err: err} } props := clientPage.Properties.(nt.DatabasePageProperties) @@ -191,7 +191,7 @@ func (h *handler) generateEmailChangelog( for _, c := range v.Relation { recipientsPage, err := h.service.Notion.FindClientPageForChangelog(c.ID) if err != nil { - h.logger.Error(err, "download page") + h.logger.Errorf(err, "failed to find page for changelogs", "clientPage", c.ID) return nil, nil, singleChangelogError{ProjectName: projectName, Err: err} } props := recipientsPage.Properties.(nt.DatabasePageProperties) @@ -247,7 +247,7 @@ func (h *handler) generateEmailChangelog( pageContent, err := h.service.Notion.GetBlockChildren(latestChangelogPage.ID) if err != nil { - h.logger.Error(err, "download page") + h.logger.Errorf(err, "failed to download page", "pageID", latestChangelogPage.ID) return nil, nil, singleChangelogError{ProjectName: projectName, Err: err} } changelogBlocks = pageContent.Results @@ -267,7 +267,7 @@ func (h *handler) generateEmailChangelog( if block.HasChildren() { children, err := h.service.Notion.GetBlockChildren(block.ID()) if err != nil { - h.logger.Error(err, "get block children") + h.logger.Error(err, "failed to get block children") return nil, nil, singleChangelogError{ProjectName: projectName, Err: err} } diff --git a/pkg/handler/digest/digest.go b/pkg/handler/notion/digest.go similarity index 60% rename from pkg/handler/digest/digest.go rename to pkg/handler/notion/digest.go index 8c42a61e3..57fb3608a 100644 --- a/pkg/handler/digest/digest.go +++ b/pkg/handler/notion/digest.go @@ -1,39 +1,17 @@ -// please edit this file only with approval from hnh -package digest +// Package notion please edit this file only with approval from hnh +package notion import ( "net/http" "github.com/dstotijn/go-notion" - "github.com/dwarvesf/fortress-api/pkg/config" - "github.com/dwarvesf/fortress-api/pkg/logger" + "github.com/gin-gonic/gin" + "github.com/dwarvesf/fortress-api/pkg/model" - "github.com/dwarvesf/fortress-api/pkg/service" - "github.com/dwarvesf/fortress-api/pkg/store" "github.com/dwarvesf/fortress-api/pkg/view" - "github.com/gin-gonic/gin" ) -type handler struct { - store *store.Store - service *service.Service - logger logger.Logger - repo store.DBRepo - config *config.Config -} - -// New returns a handler -func New(store *store.Store, repo store.DBRepo, service *service.Service, logger logger.Logger, cfg *config.Config) IHandler { - return &handler{ - store: store, - repo: repo, - service: service, - logger: logger, - config: cfg, - } -} - -// List godoc +// ListDigests godoc // @Summary Get list digests from DF Internal Digest // @Description Get list digests from DF Internal Digest // @Tags digests @@ -41,7 +19,7 @@ func New(store *store.Store, repo store.DBRepo, service *service.Service, logger // @Produce json // @Success 200 {object} []model.Digest // @Failure 400 {object} view.ErrorResponse -func (h *handler) List(c *gin.Context) { +func (h *handler) ListDigests(c *gin.Context) { resp, err := h.service.Notion.GetDatabase(h.config.Notion.Databases.Digest, nil, []notion.DatabaseQuerySort{ { Property: "Created at", @@ -53,7 +31,7 @@ func (h *handler) List(c *gin.Context) { return } - var digests = []model.Digest{} + var digests []model.NotionDigest for _, r := range resp.Results { props := r.Properties.(notion.DatabasePageProperties) @@ -63,7 +41,7 @@ func (h *handler) List(c *gin.Context) { name = *r.Icon.Emoji + " " + props["Name"].Title[0].Text.Content } - digests = append(digests, model.Digest{ + digests = append(digests, model.NotionDigest{ ID: r.ID, Name: name, CreatedAt: props["Created at"].Date.Start.Time, diff --git a/pkg/handler/earn/earn.go b/pkg/handler/notion/earn.go similarity index 69% rename from pkg/handler/earn/earn.go rename to pkg/handler/notion/earn.go index 6f9a1bc18..982c70e83 100644 --- a/pkg/handler/earn/earn.go +++ b/pkg/handler/notion/earn.go @@ -1,40 +1,17 @@ -// please edit this file only with approval from hnh -package earn +// Package notion please edit this file only with approval from hnh +package notion import ( "net/http" "time" "github.com/dstotijn/go-notion" - "github.com/dwarvesf/fortress-api/pkg/config" - "github.com/dwarvesf/fortress-api/pkg/logger" "github.com/dwarvesf/fortress-api/pkg/model" - "github.com/dwarvesf/fortress-api/pkg/service" - "github.com/dwarvesf/fortress-api/pkg/store" "github.com/dwarvesf/fortress-api/pkg/view" "github.com/gin-gonic/gin" ) -type handler struct { - store *store.Store - service *service.Service - logger logger.Logger - repo store.DBRepo - config *config.Config -} - -// New returns a handler -func New(store *store.Store, repo store.DBRepo, service *service.Service, logger logger.Logger, cfg *config.Config) IHandler { - return &handler{ - store: store, - repo: repo, - service: service, - logger: logger, - config: cfg, - } -} - -// List godoc +// ListEarns godoc // @Summary Get list items from DF earn // @Description Get list items from DF earn // @Tags earn @@ -42,29 +19,29 @@ func New(store *store.Store, repo store.DBRepo, service *service.Service, logger // @Produce json // @Success 200 {object} []model.Earn // @Failure 400 {object} view.ErrorResponse -func (h *handler) List(c *gin.Context) { +func (h *handler) ListEarns(c *gin.Context) { resp, err := h.service.Notion.GetDatabase(h.config.Notion.Databases.Earn, nil, nil, 0) if err != nil { c.JSON(http.StatusBadRequest, view.CreateResponse[any](nil, nil, err, nil, "can't get items earn from notion")) return } - var earns = []model.Earn{} + var earns []model.NotionEarn for _, r := range resp.Results { props := r.Properties.(notion.DatabasePageProperties) if (props["Status"].Status == nil || props["Status"].Status.Name == "Done") || (props["Reward 🧊"].Number == nil || *props["Reward 🧊"].Number == 0) { continue } - tags := []string{} + var tags []string for _, tag := range props["Tags"].MultiSelect { tags = append(tags, tag.Name) } - functions := []string{} + var functions []string for _, f := range props["Function"].MultiSelect { functions = append(functions, f.Name) } - employees := []model.Employee{} + var employees []model.Employee for _, e := range props["PICs"].People { employees = append(employees, model.Employee{ FullName: e.Name, @@ -82,7 +59,7 @@ func (h *handler) List(c *gin.Context) { name = *r.Icon.Emoji + " " + props["Name"].Title[0].Text.Content } - earns = append(earns, model.Earn{ + earns = append(earns, model.NotionEarn{ ID: r.ID, Name: name, Reward: int(*props["Reward 🧊"].Number), diff --git a/pkg/handler/event/event.go b/pkg/handler/notion/event.go similarity index 75% rename from pkg/handler/event/event.go rename to pkg/handler/notion/event.go index ebf1c670c..39084dde3 100644 --- a/pkg/handler/event/event.go +++ b/pkg/handler/notion/event.go @@ -1,5 +1,5 @@ -// please edit this file only with approval from hnh -package event +// Package notion please edit this file only with approval from hnh +package notion import ( "net/http" @@ -7,35 +7,13 @@ import ( "time" "github.com/dstotijn/go-notion" - "github.com/dwarvesf/fortress-api/pkg/config" - "github.com/dwarvesf/fortress-api/pkg/logger" + "github.com/gin-gonic/gin" + "github.com/dwarvesf/fortress-api/pkg/model" - "github.com/dwarvesf/fortress-api/pkg/service" - "github.com/dwarvesf/fortress-api/pkg/store" "github.com/dwarvesf/fortress-api/pkg/view" - "github.com/gin-gonic/gin" ) -type handler struct { - store *store.Store - service *service.Service - logger logger.Logger - repo store.DBRepo - config *config.Config -} - -// New returns a handler -func New(store *store.Store, repo store.DBRepo, service *service.Service, logger logger.Logger, cfg *config.Config) IHandler { - return &handler{ - store: store, - repo: repo, - service: service, - logger: logger, - config: cfg, - } -} - -// List godoc +// ListEvents godoc // @Summary Get list events from DF Dwarves Community Events // @Description Get list events from DF Dwarves Community Events // @Tags events @@ -43,7 +21,7 @@ func New(store *store.Store, repo store.DBRepo, service *service.Service, logger // @Produce json // @Success 200 {object} []model.Event // @Failure 400 {object} view.ErrorResponse -func (h *handler) List(c *gin.Context) { +func (h *handler) ListEvents(c *gin.Context) { filter := ¬ion.DatabaseQueryFilter{} nextDays := 7 @@ -89,7 +67,7 @@ func (h *handler) List(c *gin.Context) { return } - var events = []model.Event{} + var events []model.Event for _, r := range resp.Results { props := r.Properties.(notion.DatabasePageProperties) diff --git a/pkg/handler/hiring/hiring.go b/pkg/handler/notion/hiring.go similarity index 69% rename from pkg/handler/hiring/hiring.go rename to pkg/handler/notion/hiring.go index b210617d9..1a08980de 100644 --- a/pkg/handler/hiring/hiring.go +++ b/pkg/handler/notion/hiring.go @@ -1,49 +1,27 @@ -// please edit this file only with approval from hnh -package hiring +// Package notion Package hiring please edit this file only with approval from hnh +package notion import ( "net/http" "github.com/dstotijn/go-notion" - "github.com/dwarvesf/fortress-api/pkg/config" - "github.com/dwarvesf/fortress-api/pkg/logger" - "github.com/dwarvesf/fortress-api/pkg/model" - "github.com/dwarvesf/fortress-api/pkg/service" - "github.com/dwarvesf/fortress-api/pkg/store" - "github.com/dwarvesf/fortress-api/pkg/view" "github.com/gin-gonic/gin" "github.com/thoas/go-funk" -) - -type handler struct { - store *store.Store - service *service.Service - logger logger.Logger - repo store.DBRepo - config *config.Config -} -// New returns a handler -func New(store *store.Store, repo store.DBRepo, service *service.Service, logger logger.Logger, cfg *config.Config) IHandler { - return &handler{ - store: store, - repo: repo, - service: service, - logger: logger, - config: cfg, - } -} + "github.com/dwarvesf/fortress-api/pkg/model" + "github.com/dwarvesf/fortress-api/pkg/view" +) -// List godoc -// @Summary Get list hirings from DF Dwarves Hiring -// @Description Get list hirings from DF Dwarves Hiring +// ListHiringPositions godoc +// @Summary Get list hiring from DF Dwarves Hiring +// @Description Get list hiring from DF Dwarves Hiring // @Tags hiring // @Accept json // @Produce json // @Success 200 {object} view.HiringResponse // @Failure 400 {object} view.ErrorResponse // @Router /hiring-positions [get] -func (h *handler) List(c *gin.Context) { +func (h *handler) ListHiringPositions(c *gin.Context) { filter := ¬ion.DatabaseQueryFilter{} status := "Active" @@ -74,7 +52,7 @@ func (h *handler) List(c *gin.Context) { return } - var positions = []model.HiringPosition{} + var positions []model.NotionHiringPosition for _, r := range resp.Results { props := r.Properties.(notion.DatabasePageProperties) @@ -95,7 +73,7 @@ func (h *handler) List(c *gin.Context) { } } - positions = append(positions, model.HiringPosition{ + positions = append(positions, model.NotionHiringPosition{ ID: r.ID, Name: name, Status: props["Status"].Select.Name, diff --git a/pkg/handler/changelog/interface.go b/pkg/handler/notion/interface.go similarity index 63% rename from pkg/handler/changelog/interface.go rename to pkg/handler/notion/interface.go index 68f3fcf0e..4f8a69101 100644 --- a/pkg/handler/changelog/interface.go +++ b/pkg/handler/notion/interface.go @@ -1,4 +1,4 @@ -package changelog +package notion import ( "github.com/dwarvesf/fortress-api/pkg/config" @@ -8,20 +8,21 @@ import ( "github.com/gin-gonic/gin" ) -type From struct { - Email string `json:"email,omitempty"` - Name string `json:"name,omitempty"` -} - -type ProjectChangelog struct { - ProjectPageID string `json:"project_page_id,omitempty"` - IsPreview bool `json:"is_preview"` - From From `json:"from,omitempty"` -} - -// IHandler functions of type IHandler interface { + CreateTechRadar(c *gin.Context) GetAvailableProjectsChangelog(c *gin.Context) + ListEarns(c *gin.Context) + ListMemos(c *gin.Context) + ListTechRadars(c *gin.Context) + ListAudiences(c *gin.Context) + ListEvents(c *gin.Context) + ListDigests(c *gin.Context) + ListUpdates(c *gin.Context) + ListIssues(c *gin.Context) + ListStaffingDemands(c *gin.Context) + ListHiringPositions(c *gin.Context) + ListProjectMilestones(c *gin.Context) + SendNewsLetter(c *gin.Context) SendProjectChangelog(c *gin.Context) } diff --git a/pkg/handler/issue/issue.go b/pkg/handler/notion/issue.go similarity index 73% rename from pkg/handler/issue/issue.go rename to pkg/handler/notion/issue.go index 329128ea1..c63912357 100644 --- a/pkg/handler/issue/issue.go +++ b/pkg/handler/notion/issue.go @@ -1,40 +1,18 @@ -// please edit this file only with approval from hnh -package issue +// Package notion please edit this file only with approval from hnh +package notion import ( "net/http" "time" "github.com/dstotijn/go-notion" - "github.com/dwarvesf/fortress-api/pkg/config" - "github.com/dwarvesf/fortress-api/pkg/logger" + "github.com/gin-gonic/gin" + "github.com/dwarvesf/fortress-api/pkg/model" - "github.com/dwarvesf/fortress-api/pkg/service" - "github.com/dwarvesf/fortress-api/pkg/store" "github.com/dwarvesf/fortress-api/pkg/view" - "github.com/gin-gonic/gin" ) -type handler struct { - store *store.Store - service *service.Service - logger logger.Logger - repo store.DBRepo - config *config.Config -} - -// New returns a handler -func New(store *store.Store, repo store.DBRepo, service *service.Service, logger logger.Logger, cfg *config.Config) IHandler { - return &handler{ - store: store, - repo: repo, - service: service, - logger: logger, - config: cfg, - } -} - -// List godoc +// ListIssues godoc // @Summary Get list issues from DF Issues & Resolution Log // @Description Get list issues from DF Issues & Resolution Log // @Tags issue @@ -42,7 +20,7 @@ func New(store *store.Store, repo store.DBRepo, service *service.Service, logger // @Produce json // @Success 200 {object} []model.Issue // @Failure 400 {object} view.ErrorResponse -func (h *handler) List(c *gin.Context) { +func (h *handler) ListIssues(c *gin.Context) { resp, err := h.service.Notion.GetDatabase(h.config.Notion.Databases.Issue, nil, []notion.DatabaseQuerySort{ { Property: "Incident Date", @@ -54,7 +32,7 @@ func (h *handler) List(c *gin.Context) { return } - var issues = []model.Issue{} + var issues []model.NotionIssue for _, r := range resp.Results { props := r.Properties.(notion.DatabasePageProperties) if props["Status"].Status == nil || props["Status"].Status.Name == "Done" { @@ -73,7 +51,7 @@ func (h *handler) List(c *gin.Context) { if len(props["Scope"].MultiSelect) > 0 { scope = props["Scope"].MultiSelect[0].Name } - projects := []string{} + var projects []string if len(props["Project"].Relation) > 0 { for _, p := range props["Project"].Relation { projects = append(projects, p.ID) @@ -83,9 +61,9 @@ func (h *handler) List(c *gin.Context) { if len(props["PIC"].People) > 0 { pic = props["PIC"].People[0].Name } - prority := "" + priority := "" if props["Priority"].Select != nil { - prority = props["Priority"].Select.Name + priority = props["Priority"].Select.Name } profile := "" if len(props["Profile"].Relation) > 0 { @@ -103,9 +81,9 @@ func (h *handler) List(c *gin.Context) { if props["Solved Date"].Date != nil { solvedDate = props["Solved Date"].Date.Start.Time } - rootcause := "" + rootCause := "" if len(props["Rootcause"].RichText) > 0 { - rootcause = props["Rootcause"].RichText[0].Text.Content + rootCause = props["Rootcause"].RichText[0].Text.Content } name := props["Name"].Title[0].Text.Content @@ -113,19 +91,19 @@ func (h *handler) List(c *gin.Context) { name = *r.Icon.Emoji + " " + props["Name"].Title[0].Text.Content } - issues = append(issues, model.Issue{ + issues = append(issues, model.NotionIssue{ ID: r.ID, Name: name, Status: props["Status"].Status.Name, Source: source, - Rootcause: rootcause, + RootCause: rootCause, IncidentDate: &incidentDate, SolvedDate: &solvedDate, Severity: serverity, Scope: scope, Projects: projects, PIC: pic, - Priority: prority, + Priority: priority, Profile: profile, Resolution: resolution, }) diff --git a/pkg/handler/memo/memo.go b/pkg/handler/notion/memo.go similarity index 62% rename from pkg/handler/memo/memo.go rename to pkg/handler/notion/memo.go index 2b88195ac..293135e84 100644 --- a/pkg/handler/memo/memo.go +++ b/pkg/handler/notion/memo.go @@ -1,47 +1,24 @@ -// please edit this file only with approval from hnh -package memo +// Package notion please edit this file only with approval from hnh +package notion import ( "net/http" "github.com/dstotijn/go-notion" - "github.com/dwarvesf/fortress-api/pkg/config" - "github.com/dwarvesf/fortress-api/pkg/logger" "github.com/dwarvesf/fortress-api/pkg/model" - "github.com/dwarvesf/fortress-api/pkg/service" - "github.com/dwarvesf/fortress-api/pkg/store" "github.com/dwarvesf/fortress-api/pkg/view" "github.com/gin-gonic/gin" ) -type handler struct { - store *store.Store - service *service.Service - logger logger.Logger - repo store.DBRepo - config *config.Config -} - -// New returns a handler -func New(store *store.Store, repo store.DBRepo, service *service.Service, logger logger.Logger, cfg *config.Config) IHandler { - return &handler{ - store: store, - repo: repo, - service: service, - logger: logger, - config: cfg, - } -} - -// List godoc +// ListMemos godoc // @Summary Get list memos from DF Memos // @Description Get list memos from DF Memos // @Tags memos // @Accept json // @Produce json -// @Success 200 {object} []model.Memo +// @Success 200 {object} []model.NotionMemo // @Failure 400 {object} view.ErrorResponse -func (h *handler) List(c *gin.Context) { +func (h *handler) ListMemos(c *gin.Context) { resp, err := h.service.Notion.GetDatabase(h.config.Notion.Databases.Memo, nil, []notion.DatabaseQuerySort{ { Property: "Created", @@ -53,7 +30,7 @@ func (h *handler) List(c *gin.Context) { return } - var memos = []model.Memo{} + var memos []model.NotionMemo for _, r := range resp.Results { props := r.Properties.(notion.DatabasePageProperties) @@ -68,14 +45,14 @@ func (h *handler) List(c *gin.Context) { author = props["Author"].People[0].Name } - tags := []string{} + var tags []string if len(props["Tags"].MultiSelect) > 0 { for _, t := range props["Tags"].MultiSelect { tags = append(tags, t.Name) } } - memos = append(memos, model.Memo{ + memos = append(memos, model.NotionMemo{ ID: r.ID, Name: name, CreatedAt: props["Created"].Date.Start.Time, diff --git a/pkg/handler/dfupdate/df_update.go b/pkg/handler/notion/newsletter.go similarity index 86% rename from pkg/handler/dfupdate/df_update.go rename to pkg/handler/notion/newsletter.go index ecd1c533d..e3f560189 100644 --- a/pkg/handler/dfupdate/df_update.go +++ b/pkg/handler/notion/newsletter.go @@ -1,4 +1,4 @@ -package dfupdate +package notion import ( "context" @@ -17,8 +17,19 @@ import ( "github.com/sendgrid/sendgrid-go/helpers/mail" ) -// Send implements IHandler -func (h *handler) Send(c *gin.Context) { +type From struct { + Email string `json:"email,omitempty"` + Name string `json:"name,omitempty"` +} + +type ProjectChangelog struct { + ProjectPageID string `json:"project_page_id,omitempty"` + IsPreview bool `json:"is_preview"` + From From `json:"from,omitempty"` +} + +// SendNewsLetter implements IHandler +func (h *handler) SendNewsLetter(c *gin.Context) { contentID := c.Param("id") isPreview := false if c.Query("preview") == "true" { @@ -59,9 +70,9 @@ func (h *handler) Send(c *gin.Context) { } } else { // get subscribers - subscribers, _, err := h.getSubcribers(h.config.Notion.Databases.Audience, "Dwarves Updates") + subscribers, _, err := h.getSubscribers(h.config.Notion.Databases.Audience, "Dwarves Updates") if err != nil { - h.logger.Error(err, "getSubcribers() failed") + h.logger.Error(err, "getSubscribers() failed") c.JSON(http.StatusInternalServerError, view.CreateResponse[any](nil, nil, err, nil, "")) return } @@ -100,7 +111,7 @@ func (h *handler) Send(c *gin.Context) { c.JSON(http.StatusOK, view.CreateResponse[any](nil, nil, nil, nil, "ok")) } -func (h *handler) getSubcribers(pageID, audience string) ([]*mail.Email, []string, error) { +func (h *handler) getSubscribers(pageID, audience string) ([]*mail.Email, []string, error) { records, err := h.service.Notion.QueryAudienceDatabase(pageID, audience) if err != nil { h.logger.Error(err, "query audience database") @@ -151,7 +162,7 @@ func (h *handler) generateEmailNewsletter(id string, from *mail.Email, categorie pageContent, err := h.service.Notion.GetBlockChildren(id) if err != nil { - h.logger.Error(err, "download page") + h.logger.Errorf(err, "failed to download page", "pageID", id) return nil, err } changelogBlocks = pageContent.Results @@ -161,7 +172,7 @@ func (h *handler) generateEmailNewsletter(id string, from *mail.Email, categorie if block.HasChildren() { children, err := h.service.Notion.GetBlockChildren(block.ID()) if err != nil { - h.logger.Error(err, "get block children") + h.logger.Errorf(err, "failed to get block children", "blockID", block.ID()) return nil, err } diff --git a/pkg/handler/notion/project_milestone.go b/pkg/handler/notion/project_milestone.go new file mode 100644 index 000000000..569855dbf --- /dev/null +++ b/pkg/handler/notion/project_milestone.go @@ -0,0 +1,156 @@ +package notion + +import ( + "net/http" + "regexp" + "sort" + "strings" + "sync" + + "github.com/dstotijn/go-notion" + "github.com/gin-gonic/gin" + + "github.com/dwarvesf/fortress-api/pkg/model" + "github.com/dwarvesf/fortress-api/pkg/view" +) + +func (h *handler) ListProjectMilestones(c *gin.Context) { + filter := ¬ion.DatabaseQueryFilter{} + + filter.And = append(filter.And, notion.DatabaseQueryFilter{ + Property: "Status", + DatabaseQueryPropertyFilter: notion.DatabaseQueryPropertyFilter{ + Select: ¬ion.SelectDatabaseQueryFilter{ + Equals: "Active", + }, + }, + }) + + resp, err := h.service.Notion.GetDatabase(h.config.Notion.Databases.Project, filter, nil, 0) + if err != nil { + c.JSON(http.StatusBadRequest, view.CreateResponse[any](nil, nil, err, nil, "failed to get projects from notion")) + return + } + + var projects []struct { + Name string `json:"name"` + Milestones []model.NotionProjectMilestone `json:"milestones"` + } + + var wg sync.WaitGroup + var pmu sync.Mutex + + for _, r := range resp.Results { + props := r.Properties.(notion.DatabasePageProperties) + + if len(props["Project"].Title) == 0 || len(props["Parent item"].Relation) > 0 { + continue + } + + if c.Query("project_name") != "" { + matched, err := regexp.MatchString(".*"+strings.ToLower(c.Query("project_name"))+".*", strings.ToLower(props["Project"].Title[0].Text.Content)) + if err != nil || !matched { + continue + } + } + + var p = struct { + Name string `json:"name"` + Milestones []model.NotionProjectMilestone `json:"milestones"` + }{} + var milestones []model.NotionProjectMilestone + + p.Name = props["Project"].Title[0].Text.Content + + wg.Add(1) + go func() { + defer wg.Done() + + workers := make(chan struct{}, 10) // limit to 10 workers + + var mmilestones = make(map[string]model.NotionProjectMilestone) + for _, p := range props["Sub-item"].Relation { + workers <- struct{}{} + go func(p notion.Relation) { + defer func() { <-workers }() + if x, found := h.service.Cache.Get(p.ID); found { + mmilestones[p.ID] = x.(model.NotionProjectMilestone) + return + } + resp, err := h.service.Notion.GetPage(p.ID) + if err != nil { + return + } + props := resp.Properties.(notion.DatabasePageProperties) + name := "" + if len(props["Project"].Title) > 0 { + name = props["Project"].Title[0].Text.Content + } + m := model.NotionProjectMilestone{ + ID: resp.ID, + Name: name, + SubMilestones: []*model.NotionProjectMilestone{}, + } + if props["Milestone Date"].Date != nil { + m.StartDate = props["Milestone Date"].Date.Start.Time + m.EndDate = props["Milestone Date"].Date.End.Time + } + mmilestones[p.ID] = m + h.service.Cache.Set(p.ID, m, 0) + }(p) + } + for i := 0; i < cap(workers); i++ { + workers <- struct{}{} + } + for _, m := range mmilestones { + milestones = append(milestones, m) + } + sort.Slice(milestones[:], func(i, j int) bool { + return milestones[i].StartDate.Before(milestones[j].StartDate) + }) + + p.Milestones = milestones + + pmu.Lock() + projects = append(projects, p) + pmu.Unlock() + }() + } + wg.Wait() + sort.Slice(projects[:], func(i, j int) bool { + return projects[i].Name < projects[j].Name + }) + + c.JSON(http.StatusOK, view.CreateResponse[any](projects, nil, nil, nil, "get list milestones successfully")) +} + +// func (h *handler) getMilestones(item *model.ProjectMilestone, subItems []*model.ProjectMilestone) []*model.ProjectMilestone { +// resp, err := h.service.Notion.GetPage(item.ID) +// if err != nil { +// return subItems +// } +// props := resp.Properties.(notion.DatabasePageProperties) +// for _, p := range props["Sub-item"].Relation { +// resp, err := h.service.Notion.GetPage(p.ID) +// if err != nil { +// continue +// } +// props := resp.Properties.(notion.DatabasePageProperties) +// name := "" +// if len(props["Project"].Title) > 0 { +// name = props["Project"].Title[0].Text.Content +// } +// m := &model.ProjectMilestone{ +// ID: resp.ID, +// Name: name, +// SubMilestones: []*model.ProjectMilestone{}, +// } +// if props["Milestone Date"].Date != nil { +// m.StartDate = props["Milestone Date"].Date.Start.Time +// m.EndDate = props["Milestone Date"].Date.End.Time +// } +// subItems = append(subItems, m) +// } + +// return subItems +// } diff --git a/pkg/handler/staffingdemand/staffing_demand.go b/pkg/handler/notion/staffing_demand.go similarity index 57% rename from pkg/handler/staffingdemand/staffing_demand.go rename to pkg/handler/notion/staffing_demand.go index afba5df37..32ce5bcd8 100644 --- a/pkg/handler/staffingdemand/staffing_demand.go +++ b/pkg/handler/notion/staffing_demand.go @@ -1,39 +1,17 @@ -// please edit this file only with approval from hnh -package staffingdemand +// Package notion please edit this file only with approval from hnh +package notion import ( "net/http" "github.com/dstotijn/go-notion" - "github.com/dwarvesf/fortress-api/pkg/config" - "github.com/dwarvesf/fortress-api/pkg/logger" + "github.com/gin-gonic/gin" + "github.com/dwarvesf/fortress-api/pkg/model" - "github.com/dwarvesf/fortress-api/pkg/service" - "github.com/dwarvesf/fortress-api/pkg/store" "github.com/dwarvesf/fortress-api/pkg/view" - "github.com/gin-gonic/gin" ) -type handler struct { - store *store.Store - service *service.Service - logger logger.Logger - repo store.DBRepo - config *config.Config -} - -// New returns a handler -func New(store *store.Store, repo store.DBRepo, service *service.Service, logger logger.Logger, cfg *config.Config) IHandler { - return &handler{ - store: store, - repo: repo, - service: service, - logger: logger, - config: cfg, - } -} - -// List godoc +// ListStaffingDemands godoc // @Summary Get list staffing demands from DF Staffing Demand // @Description Get list staffing demands from DF Staffing Demand // @Tags staffing-demands @@ -41,14 +19,14 @@ func New(store *store.Store, repo store.DBRepo, service *service.Service, logger // @Produce json // @Success 200 {object} []model.StaffingDemand // @Failure 400 {object} view.ErrorResponse -func (h *handler) List(c *gin.Context) { +func (h *handler) ListStaffingDemands(c *gin.Context) { resp, err := h.service.Notion.GetDatabase(h.config.Notion.Databases.StaffingDemand, nil, nil, 0) if err != nil { - c.JSON(http.StatusBadRequest, view.CreateResponse[any](nil, nil, err, nil, "can't get staffing demands from notion")) + c.JSON(http.StatusBadRequest, view.CreateResponse[any](nil, nil, err, nil, "failed to get staffing demands from notion")) return } - var staffingDemands = []model.StaffingDemand{} + var staffingDemands []model.NotionStaffingDemand for _, r := range resp.Results { props := r.Properties.(notion.DatabasePageProperties) @@ -63,7 +41,7 @@ func (h *handler) List(c *gin.Context) { request = props["Request"].RichText[0].Text.Content } - staffingDemands = append(staffingDemands, model.StaffingDemand{ + staffingDemands = append(staffingDemands, model.NotionStaffingDemand{ ID: r.ID, Name: name, Request: request, diff --git a/pkg/handler/techradar/tech_radar.go b/pkg/handler/notion/tech_radar.go similarity index 82% rename from pkg/handler/techradar/tech_radar.go rename to pkg/handler/notion/tech_radar.go index d77612306..2ff232268 100644 --- a/pkg/handler/techradar/tech_radar.go +++ b/pkg/handler/notion/tech_radar.go @@ -1,5 +1,5 @@ -// please edit this file only with approval from hnh -package techradar +// Package notion please edit this file only with approval from hnh +package notion import ( "html" @@ -11,34 +11,11 @@ import ( "github.com/gin-gonic/gin" "github.com/thoas/go-funk" - "github.com/dwarvesf/fortress-api/pkg/config" - "github.com/dwarvesf/fortress-api/pkg/logger" "github.com/dwarvesf/fortress-api/pkg/model" - "github.com/dwarvesf/fortress-api/pkg/service" - "github.com/dwarvesf/fortress-api/pkg/store" "github.com/dwarvesf/fortress-api/pkg/view" ) -type handler struct { - store *store.Store - service *service.Service - logger logger.Logger - repo store.DBRepo - config *config.Config -} - -// New returns a handler -func New(store *store.Store, repo store.DBRepo, service *service.Service, logger logger.Logger, cfg *config.Config) IHandler { - return &handler{ - store: store, - repo: repo, - service: service, - logger: logger, - config: cfg, - } -} - -// List godoc +// ListTechRadars godoc // @Summary Get list items from DF TechRadar // @Description Get list items from DF TechRadar // @Tags TechRadar @@ -46,7 +23,7 @@ func New(store *store.Store, repo store.DBRepo, service *service.Service, logger // @Produce json // @Success 200 {object} []model.TechRadar // @Failure 400 {object} view.ErrorResponse -func (h *handler) List(c *gin.Context) { +func (h *handler) ListTechRadars(c *gin.Context) { filter := ¬ion.DatabaseQueryFilter{} rings := []string{"Adopt", "Trial", "Assess", "Hold"} @@ -81,7 +58,7 @@ func (h *handler) List(c *gin.Context) { return } - var techs = []model.TechRadar{} + var techs []model.NotionTechRadar for _, r := range resp.Results { props := r.Properties.(notion.DatabasePageProperties) @@ -115,16 +92,16 @@ func (h *handler) List(c *gin.Context) { if props["Status"].Select != nil { ring = props["Status"].Select.Name } - categories := []string{} + var categories []string for _, c := range props["Categories"].MultiSelect { categories = append(categories, c.Name) } - tags := []string{} + var tags []string for _, t := range props["Tag"].MultiSelect { tags = append(tags, t.Name) } - techs = append(techs, model.TechRadar{ + techs = append(techs, model.NotionTechRadar{ ID: r.ID, Name: name, Assign: assign, @@ -138,7 +115,7 @@ func (h *handler) List(c *gin.Context) { c.JSON(http.StatusOK, view.CreateResponse[any](techs, nil, nil, nil, "get list earn items successfully")) } -// create a new tech radar item +// CreateTechRadar create a new tech radar item // @Summary Create a new tech radar item // @Description Create a new tech radar item // @Tags TechRadar @@ -147,8 +124,8 @@ func (h *handler) List(c *gin.Context) { // @Param body body model.TechRadar true "body for create tech radar item" // @Success 200 {object} model.TechRadar // @Failure 400 {object} view.ErrorResponse -func (h *handler) Create(c *gin.Context) { - var input model.TechRadar +func (h *handler) CreateTechRadar(c *gin.Context) { + var input model.NotionTechRadar if err := c.ShouldBindJSON(&input); err != nil { c.JSON(http.StatusBadRequest, view.CreateResponse[any](nil, nil, err, nil, "invalid input")) return @@ -158,7 +135,7 @@ func (h *handler) Create(c *gin.Context) { return } - // check item is exist + // check item is existed var filter = ¬ion.DatabaseQueryFilter{} filter.And = append(filter.And, notion.DatabaseQueryFilter{ Property: "Name", diff --git a/pkg/handler/update/update.go b/pkg/handler/notion/update.go similarity index 61% rename from pkg/handler/update/update.go rename to pkg/handler/notion/update.go index 9c22e39a3..f48eab4f0 100644 --- a/pkg/handler/update/update.go +++ b/pkg/handler/notion/update.go @@ -1,47 +1,25 @@ -// please edit this file only with approval from hnh -package update +// Package notion please edit this file only with approval from hnh +package notion import ( "net/http" "github.com/dstotijn/go-notion" - "github.com/dwarvesf/fortress-api/pkg/config" - "github.com/dwarvesf/fortress-api/pkg/logger" + "github.com/gin-gonic/gin" + "github.com/dwarvesf/fortress-api/pkg/model" - "github.com/dwarvesf/fortress-api/pkg/service" - "github.com/dwarvesf/fortress-api/pkg/store" "github.com/dwarvesf/fortress-api/pkg/view" - "github.com/gin-gonic/gin" ) -type handler struct { - store *store.Store - service *service.Service - logger logger.Logger - repo store.DBRepo - config *config.Config -} - -// New returns a handler -func New(store *store.Store, repo store.DBRepo, service *service.Service, logger logger.Logger, cfg *config.Config) IHandler { - return &handler{ - store: store, - repo: repo, - service: service, - logger: logger, - config: cfg, - } -} - -// List godoc +// ListUpdates godoc // @Summary Get list updates from DF Updates // @Description Get list updates from DF Updates // @Tags updates // @Accept json // @Produce json -// @Success 200 {object} []model.Update +// @Success 200 {object} []model.NotionUpdate // @Failure 400 {object} view.ErrorResponse -func (h *handler) List(c *gin.Context) { +func (h *handler) ListUpdates(c *gin.Context) { resp, err := h.service.Notion.GetDatabase(h.config.Notion.Databases.Updates, nil, []notion.DatabaseQuerySort{ { Property: "Created at", @@ -53,7 +31,7 @@ func (h *handler) List(c *gin.Context) { return } - var updates = []model.Update{} + var updates []model.NotionUpdate for _, r := range resp.Results { props := r.Properties.(notion.DatabasePageProperties) @@ -68,7 +46,7 @@ func (h *handler) List(c *gin.Context) { audience = props["Audience"].MultiSelect[0].Name } - updates = append(updates, model.Update{ + updates = append(updates, model.NotionUpdate{ ID: r.ID, Name: name, CreatedAt: props["Created at"].Date.Start.Time, diff --git a/pkg/handler/project/interface.go b/pkg/handler/project/interface.go index d5a04c97b..518f37779 100644 --- a/pkg/handler/project/interface.go +++ b/pkg/handler/project/interface.go @@ -22,5 +22,4 @@ type IHandler interface { UnarchiveWorkUnit(c *gin.Context) UpdateSendingSurveyState(c *gin.Context) UploadAvatar(c *gin.Context) - ListMilestones(c *gin.Context) } diff --git a/pkg/handler/project/project.go b/pkg/handler/project/project.go index 4146b9dc8..20bace997 100644 --- a/pkg/handler/project/project.go +++ b/pkg/handler/project/project.go @@ -5,13 +5,9 @@ import ( "fmt" "net/http" "path/filepath" - "regexp" - "sort" "strings" - "sync" "time" - "github.com/dstotijn/go-notion" "github.com/gin-gonic/gin" "github.com/shopspring/decimal" "gorm.io/gorm" @@ -2920,144 +2916,3 @@ func (h *handler) UploadAvatar(c *gin.Context) { c.JSON(http.StatusOK, view.CreateResponse[any](view.ToProjectContentData(filePath), nil, done(nil), nil, "")) } - -func (h *handler) ListMilestones(c *gin.Context) { - filter := ¬ion.DatabaseQueryFilter{} - - filter.And = append(filter.And, notion.DatabaseQueryFilter{ - Property: "Status", - DatabaseQueryPropertyFilter: notion.DatabaseQueryPropertyFilter{ - Select: ¬ion.SelectDatabaseQueryFilter{ - Equals: "Active", - }, - }, - }) - - resp, err := h.service.Notion.GetDatabase(h.config.Notion.Databases.Project, filter, nil, 0) - if err != nil { - c.JSON(http.StatusBadRequest, view.CreateResponse[any](nil, nil, err, nil, "can't get projects from notion")) - return - } - - var projects = []struct { - Name string `json:"name"` - Milestones []model.ProjectMilestone `json:"milestones"` - }{} - - var wg sync.WaitGroup - var pmu sync.Mutex - - for _, r := range resp.Results { - props := r.Properties.(notion.DatabasePageProperties) - - if len(props["Project"].Title) == 0 || len(props["Parent item"].Relation) > 0 { - continue - } - - if c.Query("project_name") != "" { - matched, err := regexp.MatchString(".*"+strings.ToLower(c.Query("project_name"))+".*", strings.ToLower(props["Project"].Title[0].Text.Content)) - if err != nil || !matched { - continue - } - } - - var p = struct { - Name string `json:"name"` - Milestones []model.ProjectMilestone `json:"milestones"` - }{} - var milestones = []model.ProjectMilestone{} - - p.Name = props["Project"].Title[0].Text.Content - - wg.Add(1) - go func() { - defer wg.Done() - - workers := make(chan struct{}, 10) // limit to 10 workers - - var mmilestones = make(map[string]model.ProjectMilestone) - for _, p := range props["Sub-item"].Relation { - workers <- struct{}{} - go func(p notion.Relation) { - defer func() { <-workers }() - if x, found := h.service.Cache.Get(p.ID); found { - mmilestones[p.ID] = x.(model.ProjectMilestone) - return - } - resp, err := h.service.Notion.GetPage(p.ID) - if err != nil { - return - } - props := resp.Properties.(notion.DatabasePageProperties) - name := "" - if len(props["Project"].Title) > 0 { - name = props["Project"].Title[0].Text.Content - } - m := model.ProjectMilestone{ - ID: resp.ID, - Name: name, - SubMilestones: []*model.ProjectMilestone{}, - } - if props["Milestone Date"].Date != nil { - m.StartDate = props["Milestone Date"].Date.Start.Time - m.EndDate = props["Milestone Date"].Date.End.Time - } - mmilestones[p.ID] = m - h.service.Cache.Set(p.ID, m, 0) - }(p) - } - for i := 0; i < cap(workers); i++ { - workers <- struct{}{} - } - for _, m := range mmilestones { - milestones = append(milestones, m) - } - sort.Slice(milestones[:], func(i, j int) bool { - return milestones[i].StartDate.Before(milestones[j].StartDate) - }) - - p.Milestones = milestones - - pmu.Lock() - projects = append(projects, p) - pmu.Unlock() - }() - } - wg.Wait() - sort.Slice(projects[:], func(i, j int) bool { - return projects[i].Name < projects[j].Name - }) - - c.JSON(http.StatusOK, view.CreateResponse[any](projects, nil, nil, nil, "get list milestones successfully")) -} - -// func (h *handler) getMilestones(item *model.ProjectMilestone, subItems []*model.ProjectMilestone) []*model.ProjectMilestone { -// resp, err := h.service.Notion.GetPage(item.ID) -// if err != nil { -// return subItems -// } -// props := resp.Properties.(notion.DatabasePageProperties) -// for _, p := range props["Sub-item"].Relation { -// resp, err := h.service.Notion.GetPage(p.ID) -// if err != nil { -// continue -// } -// props := resp.Properties.(notion.DatabasePageProperties) -// name := "" -// if len(props["Project"].Title) > 0 { -// name = props["Project"].Title[0].Text.Content -// } -// m := &model.ProjectMilestone{ -// ID: resp.ID, -// Name: name, -// SubMilestones: []*model.ProjectMilestone{}, -// } -// if props["Milestone Date"].Date != nil { -// m.StartDate = props["Milestone Date"].Date.Start.Time -// m.EndDate = props["Milestone Date"].Date.End.Time -// } -// subItems = append(subItems, m) -// } - -// return subItems -// } diff --git a/pkg/handler/staffingdemand/interface.go b/pkg/handler/staffingdemand/interface.go deleted file mode 100644 index ae09acc4f..000000000 --- a/pkg/handler/staffingdemand/interface.go +++ /dev/null @@ -1,7 +0,0 @@ -package staffingdemand - -import "github.com/gin-gonic/gin" - -type IHandler interface { - List(c *gin.Context) -} diff --git a/pkg/handler/techradar/interface.go b/pkg/handler/techradar/interface.go deleted file mode 100644 index abae5c55b..000000000 --- a/pkg/handler/techradar/interface.go +++ /dev/null @@ -1,8 +0,0 @@ -package techradar - -import "github.com/gin-gonic/gin" - -type IHandler interface { - List(c *gin.Context) - Create(c *gin.Context) -} diff --git a/pkg/handler/update/interface.go b/pkg/handler/update/interface.go deleted file mode 100644 index 715f58ae8..000000000 --- a/pkg/handler/update/interface.go +++ /dev/null @@ -1,7 +0,0 @@ -package update - -import "github.com/gin-gonic/gin" - -type IHandler interface { - List(c *gin.Context) -} diff --git a/pkg/model/audience.go b/pkg/model/audience.go deleted file mode 100644 index f1d20b848..000000000 --- a/pkg/model/audience.go +++ /dev/null @@ -1,11 +0,0 @@ -package model - -import "time" - -type Audience struct { - ID string `json:"id"` - FullName string `json:"full_name"` - Email string `json:"email"` - Sources []string `json:"source"` - CreatedAt time.Time `json:"created_at"` -} diff --git a/pkg/model/digest.go b/pkg/model/digest.go deleted file mode 100644 index 1bab3e927..000000000 --- a/pkg/model/digest.go +++ /dev/null @@ -1,9 +0,0 @@ -package model - -import "time" - -type Digest struct { - ID string `json:"id"` - Name string `json:"name"` - CreatedAt time.Time `json:"created_at"` -} diff --git a/pkg/model/earn.go b/pkg/model/earn.go deleted file mode 100644 index b5a00e405..000000000 --- a/pkg/model/earn.go +++ /dev/null @@ -1,16 +0,0 @@ -package model - -import "time" - -type Earn struct { - ID string `json:"id"` - Name string `json:"name"` - Reward int `json:"reward"` - Progress int `json:"progress"` - Priority string `json:"priority"` - Tags []string `json:"tags"` - PICs []Employee `json:"pics"` - Status string `json:"status"` - Function []string `json:"function"` - DueDate *time.Time `json:"due_date"` -} diff --git a/pkg/model/hiring.go b/pkg/model/hiring.go deleted file mode 100644 index b8132c1c4..000000000 --- a/pkg/model/hiring.go +++ /dev/null @@ -1,19 +0,0 @@ -package model - -type HiringType string - -const ( - DirectHiringType HiringType = "direct" - ReferralHiringType HiringType = "referral" - InternshipHiringType HiringType = "internship" -) - -type HiringRelationship struct { - BaseModel - - UserID UUID `json:"user_id"` - SupplierID UUID `json:"supplier_id"` - HiringType HiringType `json:"hiring_type"` - - Employee Employee `json:"user"` -} diff --git a/pkg/model/hiring_position.go b/pkg/model/hiring_position.go deleted file mode 100644 index b58ee40c6..000000000 --- a/pkg/model/hiring_position.go +++ /dev/null @@ -1,13 +0,0 @@ -package model - -import ( - "time" -) - -type HiringPosition struct { - ID string `json:"id"` - Name string `json:"name"` - Projects []string `json:"project"` - Status string `json:"status"` - CreatedAt time.Time `json:"created_at"` -} diff --git a/pkg/model/issue.go b/pkg/model/issue.go deleted file mode 100644 index 6886a7e5e..000000000 --- a/pkg/model/issue.go +++ /dev/null @@ -1,20 +0,0 @@ -package model - -import "time" - -type Issue struct { - ID string `json:"id"` - Name string `json:"name"` - Rootcause string `json:"rootcause"` - Resolution string `json:"resolution"` - Scope string `json:"scope"` - Priority string `json:"priority"` - Severity string `json:"severity"` - IncidentDate *time.Time `json:"incident_date"` - SolvedDate *time.Time `json:"solve_date"` - PIC string `json:"pic"` - Projects []string `json:"projects"` - Status string `json:"status"` - Source string `json:"source"` - Profile string `json:"profile"` -} diff --git a/pkg/model/memo.go b/pkg/model/memo.go deleted file mode 100644 index 7ce3084f5..000000000 --- a/pkg/model/memo.go +++ /dev/null @@ -1,11 +0,0 @@ -package model - -import "time" - -type Memo struct { - ID string `json:"id"` - Name string `json:"name"` - Tags []string `json:"tags"` - Author string `json:"author"` - CreatedAt time.Time `json:"created_at"` -} diff --git a/pkg/model/notion.go b/pkg/model/notion.go index 0d093b8e2..a1775e894 100644 --- a/pkg/model/notion.go +++ b/pkg/model/notion.go @@ -1,5 +1,7 @@ package model +import "time" + // ProjectChangelogPage -- notion project changelog page type ProjectChangelogPage struct { RowID string `json:"row_id"` @@ -7,3 +9,116 @@ type ProjectChangelogPage struct { Title string `json:"title"` ChangelogURL string `json:"changelog_url"` } + +type NotionMemo struct { + ID string `json:"id"` + Name string `json:"name"` + Tags []string `json:"tags"` + Author string `json:"author"` + CreatedAt time.Time `json:"created_at"` +} + +type NotionUpdate struct { + ID string `json:"id"` + Name string `json:"name"` + Audience string `json:"audience"` + CreatedAt time.Time `json:"created_at"` +} + +type NotionEarn struct { + ID string `json:"id"` + Name string `json:"name"` + Reward int `json:"reward"` + Progress int `json:"progress"` + Priority string `json:"priority"` + Tags []string `json:"tags"` + PICs []Employee `json:"pics"` + Status string `json:"status"` + Function []string `json:"function"` + DueDate *time.Time `json:"due_date"` +} + +type NotionAudience struct { + ID string `json:"id"` + FullName string `json:"full_name"` + Email string `json:"email"` + Sources []string `json:"source"` + CreatedAt time.Time `json:"created_at"` +} + +type NotionTechRadar struct { + ID string `json:"id"` + Name string `json:"name"` + Assign string `json:"assign"` + Categories []string `json:"categories"` + Tags []string `json:"tags"` + Quadrant string `json:"quadrant"` + Ring string `json:"ring"` +} + +type NotionDigest struct { + ID string `json:"id"` + Name string `json:"name"` + CreatedAt time.Time `json:"created_at"` +} + +type NotionStaffingDemand struct { + ID string `json:"id"` + Name string `json:"name"` + Request string `json:"request"` +} + +type NotionIssue struct { + ID string `json:"id"` + Name string `json:"name"` + RootCause string `json:"rootcause"` + Resolution string `json:"resolution"` + Scope string `json:"scope"` + Priority string `json:"priority"` + Severity string `json:"severity"` + IncidentDate *time.Time `json:"incident_date"` + SolvedDate *time.Time `json:"solve_date"` + PIC string `json:"pic"` + Projects []string `json:"projects"` + Status string `json:"status"` + Source string `json:"source"` + Profile string `json:"profile"` +} + +type HiringType string + +const ( + HiringTypeDirect HiringType = "direct" + HiringTypeReferral HiringType = "referral" + HiringTypeInternship HiringType = "internship" +) + +type NotionHiringRelationship struct { + BaseModel + + UserID UUID `json:"user_id"` + SupplierID UUID `json:"supplier_id"` + HiringType HiringType `json:"hiring_type"` + + Employee Employee `json:"user"` +} + +type NotionHiringPosition struct { + ID string `json:"id"` + Name string `json:"name"` + Projects []string `json:"project"` + Status string `json:"status"` + CreatedAt time.Time `json:"created_at"` +} + +type NotionProjectMilestone struct { + ID string `json:"id"` + Name string `json:"name"` + StartDate time.Time `json:"start_date"` + EndDate time.Time `json:"end_date"` + SubMilestones []*NotionProjectMilestone `json:"sub_milestones"` +} + +func (o *NotionProjectMilestone) GetSubMilestones() []*NotionProjectMilestone { + return o.SubMilestones +} diff --git a/pkg/model/project_milestone.go b/pkg/model/project_milestone.go deleted file mode 100644 index 4e71c3efa..000000000 --- a/pkg/model/project_milestone.go +++ /dev/null @@ -1,15 +0,0 @@ -package model - -import "time" - -type ProjectMilestone struct { - ID string `json:"id"` - Name string `json:"name"` - StartDate time.Time `json:"start_date"` - EndDate time.Time `json:"end_date"` - SubMilestones []*ProjectMilestone `json:"sub_milestones"` -} - -func (o *ProjectMilestone) GetSubMilestones() []*ProjectMilestone { - return o.SubMilestones -} diff --git a/pkg/model/staffing_demand.go b/pkg/model/staffing_demand.go deleted file mode 100644 index 3fb9c5fe1..000000000 --- a/pkg/model/staffing_demand.go +++ /dev/null @@ -1,7 +0,0 @@ -package model - -type StaffingDemand struct { - ID string `json:"id"` - Name string `json:"name"` - Request string `json:"request"` -} diff --git a/pkg/model/tech_radar.go b/pkg/model/tech_radar.go deleted file mode 100644 index b44fd0d26..000000000 --- a/pkg/model/tech_radar.go +++ /dev/null @@ -1,11 +0,0 @@ -package model - -type TechRadar struct { - ID string `json:"id"` - Name string `json:"name"` - Assign string `json:"assign"` - Categories []string `json:"categories"` - Tags []string `json:"tags"` - Quadrant string `json:"quadrant"` - Ring string `json:"ring"` -} diff --git a/pkg/model/update.go b/pkg/model/update.go deleted file mode 100644 index 5d94ad52a..000000000 --- a/pkg/model/update.go +++ /dev/null @@ -1,10 +0,0 @@ -package model - -import "time" - -type Update struct { - ID string `json:"id"` - Name string `json:"name"` - Audience string `json:"audience"` - CreatedAt time.Time `json:"created_at"` -} diff --git a/pkg/routes/v1.go b/pkg/routes/v1.go index 72e222d9a..7a0dd441a 100644 --- a/pkg/routes/v1.go +++ b/pkg/routes/v1.go @@ -173,46 +173,61 @@ func loadV1Routes(r *gin.Engine, h *handler.Handler, repo store.DBRepo, s *store { earn := notion.Group("/earn") { - earn.GET("", h.Earn.List) + earn.GET("", h.Notion.ListEarns) } techradar := notion.Group("/tech-radar") { - techradar.GET("", h.TechRadar.List) - techradar.POST("", h.TechRadar.Create) + techradar.GET("", h.Notion.ListTechRadars) + techradar.POST("", h.Notion.CreateTechRadar) } audience := notion.Group("/audiences") { - audience.GET("", h.Audience.List) + audience.GET("", h.Notion.ListAudiences) } event := notion.Group("/events") { - event.GET("", h.Event.List) + event.GET("", h.Notion.ListEvents) } digest := notion.Group("/digests") { - digest.GET("", h.Digest.List) + digest.GET("", h.Notion.ListDigests) } update := notion.Group("/updates") { - update.GET("", h.Update.List) + update.GET("", h.Notion.ListUpdates) } memo := notion.Group("/memos") { - memo.GET("", h.Memo.List) + memo.GET("", h.Notion.ListMemos) } issue := notion.Group("/issues") { - issue.GET("", h.Issue.List) + issue.GET("", h.Notion.ListIssues) } staffingDemand := notion.Group("/staffing-demands") { - staffingDemand.GET("", h.StaffingDemand.List) + staffingDemand.GET("", h.Notion.ListStaffingDemands) } hiring := notion.Group("/hiring-positions") { - hiring.GET("", h.Hiring.List) + hiring.GET("", h.Notion.ListHiringPositions) + } + + projectNotion := notion.Group("/projects") + { + projectNotion.GET("/milestones", h.Notion.ListProjectMilestones) + } + + dfUpdates := notion.Group("df-updates") + { + dfUpdates.POST("/:id/send", h.Notion.SendNewsLetter) + } + + notionChangelog := notion.Group("changelogs") + { + notionChangelog.GET("/projects/available", h.Notion.GetAvailableProjectsChangelog) + notionChangelog.POST("/project", h.Notion.SendProjectChangelog) } - notion.GET("/projects/milestones", h.Project.ListMilestones) } dashboard := v1.Group("/dashboards") @@ -244,17 +259,6 @@ func loadV1Routes(r *gin.Engine, h *handler.Handler, repo store.DBRepo, s *store } } - notionChangelog := v1.Group("notion-changelog") - { - notionChangelog.GET("/projects/available", h.Changelog.GetAvailableProjectsChangelog) - notionChangelog.POST("/project", h.Changelog.SendProjectChangelog) - } - - dfUpdates := v1.Group("df-updates") - { - dfUpdates.POST("/:id/send", h.DFUpdate.Send) - } - payroll := v1.Group("payrolls") { payroll.PUT("", h.Payroll.MarkPayrollAsPaid) diff --git a/pkg/routes/v1_test.go b/pkg/routes/v1_test.go index a081f23fc..f735da329 100644 --- a/pkg/routes/v1_test.go +++ b/pkg/routes/v1_test.go @@ -440,71 +440,71 @@ func Test_loadV1Routes(t *testing.T) { "/api/v1/notion/earn": { "GET": { Method: "GET", - Handler: "github.com/dwarvesf/fortress-api/pkg/handler/earn.IHandler.List-fm", + Handler: "github.com/dwarvesf/fortress-api/pkg/handler/notion.IHandler.ListEarns-fm", }, }, "/api/v1/notion/tech-radar": { "GET": { Method: "GET", - Handler: "github.com/dwarvesf/fortress-api/pkg/handler/techradar.IHandler.List-fm", + Handler: "github.com/dwarvesf/fortress-api/pkg/handler/notion.IHandler.ListTechRadars-fm", }, "POST": { Method: "POST", - Handler: "github.com/dwarvesf/fortress-api/pkg/handler/techradar.IHandler.Create-fm", + Handler: "github.com/dwarvesf/fortress-api/pkg/handler/notion.IHandler.CreateTechRadar-fm", }, }, "/api/v1/notion/audiences": { "GET": { Method: "GET", - Handler: "github.com/dwarvesf/fortress-api/pkg/handler/audience.IHandler.List-fm", + Handler: "github.com/dwarvesf/fortress-api/pkg/handler/notion.IHandler.ListAudiences-fm", }, }, "/api/v1/notion/events": { "GET": { Method: "GET", - Handler: "github.com/dwarvesf/fortress-api/pkg/handler/event.IHandler.List-fm", + Handler: "github.com/dwarvesf/fortress-api/pkg/handler/notion.IHandler.ListEvents-fm", }, }, "/api/v1/notion/digests": { "GET": { Method: "GET", - Handler: "github.com/dwarvesf/fortress-api/pkg/handler/digest.IHandler.List-fm", + Handler: "github.com/dwarvesf/fortress-api/pkg/handler/notion.IHandler.ListDigests-fm", }, }, "/api/v1/notion/issues": { "GET": { Method: "GET", - Handler: "github.com/dwarvesf/fortress-api/pkg/handler/issue.IHandler.List-fm", + Handler: "github.com/dwarvesf/fortress-api/pkg/handler/notion.IHandler.ListIssues-fm", }, }, "/api/v1/notion/updates": { "GET": { Method: "GET", - Handler: "github.com/dwarvesf/fortress-api/pkg/handler/update.IHandler.List-fm", + Handler: "github.com/dwarvesf/fortress-api/pkg/handler/notion.IHandler.ListUpdates-fm", }, }, "/api/v1/notion/memos": { "GET": { Method: "GET", - Handler: "github.com/dwarvesf/fortress-api/pkg/handler/memo.IHandler.List-fm", + Handler: "github.com/dwarvesf/fortress-api/pkg/handler/notion.IHandler.ListMemos-fm", }, }, "/api/v1/notion/hiring-positions": { "GET": { Method: "GET", - Handler: "github.com/dwarvesf/fortress-api/pkg/handler/hiring.IHandler.List-fm", + Handler: "github.com/dwarvesf/fortress-api/pkg/handler/notion.IHandler.ListHiringPositions-fm", }, }, "/api/v1/notion/staffing-demands": { "GET": { Method: "GET", - Handler: "github.com/dwarvesf/fortress-api/pkg/handler/staffingdemand.IHandler.List-fm", + Handler: "github.com/dwarvesf/fortress-api/pkg/handler/notion.IHandler.ListStaffingDemands-fm", }, }, "/api/v1/notion/projects/milestones": { "GET": { Method: "GET", - Handler: "github.com/dwarvesf/fortress-api/pkg/handler/project.IHandler.ListMilestones-fm", + Handler: "github.com/dwarvesf/fortress-api/pkg/handler/notion.IHandler.ListProjectMilestones-fm", }, }, "/api/v1/dashboards/projects/action-item-squash": { @@ -673,22 +673,22 @@ func Test_loadV1Routes(t *testing.T) { Handler: "github.com/dwarvesf/fortress-api/pkg/handler/client.IHandler.Delete-fm", }, }, - "/api/v1/notion-changelog/projects/available": { + "/api/v1/notion/changelogs/projects/available": { "GET": { Method: "GET", - Handler: "github.com/dwarvesf/fortress-api/pkg/handler/changelog.IHandler.GetAvailableProjectsChangelog-fm", + Handler: "github.com/dwarvesf/fortress-api/pkg/handler/notion.IHandler.GetAvailableProjectsChangelog-fm", }, }, - "/api/v1/notion-changelog/project": { + "/api/v1/notion/changelogs/project": { "POST": { Method: "POST", - Handler: "github.com/dwarvesf/fortress-api/pkg/handler/changelog.IHandler.SendProjectChangelog-fm", + Handler: "github.com/dwarvesf/fortress-api/pkg/handler/notion.IHandler.SendProjectChangelog-fm", }, }, - "/api/v1/df-updates/:id/send": { + "/api/v1/notion/df-updates/:id/send": { "POST": { Method: "POST", - Handler: "github.com/dwarvesf/fortress-api/pkg/handler/dfupdate.IHandler.Send-fm", + Handler: "github.com/dwarvesf/fortress-api/pkg/handler/notion.IHandler.SendNewsLetter-fm", }, }, "/api/v1/payrolls": { diff --git a/pkg/view/hiring.go b/pkg/view/hiring.go index 4d6fbfbd0..0e272512f 100644 --- a/pkg/view/hiring.go +++ b/pkg/view/hiring.go @@ -3,5 +3,5 @@ package view import "github.com/dwarvesf/fortress-api/pkg/model" type HiringResponse struct { - Data []model.HiringPosition `json:"data"` + Data []model.NotionHiringPosition `json:"data"` } From 26693b89957f4c9bcc2b48d29a941dad66c08405 Mon Sep 17 00:00:00 2001 From: Nam Nguyen Date: Wed, 19 Apr 2023 11:35:38 +0700 Subject: [PATCH 2/2] chore: update CODEOWNERS file --- CODEOWNERS | 12 ++++++------ pkg/routes/v1.go | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/CODEOWNERS b/CODEOWNERS index 4f3d0193d..8f4f8a588 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -1,7 +1,7 @@ # Default reviewers for every PR -* @huynguyenh @namnhce -.github/ @huynguyenh @namnhce @nguyennh4522 -cmd/ @huynguyenh @namnhce @nguyennh4522 @thanhpn @datphamcode295 -docs/ @huynguyenh @namnhce @nguyennh4522 @thanhpn @datphamcode295 -migrations/ @huynguyenh @namnhce @nguyennh4522 @thanhpn @datphamcode295 -pkg/ @huynguyenh @namnhce @nguyennh4522 @thanhpn @datphamcode295 +* @huynguyenh @namnhce @lmquang +.github/ @huynguyenh @namnhce @lmquang +cmd/ @huynguyenh @namnhce @lmquang +docs/ @huynguyenh @namnhce @lmquang +migrations/ @huynguyenh @namnhce @lmquang +pkg/ @huynguyenh @namnhce @lmquang diff --git a/pkg/routes/v1.go b/pkg/routes/v1.go index 7a0dd441a..c56b8de10 100644 --- a/pkg/routes/v1.go +++ b/pkg/routes/v1.go @@ -169,16 +169,16 @@ func loadV1Routes(r *gin.Engine, h *handler.Handler, repo store.DBRepo, s *store valuation.GET("/:year", pmw.WithPerm(model.PermissionValuationRead), h.Valuation.One) } - notion := v1.Group("/notion") + notion := v1.Group("/notion", amw.WithAuth, pmw.WithPerm(model.PermissionCronjobExecute)) { earn := notion.Group("/earn") { earn.GET("", h.Notion.ListEarns) } - techradar := notion.Group("/tech-radar") + techRadar := notion.Group("/tech-radar") { - techradar.GET("", h.Notion.ListTechRadars) - techradar.POST("", h.Notion.CreateTechRadar) + techRadar.GET("", h.Notion.ListTechRadars) + techRadar.POST("", h.Notion.CreateTechRadar) } audience := notion.Group("/audiences") {