Merge pull request #1 from zdam-egzamin-zawodowy/models

add models
This commit is contained in:
Dawid Wysokiński 2021-02-27 09:31:50 +01:00 committed by GitHub
commit 26abcb7a45
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 746 additions and 102 deletions

4
go.mod
View File

@ -1,11 +1,13 @@
module github.com/zdam-egzamin-zawodowy/backend
go 1.15
go 1.16
require (
github.com/99designs/gqlgen v0.13.0
github.com/gin-contrib/cors v1.3.1
github.com/gin-gonic/gin v1.6.3
github.com/go-pg/pg/v10 v10.7.7
github.com/gosimple/slug v1.9.0
github.com/joho/godotenv v1.3.0
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.8.0

57
go.sum
View File

@ -1,10 +1,19 @@
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/99designs/gqlgen v0.13.0 h1:haLTcUp3Vwp80xMVEg5KRNwzfUrgFdRmtBY8fuB8scA=
github.com/99designs/gqlgen v0.13.0/go.mod h1:NV130r6f4tpRWuAI+zsrSdooO/eWUv+Gyyoi3rEfXIk=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/agnivade/levenshtein v1.0.1/go.mod h1:CURSv5d9Uaml+FovSIICkLbAUZ9S4RqaHDIsdSBg7lM=
github.com/agnivade/levenshtein v1.0.3/go.mod h1:4SFRZbbXWLF4MU1T9Qg0pGgH3Pjs+t6ie5efyrwRJXs=
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 h1:bvNMNQO63//z+xNgfBlViaCIJKLlCJ6/fmUseuG0wVQ=
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8=
github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0/go.mod h1:t2tdKJDJF9BV14lnkjHmOQgcvEKgtqs5a1N3LNdJhGE=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
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=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgryski/trifles v0.0.0-20190318185328-a8d75aae118c/go.mod h1:if7Fbed8SFyPtHLHbg49SI7NAdJiC5WIA09pe59rfAA=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
@ -17,6 +26,7 @@ github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm
github.com/gin-gonic/gin v1.5.0/go.mod h1:Nd6IXA8m5kNZdNEHMBd93KT+mdY3+bewLgRvmCsR2Do=
github.com/gin-gonic/gin v1.6.3 h1:ahKqKTFpO5KTPHxWZjEdPScmYaGtLo8Y4DMHoEsnp14=
github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M=
github.com/go-chi/chi v3.3.2+incompatible/go.mod h1:eB3wogJHnLi3x/kFX2A+IbTBlXxmMeXJVKy9tTv1XzQ=
github.com/go-pg/pg/v10 v10.7.7 h1:jPooLMqrVVV5Ejpcxpwxv9R2gECT/+UEpz+qIzOUJ9A=
github.com/go-pg/pg/v10 v10.7.7/go.mod h1:d0w17Xw5x2DtbD/UgB9rnZg3FAck3eDHXff0Srrzuuk=
github.com/go-pg/zerochecker v0.2.0 h1:pp7f72c3DobMWOb2ErtZsnrPaSvHd2W4o9//8HtF4mU=
@ -31,11 +41,11 @@ github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD87
github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA=
github.com/go-playground/validator/v10 v10.2.0 h1:KgJ0snyC2R9VXYN2rneOtQcw5aHQB1Vv0sFl1UcHBOY=
github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI=
github.com/gogo/protobuf v1.0.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.3 h1:gyjaxf+svBWX08ZjK86iN9geUJF0H6gp2IRKX6Nf6/I=
github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
@ -54,6 +64,12 @@ github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.4 h1:L8R9j+yAqZuZjsqh/z+F1NCffTKKLShY6zXTItVIZ8M=
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/gorilla/context v0.0.0-20160226214623-1ea25387ff6f/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg=
github.com/gorilla/mux v1.6.1/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/gosimple/slug v1.9.0 h1:r5vDcYrFz9BmfIAMC829un9hq7hKM4cHUrsv36LbEqs=
github.com/gosimple/slug v1.9.0/go.mod h1:AMZ+sOVe65uByN3kgEyf9WEBKBCSS+dJjMX9x4vDJbg=
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
@ -62,7 +78,6 @@ github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqx
github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGns=
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
@ -70,11 +85,16 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/leodido/go-urn v1.1.0/go.mod h1:+cyI34gQWZcE1eQU7NVgKkkzdXDQHr1dBMtdAPozLkw=
github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y=
github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=
github.com/logrusorgru/aurora v0.0.0-20200102142835-e9ef32dff381/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4=
github.com/magefile/mage v1.10.0 h1:3HiXzCUY12kh9bIuyXShaVe529fJfyqoVM42o/uom2g=
github.com/magefile/mage v1.10.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
github.com/matryer/moq v0.0.0-20200106131100-75d0ddfc0007/go.mod h1:9ELz6aaclSIGnZBoaSLZ3NAl1VTufbOrXBPvtcy6WiQ=
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ=
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mitchellh/mapstructure v0.0.0-20180203102830-a4e142e9c047/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg=
@ -91,17 +111,29 @@ github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7J
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
github.com/onsi/gomega v1.10.3 h1:gph6h/qe9GSUw1NhH1gp+qb+h8rXD8Cy60Z32Qw3ELA=
github.com/onsi/gomega v1.10.3/go.mod h1:V9xEwhxec5O8UDM77eCW8vLymOMltsqPVYWrpDsH8xc=
github.com/opentracing/basictracer-go v1.0.0/go.mod h1:QfBfYuafItcjQuMwinw9GhYKwFXS9KnPs5lxoYwgW74=
github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/rainycape/unidecode v0.0.0-20150907023854-cb7f23ec59be h1:ta7tUOvsPHVHGom5hKW5VXNc2xZIkfCKP8iaqOyYtUQ=
github.com/rainycape/unidecode v0.0.0-20150907023854-cb7f23ec59be/go.mod h1:MIDFMn7db1kT65GmV94GzpX9Qdi7N/pQlwb+AN8wh+Q=
github.com/rs/cors v1.6.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
github.com/shurcooL/httpfs v0.0.0-20171119174359-809beceb2371/go.mod h1:ZY1cvUeJuFPAdZ/B6v7RHavJWZn2YPVFQ1OSXhCGOkg=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/shurcooL/vfsgen v0.0.0-20180121065927-ffb13db8def0/go.mod h1:TrYk7fJVaAttu97ZZKrO9UbRa8izdowaMIZcxYMbVaw=
github.com/sirupsen/logrus v1.8.0 h1:nfhvjKcUMhBMVqbKHJlk5RPrrfYr/NMo3692g0dwfWU=
github.com/sirupsen/logrus v1.8.0/go.mod h1:4GuYW9TZmE769R5STWrRakJc4UqQ3+QQ95fyz7ENv1A=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.1/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
@ -113,6 +145,10 @@ github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo=
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs=
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
github.com/urfave/cli/v2 v2.1.1/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ=
github.com/vektah/dataloaden v0.2.1-0.20190515034641-a19b9a6e7c9e/go.mod h1:/HUdMve7rvxZma+2ZELQeNh88+003LL7Pf/CZ089j8U=
github.com/vektah/gqlparser/v2 v2.1.0 h1:uiKJ+T5HMGGQM2kRKQ8Pxw8+Zq9qhhZhz/lieYvCMns=
github.com/vektah/gqlparser/v2 v2.1.0/go.mod h1:SyUiHgLATUR8BiYURfTirrTcGpcE+4XkV2se04Px1Ms=
github.com/vmihailenco/bufpool v0.1.11 h1:gOq2WmBrq0i2yW5QJ16ykccQ4wH9UyEsgLm6czKAd94=
github.com/vmihailenco/bufpool v0.1.11/go.mod h1:AFf/MOy3l2CFTKbxwt0mp2MwnqjNEs5H/UxrkA5jxTQ=
github.com/vmihailenco/msgpack/v5 v5.2.0 h1:ZhIAtVUP1mme8GIlpiAnmTzjSWMexA/uNF2We85DR0w=
@ -131,6 +167,7 @@ go.opentelemetry.io/otel/trace v0.17.0 h1:SBOj64/GAOyWzs5F680yW1ITIfJkm6cJWL2YAv
go.opentelemetry.io/otel/trace v0.17.0/go.mod h1:bIujpqg6ZL6xUTubIUgziI1jSaUPthmabA/ygf/6Cfg=
golang.org/x/crypto v0.0.0-20180910181607-0e37d006457b/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20210218145215-b8e89b74b9df/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83 h1:/ZScEX8SfEmUGRHs0gxpqteO5nfNW6axyZbBdw9A12g=
@ -139,12 +176,14 @@ golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
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-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20201006153459-a7d1128ccaa0/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b h1:uwuIcX0g4Yl1NC5XAz37xsr2lTtcqevgzYNVt49waME=
@ -156,13 +195,13 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/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-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42 h1:vEOn+mP2zCOVzKckCZy6YsCtDblrpj/w7B9nxGNELpg=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@ -176,9 +215,13 @@ golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190125232054-d66bd3c5d5a6/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190515012406-7d7faa4812bd/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
golang.org/x/tools v0.0.0-20200114235610-7ae403b6b589/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
@ -199,10 +242,9 @@ google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2
google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
google.golang.org/protobuf v1.25.0 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c=
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
@ -212,7 +254,6 @@ gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkep
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
@ -222,3 +263,5 @@ honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWh
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
mellium.im/sasl v0.2.1 h1:nspKSRg7/SyO0cRGY71OkfHab8tf9kCts6a6oTDut0w=
mellium.im/sasl v0.2.1/go.mod h1:ROaEDLQNuf9vjKqE1SrAfnsobm2YKXT1gnN1uDp1PjQ=
sourcegraph.com/sourcegraph/appdash v0.0.0-20180110180208-2cc67fd64755/go.mod h1:hI742Nqp5OhwiqlzhgfbWU4mW4yO10fP+LoT9WOswdU=
sourcegraph.com/sourcegraph/appdash-data v0.0.0-20151005221446-73f23eafcf67/go.mod h1:L5q+DGLGOQFpo1snNEkLOJT2d1YTW66rWNzatr3He1k=

View File

@ -1,3 +1,4 @@
#!/bin/sh
cd ./internal/graphql
go run github.com/99designs/gqlgen
go mod tidy

49
internal/models/answer.go Normal file
View File

@ -0,0 +1,49 @@
package models
import (
"fmt"
"io"
"strconv"
"strings"
)
type Answer string
const (
AnswerA Answer = "a"
AnswerB Answer = "b"
AnswerC Answer = "c"
AnswerD Answer = "d"
)
func (role Answer) IsValid() bool {
switch role {
case AnswerA,
AnswerB,
AnswerC,
AnswerD:
return true
}
return false
}
func (answer Answer) String() string {
return string(answer)
}
func (answer *Answer) UnmarshalGQL(v interface{}) error {
str, ok := v.(string)
if !ok {
return fmt.Errorf("enums must be strings")
}
*answer = Answer(strings.ToLower(str))
if !answer.IsValid() {
return fmt.Errorf("%s is not a valid Answer", str)
}
return nil
}
func (answer Answer) MarshalGQL(w io.Writer) {
fmt.Fprint(w, strconv.Quote(answer.String()))
}

View File

@ -1,59 +1,9 @@
package models
import (
"strings"
"time"
)
func addAliasToColumnName(column, prefix string) string {
if prefix != "" && !strings.HasPrefix(column, prefix+".") {
column = wrapStringInDoubleQuotes(prefix) + "." + wrapStringInDoubleQuotes(column)
} else {
column = wrapStringInDoubleQuotes(column)
}
return column
}
func wrapStringInDoubleQuotes(str string) string {
return `"` + str + `"`
}
func buildConditionEquals(column string) string {
return column + " = ?"
}
func buildConditionLT(column string) string {
return column + " < ?"
}
func buildConditionLTE(column string) string {
return column + " <= ?"
}
func buildConditionGT(column string) string {
return column + " > ?"
}
func buildConditionGTE(column string) string {
return column + " >= ?"
}
func buildConditionMatch(column string) string {
return column + " LIKE ?"
}
func buildConditionIEQ(column string) string {
return column + " ILIKE ?"
}
func buildConditionArray(column string) string {
return column + " = ANY(?)"
}
func buildConditionNotInArray(column string) string {
return "NOT (" + buildConditionArray(column) + ")"
}
func isZero(v interface{}) bool {
switch c := v.(type) {
case string:

View File

@ -0,0 +1,132 @@
package models
import (
"context"
"time"
"github.com/go-pg/pg/v10"
"github.com/go-pg/pg/v10/orm"
"github.com/gosimple/slug"
sqlutils "github.com/zdam-egzamin-zawodowy/backend/pkg/utils/sql"
)
type Profession struct {
tableName struct{} `pg:"alias:profession"`
ID int `json:"id,omitempty" xml:"id" gqlgen:"id"`
Slug string `json:"slug" pg:",unique" xml:"slug" gqlgen:"slug"`
Name string `json:"name,omitempty" pg:",unique" xml:"name" gqlgen:"name"`
Description string `json:"description,omitempty" pg:",use_zero" xml:"description" gqlgen:"description"`
CreatedAt time.Time `json:"createdAt,omitempty" pg:"default:now()" xml:"createdAt" gqlgen:"createdAt"`
}
func (p *Profession) BeforeInsert(ctx context.Context) (context.Context, error) {
p.CreatedAt = time.Now()
p.Slug = slug.Make(p.Name)
return ctx, nil
}
func (p *Profession) BeforeUpdate(ctx context.Context) (context.Context, error) {
if p.Name != "" {
p.Slug = slug.Make(p.Name)
}
return ctx, nil
}
type ProfessionInput struct {
Name *string `json:"name,omitempty" xml:"name" gqlgen:"name"`
Description *string `json:"description,omitempty" xml:"description" gqlgen:"description"`
}
func (input *ProfessionInput) ToProfession() *Profession {
p := &Profession{}
if input.Name != nil {
p.Name = *input.Name
}
if input.Description != nil {
p.Description = *input.Description
}
return p
}
type ProfessionFilter struct {
ID []int `gqlgen:"id" json:"id" xml:"id"`
IDNEQ []int `gqlgen:"idNEQ" json:"idNEQ" xml:"idNEQ"`
Slug []string `json:"slug" xml:"slug" gqlgen:"slug"`
SlugNEQ []string `json:"slugNEQ" xml:"slugNEQ" gqlgen:"slugNEQ"`
Name []string `gqlgen:"name" json:"name" xml:"name"`
NameNEQ []string `json:"nameNEQ" xml:"nameNEQ" gqlgen:"nameNEQ"`
NameMATCH string `json:"nameMATCH" xml:"nameMATCH" gqlgen:"nameMATCH"`
NameIEQ string `gqlgen:"nameIEQ" json:"nameIEQ" xml:"nameIEQ"`
DescriptionMATCH string `gqlgen:"descriptionMATCH" json:"descriptionMATCH" xml:"descriptionMATCH"`
DescriptionIEQ string `json:"descriptionIEQ" xml:"descriptionIEQ" gqlgen:"descriptionIEQ"`
CreatedAt time.Time `gqlgen:"createdAt" json:"createdAt" xml:"createdAt"`
CreatedAtGT time.Time `gqlgen:"createdAtGT" json:"createdAtGT" xml:"createdAtGT"`
CreatedAtGTE time.Time `json:"createdAtGTE" xml:"createdAtGTE" gqlgen:"createdAtGTE"`
CreatedAtLT time.Time `gqlgen:"createdAtLT" json:"createdAtLT" xml:"createdAtLT"`
CreatedAtLTE time.Time `json:"createdAtLTE" xml:"createdAtLTE" gqlgen:"createdAtLTE"`
}
func (f *ProfessionFilter) WhereWithAlias(q *orm.Query, alias string) (*orm.Query, error) {
if !isZero(f.ID) {
q = q.Where(sqlutils.BuildConditionArray(sqlutils.AddAliasToColumnName("id", alias)), pg.Array(f.ID))
}
if !isZero(f.IDNEQ) {
q = q.Where(sqlutils.BuildConditionNotInArray(sqlutils.AddAliasToColumnName("id", alias)), pg.Array(f.IDNEQ))
}
if !isZero(f.Slug) {
q = q.Where(sqlutils.BuildConditionArray(sqlutils.AddAliasToColumnName("slug", alias)), pg.Array(f.Slug))
}
if !isZero(f.SlugNEQ) {
q = q.Where(sqlutils.BuildConditionNotInArray(sqlutils.AddAliasToColumnName("slug", alias)), pg.Array(f.SlugNEQ))
}
if !isZero(f.Name) {
q = q.Where(sqlutils.BuildConditionArray(sqlutils.AddAliasToColumnName("name", alias)), pg.Array(f.Name))
}
if !isZero(f.NameNEQ) {
q = q.Where(sqlutils.BuildConditionNotInArray(sqlutils.AddAliasToColumnName("name", alias)), pg.Array(f.NameNEQ))
}
if !isZero(f.NameMATCH) {
q = q.Where(sqlutils.BuildConditionMatch(sqlutils.AddAliasToColumnName("name", alias)), f.NameMATCH)
}
if !isZero(f.NameIEQ) {
q = q.Where(sqlutils.BuildConditionIEQ(sqlutils.AddAliasToColumnName("name", alias)), f.NameIEQ)
}
if !isZero(f.DescriptionMATCH) {
q = q.Where(sqlutils.BuildConditionMatch(sqlutils.AddAliasToColumnName("description", alias)), f.DescriptionMATCH)
}
if !isZero(f.DescriptionIEQ) {
q = q.Where(sqlutils.BuildConditionIEQ(sqlutils.AddAliasToColumnName("description", alias)), f.DescriptionIEQ)
}
if !isZero(f.CreatedAt) {
q = q.Where(sqlutils.BuildConditionEquals(sqlutils.AddAliasToColumnName("created_at", alias)), f.CreatedAt)
}
if !isZero(f.CreatedAtGT) {
q = q.Where(sqlutils.BuildConditionGT(sqlutils.AddAliasToColumnName("created_at", alias)), f.CreatedAtGT)
}
if !isZero(f.CreatedAtGTE) {
q = q.Where(sqlutils.BuildConditionGTE(sqlutils.AddAliasToColumnName("created_at", alias)), f.CreatedAtGTE)
}
if !isZero(f.CreatedAtLT) {
q = q.Where(sqlutils.BuildConditionLT(sqlutils.AddAliasToColumnName("created_at", alias)), f.CreatedAtLT)
}
if !isZero(f.CreatedAtLTE) {
q = q.Where(sqlutils.BuildConditionLTE(sqlutils.AddAliasToColumnName("created_at", alias)), f.CreatedAtLTE)
}
return q, nil
}
func (f *ProfessionFilter) Where(q *orm.Query) (*orm.Query, error) {
return f.WhereWithAlias(q, "profession")
}

View File

@ -0,0 +1,230 @@
package models
import (
"context"
"time"
"github.com/go-pg/pg/v10"
"github.com/go-pg/pg/v10/orm"
"github.com/gosimple/slug"
sqlutils "github.com/zdam-egzamin-zawodowy/backend/pkg/utils/sql"
)
type Qualification struct {
tableName struct{} `pg:"alias:qualification"`
ID int `json:"id" xml:"id" gqlgen:"id"`
Slug string `json:"slug" pg:",unique" xml:"slug" gqlgen:"slug"`
Name string `json:"name" pg:",unique:group_1" xml:"name" gqlgen:"name"`
Code string `json:"code" pg:",unique:group_1" xml:"code" gqlgen:"code"`
Formula string `json:"formula" xml:"formula" gqlgen:"formula"`
Description string `json:"description" xml:"description" gqlgen:"description"`
CreatedAt time.Time `json:"createdAt,omitempty" pg:"default:now()" xml:"createdAt" gqlgen:"createdAt"`
}
func (q *Qualification) BeforeInsert(ctx context.Context) (context.Context, error) {
q.CreatedAt = time.Now()
q.Slug = slug.Make(q.Code)
return ctx, nil
}
func (q *Qualification) BeforeUpdate(ctx context.Context) (context.Context, error) {
if q.Code != "" {
q.Slug = slug.Make(q.Code)
}
return ctx, nil
}
type QualificationToProfession struct {
QualificationID int `pg:"on_delete:CASCADE" json:"qualificationID" xml:"qualificationID" gqlgen:"qualificationID"`
ProfessionID int `pg:"on_delete:CASCADE" json:"professionID" xml:"professionID" gqlgen:"professionID"`
}
type QualificationInput struct {
Name *string `json:"name" xml:"name" gqlgen:"name"`
Description *string `json:"description" xml:"description" gqlgen:"description"`
Code *string `json:"code" xml:"code" gqlgen:"code"`
Formula *string `json:"formula" xml:"formula" gqlgen:"formula"`
AssociateProfession []int `json:"associateProfession" xml:"associateProfession" gqlgen:"associateProfession"`
DissociateProfession []int `json:"dissociateProfession" xml:"dissociateProfession" gqlgen:"dissociateProfession"`
}
func (input *QualificationInput) ToQualification() *Qualification {
q := &Qualification{}
if input.Name != nil {
q.Name = *input.Name
}
if input.Description != nil {
q.Description = *input.Description
}
if input.Code != nil {
q.Code = *input.Code
}
if input.Formula != nil {
q.Formula = *input.Formula
}
return q
}
type QualificationFilterOr struct {
NameMATCH string `json:"nameMATCH" xml:"nameMATCH" gqlgen:"nameMATCH"`
NameIEQ string `gqlgen:"nameIEQ" json:"nameIEQ" xml:"nameIEQ"`
CodeMATCH string `json:"codeMATCH" xml:"codeMATCH" gqlgen:"codeMATCH"`
CodeIEQ string `gqlgen:"codeIEQ" json:"codeIEQ" xml:"codeIEQ"`
}
func (f *QualificationFilterOr) WhereWithAlias(q *orm.Query, alias string) *orm.Query {
q = q.WhereGroup(func(q *orm.Query) (*orm.Query, error) {
if !isZero(f.NameMATCH) {
q = q.Where(sqlutils.BuildConditionMatch(sqlutils.AddAliasToColumnName("name", alias)), f.NameMATCH)
}
if !isZero(f.NameIEQ) {
q = q.Where(sqlutils.BuildConditionIEQ(sqlutils.AddAliasToColumnName("name", alias)), f.NameIEQ)
}
if !isZero(f.CodeMATCH) {
q = q.Where(sqlutils.BuildConditionMatch(sqlutils.AddAliasToColumnName("code", alias)), f.CodeMATCH)
}
if !isZero(f.CodeIEQ) {
q = q.Where(sqlutils.BuildConditionIEQ(sqlutils.AddAliasToColumnName("code", alias)), f.CodeIEQ)
}
return q, nil
})
return q
}
type QualificationFilter struct {
ID []int `gqlgen:"id" json:"id" xml:"id"`
IDNEQ []int `gqlgen:"idNEQ" json:"idNEQ" xml:"idNEQ"`
Slug []string `json:"slug" xml:"slug" gqlgen:"slug"`
SlugNEQ []string `json:"slugNEQ" xml:"slugNEQ" gqlgen:"slugNEQ"`
Name []string `gqlgen:"name" json:"name" xml:"name"`
NameNEQ []string `json:"nameNEQ" xml:"nameNEQ" gqlgen:"nameNEQ"`
NameMATCH string `json:"nameMATCH" xml:"nameMATCH" gqlgen:"nameMATCH"`
NameIEQ string `gqlgen:"nameIEQ" json:"nameIEQ" xml:"nameIEQ"`
Code []string `gqlgen:"code" json:"code" xml:"code"`
CodeNEQ []string `json:"codeNEQ" xml:"codeNEQ" gqlgen:"codeNEQ"`
CodeMATCH string `json:"codeMATCH" xml:"codeMATCH" gqlgen:"codeMATCH"`
CodeIEQ string `gqlgen:"codeIEQ" json:"codeIEQ" xml:"codeIEQ"`
Formula []string `gqlgen:"formula" json:"formula" xml:"formula"`
FormulaNEQ []string `json:"formulaNEQ" xml:"formulaNEQ" gqlgen:"formulaNEQ"`
DescriptionMATCH string `gqlgen:"descriptionMATCH" json:"descriptionMATCH" xml:"descriptionMATCH"`
DescriptionIEQ string `json:"descriptionIEQ" xml:"descriptionIEQ" gqlgen:"descriptionIEQ"`
ProfessionID []int `json:"professionID" xml:"professionID" gqlgen:"professionID"`
CreatedAt time.Time `gqlgen:"createdAt" json:"createdAt" xml:"createdAt"`
CreatedAtGT time.Time `gqlgen:"createdAtGT" json:"createdAtGT" xml:"createdAtGT"`
CreatedAtGTE time.Time `json:"createdAtGTE" xml:"createdAtGTE" gqlgen:"createdAtGTE"`
CreatedAtLT time.Time `gqlgen:"createdAtLT" json:"createdAtLT" xml:"createdAtLT"`
CreatedAtLTE time.Time `json:"createdAtLTE" xml:"createdAtLTE" gqlgen:"createdAtLTE"`
Or *QualificationFilterOr `json:"or" xml:"or" gqlgen:"or"`
}
func (f *QualificationFilter) WhereWithAlias(q *orm.Query, alias string) (*orm.Query, error) {
if !isZero(f.ID) {
q = q.Where(sqlutils.BuildConditionArray(sqlutils.AddAliasToColumnName("id", alias)), pg.Array(f.ID))
}
if !isZero(f.IDNEQ) {
q = q.Where(sqlutils.BuildConditionNotInArray(sqlutils.AddAliasToColumnName("id", alias)), pg.Array(f.IDNEQ))
}
if !isZero(f.Slug) {
q = q.Where(sqlutils.BuildConditionArray(sqlutils.AddAliasToColumnName("slug", alias)), pg.Array(f.Slug))
}
if !isZero(f.SlugNEQ) {
q = q.Where(sqlutils.BuildConditionNotInArray(sqlutils.AddAliasToColumnName("slug", alias)), pg.Array(f.SlugNEQ))
}
if !isZero(f.Name) {
q = q.Where(sqlutils.BuildConditionArray(sqlutils.AddAliasToColumnName("name", alias)), pg.Array(f.Name))
}
if !isZero(f.NameNEQ) {
q = q.Where(sqlutils.BuildConditionNotInArray(sqlutils.AddAliasToColumnName("name", alias)), pg.Array(f.NameNEQ))
}
if !isZero(f.NameMATCH) {
q = q.Where(sqlutils.BuildConditionMatch(sqlutils.AddAliasToColumnName("name", alias)), f.NameMATCH)
}
if !isZero(f.NameIEQ) {
q = q.Where(sqlutils.BuildConditionIEQ(sqlutils.AddAliasToColumnName("name", alias)), f.NameIEQ)
}
if !isZero(f.Code) {
q = q.Where(sqlutils.BuildConditionArray(sqlutils.AddAliasToColumnName("code", alias)), pg.Array(f.Code))
}
if !isZero(f.CodeNEQ) {
q = q.Where(sqlutils.BuildConditionNotInArray(sqlutils.AddAliasToColumnName("code", alias)), pg.Array(f.CodeNEQ))
}
if !isZero(f.CodeMATCH) {
q = q.Where(sqlutils.BuildConditionMatch(sqlutils.AddAliasToColumnName("code", alias)), f.CodeMATCH)
}
if !isZero(f.CodeIEQ) {
q = q.Where(sqlutils.BuildConditionIEQ(sqlutils.AddAliasToColumnName("code", alias)), f.CodeIEQ)
}
if !isZero(f.Formula) {
q = q.Where(sqlutils.BuildConditionArray(sqlutils.AddAliasToColumnName("formula", alias)), pg.Array(f.Formula))
}
if !isZero(f.FormulaNEQ) {
q = q.Where(sqlutils.BuildConditionNotInArray(sqlutils.AddAliasToColumnName("formula", alias)), pg.Array(f.FormulaNEQ))
}
if !isZero(f.DescriptionMATCH) {
q = q.Where(sqlutils.BuildConditionMatch(sqlutils.AddAliasToColumnName("description", alias)), f.DescriptionMATCH)
}
if !isZero(f.DescriptionIEQ) {
q = q.Where(sqlutils.BuildConditionIEQ(sqlutils.AddAliasToColumnName("description", alias)), f.DescriptionIEQ)
}
if !isZero(f.ProfessionID) {
// q = q.Where(sqlutils.BuildConditionArray(sqlutils.AddAliasToColumnName("formula", alias)), pg.Array(f.Formula))
sliceLength := len(f.ProfessionID)
subquery := q.
New().
Model(&QualificationToProfession{}).
ColumnExpr(sqlutils.BuildCountColumnExpr("profession_id", "count")).
Column("qualification_id").
Where(sqlutils.BuildConditionArray("profession_id"), pg.Array(f.ProfessionID)).
Group("qualification_id")
q = q.
Join(`INNER JOIN (?) AS qualification_to_professions ON qualification_to_professions.qualification_id = qualification.id`, subquery).
Where(sqlutils.BuildConditionGTE("count"), sliceLength)
}
if !isZero(f.CreatedAt) {
q = q.Where(sqlutils.BuildConditionEquals(sqlutils.AddAliasToColumnName("created_at", alias)), f.CreatedAt)
}
if !isZero(f.CreatedAtGT) {
q = q.Where(sqlutils.BuildConditionGT(sqlutils.AddAliasToColumnName("created_at", alias)), f.CreatedAtGT)
}
if !isZero(f.CreatedAtGTE) {
q = q.Where(sqlutils.BuildConditionGTE(sqlutils.AddAliasToColumnName("created_at", alias)), f.CreatedAtGTE)
}
if !isZero(f.CreatedAtLT) {
q = q.Where(sqlutils.BuildConditionLT(sqlutils.AddAliasToColumnName("created_at", alias)), f.CreatedAtLT)
}
if !isZero(f.CreatedAtLTE) {
q = q.Where(sqlutils.BuildConditionLTE(sqlutils.AddAliasToColumnName("created_at", alias)), f.CreatedAtLTE)
}
if f.Or != nil {
q = f.Or.WhereWithAlias(q, alias)
}
return q, nil
}
func (f *QualificationFilter) Where(q *orm.Query) (*orm.Query, error) {
return f.WhereWithAlias(q, "qualification")
}

176
internal/models/question.go Normal file
View File

@ -0,0 +1,176 @@
package models
import (
"context"
"time"
"github.com/99designs/gqlgen/graphql"
"github.com/go-pg/pg/v10"
"github.com/go-pg/pg/v10/orm"
sqlutils "github.com/zdam-egzamin-zawodowy/backend/pkg/utils/sql"
)
type Question struct {
ID int `json:"id" xml:"id" gqlgen:"id"`
From string `pg:",unique:group_1" json:"from" xml:"from" gqlgen:"from"`
Content string `pg:",unique:group_1,notnull" json:"content" xml:"content" gqlgen:"content"`
Explanation string `json:"explanation" xml:"explanation" gqlgen:"explanation"`
CorrectAnswer Answer `pg:",unique:group_1,notnull" json:"correctAnswer" xml:"correctAnswer" gqlgen:"correctAnswer"`
Image string `json:"image" xml:"image" gqlgen:"image"`
AnswerA Answer `json:"answerA" xml:"answerA" gqlgen:"answerA"`
AnswerAImage string `pg:"answer_a_image" json:"answerAImage" xml:"answerAImage" gqlgen:"answerAImage"`
AnswerB Answer `json:"answerB" xml:"answerB" gqlgen:"answerB"`
AnswerBImage string `pg:"answer_b_image" json:"answerBImage" xml:"answerBImage" gqlgen:"answerBImage"`
AnswerC Answer `json:"answerC" xml:"answerC" gqlgen:"answerC"`
AnswerCImage string `pg:"answer_c_image" json:"answerCImage" xml:"answerCImage" gqlgen:"answerCImage"`
AnswerD Answer `json:"answerD" xml:"answerD" gqlgen:"answerD"`
AnswerDImage string `pg:"answer_d_image" json:"answerDImage" xml:"answerDImage" gqlgen:"answerDImage"`
QualificationID int `pg:",unique:group_1,on_delete:CASCADE" json:"qualificationID" xml:"qualificationID" gqlgen:"qualificationID"`
Qualification *Qualification `pg:"rel:has-one" json:"qualification" xml:"qualification" gqlgen:"qualification"`
CreatedAt time.Time `json:"createdAt,omitempty" pg:"default:now()" xml:"createdAt" gqlgen:"createdAt"`
}
func (q *Question) BeforeInsert(ctx context.Context) (context.Context, error) {
q.CreatedAt = time.Now()
return ctx, nil
}
type QuestionInput struct {
Content *string `json:"content" xml:"content" gqlgen:"content"`
From *string `json:"from" xml:"from" gqlgen:"from"`
Explanation *string `json:"explanation" xml:"explanation" gqlgen:"explanation"`
CorrectAnswer *Answer `json:"correctAnswer" xml:"correctAnswer" gqlgen:"correctAnswer"`
AnswerA *Answer `gqlgen:"answerA" json:"answerA" xml:"answerA"`
AnswerB *Answer `gqlgen:"answerB" json:"answerB" xml:"answerB"`
AnswerC *Answer `gqlgen:"answerC" json:"answerC" xml:"answerC"`
AnswerD *Answer `gqlgen:"answerD" json:"answerD" xml:"answerD"`
QualificationID *int `gqlgen:"qualificationID" json:"qualificationID" xml:"qualificationID"`
Image *graphql.Upload `json:"image" xml:"image" gqlgen:"image"`
AnswerAImage *graphql.Upload `json:"answerAImage" gqlgen:"answerAImage" xml:"answerAImage"`
AnswerAImagePath *string `json:"answerAImagePath" gqlgen:"answerAImagePath" xml:"answerAImagePath"`
AnswerBImage *graphql.Upload `json:"answerBImage" gqlgen:"answerBImage" xml:"answerBImage"`
AnswerBImagePath *string `json:"answerBImagePath" gqlgen:"answerBImagePath" xml:"answerBImagePath"`
AnswerCImage *graphql.Upload `json:"answerCImage" gqlgen:"answerCImage" xml:"answerCImage"`
AnswerCImagePath *string `json:"answerCImagePath" gqlgen:"answerCImagePath" xml:"answerCImagePath"`
AnswerDImage *graphql.Upload `json:"answerDImage" gqlgen:"answerDImage" xml:"answerDImage"`
AnswerDImagePath *string `json:"answerDImagePath" gqlgen:"answerDImagePath" xml:"answerDImagePath"`
}
func (input *QuestionInput) ToQuestion() *Question {
q := &Question{}
if input.Content != nil {
q.Content = *input.Content
}
if input.From != nil {
q.From = *input.From
}
if input.Explanation != nil {
q.Explanation = *input.Explanation
}
if input.CorrectAnswer != nil {
q.CorrectAnswer = *input.CorrectAnswer
}
if input.AnswerA != nil {
q.AnswerA = *input.AnswerA
}
if input.AnswerAImagePath != nil {
q.AnswerAImage = *input.AnswerAImagePath
}
if input.AnswerB != nil {
q.AnswerB = *input.AnswerB
}
if input.AnswerBImagePath != nil {
q.AnswerBImage = *input.AnswerBImagePath
}
if input.AnswerC != nil {
q.AnswerC = *input.AnswerC
}
if input.AnswerCImagePath != nil {
q.AnswerCImage = *input.AnswerCImagePath
}
if input.AnswerD != nil {
q.AnswerD = *input.AnswerD
}
if input.AnswerDImagePath != nil {
q.AnswerDImage = *input.AnswerDImagePath
}
if input.QualificationID != nil {
q.QualificationID = *input.QualificationID
}
return q
}
type QuestionFilter struct {
ID []int `gqlgen:"id" json:"id" xml:"id"`
IDNEQ []int `gqlgen:"idNEQ" json:"idNEQ" xml:"idNEQ"`
From []string `json:"from" xml:"from" gqlgen:"from"`
ContentMATCH string `json:"contentMATCH" xml:"contentMATCH" gqlgen:"contentMATCH"`
ContentIEQ string `json:"contentIEQ" xml:"contentIEQ" gqlgen:"contentIEQ"`
QualificationID []int `json:"qualificationID" xml:"qualificationID" gqlgen:"qualificationID"`
QualificationIDNEQ []int `json:"qualificationIDNEQ" xml:"qualificationIDNEQ" gqlgen:"qualificationIDNEQ"`
QualificationFilter *QualificationFilter `json:"qualificationFilter" xml:"qualificationFilter" gqlgen:"qualificationFilter"`
CreatedAt time.Time `gqlgen:"createdAt" json:"createdAt" xml:"createdAt"`
CreatedAtGT time.Time `gqlgen:"createdAtGT" json:"createdAtGT" xml:"createdAtGT"`
CreatedAtGTE time.Time `json:"createdAtGTE" xml:"createdAtGTE" gqlgen:"createdAtGTE"`
CreatedAtLT time.Time `gqlgen:"createdAtLT" json:"createdAtLT" xml:"createdAtLT"`
CreatedAtLTE time.Time `json:"createdAtLTE" xml:"createdAtLTE" gqlgen:"createdAtLTE"`
}
func (f *QuestionFilter) WhereWithAlias(q *orm.Query, alias string) (*orm.Query, error) {
if !isZero(f.ID) {
q = q.Where(sqlutils.BuildConditionArray(sqlutils.AddAliasToColumnName("id", alias)), pg.Array(f.ID))
}
if !isZero(f.IDNEQ) {
q = q.Where(sqlutils.BuildConditionNotInArray(sqlutils.AddAliasToColumnName("id", alias)), pg.Array(f.IDNEQ))
}
if !isZero(f.From) {
q = q.Where(sqlutils.BuildConditionArray(sqlutils.AddAliasToColumnName("from", alias)), pg.Array(f.From))
}
if !isZero(f.ContentMATCH) {
q = q.Where(sqlutils.BuildConditionMatch(sqlutils.AddAliasToColumnName("content", alias)), f.ContentMATCH)
}
if !isZero(f.ContentIEQ) {
q = q.Where(sqlutils.BuildConditionIEQ(sqlutils.AddAliasToColumnName("content", alias)), f.ContentIEQ)
}
if !isZero(f.QualificationID) {
q = q.Where(sqlutils.BuildConditionArray(sqlutils.AddAliasToColumnName("qualification_id", alias)), pg.Array(f.QualificationID))
}
if !isZero(f.QualificationIDNEQ) {
q = q.Where(sqlutils.BuildConditionNotInArray(sqlutils.AddAliasToColumnName("qualification_id", alias)), pg.Array(f.QualificationIDNEQ))
}
if f.QualificationFilter != nil {
q = q.Relation("Qualification._")
q, _ = f.QualificationFilter.WhereWithAlias(q, "qualification")
}
if !isZero(f.CreatedAt) {
q = q.Where(sqlutils.BuildConditionEquals(sqlutils.AddAliasToColumnName("created_at", alias)), f.CreatedAt)
}
if !isZero(f.CreatedAtGT) {
q = q.Where(sqlutils.BuildConditionGT(sqlutils.AddAliasToColumnName("created_at", alias)), f.CreatedAtGT)
}
if !isZero(f.CreatedAtGTE) {
q = q.Where(sqlutils.BuildConditionGTE(sqlutils.AddAliasToColumnName("created_at", alias)), f.CreatedAtGTE)
}
if !isZero(f.CreatedAtLT) {
q = q.Where(sqlutils.BuildConditionLT(sqlutils.AddAliasToColumnName("created_at", alias)), f.CreatedAtLT)
}
if !isZero(f.CreatedAtLTE) {
q = q.Where(sqlutils.BuildConditionLTE(sqlutils.AddAliasToColumnName("created_at", alias)), f.CreatedAtLTE)
}
return q, nil
}
func (f *QuestionFilter) Where(q *orm.Query) (*orm.Query, error) {
return f.WhereWithAlias(q, "question")
}

View File

@ -4,8 +4,11 @@ import (
"context"
"time"
sqlutils "github.com/zdam-egzamin-zawodowy/backend/pkg/utils/sql"
"github.com/go-pg/pg/v10"
"github.com/go-pg/pg/v10/orm"
"github.com/gosimple/slug"
"github.com/pkg/errors"
"golang.org/x/crypto/bcrypt"
)
@ -35,6 +38,7 @@ func (u *User) BeforeInsert(ctx context.Context) (context.Context, error) {
return ctx, err
}
u.Password = string(hashedPassword)
u.Slug = slug.Make(u.DisplayName)
return ctx, nil
}
@ -51,21 +55,6 @@ func (u *User) BeforeUpdate(ctx context.Context) (context.Context, error) {
return ctx, nil
}
func (u *User) MergeInput(input *UserInput) {
if input.DisplayName != "" {
u.DisplayName = input.DisplayName
}
if input.Password != "" {
u.Password = input.Password
}
if input.Role.IsValid() {
u.Role = input.Role
}
if input.Activated != nil {
u.Activated = input.Activated
}
}
func (u *User) CompareHashAndPassword(password string) error {
if password == u.Password {
return nil
@ -77,21 +66,30 @@ func (u *User) CompareHashAndPassword(password string) error {
}
type UserInput struct {
DisplayName string `json:"displayName" xml:"displayName" gqlgen:"displayName"`
Password string `json:"password" xml:"password" gqlgen:"password"`
Email string `json:"email" xml:"email" gqlgen:"email"`
Role Role `json:"role" xml:"role" gqlgen:"role"`
Activated *bool `json:"activated" xml:"activated" gqlgen:"activated"`
DisplayName *string `json:"displayName" xml:"displayName" gqlgen:"displayName"`
Password *string `json:"password" xml:"password" gqlgen:"password"`
Email *string `json:"email" xml:"email" gqlgen:"email"`
Role *Role `json:"role" xml:"role" gqlgen:"role"`
Activated *bool `json:"activated" xml:"activated" gqlgen:"activated"`
}
func (input *UserInput) ToUser() *User {
return &User{
DisplayName: input.DisplayName,
Password: input.Password,
Email: input.Email,
Role: input.Role,
Activated: input.Activated,
u := &User{
Activated: input.Activated,
}
if input.DisplayName != nil {
u.DisplayName = *input.DisplayName
}
if input.Password != nil {
u.Password = *input.Password
}
if input.Email != nil {
u.Email = *input.Email
}
if input.Role != nil {
u.Role = *input.Role
}
return u
}
type UserFilter struct {
@ -125,63 +123,63 @@ type UserFilter struct {
func (f *UserFilter) WhereWithAlias(q *orm.Query, alias string) (*orm.Query, error) {
if !isZero(f.ID) {
q = q.Where(buildConditionArray(addAliasToColumnName("id", alias)), pg.Array(f.ID))
q = q.Where(sqlutils.BuildConditionArray(sqlutils.AddAliasToColumnName("id", alias)), pg.Array(f.ID))
}
if !isZero(f.IDNEQ) {
q = q.Where(buildConditionNotInArray(addAliasToColumnName("id", alias)), pg.Array(f.IDNEQ))
q = q.Where(sqlutils.BuildConditionNotInArray(sqlutils.AddAliasToColumnName("id", alias)), pg.Array(f.IDNEQ))
}
if !isZero(f.Slug) {
q = q.Where(buildConditionArray(addAliasToColumnName("tag", alias)), pg.Array(f.Slug))
q = q.Where(sqlutils.BuildConditionArray(sqlutils.AddAliasToColumnName("slug", alias)), pg.Array(f.Slug))
}
if !isZero(f.SlugNEQ) {
q = q.Where(buildConditionNotInArray(addAliasToColumnName("tag", alias)), pg.Array(f.SlugNEQ))
q = q.Where(sqlutils.BuildConditionNotInArray(sqlutils.AddAliasToColumnName("slug", alias)), pg.Array(f.SlugNEQ))
}
if !isZero(f.Activated) {
q = q.Where(buildConditionEquals(addAliasToColumnName("activated", alias)), f.Activated)
q = q.Where(sqlutils.BuildConditionEquals(sqlutils.AddAliasToColumnName("activated", alias)), f.Activated)
}
if !isZero(f.DisplayName) {
q = q.Where(buildConditionArray(addAliasToColumnName("name", alias)), pg.Array(f.DisplayName))
q = q.Where(sqlutils.BuildConditionArray(sqlutils.AddAliasToColumnName("display_name", alias)), pg.Array(f.DisplayName))
}
if !isZero(f.DisplayNameNEQ) {
q = q.Where(buildConditionNotInArray(addAliasToColumnName("name", alias)), pg.Array(f.DisplayNameNEQ))
q = q.Where(sqlutils.BuildConditionNotInArray(sqlutils.AddAliasToColumnName("display_name", alias)), pg.Array(f.DisplayNameNEQ))
}
if !isZero(f.DisplayNameMATCH) {
q = q.Where(buildConditionMatch(addAliasToColumnName("name", alias)), f.DisplayNameMATCH)
q = q.Where(sqlutils.BuildConditionMatch(sqlutils.AddAliasToColumnName("display_name", alias)), f.DisplayNameMATCH)
}
if !isZero(f.DisplayNameIEQ) {
q = q.Where(buildConditionIEQ(addAliasToColumnName("name", alias)), f.DisplayNameIEQ)
q = q.Where(sqlutils.BuildConditionIEQ(sqlutils.AddAliasToColumnName("display_name", alias)), f.DisplayNameIEQ)
}
if !isZero(f.Email) {
q = q.Where(buildConditionArray(addAliasToColumnName("name", alias)), pg.Array(f.Email))
q = q.Where(sqlutils.BuildConditionArray(sqlutils.AddAliasToColumnName("email", alias)), pg.Array(f.Email))
}
if !isZero(f.EmailNEQ) {
q = q.Where(buildConditionNotInArray(addAliasToColumnName("name", alias)), pg.Array(f.EmailNEQ))
q = q.Where(sqlutils.BuildConditionNotInArray(sqlutils.AddAliasToColumnName("email", alias)), pg.Array(f.EmailNEQ))
}
if !isZero(f.EmailMATCH) {
q = q.Where(buildConditionMatch(addAliasToColumnName("name", alias)), f.EmailMATCH)
q = q.Where(sqlutils.BuildConditionMatch(sqlutils.AddAliasToColumnName("email", alias)), f.EmailMATCH)
}
if !isZero(f.EmailIEQ) {
q = q.Where(buildConditionIEQ(addAliasToColumnName("name", alias)), f.EmailIEQ)
q = q.Where(sqlutils.BuildConditionIEQ(sqlutils.AddAliasToColumnName("email", alias)), f.EmailIEQ)
}
if !isZero(f.CreatedAt) {
q = q.Where(buildConditionEquals(addAliasToColumnName("created_at", alias)), f.CreatedAt)
q = q.Where(sqlutils.BuildConditionEquals(sqlutils.AddAliasToColumnName("created_at", alias)), f.CreatedAt)
}
if !isZero(f.CreatedAtGT) {
q = q.Where(buildConditionGT(addAliasToColumnName("created_at", alias)), f.CreatedAtGT)
q = q.Where(sqlutils.BuildConditionGT(sqlutils.AddAliasToColumnName("created_at", alias)), f.CreatedAtGT)
}
if !isZero(f.CreatedAtGTE) {
q = q.Where(buildConditionGTE(addAliasToColumnName("created_at", alias)), f.CreatedAtGTE)
q = q.Where(sqlutils.BuildConditionGTE(sqlutils.AddAliasToColumnName("created_at", alias)), f.CreatedAtGTE)
}
if !isZero(f.CreatedAtLT) {
q = q.Where(buildConditionLT(addAliasToColumnName("created_at", alias)), f.CreatedAtLT)
q = q.Where(sqlutils.BuildConditionLT(sqlutils.AddAliasToColumnName("created_at", alias)), f.CreatedAtLT)
}
if !isZero(f.CreatedAtLTE) {
q = q.Where(buildConditionLTE(addAliasToColumnName("created_at", alias)), f.CreatedAtLTE)
q = q.Where(sqlutils.BuildConditionLTE(sqlutils.AddAliasToColumnName("created_at", alias)), f.CreatedAtLTE)
}
return q, nil

63
pkg/utils/sql/sql.go Normal file
View File

@ -0,0 +1,63 @@
package sqlutils
import (
"fmt"
"strings"
)
func AddAliasToColumnName(column, prefix string) string {
if prefix != "" && !strings.HasPrefix(column, prefix+".") {
column = WrapStringInDoubleQuotes(prefix) + "." + WrapStringInDoubleQuotes(column)
} else {
column = WrapStringInDoubleQuotes(column)
}
return column
}
func WrapStringInDoubleQuotes(str string) string {
return `"` + str + `"`
}
func BuildConditionEquals(column string) string {
return column + " = ?"
}
func BuildConditionLT(column string) string {
return column + " < ?"
}
func BuildConditionLTE(column string) string {
return column + " <= ?"
}
func BuildConditionGT(column string) string {
return column + " > ?"
}
func BuildConditionGTE(column string) string {
return column + " >= ?"
}
func BuildConditionMatch(column string) string {
return column + " LIKE ?"
}
func BuildConditionIEQ(column string) string {
return column + " ILIKE ?"
}
func BuildConditionArray(column string) string {
return column + " = ANY(?)"
}
func BuildConditionNotInArray(column string) string {
return "NOT (" + BuildConditionArray(column) + ")"
}
func BuildCountColumnExpr(column, alias string) string {
base := fmt.Sprintf("count(%s)", column)
if alias != "" {
return base + " as " + alias
}
return base
}