From f54c5660ea8e6fc7f6cff75cedddea6c4e58eb29 Mon Sep 17 00:00:00 2001 From: ctengiz Date: Fri, 14 Jun 2024 17:19:38 +0300 Subject: [PATCH] comnpany to cm --- db/migration/base/002.up.company.sql | 4 ++-- db/migration/base/003.up.company_tmpl.sql | 2 +- db/migration/base/004.upcompany to cm.sql | 12 ++++++++++++ db/sqls/{company.sql => cm.sql} | 23 +++++++++++------------ svc/api/acompany.go | 4 ++-- svc/api/atmpl.go | 4 ++-- svc/api/public/login.go | 18 ------------------ svc/api/public/zrouter.go | 14 -------------- svc/api/zhandler.go | 8 +++----- svc/main.go | 3 ++- svc/model/company/company.go | 20 ++++++++++---------- ui/src/model/company.js | 6 ++---- ui/src/pages/company.vue | 2 +- ui/src/pages/map.vue | 2 +- ui/src/pages/tmpl.vue | 2 +- 15 files changed, 50 insertions(+), 74 deletions(-) create mode 100644 db/migration/base/004.upcompany to cm.sql rename db/sqls/{company.sql => cm.sql} (73%) delete mode 100644 svc/api/public/login.go delete mode 100644 svc/api/public/zrouter.go diff --git a/db/migration/base/002.up.company.sql b/db/migration/base/002.up.company.sql index 26f7a34..895890a 100644 --- a/db/migration/base/002.up.company.sql +++ b/db/migration/base/002.up.company.sql @@ -13,7 +13,7 @@ create table company ( constraint uq_company unique (clid, code) ); -CREATE TRIGGER zl_company before INSERT or UPDATE ON company +CREATE TRIGGER zl_company before INSERT or UPDATE ON cm FOR EACH ROW EXECUTE FUNCTION zllog(); create table company_usr ( @@ -22,5 +22,5 @@ create table company_usr ( usr_id dmn_usrid, constraint uq_company_usr unique (company_id, usr_id), constraint fk_company_usr_company foreign key (company_id) - references company(id) on update cascade on delete cascade + references cm(id) on update cascade on delete cascade ); diff --git a/db/migration/base/003.up.company_tmpl.sql b/db/migration/base/003.up.company_tmpl.sql index 1748499..f14ea6b 100644 --- a/db/migration/base/003.up.company_tmpl.sql +++ b/db/migration/base/003.up.company_tmpl.sql @@ -1 +1 @@ -alter table company add tmpl jsonb; \ No newline at end of file +alter table cm add tmpl jsonb; \ No newline at end of file diff --git a/db/migration/base/004.upcompany to cm.sql b/db/migration/base/004.upcompany to cm.sql new file mode 100644 index 0000000..e47e700 --- /dev/null +++ b/db/migration/base/004.upcompany to cm.sql @@ -0,0 +1,12 @@ +alter table public.cm + rename to cm; + +alter table public.cm + rename column title to name; + +alter table public.company_usr + rename to cm_usr; + +alter table public.cm_usr + rename column company_id to cm_id; + diff --git a/db/sqls/company.sql b/db/sqls/cm.sql similarity index 73% rename from db/sqls/company.sql rename to db/sqls/cm.sql index 06a8a8f..20bed75 100644 --- a/db/sqls/company.sql +++ b/db/sqls/cm.sql @@ -1,13 +1,13 @@ -- << Create -insert into company ( clid +insert into cm ( clid , code - , title + , name , is_active , notes , tmpl) values ( @clid , @code - , @title + , @name , @is_active , @notes , @tmpl) @@ -18,20 +18,19 @@ returning id select clid , id , code - , title + , name , is_active , notes , tmpl -from company +from cm where id = $1 -- Read >> -- << Update -update company -set clid = @clid - , code = @code - , title = @title +update cm +set code = @code + , name = @name , is_active = @is_active , notes = @notes , tmpl = @tmpl @@ -41,7 +40,7 @@ where id = @id -- << Delete delete -from company +from cm where id = $1 -- Delete >> @@ -49,12 +48,12 @@ where id = $1 select clid , id , code - , title + , name , is_active , notes , tmpl -from company {{.Where}} +from cm {{.Where}} {{.OrderBy}} {{.Rows}} -- List >> diff --git a/svc/api/acompany.go b/svc/api/acompany.go index 1895a30..9823511 100644 --- a/svc/api/acompany.go +++ b/svc/api/acompany.go @@ -5,7 +5,7 @@ import ( "git.makki.io/makki/libgo/cmn" "git.makki.io/makki/libgo/dbu" "git.makki.io/makki/libgo/mhttp" - "git.makki.io/makki/libgo/nauth" + "git.notitek.com.tr/common/notgo/nauth" "github.com/go-chi/chi/v5" "net/http" ) @@ -146,7 +146,7 @@ func companyList(w http.ResponseWriter, r *http.Request) { return } - rp, err := dbu.NewRepoWithFile(r.Context(), "company", nil) + rp, err := dbu.NewRepoWithFile(r.Context(), "cm", nil) if err != nil { mhttp.InternalServerError(w, err) return diff --git a/svc/api/atmpl.go b/svc/api/atmpl.go index f60bb33..660d541 100644 --- a/svc/api/atmpl.go +++ b/svc/api/atmpl.go @@ -19,7 +19,7 @@ func tmplPost(w http.ResponseWriter, r *http.Request) { return } - sq := "update company set tmpl = $2 where id = $1" + sq := "update cm set tmpl = $2 where id = $1" _, err = dbu.DB.Exec(r.Context(), sq, companyID, body) if err != nil { mhttp.InternalServerError(w, err) @@ -33,7 +33,7 @@ func tmplGet(w http.ResponseWriter, r *http.Request) { companyID := cmn.StrToInt64(chi.URLParam(r, "companyID")) var body json.RawMessage - sq := "select tmpl from company where id = $1" + sq := "select tmpl from cm where id = $1" err := dbu.DB.QueryRow(r.Context(), sq, companyID).Scan(&body) if err != nil { mhttp.InternalServerError(w, err) diff --git a/svc/api/public/login.go b/svc/api/public/login.go deleted file mode 100644 index 3129fd5..0000000 --- a/svc/api/public/login.go +++ /dev/null @@ -1,18 +0,0 @@ -package public - -import ( - "git.makki.io/makki/libgo/mhttp" - "git.makki.io/makki/libgo/svc" - "net/http" -) - -func login(w http.ResponseWriter, r *http.Request) { - authResp, err := svc.S.Authenticate(r) - if err != nil { - mhttp.InternalServerError(w, err) - return - } - - clientResp := authResp.GetEndUserResponse() - mhttp.ResponseSuccess(w, clientResp) -} diff --git a/svc/api/public/zrouter.go b/svc/api/public/zrouter.go deleted file mode 100644 index 228ea5f..0000000 --- a/svc/api/public/zrouter.go +++ /dev/null @@ -1,14 +0,0 @@ -package public - -import ( - "github.com/go-chi/chi/v5" - "net/http" -) - -func Router() http.Handler { - r := chi.NewRouter() - - // user authentication - r.Post("/login", login) - return r -} diff --git a/svc/api/zhandler.go b/svc/api/zhandler.go index 5e1d3f1..f052678 100644 --- a/svc/api/zhandler.go +++ b/svc/api/zhandler.go @@ -1,10 +1,9 @@ package api import ( - "bordro-esleme/api/public" "fmt" - "git.makki.io/makki/libgo/napi" - "git.makki.io/makki/libgo/nauth" + "git.notitek.com.tr/common/notgo/napi" + "git.notitek.com.tr/common/notgo/nauth" "net/http" "os" "path" @@ -51,8 +50,7 @@ func HttpHandler(re enums.TRunEnv) http.Handler { mux.Route("/api", func(mr chi.Router) { // Public Route endpoints - mr.Mount("/", public.Router()) - //mr.Mount("/admin", admin.Router()) + mr.Post("/login", napi.Login) //protected end points mr.Group(func(r chi.Router) { diff --git a/svc/main.go b/svc/main.go index 8c9af04..0534208 100644 --- a/svc/main.go +++ b/svc/main.go @@ -5,6 +5,7 @@ import ( "git.makki.io/makki/libgo/dbu" "git.makki.io/makki/libgo/mlog" "git.makki.io/makki/libgo/svc" + "git.notitek.com.tr/common/notgo/nauth" "time" ) @@ -35,7 +36,7 @@ func main() { if svc.S.DevMode() { expire = time.Hour * 48 } - err = s.SubscribeToAuthServer(expire) + err = nauth.SubscribeToAuthServer(s.Ctx, expire) if err != nil { mlog.Fatal(err) } diff --git a/svc/model/company/company.go b/svc/model/company/company.go index d031880..304ca84 100644 --- a/svc/model/company/company.go +++ b/svc/model/company/company.go @@ -9,10 +9,10 @@ import ( ) type Company struct { - Clid int64 `db:"clid" json:"-"` + ClID int64 `db:"clid" json:"-"` ID int64 `db:"id"` Code string `db:"code"` - Title null.String `db:"title"` + Name null.String `db:"name"` IsActive bool `db:"is_active"` Notes null.String `db:"notes"` @@ -30,7 +30,7 @@ func New() *Company { } func DbRead(ctx context.Context, id int64) (*Company, error) { - rp, err := dbu.NewRepoWithFile(ctx, "company", nil) + rp, err := dbu.NewRepoWithFile(ctx, "cm", nil) if err != nil { return nil, err } @@ -55,7 +55,7 @@ func DbDelete(ctx context.Context, id int64, log bool, usrID *int64) error { } defer tx.Rollback(ctx) - rp, err := dbu.NewRepoWithFile(ctx, "company", tx) + rp, err := dbu.NewRepoWithFile(ctx, "cm", tx) if err != nil { return err } @@ -66,7 +66,7 @@ func DbDelete(ctx context.Context, id int64, log bool, usrID *int64) error { if err != nil { return dbu.ParsedErrSuppressNoRows(err) } - err = dbu.DB.LogDMLTx("d", "company", oldData.ID, usrID, "", oldData, nil, tx) + err = dbu.DB.LogDMLTx("d", "cm", oldData.ID, usrID, "", oldData, nil, tx) if err != nil { slog.Error(err.Error()) } @@ -81,9 +81,9 @@ func DbDelete(ctx context.Context, id int64, log bool, usrID *int64) error { } func (m *Company) DbCreate(ctx context.Context, clID int64, log bool, usrID *int64) error { - m.Clid = clID + m.ClID = clID - rp, err := dbu.NewRepoWithFile(ctx, "company", nil) + rp, err := dbu.NewRepoWithFile(ctx, "cm", nil) if err != nil { return err } @@ -94,7 +94,7 @@ func (m *Company) DbCreate(ctx context.Context, clID int64, log bool, usrID *int } if log { - err = dbu.DB.LogDMLTx("c", "company", m.ID, usrID, "", nil, m, nil) + err = dbu.DB.LogDMLTx("c", "cm", m.ID, usrID, "", nil, m, nil) if err != nil { slog.Error(err.Error()) } @@ -110,7 +110,7 @@ func (m *Company) DbUpdate(ctx context.Context, log bool, usrID *int64) error { } defer tx.Rollback(ctx) - rp, err := dbu.NewRepoWithFile(ctx, "company", tx) + rp, err := dbu.NewRepoWithFile(ctx, "cm", tx) if err != nil { return err } @@ -121,7 +121,7 @@ func (m *Company) DbUpdate(ctx context.Context, log bool, usrID *int64) error { if err != nil { return err } - err = dbu.DB.LogDMLTx("u", "company", oldData.ID, usrID, "", oldData, m, tx) + err = dbu.DB.LogDMLTx("u", "cm", oldData.ID, usrID, "", oldData, m, tx) if err != nil { slog.Error(err.Error()) } diff --git a/ui/src/model/company.js b/ui/src/model/company.js index fffb09d..7f19306 100644 --- a/ui/src/model/company.js +++ b/ui/src/model/company.js @@ -5,14 +5,12 @@ const t = i18n.global.t class Company extends Model { ID = null Code = '' - Title = '' + Name = '' IsActive = true Notes = '' - Tmpl = '' - _colOptions = { ID: { label: t('Company.ID'), @@ -40,7 +38,7 @@ class Company extends Model { }, - Title: { + Name: { label: t('Company.Title'), visible: true, dataType: 'text', //numeric, text, date, bool, datetime, time, inet diff --git a/ui/src/pages/company.vue b/ui/src/pages/company.vue index 7284dc2..ba73d73 100644 --- a/ui/src/pages/company.vue +++ b/ui/src/pages/company.vue @@ -21,7 +21,7 @@ />