diff --git a/Readme.md b/Readme.md new file mode 100644 index 0000000..ec033aa --- /dev/null +++ b/Readme.md @@ -0,0 +1,4 @@ +1. Go stores empty arrays as null by default when you assign an empty array and store it in mongodb +2. Omitempty doesnot work on structs +3. Our datetimes are in Unix Time Stamp in UTC Timezone +4. Synchronise your computer clock if your iat in JWT is causing issues. \ No newline at end of file diff --git a/go.mod b/go.mod index 5ce615d..792dcfb 100644 --- a/go.mod +++ b/go.mod @@ -1,13 +1,13 @@ module github.com/FrosTiK-SD/auth -go 1.21.1 +go 1.21.6 require ( github.com/FrosTiK-SD/mongik v0.1.18 github.com/allegro/bigcache/v3 v3.1.0 github.com/gin-gonic/gin v1.9.0 github.com/lestrrat-go/jwx/v2 v2.0.16 - go.mongodb.org/mongo-driver v1.13.0 + go.mongodb.org/mongo-driver v1.13.1 ) require ( @@ -32,6 +32,7 @@ require ( ) require ( + github.com/FrosTiK-SD/models v0.4.3 github.com/bytedance/sonic v1.8.2 // indirect github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect github.com/gin-contrib/cors v1.4.0 @@ -41,7 +42,7 @@ require ( github.com/go-playground/validator/v10 v10.11.2 // indirect github.com/goccy/go-json v0.10.2 // indirect github.com/google/go-cmp v0.5.9 // indirect - github.com/json-iterator/go v1.1.12 // indirect + github.com/json-iterator/go v1.1.12 github.com/klauspost/cpuid/v2 v2.2.4 // indirect github.com/leodido/go-urn v1.2.2 // indirect github.com/mattn/go-isatty v0.0.17 // indirect diff --git a/go.sum b/go.sum index ae9f00f..9145db2 100644 --- a/go.sum +++ b/go.sum @@ -1,29 +1,21 @@ -github.com/FrosTiK-SD/mongik v0.1.4 h1:7Wa46bWDy7FxhjdVTC6p7kJgpewiIOl8vZBgfLK4V50= -github.com/FrosTiK-SD/mongik v0.1.4/go.mod h1:OnabLBpqWYNf+8Dn5ZPa7mAqEnnAkyOOEsTDzuvPN1o= -github.com/FrosTiK-SD/mongik v0.1.5 h1:CkredRLbvy6WmV81Ynl5INq8DPvR73gKYbnqoH/WEv8= -github.com/FrosTiK-SD/mongik v0.1.5/go.mod h1:EAFjp0U+R9SQcEe2tCa7In2lc58bhmO+0a08Ss3OaN4= -github.com/FrosTiK-SD/mongik v0.1.17 h1:hCcohfz7rRG5om6+5K84RZ2Nlz4UpZg6DUY+zWmyKCc= -github.com/FrosTiK-SD/mongik v0.1.17/go.mod h1:AjFFmUGUAix1sf24uxh0Wxq5fNIpykx4EEd44AMYhfw= +github.com/FrosTiK-SD/models v0.4.3 h1:pdN7ucbuwQl86Y1luMmw8ePKodf6+yuvdAe+6KGMuyQ= +github.com/FrosTiK-SD/models v0.4.3/go.mod h1:F/IJox0VzLbPKYni9jC/n+jlKh7Ie5EjaY2YfyUDQzg= github.com/FrosTiK-SD/mongik v0.1.18 h1:kDhGDEhgDyfEG4lEkVRfe2mVrtDB9QDsY9g2HOASjCw= github.com/FrosTiK-SD/mongik v0.1.18/go.mod h1:AjFFmUGUAix1sf24uxh0Wxq5fNIpykx4EEd44AMYhfw= github.com/allegro/bigcache/v3 v3.1.0 h1:H2Vp8VOvxcrB91o86fUSVJFqeuz8kpyyB02eH3bSzwk= github.com/allegro/bigcache/v3 v3.1.0/go.mod h1:aPyh7jEvrog9zAwx5N7+JUQX5dZTSGpxF1LAR4dr35I= +github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs= +github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c= +github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA= +github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0= github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM= github.com/bytedance/sonic v1.8.2 h1:Eq1oE3xWIBE3tj2ZtJFK1rDAx7+uA4bRytozVhXMHKY= github.com/bytedance/sonic v1.8.2/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U= -github.com/bytedance/sonic v1.10.0-rc/go.mod h1:ElCzW+ufi8qKqNW0FY314xriJhyJhuoJ3gFZdAHF7NM= -github.com/bytedance/sonic v1.10.2 h1:GQebETVBxYB7JGWJtLBi07OVzWwt+8dWA00gEVW2ZFE= -github.com/bytedance/sonic v1.10.2/go.mod h1:iZcSUejdk5aukTND/Eu/ivjQuEL0Cu9/rf50Hi0u/g4= github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY= github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 h1:qSGYFH7+jGhDF8vLC+iwCD4WpbV1EBDSzWkJODFLams= github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk= -github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d h1:77cEq6EriyTZ0g/qfRdp61a3Uu/AWrgIq2s0ClJV1g0= -github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d/go.mod h1:8EPpVsBuRksnlj1mLy4AWzRNQYxauNi62uWcE3to6eA= -github.com/chenzhuoyu/iasm v0.9.0/go.mod h1:Xjy2NpN3h7aUqeqM+woSuuvxmIe6+DDsiNLIrkAmYog= -github.com/chenzhuoyu/iasm v0.9.1 h1:tUHQJXo3NhBqw6s33wkGn9SP3bvrWLdlVIJ3hQBL7P0= -github.com/chenzhuoyu/iasm v0.9.1/go.mod h1:Xjy2NpN3h7aUqeqM+woSuuvxmIe6+DDsiNLIrkAmYog= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= @@ -33,8 +25,6 @@ github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 h1:8UrgZ3GkP4i/CLijOJx79Yu+etly github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= -github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0= -github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk= github.com/gin-contrib/cors v1.4.0 h1:oJ6gwtUl3lqV0WEIwM/LxPF1QZ5qe2lGWdY2+bz7y0g= github.com/gin-contrib/cors v1.4.0/go.mod h1:bs9pNM0x/UsmHPBWT2xZz9ROh8xYjYkiURUfmBoMlcs= github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= @@ -42,8 +32,6 @@ github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm github.com/gin-gonic/gin v1.8.1/go.mod h1:ji8BvRH1azfM+SYow9zQ6SZMvR8qOMZHmsCuWR9tTTk= github.com/gin-gonic/gin v1.9.0 h1:OjyFBKICoexlu99ctXNR2gg+c5pKrKMuyjgARg9qeY8= github.com/gin-gonic/gin v1.9.0/go.mod h1:W1Me9+hsUSyj3CePGrd1/QrKJMSJ1Tu/0hFEH89961k= -github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg= -github.com/gin-gonic/gin v1.9.1/go.mod h1:hPrL7YrpYKXt5YId3A/Tnip5kqbEAP+KLuI3SUcPTeU= github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= @@ -56,8 +44,6 @@ github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91 github.com/go-playground/validator/v10 v10.10.0/go.mod h1:74x4gJWsvQexRdW8Pn3dXSGrTK4nAUsbPlLADvpJkos= github.com/go-playground/validator/v10 v10.11.2 h1:q3SHpufmypg+erIExEKUmsgmhDTyhcJ38oeKGACXohU= github.com/go-playground/validator/v10 v10.11.2/go.mod h1:NieE624vt4SCTJtD87arVLvdmjPAeV8BQlHtMnw9D7s= -github.com/go-playground/validator/v10 v10.16.0 h1:x+plE831WK4vaKHO/jpgUGsvLKIqRRkz6M78GuJAfGE= -github.com/go-playground/validator/v10 v10.16.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU= github.com/goccy/go-json v0.9.7/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= @@ -65,8 +51,6 @@ github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaS github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golang/snappy v0.0.3 h1:fHPg5GQYlCeLIPB9BZqMVR5nR9A+IM5zcgeTdjMYmLA= github.com/golang/snappy v0.0.3/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.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= @@ -76,14 +60,9 @@ github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnr github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/klauspost/compress v1.13.6 h1:P76CopJELS0TiO2mebmnzgWaajssP/EszplttgQxcgc= github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= -github.com/klauspost/compress v1.17.3 h1:qkRjuerhUU1EmXLYGkSH6EZL+vPSxIrYjLNAK4slzwA= -github.com/klauspost/compress v1.17.3/go.mod h1:/dCuZOvVtNoHsyb+cuJD3itjs3NbnF6KH9zAO4BDxPM= github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= github.com/klauspost/cpuid/v2 v2.2.4 h1:acbojRNwl3o09bUq+yDCtZFc1aiwaAAxtcn8YkZXnvk= github.com/klauspost/cpuid/v2 v2.2.4/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY= -github.com/klauspost/cpuid/v2 v2.2.6 h1:ndNyv040zDGIDh8thGkXYjnFtiN02M1PVVF+JE/48xc= -github.com/klauspost/cpuid/v2 v2.2.6/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= -github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= @@ -95,8 +74,6 @@ github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY= github.com/leodido/go-urn v1.2.2 h1:7z68G0FCGvDk646jz1AelTYNYWrTNm0bEcFAo147wt4= github.com/leodido/go-urn v1.2.2/go.mod h1:kUaIbLZWttglzwNuG0pgsh5vuV6u2YcGBYz1hIPjtOQ= -github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q= -github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4= github.com/lestrrat-go/blackmagic v1.0.2 h1:Cg2gVSc9h7sz9NOByczrbUvLopQmXrfFx//N+AkAr5k= github.com/lestrrat-go/blackmagic v1.0.2/go.mod h1:UrEqBzIR2U6CnzVyUtfM6oZNMt/7O7Vohk2J0OGSAtU= github.com/lestrrat-go/httpcc v1.0.1 h1:ydWCStUeJLkpYyjLDHihupbn2tYmZ7m22BGkcvZZrIE= @@ -113,8 +90,6 @@ github.com/lestrrat-go/option v1.0.1/go.mod h1:5ZHFbivi4xwXxhxY9XHDe2FHo6/Z7WWmt github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng= github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= -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/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= @@ -122,13 +97,9 @@ 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/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe h1:iruDEfMl2E6fbMZ9s0scYfZQ84/6SPL6zC8ACM2oIL0= github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc= -github.com/montanaflynn/stats v0.7.1 h1:etflOAAHORrCC44V+aR6Ftzort912ZU+YLiSTuV8eaE= -github.com/montanaflynn/stats v0.7.1/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow= github.com/pelletier/go-toml/v2 v2.0.1/go.mod h1:r9LEWfGN8R5k0VXJ+0BkIe7MYkRdwZOjgMj2KwnJFUo= github.com/pelletier/go-toml/v2 v2.0.6 h1:nrzqCb7j9cDFj2coyLNLaZuJTLjWjlaz6nvTvIwycIU= github.com/pelletier/go-toml/v2 v2.0.6/go.mod h1:eumQOmlWiOPt5WriQQqoM5y18pDHwha2N+QD+EUNTek= -github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4= -github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= @@ -158,8 +129,6 @@ github.com/ugorji/go v1.2.7/go.mod h1:nF9osbDWLy6bDVv/Rtoh6QgnvNDpmCalQV5urGCCS6 github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY= github.com/ugorji/go/codec v1.2.10 h1:eimT6Lsr+2lzmSZxPhLFoOWFmQqwk0fllJJ5hEbTXtQ= github.com/ugorji/go/codec v1.2.10/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= -github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU= -github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c= github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI= github.com/xdg-go/scram v1.1.2 h1:FHX5I5B4i4hKRVRBCFRxq1iQRej7WO3hhBuJf+UUySY= @@ -168,28 +137,20 @@ github.com/xdg-go/stringprep v1.0.4 h1:XLI/Ng3O1Atzq0oBs3TWm+5ZVgkq2aqdlvP9JtoZ6 github.com/xdg-go/stringprep v1.0.4/go.mod h1:mPGuuIYwz7CmR2bT9j4GbQqutWS1zV24gijq1dTyGkM= github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d h1:splanxYIlg+5LfHAM6xpdFEAYOk8iySO56hMFq6uLyA= github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA= -github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a h1:fZHgsYlfvtyqToslyjUt3VOPF4J7aK/3MPcK7xp3PDk= -github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a/go.mod h1:ul22v+Nro/R083muKhosV54bj5niojjWZvU8xrevuH4= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= -go.mongodb.org/mongo-driver v1.13.0 h1:67DgFFjYOCMWdtTEmKFpV3ffWlFnh+CYZ8ZS/tXWUfY= -go.mongodb.org/mongo-driver v1.13.0/go.mod h1:/rGBTebI3XYboVmgz+Wv3Bcbl3aD0QF9zl6kDDw18rQ= +go.mongodb.org/mongo-driver v1.13.1 h1:YIc7HTYsKndGK4RFzJ3covLz1byri52x0IoMB0Pt/vk= +go.mongodb.org/mongo-driver v1.13.1/go.mod h1:wcDf1JBCXy2mOW0bWHwO/IOYqdca1MPCwDtFu/Z9+eo= golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= golang.org/x/arch v0.2.0 h1:W1sUEHXiJTfjaFJ5SLo0N6lZn+0eO5gWD1MFeTGqQEY= golang.org/x/arch v0.2.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= -golang.org/x/arch v0.6.0 h1:S0JTfE48HbRj80+4tbvZDYsJ3tGv6BUU3XxyZ7CirAc= -golang.org/x/arch v0.6.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc= golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= -golang.org/x/crypto v0.15.0 h1:frVn1TEaCEaZcn3Tmd7Y2b5KKPaZ+I32Q2OA3kYp5TA= -golang.org/x/crypto v0.15.0/go.mod h1:4ChreQoLWfG3xLDer1WdlH5NdlQ3+mwnQq1YTKY+72g= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= @@ -197,16 +158,11 @@ golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M= golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= -golang.org/x/net v0.18.0 h1:mIYleuAkSbHh0tCv7RvjL3F6ZVbLjq4+R7zbOn3Kokg= -golang.org/x/net v0.18.0/go.mod h1:/czyP5RqHAH4odGYxBJ1qz0+CE5WZ+2j1YgoEo8F2jQ= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE= -golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -218,12 +174,9 @@ golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q= -golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= @@ -238,8 +191,6 @@ golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= -golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= -golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= @@ -250,8 +201,6 @@ google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp0 google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w= google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= -google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= -google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= @@ -262,5 +211,4 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50= rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= diff --git a/handler/migration.go b/handler/migration.go new file mode 100644 index 0000000..581f44f --- /dev/null +++ b/handler/migration.go @@ -0,0 +1,355 @@ +package handler + +import ( + "fmt" + "regexp" + "strconv" + "strings" + "time" + + "github.com/FrosTiK-SD/auth/model" + Student "github.com/FrosTiK-SD/auth/model" + Constant "github.com/FrosTiK-SD/models/constant" + "github.com/gin-gonic/gin" + "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/mongo" +) + +func GetDOBFromString(input string) (primitive.DateTime, error) { + t, err := time.Parse("02-01-2006", input) + if err != nil { + return 0, err + } + return primitive.NewDateTimeFromTime(t), nil +} + +func GetCategoryFromString(input string) Student.ReservationCategory { + category := Student.ReservationCategory{ + Category: "", + IsPWD: false, + IsEWS: false, + } + + if input == "" { + return category + } + + for _, c := range [4]string{"GEN", "SC", "ST", "OBC-NCL"} { + re := regexp.MustCompile("(?i)" + c) + + if re.MatchString(input) { + category.Category = c + break + } + } + + if regexp.MustCompile("(?i)pwd").MatchString(input) { + category.IsPWD = true + } + + if regexp.MustCompile("(?i)ews").MatchString(input) { + category.IsEWS = true + } + + return category +} + +func GetRankFromString(input string, rc Student.ReservationCategory) (Student.RankDetails, error) { + srd := Student.RankDetails{ + Rank: -1, + RankCategory: GetCategoryFromString(input), + } + + num, err := strconv.Atoi(regexp.MustCompile(`\d+`).FindString(input)) + if err != nil { + return srd, err + } + srd.Rank = num + + if regexp.MustCompile("(?i)category").MatchString(input) { + srd.RankCategory = rc + } + + return srd, nil + +} + +func GetEducationGapJeeRank(cursor *mongo.Cursor, errorArray *[]string, category model.ReservationCategory) (model.RankDetails, int) { + var type1 model.EuducationGapJeeRankStrings + var type2 model.EuducationGapJeeRankIntegers + + if err1 := cursor.Decode(&type1); err1 == nil { + jeeRank, errJeeRank := GetRankFromString(type1.JeeRank, category) + if errJeeRank != nil { + fmt.Println(errJeeRank) + *errorArray = append(*errorArray, "jeeRank") + jeeRank.Rank = -1 + } + + educationGap, err := strconv.Atoi(regexp.MustCompile(`\d+`).FindString(type1.EducationGap)) + if err != nil { + fmt.Println(educationGap) + *errorArray = append(*errorArray, "educationGap") + educationGap = -1 + } + + return jeeRank, educationGap + } + + if err1 := cursor.Decode(&type2); err1 == nil { + return model.RankDetails{Rank: type2.JeeRank, RankCategory: model.ReservationCategory{Category: "GEN"}}, type2.EducationGap + } + + return model.RankDetails{Rank: -1, RankCategory: model.ReservationCategory{Category: "GEN"}}, -1 +} + +func GetXXIIYear(cursor *mongo.Cursor) (int, int) { + var type1 model.XXIIYearType1 + var type2 model.XXIIYearType2 + + if err1 := cursor.Decode(&type1); err1 == nil { + xyear, errx := strconv.Atoi(type1.XYear) + if errx != nil { + xyear = 0 + } + xiiyear, errxii := strconv.Atoi(type1.XiiYear) + if errxii != nil { + xiiyear = 0 + } + + return xyear, xiiyear + } + + if err1 := cursor.Decode(&type2); err1 == nil { + return type2.XYear, type2.XiiYear + } + + return -1, -1 +} + +func (h *Handler) MigrateStudentDataToV2(ctx *gin.Context) { + studentCollection := h.MongikClient.MongoClient.Database(Constant.DB).Collection(Constant.StudentCollection) + cursor, errFind := studentCollection.Find(ctx, bson.D{{Key: "version", Value: bson.D{{Key: "$exists", Value: false}}}}) + if errFind != nil { + ctx.AbortWithStatusJSON(400, gin.H{"count": 0, "error": errFind.Error(), "reason": "Find not successful"}) + return + } + + var count int64 = 0 + + for cursor.Next(ctx) { + var oldStudent model.OldStudent + if errDecode := cursor.Decode(&oldStudent); errDecode != nil { + fmt.Println(errDecode) + continue + } + + if oldStudent.Email == "tpo@itbhu.ac.in" { + continue + } + + if oldStudent.CompaniesAlloted == nil { + oldStudent.CompaniesAlloted = []string{} + } + + errorArray := []string{} + var EndYearOffset int + var Course Constant.Course + var courseError bool = false + + switch oldStudent.Course { + case "idd": + EndYearOffset = 5 + Course = Constant.IDD + case "mtech": + EndYearOffset = 2 + Course = Constant.MTECH + case "phd": + EndYearOffset = 6 + Course = Constant.PHD + case "btech": + EndYearOffset = 4 + Course = Constant.BTECH + default: + EndYearOffset = -1 + Course = Constant.BTECH + errorArray = append(errorArray, "course") + courseError = true + } + + category := GetCategoryFromString(oldStudent.Category) + + kaggle := "" + if oldStudent.Kaggle != "" { + kaggle = oldStudent.Kaggle + } + if oldStudent.Kaggel != "" { + kaggle = oldStudent.Kaggel + } + + jeeRank, educationGap := GetEducationGapJeeRank(cursor, &errorArray, category) + + xYear, xiiYear := GetXXIIYear(cursor) + if xYear <= 0 { + errorArray = append(errorArray, "xYear") + } + + if xiiYear <= 0 { + errorArray = append(errorArray, "xiiYear") + } + + dob, errDOB := GetDOBFromString(oldStudent.Dob) + if errDOB != nil { + fmt.Println(errDOB) + errorArray = append(errorArray, "dob") + dob = 0 + } + + mobile := strconv.FormatInt(oldStudent.Mobile, 10) + mobileError := false + if mobile == "0" { + mobileError = true + errorArray = append(errorArray, "mobile") + } + + gender := Constant.Gender(strings.ToLower(oldStudent.Gender)) + + var userError map[string]model.UserError = make(map[string]model.UserError) + + for _, err := range errorArray { + userError[err] = model.MIGRATION + } + + newStudent := Student.Student{ + Id: oldStudent.ID, + Groups: oldStudent.Groups, + CompaniesAlloted: oldStudent.CompaniesAlloted, + + Batch: &Student.Batch{ + StartYear: oldStudent.Batch, + EndYear: oldStudent.Batch + EndYearOffset, + }, + RollNo: oldStudent.RollNo, + InstituteEmail: oldStudent.Email, + Department: oldStudent.Department, + Course: &Course, + + FirstName: oldStudent.FirstName, + LastName: oldStudent.LastName, + + Gender: &gender, + DOB: &dob, + PermanentAddress: oldStudent.PermanentAddress, + PresentAddress: oldStudent.PresentAddress, + PersonalEmail: oldStudent.PersonalEmail, + Mobile: &mobile, + Category: &category, + MotherTongue: oldStudent.MotherTongue, + ParentsDetails: &Student.ParentsDetails{ + FatherName: oldStudent.FatherName, + FatherOccupation: oldStudent.FatherOccupation, + MotherName: oldStudent.MotherName, + MotherOccupation: oldStudent.MotherOccupation, + }, + + Academics: Student.Academics{ + JEERank: &jeeRank, + XthClass: &Student.EducationDetails{ + Certification: oldStudent.XBoard, + Institute: oldStudent.XInstitute, + Year: xYear, + Score: oldStudent.XPercentage, + }, + XIIthClass: &Student.EducationDetails{ + Certification: oldStudent.XiiBoard, + Institute: oldStudent.XiiInstitute, + Year: xiiYear, + Score: oldStudent.XiiPercentage, + }, + EducationGap: &educationGap, + SemesterSPI: Student.SemesterSPI{ + One: oldStudent.SemesterOne, + Two: oldStudent.SemesterTwo, + Three: oldStudent.SemesterThree, + Four: oldStudent.SemesterFour, + Five: oldStudent.SemesterFive, + Six: oldStudent.SemesterSix, + Seven: oldStudent.SemesterSeven, + Eight: oldStudent.SemesterEight, + }, + SummerTermSPI: Student.SummerTermSPI{ + One: oldStudent.SummerOne, + Two: oldStudent.SummerTwo, + Three: oldStudent.SummerThree, + Four: oldStudent.SummerFour, + Five: oldStudent.SummerFive, + }, + UnderGraduate: &Student.EducationDetails{ + Certification: oldStudent.UgIn, + Institute: oldStudent.UgCollege, + Year: oldStudent.UgYear, + Score: oldStudent.UgScore, + }, + PostGraduate: &Student.EducationDetails{ + Certification: oldStudent.PgIn, + Institute: oldStudent.PgCollege, + Year: oldStudent.PgYear, + Score: oldStudent.PgScore, + }, + CurrentCGPA: oldStudent.Cgpa, + ActiveBacklogs: oldStudent.ActiveBacklogs, + TotalBacklogs: oldStudent.TotalBacklogs, + }, + WorkExperience: []Student.WorkExperience{}, + SocialProfiles: Student.SocialProfiles{ + LinkedIn: &Student.SocialProfile{ + URL: oldStudent.LinkedIn, + }, + MicrosoftTeams: &Student.SocialProfile{ + URL: oldStudent.MicrosoftTeams, + }, + Github: &Student.SocialProfile{ + URL: oldStudent.Github, + }, + Kaggle: &Student.SocialProfile{ + URL: kaggle, + }, + Skype: &Student.SocialProfile{ + URL: oldStudent.Skype, + }, + }, + Extras: Student.Extras{ + VideoResume: oldStudent.VideoResume, + }, + + StructVersion: 2, + CreatedAt: primitive.NewDateTimeFromTime(time.Now()), + UpdatedAt: primitive.NewDateTimeFromTime(time.Now()), + DataErrors: Student.DataErrors{ + User: userError, + }, + } + + if courseError { + newStudent.Course = nil + } + + if mobileError { + newStudent.Mobile = nil + } + + ValidateData(&newStudent) + + filter := bson.D{{Key: "_id", Value: oldStudent.ID}} + + if _, errUpdate := studentCollection.ReplaceOne(ctx, filter, newStudent); errUpdate != nil { + ctx.AbortWithStatusJSON(400, gin.H{"count": count, "error": errUpdate.Error(), "id": oldStudent.ID}) + return + } + + count = count + 1 + } + + ctx.JSON(200, gin.H{"count": count}) +} diff --git a/handler/verify.go b/handler/verify.go index b6e2eaa..95ce675 100644 --- a/handler/verify.go +++ b/handler/verify.go @@ -3,6 +3,9 @@ package handler import ( "github.com/FrosTiK-SD/auth/constants" "github.com/FrosTiK-SD/auth/controller" + "github.com/FrosTiK-SD/auth/model" + constant "github.com/FrosTiK-SD/models/constant" + "github.com/FrosTiK-SD/models/misc" "github.com/gin-gonic/gin" ) @@ -43,3 +46,127 @@ func (h *Handler) InvalidateCache(ctx *gin.Context) { "message": "Successfully invalidated cache", }) } + +func ValidatePositiveInteger(i **int) { + if *i != nil && **i <= 0 { + *i = nil + } +} + +func ValidateFloat64ZeroesToNull(f **float64) { + if *f != nil && **f <= 0 { + *f = nil + } +} + +func ValidateEducationDetails(ed **model.EducationDetails) { + if *ed != nil && (*ed).Score <= 0 { + *ed = nil + } +} + +func ValidateRankDetails(rd **model.RankDetails) { + if *rd != nil && (*rd).Rank <= 0 { + *rd = nil + } +} + +func ValidateString(s **string) { + if *s != nil && *(*s) == "" { + *s = nil + } +} + +func ValidateSocialProfile(sp **model.SocialProfile) { + if *sp != nil && (*sp).URL == "" { + *sp = nil + } +} + +func ValidateAttachment(a **misc.Attachment) { + if *a != nil && (*a).URL == "" { + *a = nil + } +} + +func ValidateBatch(b **model.Batch) { + if *b != nil && (*b).StartYear <= 0 { + *b = nil + } +} + +func ValidateGender(g **constant.Gender) { + if *g != nil && *(*g) == "" { + *g = nil + } +} + +func ValidateCourse(c **constant.Course) { + if *c != nil && *(*c) == "" { + *c = nil + } +} + +func ValidateData(student *model.Student) { + ValidateBatch(&student.Batch) + ValidateCourse(&student.Course) + ValidateString(&student.Specialisation) + ValidateString(&student.MiddleName) + ValidateAttachment(&student.ProfilePicture) + ValidateGender(&student.Gender) + + if student.DOB != nil && *student.DOB <= 10 { + student.DOB = nil + } + + if student.Category.Category == "" { + student.Category = nil + } + + if student.ParentsDetails.FatherName == "" && student.ParentsDetails.FatherOccupation == "" && student.ParentsDetails.MotherName == "" && student.ParentsDetails.MotherOccupation == "" { + student.ParentsDetails = nil + } + + ValidatePositiveInteger(&student.Academics.EducationGap) + ValidatePositiveInteger(&student.Academics.ActiveBacklogs) + ValidatePositiveInteger(&student.Academics.TotalBacklogs) + + ValidateRankDetails(&student.Academics.JEERank) + ValidateRankDetails(&student.Academics.GATERank) + ValidateEducationDetails(&student.Academics.XthClass) + ValidateEducationDetails(&student.Academics.XIIthClass) + ValidateEducationDetails(&student.Academics.UnderGraduate) + ValidateString(&student.Academics.Honours) + ValidateEducationDetails(&student.Academics.PostGraduate) + + if student.Academics.ThesisEndDate != nil && *student.Academics.ThesisEndDate <= 0 { + student.Academics.ThesisEndDate = nil + } + + ValidateSocialProfile(&student.SocialProfiles.LinkedIn) + ValidateSocialProfile(&student.SocialProfiles.Github) + ValidateSocialProfile(&student.SocialProfiles.MicrosoftTeams) + ValidateSocialProfile(&student.SocialProfiles.Skype) + ValidateSocialProfile(&student.SocialProfiles.GoogleScholar) + ValidateSocialProfile(&student.SocialProfiles.Codeforces) + ValidateSocialProfile(&student.SocialProfiles.CodeChef) + ValidateSocialProfile(&student.SocialProfiles.LeetCode) + ValidateSocialProfile(&student.SocialProfiles.Kaggle) + + ValidateFloat64ZeroesToNull(&student.Academics.SemesterSPI.One) + ValidateFloat64ZeroesToNull(&student.Academics.SemesterSPI.Two) + ValidateFloat64ZeroesToNull(&student.Academics.SemesterSPI.Three) + ValidateFloat64ZeroesToNull(&student.Academics.SemesterSPI.Four) + ValidateFloat64ZeroesToNull(&student.Academics.SemesterSPI.Five) + ValidateFloat64ZeroesToNull(&student.Academics.SemesterSPI.Six) + ValidateFloat64ZeroesToNull(&student.Academics.SemesterSPI.Seven) + ValidateFloat64ZeroesToNull(&student.Academics.SemesterSPI.Eight) + ValidateFloat64ZeroesToNull(&student.Academics.SemesterSPI.Nine) + ValidateFloat64ZeroesToNull(&student.Academics.SemesterSPI.Ten) + + ValidateFloat64ZeroesToNull(&student.Academics.SummerTermSPI.One) + ValidateFloat64ZeroesToNull(&student.Academics.SummerTermSPI.Two) + ValidateFloat64ZeroesToNull(&student.Academics.SummerTermSPI.Three) + ValidateFloat64ZeroesToNull(&student.Academics.SummerTermSPI.Four) + ValidateFloat64ZeroesToNull(&student.Academics.SummerTermSPI.Five) +} diff --git a/main.go b/main.go index 74af1d7..c0d8d22 100644 --- a/main.go +++ b/main.go @@ -47,6 +47,7 @@ func main() { r.GET("/api/token/student/verify", handler.HandlerVerifyStudentIdToken) r.GET("/api/token/invalidate_cache", handler.InvalidateCache) + r.GET("/migrate/student/newformat", handler.MigrateStudentDataToV2) port := "" + os.Getenv("PORT") if port == "" { diff --git a/mapper/student.go b/mapper/student.go index 735b9bd..f3546e6 100644 --- a/mapper/student.go +++ b/mapper/student.go @@ -4,13 +4,12 @@ import ( "github.com/FrosTiK-SD/auth/model" ) -func TransformStudentToStudentPopulated(student model.Student) model.StudentPopulated { +func TransformStudentToStudentPopulated(student model.OldStudent) model.StudentPopulated { return model.StudentPopulated{ ID: student.ID, Batch: student.Batch, RollNo: student.RollNo, FirstName: student.FirstName, - LastName: student.LastName, Department: student.Department, Course: student.Course, Email: student.Email, @@ -29,25 +28,12 @@ func TransformStudentToStudentPopulated(student model.Student) model.StudentPopu MotherName: student.MotherName, MotherOccupation: student.MotherOccupation, MotherTongue: student.MotherTongue, - EducationGap: student.EducationGap, - JeeRank: student.JeeRank, - Cgpa: student.Cgpa, - ActiveBacklogs: student.ActiveBacklogs, - TotalBacklogs: student.TotalBacklogs, XBoard: student.XBoard, - XYear: student.XYear, XPercentage: student.XPercentage, XInstitute: student.XInstitute, XiiBoard: student.XiiBoard, - XiiYear: student.XiiYear, XiiPercentage: student.XiiPercentage, XiiInstitute: student.XiiInstitute, - SemesterOne: student.SemesterOne, - SemesterTwo: student.SemesterTwo, - SemesterThree: student.SemesterThree, - SemesterFour: student.SemesterFour, - SemesterFive: student.SemesterFive, - SemesterSix: student.SemesterSix, Groups: []model.Group{}, CompaniesAlloted: student.CompaniesAlloted, UpdatedAt: student.UpdatedAt, diff --git a/model/student.go b/model/student.go index 9df70f8..162a7f3 100644 --- a/model/student.go +++ b/model/student.go @@ -4,14 +4,14 @@ import ( "go.mongodb.org/mongo-driver/bson/primitive" ) -type Student struct { +type OldStudent struct { ID primitive.ObjectID `json:"_id" bson:"_id"` Groups []primitive.ObjectID `json:"groups" bson:"groups"` CompaniesAlloted []string `json:"companiesAlloted" bson:"companiesAlloted"` Batch int `json:"batch" bson:"batch"` RollNo int `json:"rollNo" bson:"rollNo"` FirstName string `json:"firstName" bson:"firstName"` - LastName string `json:"lastName" bson:"lastName"` + LastName *string `json:"lastName" bson:"lastName"` Department string `json:"department" bson:"department"` Course string `json:"course" bson:"course"` Email string `json:"email" bson:"email"` @@ -19,6 +19,9 @@ type Student struct { LinkedIn string `json:"linkedIn" bson:"linkedIn"` Github string `json:"github" bson:"github"` MicrosoftTeams string `json:"microsoftTeams" bson:"microsoftTeams"` + Kaggle string `json:"kaggle" bson:"kaggle"` + Kaggel string `json:"kaggel" bson:"kaggel"` + Skype string `json:"skypeId" bson:"skypeId"` Mobile int64 `json:"mobile" bson:"mobile"` Gender string `json:"gender" bson:"gender"` Dob string `json:"dob" bson:"dob"` @@ -30,26 +33,58 @@ type Student struct { MotherName string `json:"motherName" bson:"motherName"` MotherOccupation string `json:"motherOccupation" bson:"motherOccupation"` MotherTongue string `json:"motherTongue" bson:"motherTongue"` - EducationGap string `json:"educationGap" bson:"educationGap"` - JeeRank string `json:"jeeRank" bson:"jeeRank"` - Cgpa float64 `json:"cgpa" bson:"cgpa"` - ActiveBacklogs int `json:"activeBacklogs" bson:"activeBacklogs"` - TotalBacklogs int `json:"totalBacklogs" bson:"totalBacklogs"` + Cgpa *float64 `json:"cgpa" bson:"cgpa"` + ActiveBacklogs *int `json:"activeBacklogs" bson:"activeBacklogs"` + TotalBacklogs *int `json:"totalBacklogs" bson:"totalBacklogs"` XBoard string `json:"xBoard" bson:"xBoard"` - XYear string `json:"xYear" bson:"xYear"` XPercentage float64 `json:"xPercentage" bson:"xPercentage"` XInstitute string `json:"xInstitute" bson:"xInstitute"` XiiBoard string `json:"xiiBoard" bson:"xiiBoard"` - XiiYear string `json:"xiiYear" bson:"xiiYear"` XiiPercentage float64 `json:"xiiPercentage" bson:"xiiPercentage"` XiiInstitute string `json:"xiiInstitute" bson:"xiiInstitute"` - SemesterOne float64 `json:"semesterOne" bson:"semesterOne"` - SemesterTwo float64 `json:"semesterTwo" bson:"semesterTwo"` - SemesterThree float64 `json:"semesterThree" bson:"semesterThree"` - SemesterFour float64 `json:"semesterFour" bson:"semesterFour"` - SemesterFive float64 `json:"semesterFive" bson:"semesterFive"` - SemesterSix float64 `json:"semesterSix" bson:"semesterSix"` - UpdatedAt string `json:"updatedAt" bson:"updatedAt"` + PgIn string `json:"pgIn" bson:"pgIn"` + PgCollege string `json:"pgCollege" bson:"pgCollege"` + PgScore float64 `json:"pgScore" bson:"pgScore"` + PgYear int `json:"pgPassingyear" bson:"pgPassingyear"` + UgIn string `json:"ugIn" bson:"ugIn"` + UgCollege string `json:"ugCollege" bson:"ugCollege"` + UgScore float64 `json:"ugScore" bson:"ugScore"` + UgYear int `json:"ugPassingyear" bson:"ugPassingyear"` + VideoResume *string `json:"videoResume" bson:"videoResume"` + SemesterOne *float64 `json:"semesterOne" bson:"semesterOne"` + SemesterTwo *float64 `json:"semesterTwo" bson:"semesterTwo"` + SemesterThree *float64 `json:"semesterThree" bson:"semesterThree"` + SemesterFour *float64 `json:"semesterFour" bson:"semesterFour"` + SemesterFive *float64 `json:"semesterFive" bson:"semesterFive"` + SemesterSix *float64 `json:"semesterSix" bson:"semesterSix"` + SemesterSeven *float64 `json:"semesterSeven" bson:"semesterSeven"` + SemesterEight *float64 `json:"semesterEight" bson:"semesterEight"` + SummerOne *float64 `json:"summerOne" bson:"summerOne"` + SummerTwo *float64 `json:"summerTwo" bson:"summerTwo"` + SummerThree *float64 `json:"summerThree" bson:"summerThree"` + SummerFour *float64 `json:"summerFour" bson:"summerFour"` + SummerFive *float64 `json:"summerFive" bson:"summerFive"` + UpdatedAt primitive.DateTime `json:"updatedAt" bson:"updatedAt"` +} + +type XXIIYearType1 struct { + XiiYear string `json:"xiiYear" bson:"xiiYear"` + XYear string `json:"xYear" bson:"xYear"` +} + +type XXIIYearType2 struct { + XiiYear int `json:"xiiYear" bson:"xiiYear"` + XYear int `json:"xYear" bson:"xYear"` +} + +type EuducationGapJeeRankIntegers struct { + JeeRank int `json:"jeeRank" bson:"jeeRank"` + EducationGap int `json:"educationGap" bson:"educationGap"` +} + +type EuducationGapJeeRankStrings struct { + JeeRank string `json:"jeeRank" bson:"jeeRank"` + EducationGap string `json:"educationGap" bson:"educationGap"` } type Group struct { @@ -101,7 +136,12 @@ type StudentPopulated struct { SemesterFour float64 `json:"semesterFour" bson:"semesterFour"` SemesterFive float64 `json:"semesterFive" bson:"semesterFive"` SemesterSix float64 `json:"semesterSix" bson:"semesterSix"` + SummerOne float64 `json:"summerOne" bson:"summerOne"` + SummerTwo float64 `json:"summerTwo" bson:"summerTwo"` + SummerThree float64 `json:"summerThree" bson:"summerThree"` + SummerFour float64 `json:"summerFour" bson:"summerFour"` + SummerFive float64 `json:"summerFive" bson:"summerFive"` Groups []Group `json:"groups" bson:"groups"` - UpdatedAt string `json:"updatedAt" bson:"updatedAt"` + UpdatedAt primitive.DateTime `json:"updatedAt" bson:"updatedAt"` CompaniesAlloted []string `json:"companiesAlloted" bson:"companiesAlloted"` } diff --git a/model/student2.go b/model/student2.go new file mode 100644 index 0000000..ff7542e --- /dev/null +++ b/model/student2.go @@ -0,0 +1,166 @@ +package model + +import ( + constant "github.com/FrosTiK-SD/models/constant" + misc "github.com/FrosTiK-SD/models/misc" + + "go.mongodb.org/mongo-driver/bson/primitive" +) + +type ReservationCategory struct { + Category string `json:"category" bson:"category"` + IsPWD bool `json:"isPWD" bson:"isPWD"` + IsEWS bool `json:"isEWS" bson:"isEWS"` +} + +type RankDetails struct { + Rank int `bson:"rank" json:"rank"` + RankCategory ReservationCategory `bson:"rankCategory" json:"rankCategory"` +} + +type SemesterSPI struct { + One *float64 `json:"one" bson:"one"` + Two *float64 `json:"two" bson:"two"` + Three *float64 `json:"three" bson:"three"` + Four *float64 `json:"four" bson:"four"` + Five *float64 `json:"five" bson:"five"` + Six *float64 `json:"six" bson:"six"` + Seven *float64 `json:"seven" bson:"seven"` + Eight *float64 `json:"eight" bson:"eight"` + Nine *float64 `json:"nine" bson:"nine"` + Ten *float64 `json:"ten" bson:"ten"` +} + +type SummerTermSPI struct { + One *float64 `json:"one" bson:"one"` + Two *float64 `json:"two" bson:"two"` + Three *float64 `json:"three" bson:"three"` + Four *float64 `json:"four" bson:"four"` + Five *float64 `json:"five" bson:"five"` +} + +type EducationDetails struct { + Certification string `bson:"certification" json:"certification"` + Institute string `bson:"institute" json:"institute"` + Year int `bson:"year" json:"year"` + Score float64 `bson:"score" json:"score"` +} + +type Academics struct { + JEERank *RankDetails `json:"jeeRank" bson:"jeeRank"` + GATERank *RankDetails `json:"gateRank" bson:"gateRank"` + XthClass *EducationDetails `json:"xClass" bson:"xClass"` + XIIthClass *EducationDetails `json:"xiiClass" bson:"xiiClass"` + UnderGraduate *EducationDetails `json:"underGraduate" bson:"underGraduate"` + Honours *string `json:"honours" bson:"honours"` + PostGraduate *EducationDetails `json:"postGraduate" bson:"postGraduate"` + ThesisEndDate *primitive.DateTime `json:"thesisEndDate" bson:"thesisEndDate"` + EducationGap *int `json:"educationGap" bson:"educationGap"` + SemesterSPI SemesterSPI `json:"semesterSPI" bson:"semesterSPI"` + SummerTermSPI SummerTermSPI `json:"summerTermSPI" bson:"summerTermSPI"` + CurrentCGPA *float64 `json:"currentCGPA" bson:"currentCGPA"` + ActiveBacklogs *int `json:"activeBacklogs" bson:"activeBacklogs"` + TotalBacklogs *int `json:"totalBacklogs" bson:"totalBacklogs"` + + Verification misc.Verification `json:"verification" bson:"verification"` +} + +type SocialProfile struct { + URL string `bson:"url" json:"url"` + Username string `bson:"username" json:"username"` + Verification misc.Verification `bson:"verification" json:"verification"` +} + +type SocialProfiles struct { + LinkedIn *SocialProfile `json:"linkedIn" bson:"linkedIn"` + Github *SocialProfile `json:"github" bson:"github"` + MicrosoftTeams *SocialProfile `json:"microsoftTeams" bson:"microsoftTeams"` + Skype *SocialProfile `json:"skype" bson:"skype"` + GoogleScholar *SocialProfile `json:"googleScholar" bson:"googleScholar"` + + Codeforces *SocialProfile `json:"codeforces" bson:"codeforces"` + CodeChef *SocialProfile `json:"codechef" bson:"codechef"` + LeetCode *SocialProfile `json:"leetcode" bson:"leetcode"` + Kaggle *SocialProfile `json:"kaggle" bson:"kaggle"` +} + +type Batch struct { + StartYear int `json:"startYear" bson:"startYear"` + EndYear int `json:"endYear" bson:"endYear"` +} + +type ParentsDetails struct { + FatherName string `json:"fatherName" bson:"fatherName"` + FatherOccupation string `json:"fatherOccupation" bson:"fatherOccupation"` + MotherName string `json:"motherName" bson:"motherName"` + MotherOccupation string `json:"motherOccupation" bson:"motherOccupation"` +} + +type Extras struct { + VideoResume *string `bson:"videoResume" json:"videoResume"` + Verification misc.Verification `bson:"verification" json:"verification"` +} + +type WorkExperience struct { + StartDate primitive.DateTime `bson:"startDate" json:"startDate"` + EndDate primitive.DateTime `bson:"endDate" json:"endDate"` + Organisation string `bson:"organisation" json:"organisation"` + Location string `bson:"location" json:"location"` + Position string `bson:"position" json:"position"` + Details string `bson:"details" json:"details"` + Verification misc.Verification `bson:"verification" json:"verification"` +} + +type UserError string + +const ( + MIGRATION UserError = "migration" +) + +type DataErrors struct { + User map[string]UserError `json:"user" bson:"user"` +} + +type Student struct { + Id primitive.ObjectID `json:"_id" bson:"_id"` + Groups []primitive.ObjectID `json:"groups" bson:"groups"` + CompaniesAlloted []string `json:"companiesAlloted" bson:"companiesAlloted"` + + Batch *Batch `json:"batch" bson:"batch"` + RollNo int `json:"rollNo" bson:"rollNo"` + InstituteEmail string `json:"email" bson:"email"` + Department string `json:"department" bson:"department"` + Course *constant.Course `json:"course" bson:"course"` + Specialisation *string `json:"specialisation" bson:"specialisation"` + + FirstName string `json:"firstName" bson:"firstName"` + MiddleName *string `json:"middleName" bson:"middleName"` + LastName *string `json:"lastName" bson:"lastName"` + + ProfilePicture *misc.Attachment `json:"profilePicture" bson:"profilePicture"` + Gender *constant.Gender `json:"gender" bson:"gender"` + DOB *primitive.DateTime `json:"dob" bson:"dob"` + PermanentAddress string `json:"permanentAddress" bson:"permanentAddress"` + PresentAddress string `json:"presentAddress" bson:"presentAddress"` + PersonalEmail string `json:"personalEmail" bson:"personalEmail"` + Mobile *string `json:"mobile" bson:"mobile"` + Category *ReservationCategory `json:"category" bson:"category"` + MotherTongue string `json:"motherTongue" bson:"motherTongue"` + ParentsDetails *ParentsDetails `json:"parentsDetails" bson:"parentsDetails"` + + Academics Academics `json:"academics" bson:"academics"` + WorkExperience []WorkExperience `json:"workExperience" bson:"workExperience"` + SocialProfiles SocialProfiles `json:"socialProfiles" bson:"socialProfiles"` + Extras Extras `json:"extras" bson:"extras"` + + // metadata + StructVersion int `json:"version" bson:"version"` + UpdatedAt primitive.DateTime `json:"updatedAt" bson:"updatedAt"` + CreatedAt primitive.DateTime `json:"createdAt" bson:"createdAt"` + RawKeyStore map[string]interface{} `json:"raw_key_store" bson:"raw_key_store"` + DataErrors DataErrors `json:"dataErrors" bson:"dataErrors"` +} + +// at some point I expect to use * pointers to omit fields which are not necessary +// https://willnorris.com/2014/go-rest-apis-and-pointers/ +// https://stackoverflow.com/questions/47158987/how-to-update-mongodb-fields-with-omitempty-flag-in-golang-structure