Compare commits
	
		
			698 Commits
		
	
	
		
			6fe30231d8
			...
			create-cat
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					adc6e0a2cf | ||
| 
						 | 
					4d04529ae2 | ||
| 
						 | 
					2559d2dbdb | ||
| 
						 | 
					ac39ec07a4 | ||
| 
						 | 
					5792aed089 | ||
| 
						 | 
					69cb27fc51 | ||
| 
						 | 
					907be875c8 | ||
| 
						 | 
					cfe8599ed0 | ||
| 
						 | 
					98e1fbb071 | ||
| 
						 | 
					5d57045efb | ||
| 
						 | 
					5456e0223a | ||
| a0e6dc0f1b | |||
| 88283a8817 | |||
| 31a4135f2e | |||
| 94c2465109 | |||
| 6a5bf419e2 | |||
| b55744aad7 | |||
| 5658f31457 | |||
| fc15d8b56e | |||
| 403544e99f | |||
| 99979a35b0 | |||
| 49cf6a65da | |||
| 2b15231ed1 | |||
| bae9f030b2 | |||
| a06d0df142 | |||
| 0567619408 | |||
| 0c375884aa | |||
| ca964f1c5f | |||
| b2542fa6d1 | |||
| 77de2a833e | |||
| 10a870a300 | |||
| a241298170 | |||
| 9248c12aab | |||
| 8817e665e9 | |||
| 0b36048f47 | |||
| 0c2438373d | |||
| 2f636b5f9c | |||
| 4ef0b759ef | |||
| 08fbacc7e6 | |||
| 1c003486ca | |||
| 71be1ac49f | |||
| d258ab63e4 | |||
| 9da4a6f03e | |||
| 1a11555075 | |||
| b573553424 | |||
| dd0f620b7a | |||
| 42b732eedc | |||
| f437491823 | |||
| dc15ae307b | |||
| f8a8a6fc0c | |||
| a031dd5bb1 | |||
| d3ca3c87bf | |||
| 77c1a6dd18 | |||
| a7e1826f52 | |||
| 94b5c4bbd3 | |||
| fdb64b2000 | |||
| 2ca3328f0f | |||
| bd026732c8 | |||
| 6032f6f526 | |||
| e1c6bd22d5 | |||
| 91ed57f83d | |||
| 0817f18e33 | |||
| 704a520993 | |||
| a48509e041 | |||
| b812b19b34 | |||
| 0667e5a779 | |||
| f47ede2060 | |||
| 91ac05b575 | |||
| c30b33a070 | |||
| 4fa227c452 | |||
| cfb1dbe276 | |||
| 8f99499c2f | |||
| d22816dfd1 | |||
| 75a1839456 | |||
| 9fd70cd773 | |||
| 3b465f17cf | |||
| f56d095016 | |||
| 741589dc71 | |||
| 44254ed4d0 | |||
| 777520e9df | |||
| 07c0c56d11 | |||
| 43a4647d74 | |||
| c595f016b8 | |||
| 6702a775fb | |||
| e4df2f0de5 | |||
| ff06693f60 | |||
| 5c5429ab05 | |||
| 65424a2587 | |||
| 4563fcbbaf | |||
| df7b691bdd | |||
| f5274f69fc | |||
| c50fc63303 | |||
| 88e1dbdfde | |||
| 0e84cdfa5f | |||
| d29405bef3 | |||
| 46e665efc5 | |||
| f3eb19ef91 | |||
| 2ca05b5d48 | |||
| ed2eb53f93 | |||
| 8bf4fcfd42 | |||
| 38222c0777 | |||
| f43feb66be | |||
| 49be1d5be6 | |||
| 8ec69e4b8f | |||
| 6b3026dc8e | |||
| 9b5119d3dd | |||
| 08f48a63ad | |||
| c4fc80e47d | |||
| 23bd12147c | |||
| 3ca7bfeade | |||
| 249aa534c8 | |||
| 76ee88a1c6 | |||
| bb664494f6 | |||
| 4f681d6d89 | |||
| 11df0fbff1 | |||
| a2280e50ec | |||
| ed321d3895 | |||
| 8fe91293e1 | |||
| 35690681cf | |||
| 54e591bc5e | |||
| 01c407d4f1 | |||
| cef62574bb | |||
| ae529665a3 | |||
| 2eba947d9d | |||
| 4d70f50683 | |||
| 9b67e700be | |||
| cce9f29f17 | |||
| eb2b31e622 | |||
| 967f1c71e5 | |||
| 585951d5e2 | |||
| e7af03b702 | |||
| a1ec7e9997 | |||
| 880ed731f8 | |||
| a46ddded67 | |||
| 56485b8deb | |||
| f67f6ff0d8 | |||
| 150a7d562b | |||
| 49d96be1e3 | |||
| 8df7968175 | |||
| bd99f58ab4 | |||
| 9471c5b63b | |||
| 60d6967728 | |||
| 1913d9eaf0 | |||
| 8954cffb7a | |||
| 95eb302d26 | |||
| 93679c2932 | |||
| cb8ce79107 | |||
| 80c0f0a231 | |||
| d73eeb1b40 | |||
| ce466e0031 | |||
| 684efffbdf | |||
| cf39db52fb | |||
| f0993fd9c3 | |||
| 5f6bea4ee2 | |||
| 4332a1537b | |||
| 2feefea737 | |||
| 2d9c380cf4 | |||
| 4a66d9fdfc | |||
| 967ea784dc | |||
| 23b7a4dbdd | |||
| 4798cb95b0 | |||
| 8eabf3d1c8 | |||
| f0084b683e | |||
| 84c95d0c4e | |||
| 6576c994c9 | |||
| a552983ac4 | |||
| f99efe0e8e | |||
| e1b6056d77 | |||
| 94329ac331 | |||
| bfa67578cf | |||
| eae196aa69 | |||
| d2dd7d5280 | |||
| f707197f42 | |||
| 66322ebd86 | |||
| 3ea90a5ebe | |||
| d717ef1b4d | |||
| 61a534610f | |||
| d8d713f841 | |||
| 7ac06012ec | |||
| 9af412a8bd | |||
| 3b61028576 | |||
| 87b78e7b67 | |||
| 6a71d9643c | |||
| 450324d29e | |||
| 6f4e286b7a | |||
| 324e13f5c5 | |||
| 0201b368d4 | |||
| 984a2aa296 | |||
| d1a0296a58 | |||
| d9efa9f4a1 | |||
| b176ce26ba | |||
| 97de326527 | |||
| a62ab543b0 | |||
| 244333adbc | |||
| 67ef4745a0 | |||
| 3856e8a8a5 | |||
| db96fddde2 | |||
| ecb801b2f2 | |||
| fd6b77f154 | |||
| 442e87234c | |||
| caf39fe5ea | |||
| 0dde94f855 | |||
| 34bbdf48b7 | |||
| 1e495a5e47 | |||
| fc29b1409d | |||
| 8ecfd6b87a | |||
| d89e702669 | |||
| 3795150508 | |||
| 67c013799d | |||
| 0038db90ac | |||
| 9759a7cc1e | |||
| 81c31a3d5f | |||
| 38e21786a7 | |||
| 971c3d3be5 | |||
| 946f14c1cc | |||
| 9ce0da0182 | |||
| 4c93e4635d | |||
| f3a50c790b | |||
| 0c5f68ed80 | |||
| 7fdd8bd935 | |||
| d4287f8aac | |||
| 6712af10d9 | |||
| 70edb382e1 | |||
| 390a042441 | |||
| e8028dae34 | |||
| fc249adc9e | |||
| c186a14644 | |||
| 8a27303670 | |||
| 44e9bb6ec0 | |||
| 42d431ba8b | |||
| 3727061065 | |||
| c7a8adb3ab | |||
| 29f534bf10 | |||
| 15381c84f6 | |||
| a0cabbf4f7 | |||
| f26ee8f472 | |||
| 4fb3c2a335 | |||
| 8899ff5772 | |||
| 347a0c9e50 | |||
| 66b8e1f69f | |||
| 5d1b49c896 | |||
| 42dc51fe9a | |||
| 1ca95f8768 | |||
| a73f7c2934 | |||
| 489aa88c4b | |||
| 7b5b16c1b2 | |||
| 29cfeb6fa6 | |||
| 42baafd273 | |||
| 1e79f193be | |||
| f0ec7fb30d | |||
| 034f4f2a90 | |||
| 51ece59866 | |||
| bbfda6f402 | |||
| 2b3afbf448 | |||
| a53c3d23a4 | |||
| c899c21256 | |||
| cccc948048 | |||
| e8a0670a83 | |||
| 9638676b8f | |||
| 08bda8d14f | |||
| d0ade0f2f1 | |||
| 466239ce11 | |||
| d52e5c63d4 | |||
| 3dcb362372 | |||
| 67c9b53e91 | |||
| 7c08ddacb7 | |||
| ecbb85aeaa | |||
| 3696bbde43 | |||
| 09a227d08d | |||
| dae6185857 | |||
| 6dd8a3791f | |||
| 18149eef8b | |||
| f0f97a2e77 | |||
| 71b2f8a9a3 | |||
| 8f666a0f26 | |||
| 2b9c76960e | |||
| 7fd057f9f6 | |||
| a9be9367a9 | |||
| bc75757ac7 | |||
| a3e12df2e2 | |||
| 024c5e0a1c | |||
| 27372199f7 | |||
| b3b878854e | |||
| bbb12a788d | |||
| 7dfbef60a4 | |||
| d8a96535dc | |||
| ce26e76e8f | |||
| 6b3ac199fc | |||
| 4c6d21c2b4 | |||
| faef975f1a | |||
| bd686e0c00 | |||
| 4844889e0b | |||
| 2775578713 | |||
| 27dd6e923c | |||
| 2cf6b815bf | |||
| 81aacf339e | |||
| 16bcf516f6 | |||
| 52503a4c92 | |||
| b4321395d9 | |||
| d7058a49b0 | |||
| eb9fc722aa | |||
| 511081298e | |||
| 422a74704b | |||
| c4995bcbaf | |||
| 79fd95e152 | |||
| af8fda178d | |||
| 71f4d2384b | |||
| eb52bd5def | |||
| adcb64f4ad | |||
| a73c5ce04b | |||
| 52bb343402 | |||
| 27ce8d250f | |||
| 408207df92 | |||
| 98890f10eb | |||
| 5621d63436 | |||
| 05099e469f | |||
| ae9e9d34c9 | |||
| 32439e3e87 | |||
| 4ed15b740b | |||
| 5f161b2163 | |||
| 10ea73663f | |||
| 07804e4241 | |||
| 2f4f8a7568 | |||
| 13d0194632 | |||
| c864666eb6 | |||
| 464931babe | |||
| 480a95e096 | |||
| 2d37ec147c | |||
| 75b48be20d | |||
| 306edbf817 | |||
| be3829baf8 | |||
| a452482381 | |||
| 0f6990407d | |||
| 97be5abc8c | |||
| 1e80ba6ca8 | |||
| 1331304639 | |||
| 7435ac3667 | |||
| 55dffbbe89 | |||
| 212c81ab81 | |||
| 5b5b8215c3 | |||
| 79c0fceafe | |||
| 1ea3590fd6 | |||
| 5bb2c9c8b8 | |||
| f9e512c593 | |||
| 4f72351ee9 | |||
| 9ed4df7053 | |||
| 78389e4beb | |||
| 8ac3c22826 | |||
| ab07d3472d | |||
| 466df523ab | |||
| f51807e459 | |||
| 03d1d1e520 | |||
| d09f5be69b | |||
| b5a03b40db | |||
| 966c0ce0eb | |||
| 635f4de402 | |||
| ddf51b5922 | |||
| bbbeff92e8 | |||
| 5ccec61465 | |||
| 696fbee7cc | |||
| 7c694fb32c | |||
| 5f746f5889 | |||
| 24e5b18ded | |||
| 253ecd1720 | |||
| f445f19233 | |||
| ea6d198bff | |||
| 28c20aacd3 | |||
| d89a8f4e2e | |||
| dae9abeeea | |||
| 510c91205d | |||
| f93888cbbc | |||
| 674bef667b | |||
| fffc91269e | |||
| c3175b9be6 | |||
| 1d81aa2fb3 | |||
| e5cf439231 | |||
| cfd2388de0 | |||
| 0dfa698ada | |||
| b4aec52d4f | |||
| b5e3e7bea0 | |||
| e98e0d4779 | |||
| 6686904539 | |||
| 0478d82c1f | |||
| 34b6e450de | |||
| bc65249c03 | |||
| e0dc7800af | |||
| a7cd3512bb | |||
| ece610419f | |||
| 27188e2e27 | |||
| 4c7c61e820 | |||
| 2adb70fa01 | |||
| eeb2d425e5 | |||
| 484b1062e1 | |||
| a4ca21bb37 | |||
| ffabf1bca9 | |||
| e9d4ed1b3e | |||
| 4085868cd7 | |||
| 4019656e4d | |||
| 16b7049438 | |||
| 73e3b49b40 | |||
| 953d348bed | |||
| a6eb2a2253 | |||
| 578e7d071c | |||
| 4688d2d94d | |||
| cfda327a5d | |||
| 1bd38bb367 | |||
| 19d2ddbd65 | |||
| 3cb39d978a | |||
| e08a21b750 | |||
| 6929c940c4 | |||
| 2423bdd3ee | |||
| 22ec0433bf | |||
| c03d16878a | |||
| 545f223a97 | |||
| 260ac2d4ad | |||
| d815e8c3cd | |||
| 91b8cc06b2 | |||
| 75a6ce1577 | |||
| a0d89ee93a | |||
| e39d1dc6e3 | |||
| 1dcd0d2f6d | |||
| 62085cb694 | |||
| ca51ac5e27 | |||
| 36b2f12183 | |||
| 96b514ccf8 | |||
| b52ed21d1d | |||
| 787165b7f1 | |||
| 8035403416 | |||
| 1a1971246d | |||
| 9b92e2b551 | |||
| c5be03ab6b | |||
| 77afe700ae | |||
| f0961ccc3c | |||
| 1d2ae0e394 | |||
| b0175542f1 | |||
| 558fddc139 | |||
| 02ba80a555 | |||
| 1a19d3a197 | |||
| 052a2628ab | |||
| 46b9b82f30 | |||
| c5a0f49719 | |||
| 649f937254 | |||
| 0f2501dcbd | |||
| daadfd45bc | |||
| 72b5bdde4f | |||
| 737d5fb101 | |||
| bb4548c50d | |||
| 7b20bc9822 | |||
| 2f45c415e0 | |||
| 74a53954de | |||
| 7a0c4a17a2 | |||
| 71c54c9373 | |||
| 584e7ef393 | |||
| aaf16dbe92 | |||
| d8e0f5a160 | |||
| 38dfa540b4 | |||
| 835a15ec08 | |||
| 4bbbc0be13 | |||
| 8f6974e151 | |||
| 368ac7f15d | |||
| 0d20d9bfb8 | |||
| 4276c51268 | |||
| 57930d0e5d | |||
| fe018e1953 | |||
| e7a085273b | |||
| 5bbd096fc8 | |||
| 452d63c329 | |||
| d28c894d21 | |||
| 1a79177422 | |||
| 0aa877d7d4 | |||
| 87a70ee5fa | |||
| 0a030eaee1 | |||
| d11c0036b5 | |||
| ca93e9cd55 | |||
| a061ffd350 | |||
| 5633c029ac | |||
| a97d050ead | |||
| 958929fd16 | |||
| a61d80ee1f | |||
| 41c5095b8b | |||
| c074dfe865 | |||
| fa8a2854f2 | |||
| 15bb73de30 | |||
| e506510fde | |||
| 11ac8758da | |||
| 3db5e1e72c | |||
| 4e2a783b2e | |||
| bb83563bc6 | |||
| 0a21c59eff | |||
| 3308b58524 | |||
| 941b642f39 | |||
| 6a77c71df4 | |||
| bf20914c1c | |||
| 7874ef69a2 | |||
| 2e719b590e | |||
| 95d8e4fccc | |||
| 7cf106eb85 | |||
| 148fc18cd8 | |||
| 47095ae6ec | |||
| 200fa1835a | |||
| cd0b370b50 | |||
| 1af69b047d | |||
| f6cb6d4163 | |||
| 45389e01be | |||
| 5868c3310e | |||
| 1dc818f51f | |||
| 0e342f2bcf | |||
| 21dcd7837b | |||
| c693625e34 | |||
| 8b0e368d58 | |||
| 0c094d6f6b | |||
| 9b8ae7a44d | |||
| 08330ce33c | |||
| 2d0737a10c | |||
| 2137460187 | |||
| 6ab8a96888 | |||
| c3db535e10 | |||
| 5d292b2a31 | |||
| e934d407c2 | |||
| 2c71c521f9 | |||
| 3bd5845068 | |||
| c3a1564c4e | |||
| 922041856f | |||
| 6cafaec422 | |||
| 499d78a781 | |||
| 227c2a7564 | |||
| 07cd7a7c2b | |||
| bd1e1cbfb8 | |||
| 09a242f6f6 | |||
| 4eeecc2bd9 | |||
| 378d764220 | |||
| 2559e40ebd | |||
| 0579ec5106 | |||
| 33bdfaddc4 | |||
| eb195dfd29 | |||
| d2b414f328 | |||
| e873795562 | |||
| 33c83c0a69 | |||
| 2646c5d3b7 | |||
| 3ef5836607 | |||
| b5c657978c | |||
| 0136e3b978 | |||
| 427e7e5359 | |||
| 139b6ec636 | |||
| 9dad1dabbd | |||
| 95fcb9a586 | |||
| 3c1d83d8a2 | |||
| f09a2a4ca7 | |||
| 487aa89f18 | |||
| 5763409aa8 | |||
| 5ca09d2825 | |||
| e18e68c964 | |||
| 065159a817 | |||
| 68c2d3ff28 | |||
| 0f2db4985f | |||
| f532ffc0c1 | |||
| 4edd1a8bf1 | |||
| a7890bce16 | |||
| ddaf647d87 | |||
| 80b5a7abfe | |||
| 2204188600 | |||
| 3d1d1308ac | |||
| d5904a7c4a | |||
| d9c03e231e | |||
| dba1e8c276 | |||
| ebc2286116 | |||
| d647650142 | |||
| 057c576831 | |||
| 056071c6e6 | |||
| 0305aa86c1 | |||
| d9aed7603e | |||
| e18ef79839 | |||
| b93e44930a | |||
| c8e9a8b375 | |||
| 1d0fe60ea4 | |||
| 3f7f646120 | |||
| dfa8f369f0 | |||
| d825379a01 | |||
| f7dfc7b455 | |||
| 2203542d90 | |||
| 72f9a6413f | |||
| bf25922fc4 | |||
| 46d727c650 | |||
| b6628dd8cb | |||
| 132ae75755 | |||
| 2b885ca189 | |||
| 37a842b395 | |||
| 9353d82648 | |||
| b350fe7d74 | |||
| 7cba471de7 | |||
| 27508af3a7 | |||
| e0981630ab | |||
| a7178e39c9 | |||
| 29f0c51e35 | |||
| 9c0126b14c | |||
| 34b9c14419 | |||
| 8e2a62929e | |||
| 95b1ac5943 | |||
| 1be3b6930d | |||
| e5fe3d06c4 | |||
| 136f15badc | |||
| f091ce8945 | |||
| 24370c9d32 | |||
| e8dbb54086 | |||
| 6f7aa28d22 | |||
| e85cf0ea55 | |||
| 58683a33fb | |||
| a45d02f9e0 | |||
| 0334b35041 | |||
| b52c4cb787 | |||
| 0db6d6c67a | |||
| 0b1f673c05 | |||
| 0e438e0244 | |||
| 430c4d52da | |||
| d5a414266b | |||
| 47cbaf9660 | |||
| 7776ba90f0 | |||
| 80c00171c8 | |||
| 9cc06bbe93 | |||
| 829881bd2a | |||
| 0ad97ce4ff | |||
| 1aa6d8d58f | |||
| db8553995c | |||
| de6054359a | |||
| 9e3dde8076 | |||
| d6165c6ede | |||
| 404bd6625f | |||
| 463a52fb19 | |||
| ffed94f586 | |||
| 74c4c7cb02 | |||
| 6dcf7da861 | |||
| 4f2b3b7b22 | |||
| 3b130b8621 | |||
| a4f94cd9d9 | |||
| c2bbaebfd2 | |||
| 458f4f0e8f | |||
| e184ef933f | |||
| a2cc19d310 | |||
| 626e0ada40 | |||
| 339c230756 | |||
| 59ae9f978a | |||
| af3252277c | |||
| 33990bdccf | |||
| 5fb7542176 | |||
| c2bcd815d5 | |||
| be821bc90a | |||
| 746680a4d7 | |||
| fa4c9bcaba | |||
| 3de0447eba | |||
| d59b9bdbec | |||
| 93b1712fb5 | |||
| b2b934cfb3 | |||
| 1d39fc7976 | |||
| dd160cab17 | |||
| 0e3ece9830 | |||
| 27298a9860 | |||
| e26bb257cc | |||
| 0bd63636bb | |||
| 6086447126 | |||
| aae8bbb44e | |||
| f33f0880c4 | |||
| c069a33890 | |||
| 8b4ebadec2 | |||
| 2b556222ed | |||
| 3da2e0f2f8 | |||
| 4f72751ed6 | |||
| c2326060b3 | |||
| dad3a149d8 | |||
| 1bdd66a45a | |||
| b0ba63118e | |||
| 18d11358b2 | |||
| 4af82805ff | |||
| 15ab8a3dac | |||
| 99cf27b649 | |||
| bc78cab715 | |||
| ddab5998bc | |||
| 929db00a47 | |||
| 8a6322bc7e | |||
| 5601c965dc | |||
| 2fba4381df | |||
| bdf942a17b | |||
| d354a680f9 | |||
| 6899e4c88e | |||
| e0f822dbcc | |||
| d0e52ddfa6 | |||
| 2112192670 | |||
| 13063b47ba | |||
| 3cda536854 | |||
| 6d49a549a0 | |||
| aa33c148cb | |||
| 663f247080 | |||
| e094c2a740 | |||
| 7fba9e7e4c | |||
| cc58c0d012 | |||
| e138c264ea | |||
| a8edeaafa1 | |||
| 92725c0f26 | |||
| 337d588c3c | 
@@ -1,5 +1,5 @@
 | 
				
			|||||||
build/
 | 
					build/
 | 
				
			||||||
.git/
 | 
					docker/
 | 
				
			||||||
docker-compose.yml
 | 
					docker-compose.yml
 | 
				
			||||||
README.md
 | 
					README.md
 | 
				
			||||||
Earthfile
 | 
					Earthfile
 | 
				
			||||||
@@ -8,3 +8,4 @@ config.example.json
 | 
				
			|||||||
.vscode/
 | 
					.vscode/
 | 
				
			||||||
budgeteer
 | 
					budgeteer
 | 
				
			||||||
budgeteer.exe
 | 
					budgeteer.exe
 | 
				
			||||||
 | 
					**/node_modules/
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										54
									
								
								.drone.yml
									
									
									
									
									
								
							
							
						
						
									
										54
									
								
								.drone.yml
									
									
									
									
									
								
							@@ -4,10 +4,29 @@ type: docker
 | 
				
			|||||||
name: budgeteer
 | 
					name: budgeteer
 | 
				
			||||||
 | 
					
 | 
				
			||||||
steps:
 | 
					steps:
 | 
				
			||||||
- name: Taskfile.dev
 | 
					- name: submodules
 | 
				
			||||||
 | 
					  image: alpine/git
 | 
				
			||||||
 | 
					  commands:
 | 
				
			||||||
 | 
					  - git submodule update --recursive --init
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- name: Taskfile.dev PR
 | 
				
			||||||
  image: hub.javil.eu/budgeteer:dev
 | 
					  image: hub.javil.eu/budgeteer:dev
 | 
				
			||||||
  commands:
 | 
					  commands:
 | 
				
			||||||
    - task build
 | 
					    - task ci
 | 
				
			||||||
 | 
					  when:
 | 
				
			||||||
 | 
					    event:
 | 
				
			||||||
 | 
					    - pull_request
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- name: Taskfile.dev
 | 
				
			||||||
 | 
					  image: hub.javil.eu/budgeteer:dev
 | 
				
			||||||
 | 
					  pull: always
 | 
				
			||||||
 | 
					  commands:
 | 
				
			||||||
 | 
					    - task ci
 | 
				
			||||||
 | 
					  when:
 | 
				
			||||||
 | 
					    branch:
 | 
				
			||||||
 | 
					    - master
 | 
				
			||||||
 | 
					    event:
 | 
				
			||||||
 | 
					    - push
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- name: docker  
 | 
					- name: docker  
 | 
				
			||||||
  image: plugins/docker
 | 
					  image: plugins/docker
 | 
				
			||||||
@@ -19,9 +38,38 @@ steps:
 | 
				
			|||||||
      from_secret: docker_password
 | 
					      from_secret: docker_password
 | 
				
			||||||
    repo: hub.javil.eu/budgeteer
 | 
					    repo: hub.javil.eu/budgeteer
 | 
				
			||||||
    context: build
 | 
					    context: build
 | 
				
			||||||
    dockerfile: build/Dockerfile
 | 
					    dockerfile: docker/Dockerfile
 | 
				
			||||||
    tags: 
 | 
					    tags: 
 | 
				
			||||||
      - latest
 | 
					      - latest
 | 
				
			||||||
 | 
					  when:
 | 
				
			||||||
 | 
					    branch:
 | 
				
			||||||
 | 
					    - master
 | 
				
			||||||
 | 
					    event:
 | 
				
			||||||
 | 
					    - push
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- name: docker tag
 | 
				
			||||||
 | 
					  image: plugins/docker
 | 
				
			||||||
 | 
					  settings:
 | 
				
			||||||
 | 
					    registry: hub.javil.eu
 | 
				
			||||||
 | 
					    username: 
 | 
				
			||||||
 | 
					      from_secret: docker_user
 | 
				
			||||||
 | 
					    password:
 | 
				
			||||||
 | 
					      from_secret: docker_password
 | 
				
			||||||
 | 
					    repo: hub.javil.eu/budgeteer
 | 
				
			||||||
 | 
					    context: build
 | 
				
			||||||
 | 
					    dockerfile: docker/Dockerfile
 | 
				
			||||||
 | 
					    auto_tag: true
 | 
				
			||||||
 | 
					  when:
 | 
				
			||||||
 | 
					    event:
 | 
				
			||||||
 | 
					    - tag
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					services:
 | 
				
			||||||
 | 
					- name: db
 | 
				
			||||||
 | 
					  image: postgres:alpine
 | 
				
			||||||
 | 
					  environment:
 | 
				
			||||||
 | 
					    POSTGRES_USER: budgeteer
 | 
				
			||||||
 | 
					    POSTGRES_PASSWORD: budgeteer
 | 
				
			||||||
 | 
					    POSTGRES_DB: budgeteer_test
 | 
				
			||||||
 | 
					
 | 
				
			||||||
image_pull_secrets:
 | 
					image_pull_secrets:
 | 
				
			||||||
- hub.javil.eu 
 | 
					- hub.javil.eu 
 | 
				
			||||||
							
								
								
									
										10
									
								
								.earthignore
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								.earthignore
									
									
									
									
									
								
							@@ -1,10 +0,0 @@
 | 
				
			|||||||
build/
 | 
					 | 
				
			||||||
.git/
 | 
					 | 
				
			||||||
docker-compose.yml
 | 
					 | 
				
			||||||
README.md
 | 
					 | 
				
			||||||
Earthfile
 | 
					 | 
				
			||||||
config.example.json
 | 
					 | 
				
			||||||
.gitignore
 | 
					 | 
				
			||||||
.vscode/
 | 
					 | 
				
			||||||
budgeteer
 | 
					 | 
				
			||||||
budgeteer.exe
 | 
					 | 
				
			||||||
							
								
								
									
										6
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										6
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@@ -4,6 +4,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
# Unignore all with extensions
 | 
					# Unignore all with extensions
 | 
				
			||||||
!*.*
 | 
					!*.*
 | 
				
			||||||
 | 
					!Dockerfile
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Unignore all dirs
 | 
					# Unignore all dirs
 | 
				
			||||||
!*/
 | 
					!*/
 | 
				
			||||||
@@ -86,3 +87,8 @@ GitHub.sublime-settings
 | 
				
			|||||||
!.vscode/*.code-snippets
 | 
					!.vscode/*.code-snippets
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# End of https://www.toptal.com/developers/gitignore/api/visualstudiocode,sublimetext,go
 | 
					# End of https://www.toptal.com/developers/gitignore/api/visualstudiocode,sublimetext,go
 | 
				
			||||||
 | 
					node_modules
 | 
				
			||||||
 | 
					.DS_Store
 | 
				
			||||||
 | 
					dist
 | 
				
			||||||
 | 
					dist-ssr
 | 
				
			||||||
 | 
					*.local
 | 
				
			||||||
							
								
								
									
										3
									
								
								.gitmodules
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								.gitmodules
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,3 @@
 | 
				
			|||||||
 | 
					[submodule "testdata"]
 | 
				
			||||||
 | 
						path = testdata
 | 
				
			||||||
 | 
						url = https://git.javil.eu/jacob1123/budgeteer-testdata.git
 | 
				
			||||||
							
								
								
									
										43
									
								
								.golangci.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								.golangci.yml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,43 @@
 | 
				
			|||||||
 | 
					linters:
 | 
				
			||||||
 | 
					  enable-all: true
 | 
				
			||||||
 | 
					  disable:
 | 
				
			||||||
 | 
					    - golint
 | 
				
			||||||
 | 
					    - scopelint
 | 
				
			||||||
 | 
					    - maligned
 | 
				
			||||||
 | 
					    - interfacer
 | 
				
			||||||
 | 
					    - wsl
 | 
				
			||||||
 | 
					    - forbidigo
 | 
				
			||||||
 | 
					    - nlreturn
 | 
				
			||||||
 | 
					    - testpackage
 | 
				
			||||||
 | 
					    - ifshort
 | 
				
			||||||
 | 
					    - exhaustivestruct
 | 
				
			||||||
 | 
					    - gci # not working, shows errors on freshly formatted file
 | 
				
			||||||
 | 
					    - varnamelen
 | 
				
			||||||
 | 
					    - lll
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					linters-settings:
 | 
				
			||||||
 | 
					  errcheck:
 | 
				
			||||||
 | 
					    exclude-functions:
 | 
				
			||||||
 | 
					      - io/ioutil.ReadFile
 | 
				
			||||||
 | 
					      - io.Copy(*bytes.Buffer)
 | 
				
			||||||
 | 
					      - (*github.com/gin-gonic/gin.Context).AbortWithError
 | 
				
			||||||
 | 
					      - (*github.com/gin-gonic/gin.Context).AbortWithError
 | 
				
			||||||
 | 
					      - io.Copy(os.Stdout)
 | 
				
			||||||
 | 
					  varnamelen:
 | 
				
			||||||
 | 
					    ignore-decls:
 | 
				
			||||||
 | 
					      - c *gin.Context
 | 
				
			||||||
 | 
					  wrapcheck:
 | 
				
			||||||
 | 
					    ignoreSigs:
 | 
				
			||||||
 | 
					      - .JSON(
 | 
				
			||||||
 | 
					      - .Redirect(
 | 
				
			||||||
 | 
					      - .String(
 | 
				
			||||||
 | 
					      - .Errorf(
 | 
				
			||||||
 | 
					      - errors.New(
 | 
				
			||||||
 | 
					      - errors.Unwrap(
 | 
				
			||||||
 | 
					      - .Wrap(
 | 
				
			||||||
 | 
					      - .Wrapf(
 | 
				
			||||||
 | 
					      - .WithMessage(
 | 
				
			||||||
 | 
					      - .WithMessagef(
 | 
				
			||||||
 | 
					      - .WithStack(
 | 
				
			||||||
 | 
					    ignorePackageGlobs:
 | 
				
			||||||
 | 
					      - git.javil.eu/jacob1123/budgeteer/postgres
 | 
				
			||||||
							
								
								
									
										15
									
								
								.vscode/settings.json
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								.vscode/settings.json
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,15 @@
 | 
				
			|||||||
 | 
					{
 | 
				
			||||||
 | 
					        "files.exclude": {
 | 
				
			||||||
 | 
					                "**/node_modules": true,
 | 
				
			||||||
 | 
					                "**/vendor": true,
 | 
				
			||||||
 | 
					                "**/*.sql.go": true,
 | 
				
			||||||
 | 
					                ".task/": true,
 | 
				
			||||||
 | 
					                "build/": true,
 | 
				
			||||||
 | 
					                "web/dist/": true
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        "gopls": {
 | 
				
			||||||
 | 
					                "formatting.gofumpt": true,
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        "editor.detectIndentation": false,
 | 
				
			||||||
 | 
					        "editor.tabSize": 2
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -1,3 +0,0 @@
 | 
				
			|||||||
FROM golang:1.17
 | 
					 | 
				
			||||||
RUN go install github.com/kyleconroy/sqlc/cmd/sqlc@latest
 | 
					 | 
				
			||||||
RUN go install github.com/go-task/task/v3/cmd/task@latest
 | 
					 | 
				
			||||||
							
								
								
									
										21
									
								
								Earthfile
									
									
									
									
									
								
							
							
						
						
									
										21
									
								
								Earthfile
									
									
									
									
									
								
							@@ -1,21 +0,0 @@
 | 
				
			|||||||
FROM golang:1.17
 | 
					 | 
				
			||||||
WORKDIR /src
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
build:
 | 
					 | 
				
			||||||
	COPY go.mod go.sum .
 | 
					 | 
				
			||||||
	RUN go mod download
 | 
					 | 
				
			||||||
	COPY . .
 | 
					 | 
				
			||||||
	RUN --mount=type=cache,target=/root/.cache/go-build go build -o build/budgeteer ./cmd/budgeteer
 | 
					 | 
				
			||||||
	SAVE ARTIFACT build/budgeteer /budgeteer AS LOCAL build/budgeteer
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
docker:
 | 
					 | 
				
			||||||
	WORKDIR /app
 | 
					 | 
				
			||||||
	COPY +build/budgeteer .
 | 
					 | 
				
			||||||
	ENTRYPOINT ["/app/budgeteer"]
 | 
					 | 
				
			||||||
	SAVE IMAGE budgeteer:latest
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
run:
 | 
					 | 
				
			||||||
	LOCALLY
 | 
					 | 
				
			||||||
	WITH DOCKER --load=+docker
 | 
					 | 
				
			||||||
		RUN docker-compose up -d
 | 
					 | 
				
			||||||
	END
 | 
					 | 
				
			||||||
							
								
								
									
										17
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								README.md
									
									
									
									
									
								
							@@ -1,3 +1,18 @@
 | 
				
			|||||||
# Budgeteer
 | 
					# Budgeteer
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Budgeting Web-Application
 | 
					Budgeting Web-Application written in Go and inspired by [YNAB](https://youneedabudget.com).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## Getting started
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					The fastest way to get up and running quickly, is using docker-compose. Just download the [docker-compose.yml](https://git.javil.eu/jacob1123/budgeteer/src/branch/master/docker/docker-compose.yml) to some empty directory and run `docker-compose up -d`. This starts budgeteer, a postgres database and an adminer instance. The latter is optional and can be removed from the docker-compose.yml.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## Known issues
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Currently the application is usable when importing from YNAB via their CSV export. All balances should match the balances from YNAB. There are even unit-tests that confirm that using my personal budget.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					For people wishing to start fresh in Budgeteer, there currently are some blockers though:
 | 
				
			||||||
 | 
					- The ability to create new accounts and categories is missing (#59)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## Contributing
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					If you're willing to help, please check the issues for [help-wanted labels](https://git.javil.eu/jacob1123/budgeteer/issues?labels=4). Just using Budgeteer and reporting any issues is although very helpful. 
 | 
				
			||||||
							
								
								
									
										141
									
								
								Taskfile.yml
									
									
									
									
									
								
							
							
						
						
									
										141
									
								
								Taskfile.yml
									
									
									
									
									
								
							@@ -1,11 +1,62 @@
 | 
				
			|||||||
version: '3'
 | 
					version: '3'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					vars:
 | 
				
			||||||
 | 
					  IMAGE_NAME: hub.javil.eu/budgeteer
 | 
				
			||||||
 | 
					
 | 
				
			||||||
tasks:
 | 
					tasks:
 | 
				
			||||||
  default:
 | 
					  default:
 | 
				
			||||||
 | 
					    desc: Build budgeteer in production mode
 | 
				
			||||||
 | 
					    deps: [frontend, go-mod, go-sqlc]
 | 
				
			||||||
    cmds:
 | 
					    cmds:
 | 
				
			||||||
      - task: build
 | 
					      - task: backend
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  sqlc:
 | 
					  run:
 | 
				
			||||||
 | 
					    desc: Start budgeteer
 | 
				
			||||||
 | 
					    deps: [backend, go-mod, go-sqlc]
 | 
				
			||||||
 | 
					    cmds:
 | 
				
			||||||
 | 
					      - ./build/budgeteer{{exeExt}}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  dev:
 | 
				
			||||||
 | 
					    desc: Build budgeteer in dev mode (without frontend)
 | 
				
			||||||
 | 
					    deps: [go-mod, go-sqlc]
 | 
				
			||||||
 | 
					    cmds:
 | 
				
			||||||
 | 
					      - task: backend
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  ci:
 | 
				
			||||||
 | 
					    desc: Run CI build
 | 
				
			||||||
 | 
					    deps: [default, static]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  static:
 | 
				
			||||||
 | 
					    deps: [go-lint, go-vet, go-fmt, js-tsc, js-lint, cover]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  backend:
 | 
				
			||||||
 | 
					    desc: Build budgeteer
 | 
				
			||||||
 | 
					    sources:
 | 
				
			||||||
 | 
					      - ./go.mod
 | 
				
			||||||
 | 
					      - ./go.sum
 | 
				
			||||||
 | 
					      - ./**/*.go
 | 
				
			||||||
 | 
					      - ./web/dist/**/*
 | 
				
			||||||
 | 
					      - ./postgres/schema/*
 | 
				
			||||||
 | 
					    generates:
 | 
				
			||||||
 | 
					      - build/budgeteer{{exeExt}}
 | 
				
			||||||
 | 
					    env:
 | 
				
			||||||
 | 
					      CGO_ENABLED: '0'
 | 
				
			||||||
 | 
					    cmds:
 | 
				
			||||||
 | 
					      - go build -o ./build/budgeteer{{exeExt}} ./cmd/budgeteer
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  go-vet:
 | 
				
			||||||
 | 
					    cmds:
 | 
				
			||||||
 | 
					      - go vet
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  go-fmt:
 | 
				
			||||||
 | 
					    cmds:
 | 
				
			||||||
 | 
					      - go fmt
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  go-lint:
 | 
				
			||||||
 | 
					    cmds:
 | 
				
			||||||
 | 
					      - golangci-lint run
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  go-sqlc:
 | 
				
			||||||
    desc: sqlc code generation
 | 
					    desc: sqlc code generation
 | 
				
			||||||
    sources:
 | 
					    sources:
 | 
				
			||||||
      - ./sqlc.yaml
 | 
					      - ./sqlc.yaml
 | 
				
			||||||
@@ -16,7 +67,7 @@ tasks:
 | 
				
			|||||||
    cmds:
 | 
					    cmds:
 | 
				
			||||||
      - sqlc generate
 | 
					      - sqlc generate
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  gomod:
 | 
					  go-mod:
 | 
				
			||||||
    desc: Go modules
 | 
					    desc: Go modules
 | 
				
			||||||
    sources:
 | 
					    sources:
 | 
				
			||||||
      - ./go.mod
 | 
					      - ./go.mod
 | 
				
			||||||
@@ -25,37 +76,67 @@ tasks:
 | 
				
			|||||||
    cmds:
 | 
					    cmds:
 | 
				
			||||||
      - go mod download
 | 
					      - go mod download
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  build:
 | 
					  cover:
 | 
				
			||||||
    desc: Build budgeteer
 | 
					    desc: Run test and analyze coverage
 | 
				
			||||||
    deps: [gomod, sqlc]
 | 
					    cmds:
 | 
				
			||||||
 | 
					      - go test ./... -coverprofile=coverage.out -covermode=atomic
 | 
				
			||||||
 | 
					      - go tool cover -html=coverage.out -o=coverage.html 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  frontend:
 | 
				
			||||||
 | 
					    desc: Build vue frontend
 | 
				
			||||||
 | 
					    deps: [js-build]
 | 
				
			||||||
    sources:
 | 
					    sources:
 | 
				
			||||||
      - ./go.mod
 | 
					      - web/src/**/*
 | 
				
			||||||
      - ./go.sum
 | 
					 | 
				
			||||||
      - ./cmd/budgeteer/*.go
 | 
					 | 
				
			||||||
      - ./*.go
 | 
					 | 
				
			||||||
      - ./config/*.go
 | 
					 | 
				
			||||||
      - ./http/*.go
 | 
					 | 
				
			||||||
      - ./jwt/*.go
 | 
					 | 
				
			||||||
      - ./postgres/*.go
 | 
					 | 
				
			||||||
      - ./web/**/*
 | 
					 | 
				
			||||||
      - ./postgres/schema/*
 | 
					 | 
				
			||||||
    generates:
 | 
					    generates:
 | 
				
			||||||
      - build/budgeteer{{exeExt}}
 | 
					      - web/dist/**/*
 | 
				
			||||||
    env:
 | 
					 | 
				
			||||||
      CGO_ENABLED: '0'
 | 
					 | 
				
			||||||
    cmds:
 | 
					 | 
				
			||||||
      - go build -o ./build/budgeteer{{exeExt}} ./cmd/budgeteer
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  docker:
 | 
					  frontend-dev:
 | 
				
			||||||
    desc: Build budgeeter:latest
 | 
					    desc: Run dev-server for frontend
 | 
				
			||||||
    deps: [build]
 | 
					    dir: web
 | 
				
			||||||
 | 
					    cmds:
 | 
				
			||||||
 | 
					      - yarn run dev
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  js-build:
 | 
				
			||||||
 | 
					    dir: web
 | 
				
			||||||
 | 
					    deps: [js-mod]
 | 
				
			||||||
 | 
					    cmds:
 | 
				
			||||||
 | 
					      - yarn build
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  js-mod:
 | 
				
			||||||
 | 
					    run: once
 | 
				
			||||||
    sources:
 | 
					    sources:
 | 
				
			||||||
      - ./build/budgeteer
 | 
					      - web/src/package.json
 | 
				
			||||||
 | 
					      - web/src/yarn.lock
 | 
				
			||||||
 | 
					    generates:
 | 
				
			||||||
 | 
					      - web/node_modules/**/*
 | 
				
			||||||
 | 
					    dir: web
 | 
				
			||||||
    cmds:
 | 
					    cmds:
 | 
				
			||||||
      - docker build -t budgeteer:latest -t hub.javil.eu/budgeteer:latest ./build
 | 
					      - yarn
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  run:
 | 
					  js-tsc:
 | 
				
			||||||
    desc: Start docker-compose
 | 
					    dir: web
 | 
				
			||||||
    deps: [docker]
 | 
					    deps: [js-mod]
 | 
				
			||||||
    cmds:
 | 
					    cmds:
 | 
				
			||||||
      - docker-compose up -d
 | 
					      - yarn run vue-tsc --noEmit
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  js-lint:
 | 
				
			||||||
 | 
					    dir: web
 | 
				
			||||||
 | 
					    deps: [js-mod]
 | 
				
			||||||
 | 
					    cmds:
 | 
				
			||||||
 | 
					      - yarn run eslint "./src/**"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  dev-docker:
 | 
				
			||||||
 | 
					    desc: Build budgeeter:dev
 | 
				
			||||||
 | 
					    sources:
 | 
				
			||||||
 | 
					      - ./docker/Dockerfile.dev
 | 
				
			||||||
 | 
					      - ./web/package.json
 | 
				
			||||||
 | 
					      - ./web/yarn.lock
 | 
				
			||||||
 | 
					    cmds:
 | 
				
			||||||
 | 
					    - docker build -t {{.IMAGE_NAME}}:dev . -f docker/Dockerfile.dev
 | 
				
			||||||
 | 
					    - docker push {{.IMAGE_NAME}}:dev
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					  run-dev:
 | 
				
			||||||
 | 
					    desc: Run dev environment in docker
 | 
				
			||||||
 | 
					    deps: [dev-docker]
 | 
				
			||||||
 | 
					    cmds:
 | 
				
			||||||
 | 
					      - docker-compose -f docker/docker-compose.dev.yml up -d
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,23 +1,30 @@
 | 
				
			|||||||
package bcrypt
 | 
					package bcrypt
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import "golang.org/x/crypto/bcrypt"
 | 
					import (
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Verifier verifys passwords using Bcrypt
 | 
						"golang.org/x/crypto/bcrypt"
 | 
				
			||||||
type Verifier struct {
 | 
					)
 | 
				
			||||||
	cost int
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Verify verifys a Password
 | 
					// Verifier verifys passwords using Bcrypt.
 | 
				
			||||||
func (bv *Verifier) Verify(password string, hashOnDb string) error {
 | 
					type Verifier struct{}
 | 
				
			||||||
	return bcrypt.CompareHashAndPassword([]byte(hashOnDb), []byte(password))
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Hash calculates a hash to be stored on the database
 | 
					// Verify verifys a Password.
 | 
				
			||||||
func (bv *Verifier) Hash(password string) (string, error) {
 | 
					func (bv *Verifier) Verify(password string, hashOnDB string) error {
 | 
				
			||||||
	hash, err := bcrypt.GenerateFromPassword([]byte(password), bv.cost)
 | 
						err := bcrypt.CompareHashAndPassword([]byte(hashOnDB), []byte(password))
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return "", err
 | 
							return fmt.Errorf("verify password: %w", err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return string(hash[:]), nil
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Hash calculates a hash to be stored on the database.
 | 
				
			||||||
 | 
					func (bv *Verifier) Hash(password string) (string, error) {
 | 
				
			||||||
 | 
						hash, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return "", fmt.Errorf("hash password: %w", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return string(hash), nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,34 +1,46 @@
 | 
				
			|||||||
package main
 | 
					package main
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
						"io/fs"
 | 
				
			||||||
	"log"
 | 
						"log"
 | 
				
			||||||
 | 
						"net/http"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"git.javil.eu/jacob1123/budgeteer/bcrypt"
 | 
						"git.javil.eu/jacob1123/budgeteer/bcrypt"
 | 
				
			||||||
	"git.javil.eu/jacob1123/budgeteer/config"
 | 
						"git.javil.eu/jacob1123/budgeteer/config"
 | 
				
			||||||
	"git.javil.eu/jacob1123/budgeteer/http"
 | 
					 | 
				
			||||||
	"git.javil.eu/jacob1123/budgeteer/jwt"
 | 
						"git.javil.eu/jacob1123/budgeteer/jwt"
 | 
				
			||||||
	"git.javil.eu/jacob1123/budgeteer/postgres"
 | 
						"git.javil.eu/jacob1123/budgeteer/postgres"
 | 
				
			||||||
 | 
						"git.javil.eu/jacob1123/budgeteer/server"
 | 
				
			||||||
 | 
						"git.javil.eu/jacob1123/budgeteer/web"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func main() {
 | 
					func main() {
 | 
				
			||||||
	cfg, err := config.LoadConfig()
 | 
						cfg, err := config.LoadConfig()
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		log.Fatalf("Could not load config: %v", err)
 | 
							log.Fatalf("load config: %v", err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	bv := &bcrypt.Verifier{}
 | 
						queries, err := postgres.Connect("pgx", cfg.DatabaseConnection)
 | 
				
			||||||
 | 
					 | 
				
			||||||
	q, err := postgres.Connect(cfg.DatabaseHost, cfg.DatabaseUser, cfg.DatabasePassword, cfg.DatabaseName)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		log.Fatalf("Failed connecting to DB: %v", err)
 | 
							log.Fatalf("connect to database: %v", err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	tv := &jwt.TokenVerifier{}
 | 
						static, err := fs.Sub(web.Static, "dist")
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
	h := &http.Handler{
 | 
							panic("open static files")
 | 
				
			||||||
		Service:             q,
 | 
					 | 
				
			||||||
		TokenVerifier:       tv,
 | 
					 | 
				
			||||||
		CredentialsVerifier: bv,
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	h.Serve()
 | 
					
 | 
				
			||||||
 | 
						tokenVerifier, err := jwt.NewTokenVerifier(cfg.SessionSecret)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							panic(fmt.Errorf("create token verifier: %w", err))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						handler := &server.Handler{
 | 
				
			||||||
 | 
							Service:             queries,
 | 
				
			||||||
 | 
							TokenVerifier:       tokenVerifier,
 | 
				
			||||||
 | 
							CredentialsVerifier: &bcrypt.Verifier{},
 | 
				
			||||||
 | 
							StaticFS:            http.FS(static),
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						handler.Serve()
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,6 +0,0 @@
 | 
				
			|||||||
{
 | 
					 | 
				
			||||||
	"DatabaseHost": "localhost", 
 | 
					 | 
				
			||||||
	"DatabaseUser": "user", 
 | 
					 | 
				
			||||||
	"DatabasePassword": "thisismypassword", 
 | 
					 | 
				
			||||||
	"DatabaseName": "budgeteer"
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -4,25 +4,17 @@ import (
 | 
				
			|||||||
	"os"
 | 
						"os"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Config contains all needed configurations
 | 
					// Config contains all needed configurations.
 | 
				
			||||||
type Config struct {
 | 
					type Config struct {
 | 
				
			||||||
	DatabaseUser     string
 | 
						DatabaseConnection string
 | 
				
			||||||
	DatabaseHost     string
 | 
						SessionSecret      string
 | 
				
			||||||
	DatabasePassword string
 | 
					 | 
				
			||||||
	DatabaseName     string
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// LoadConfig from path
 | 
					// LoadConfig from path.
 | 
				
			||||||
func LoadConfig() (*Config, error) {
 | 
					func LoadConfig() (*Config, error) {
 | 
				
			||||||
	configuration := Config{
 | 
						configuration := Config{
 | 
				
			||||||
		DatabaseUser:     os.Getenv("BUDGETEER_DB_USER"),
 | 
							DatabaseConnection: os.Getenv("BUDGETEER_DB"),
 | 
				
			||||||
		DatabaseHost:     os.Getenv("BUDGETEER_DB_HOST"),
 | 
							SessionSecret:      os.Getenv("BUDGETEER_SESSION_SECRET"),
 | 
				
			||||||
		DatabasePassword: os.Getenv("BUDGETEER_DB_PASS"),
 | 
					 | 
				
			||||||
		DatabaseName:     os.Getenv("BUDGETEER_DB_NAME"),
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if configuration.DatabaseName == "" {
 | 
					 | 
				
			||||||
		configuration.DatabaseName = "budgeteer"
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return &configuration, nil
 | 
						return &configuration, nil
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										9
									
								
								docker/Dockerfile.dev
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								docker/Dockerfile.dev
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,9 @@
 | 
				
			|||||||
 | 
					FROM nixos/nix
 | 
				
			||||||
 | 
					ENV PATH="/root/.yarn/bin/:${PATH}"
 | 
				
			||||||
 | 
					RUN nix-env --install go go-task sqlc nodejs yarn git
 | 
				
			||||||
 | 
					ADD web/package.json web/yarn.lock /src/web/
 | 
				
			||||||
 | 
					WORKDIR /src/web
 | 
				
			||||||
 | 
					RUN yarn
 | 
				
			||||||
 | 
					WORKDIR /src
 | 
				
			||||||
 | 
					VOLUME /go
 | 
				
			||||||
 | 
					VOLUME /.cache
 | 
				
			||||||
							
								
								
									
										7
									
								
								docker/dev.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										7
									
								
								docker/dev.sh
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,7 @@
 | 
				
			|||||||
 | 
					#!/bin/sh
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					tmux new-session -d -s watch 'cd web; yarn dev'
 | 
				
			||||||
 | 
					tmux split-window;
 | 
				
			||||||
 | 
					tmux send 'go-task -w run' ENTER;
 | 
				
			||||||
 | 
					tmux split-window;
 | 
				
			||||||
 | 
					tmux a;
 | 
				
			||||||
							
								
								
									
										52
									
								
								docker/docker-compose.dev.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										52
									
								
								docker/docker-compose.dev.yml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,52 @@
 | 
				
			|||||||
 | 
					version: '3.7'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					name: "budgeteer"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					services:
 | 
				
			||||||
 | 
					        backend:
 | 
				
			||||||
 | 
					                image: hub.javil.eu/budgeteer:dev
 | 
				
			||||||
 | 
					                command: task -w run
 | 
				
			||||||
 | 
					                ports:
 | 
				
			||||||
 | 
					                        - 1323:1323
 | 
				
			||||||
 | 
					                volumes:
 | 
				
			||||||
 | 
					                        - ../:/src
 | 
				
			||||||
 | 
					                        - go-cache:/go
 | 
				
			||||||
 | 
					                        - yarn-cache:/.cache
 | 
				
			||||||
 | 
					                environment:
 | 
				
			||||||
 | 
					                        BUDGETEER_DB: postgres://budgeteer:budgeteer@db:5432/budgeteer
 | 
				
			||||||
 | 
					                        BUDGETEER_SESSION_SECRET: random string for JWT authorization
 | 
				
			||||||
 | 
					                depends_on:
 | 
				
			||||||
 | 
					                        - db
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        frontend:
 | 
				
			||||||
 | 
					                image: hub.javil.eu/budgeteer:dev
 | 
				
			||||||
 | 
					                command: task frontend-dev
 | 
				
			||||||
 | 
					                ports:
 | 
				
			||||||
 | 
					                        - 3000:3000
 | 
				
			||||||
 | 
					                volumes:
 | 
				
			||||||
 | 
					                        - ../:/src
 | 
				
			||||||
 | 
					                depends_on:
 | 
				
			||||||
 | 
					                        - backend
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        db:
 | 
				
			||||||
 | 
					                image: postgres:14
 | 
				
			||||||
 | 
					                ports:
 | 
				
			||||||
 | 
					                        - 5432:5432
 | 
				
			||||||
 | 
					                volumes:
 | 
				
			||||||
 | 
					                        - db:/var/lib/postgresql/data
 | 
				
			||||||
 | 
					                environment:
 | 
				
			||||||
 | 
					                        POSTGRES_USER: budgeteer
 | 
				
			||||||
 | 
					                        POSTGRES_PASSWORD: budgeteer
 | 
				
			||||||
 | 
					                        POSTGRES_DBE: budgeteer
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        adminer:
 | 
				
			||||||
 | 
					                image: adminer
 | 
				
			||||||
 | 
					                ports:
 | 
				
			||||||
 | 
					                        - 1424:8080
 | 
				
			||||||
 | 
					                depends_on:
 | 
				
			||||||
 | 
					                        - db
 | 
				
			||||||
 | 
					                
 | 
				
			||||||
 | 
					volumes:
 | 
				
			||||||
 | 
					        db:
 | 
				
			||||||
 | 
					        go-cache:
 | 
				
			||||||
 | 
					        yarn-cache:
 | 
				
			||||||
@@ -1,8 +1,10 @@
 | 
				
			|||||||
version: '3.7'
 | 
					version: '3.7'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					name: "budgeteer"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
services:
 | 
					services:
 | 
				
			||||||
        app:
 | 
					        app:
 | 
				
			||||||
                image: budgeteer:latest
 | 
					                image: hub.javil.eu/budgeteer:latest
 | 
				
			||||||
                container_name: budgeteer
 | 
					                container_name: budgeteer
 | 
				
			||||||
                ports:
 | 
					                ports:
 | 
				
			||||||
                        - 1323:1323
 | 
					                        - 1323:1323
 | 
				
			||||||
							
								
								
									
										34
									
								
								go.mod
									
									
									
									
									
								
							
							
						
						
									
										34
									
								
								go.mod
									
									
									
									
									
								
							@@ -4,7 +4,6 @@ go 1.17
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
require (
 | 
					require (
 | 
				
			||||||
	github.com/dgrijalva/jwt-go v3.2.0+incompatible
 | 
						github.com/dgrijalva/jwt-go v3.2.0+incompatible
 | 
				
			||||||
	github.com/gin-gonic/gin v1.7.4
 | 
					 | 
				
			||||||
	github.com/google/uuid v1.3.0
 | 
						github.com/google/uuid v1.3.0
 | 
				
			||||||
	github.com/jackc/pgx/v4 v4.13.0
 | 
						github.com/jackc/pgx/v4 v4.13.0
 | 
				
			||||||
	github.com/pressly/goose/v3 v3.3.1
 | 
						github.com/pressly/goose/v3 v3.3.1
 | 
				
			||||||
@@ -12,11 +11,21 @@ require (
 | 
				
			|||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
require (
 | 
					require (
 | 
				
			||||||
	github.com/gin-contrib/sse v0.1.0 // indirect
 | 
						github.com/DATA-DOG/go-txdb v0.1.5
 | 
				
			||||||
	github.com/go-playground/locales v0.13.0 // indirect
 | 
						github.com/labstack/echo/v4 v4.8.0
 | 
				
			||||||
	github.com/go-playground/universal-translator v0.17.0 // indirect
 | 
					)
 | 
				
			||||||
	github.com/go-playground/validator/v10 v10.4.1 // indirect
 | 
					
 | 
				
			||||||
	github.com/golang/protobuf v1.5.0 // indirect
 | 
					require (
 | 
				
			||||||
 | 
						github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
 | 
				
			||||||
 | 
						github.com/labstack/gommon v0.3.1 // indirect
 | 
				
			||||||
 | 
						github.com/mattn/go-colorable v0.1.11 // indirect
 | 
				
			||||||
 | 
						github.com/valyala/bytebufferpool v1.0.0 // indirect
 | 
				
			||||||
 | 
						github.com/valyala/fasttemplate v1.2.1 // indirect
 | 
				
			||||||
 | 
						golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f // indirect
 | 
				
			||||||
 | 
						golang.org/x/time v0.0.0-20201208040808-7e3f01d25324 // indirect
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					require (
 | 
				
			||||||
	github.com/jackc/chunkreader/v2 v2.0.1 // indirect
 | 
						github.com/jackc/chunkreader/v2 v2.0.1 // indirect
 | 
				
			||||||
	github.com/jackc/pgconn v1.10.0 // indirect
 | 
						github.com/jackc/pgconn v1.10.0 // indirect
 | 
				
			||||||
	github.com/jackc/pgio v1.0.0 // indirect
 | 
						github.com/jackc/pgio v1.0.0 // indirect
 | 
				
			||||||
@@ -24,16 +33,9 @@ require (
 | 
				
			|||||||
	github.com/jackc/pgproto3/v2 v2.1.1 // indirect
 | 
						github.com/jackc/pgproto3/v2 v2.1.1 // indirect
 | 
				
			||||||
	github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b // indirect
 | 
						github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b // indirect
 | 
				
			||||||
	github.com/jackc/pgtype v1.8.1 // direct
 | 
						github.com/jackc/pgtype v1.8.1 // direct
 | 
				
			||||||
	github.com/json-iterator/go v1.1.9 // indirect
 | 
						github.com/mattn/go-isatty v0.0.14 // indirect
 | 
				
			||||||
	github.com/leodido/go-urn v1.2.0 // indirect
 | 
					 | 
				
			||||||
	github.com/mattn/go-isatty v0.0.12 // indirect
 | 
					 | 
				
			||||||
	github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
 | 
					 | 
				
			||||||
	github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 // indirect
 | 
					 | 
				
			||||||
	github.com/pkg/errors v0.9.1 // indirect
 | 
						github.com/pkg/errors v0.9.1 // indirect
 | 
				
			||||||
	github.com/shopspring/decimal v1.3.1 // indirect
 | 
						github.com/shopspring/decimal v1.3.1 // indirect
 | 
				
			||||||
	github.com/ugorji/go/codec v1.1.7 // indirect
 | 
						golang.org/x/sys v0.0.0-20211103235746-7861aae1554b // indirect
 | 
				
			||||||
	golang.org/x/sys v0.0.0-20210616094352-59db8d763f22 // indirect
 | 
						golang.org/x/text v0.3.7 // indirect
 | 
				
			||||||
	golang.org/x/text v0.3.6 // indirect
 | 
					 | 
				
			||||||
	google.golang.org/protobuf v1.26.0 // indirect
 | 
					 | 
				
			||||||
	gopkg.in/yaml.v2 v2.3.0 // indirect
 | 
					 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										68
									
								
								go.sum
									
									
									
									
									
								
							
							
						
						
									
										68
									
								
								go.sum
									
									
									
									
									
								
							@@ -4,6 +4,8 @@ github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX
 | 
				
			|||||||
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
 | 
					github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
 | 
				
			||||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
 | 
					github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
 | 
				
			||||||
github.com/ClickHouse/clickhouse-go v1.5.1/go.mod h1:EaI/sW7Azgz9UATzd5ZdZHRUhHgv5+JMS9NSr2smCJI=
 | 
					github.com/ClickHouse/clickhouse-go v1.5.1/go.mod h1:EaI/sW7Azgz9UATzd5ZdZHRUhHgv5+JMS9NSr2smCJI=
 | 
				
			||||||
 | 
					github.com/DATA-DOG/go-txdb v0.1.5 h1:kKzz+LYk9qw1+fMyo8/9yDQiNXrJ2HbfX/TY61HkkB4=
 | 
				
			||||||
 | 
					github.com/DATA-DOG/go-txdb v0.1.5/go.mod h1:DhAhxMXZpUJVGnT+p9IbzJoRKvlArO2pkHjnGX7o0n0=
 | 
				
			||||||
github.com/Masterminds/semver/v3 v3.1.1 h1:hLg3sBzpNErnxhQtUy/mmLR2I9foDujNK030IGemrRc=
 | 
					github.com/Masterminds/semver/v3 v3.1.1 h1:hLg3sBzpNErnxhQtUy/mmLR2I9foDujNK030IGemrRc=
 | 
				
			||||||
github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs=
 | 
					github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs=
 | 
				
			||||||
github.com/Microsoft/go-winio v0.5.0/go.mod h1:JPGBdM1cNvN/6ISo+n8V5iA4v8pBzdOpzfwIujj1a84=
 | 
					github.com/Microsoft/go-winio v0.5.0/go.mod h1:JPGBdM1cNvN/6ISo+n8V5iA4v8pBzdOpzfwIujj1a84=
 | 
				
			||||||
@@ -54,24 +56,13 @@ github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25Kn
 | 
				
			|||||||
github.com/frankban/quicktest v1.11.3/go.mod h1:wRf/ReqHper53s+kmmSZizM8NamnL3IM0I9ntUbOk+k=
 | 
					github.com/frankban/quicktest v1.11.3/go.mod h1:wRf/ReqHper53s+kmmSZizM8NamnL3IM0I9ntUbOk+k=
 | 
				
			||||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
 | 
					github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
 | 
				
			||||||
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
 | 
					github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
 | 
				
			||||||
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
 | 
					 | 
				
			||||||
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
 | 
					 | 
				
			||||||
github.com/gin-gonic/gin v1.7.4 h1:QmUZXrvJ9qZ3GfWvQ+2wnW/1ePrTEJqPKMYEU3lD/DM=
 | 
					 | 
				
			||||||
github.com/gin-gonic/gin v1.7.4/go.mod h1:jD2toBW3GZUr5UMcdrwQA10I7RuaFOl/SGeDjXkfUtY=
 | 
					 | 
				
			||||||
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
 | 
					github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
 | 
				
			||||||
github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY=
 | 
					github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY=
 | 
				
			||||||
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
 | 
					github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
 | 
				
			||||||
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
 | 
					github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
 | 
				
			||||||
github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A=
 | 
					github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A=
 | 
				
			||||||
github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A=
 | 
					 | 
				
			||||||
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
 | 
					 | 
				
			||||||
github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q=
 | 
					 | 
				
			||||||
github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8=
 | 
					 | 
				
			||||||
github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no=
 | 
					 | 
				
			||||||
github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA=
 | 
					 | 
				
			||||||
github.com/go-playground/validator/v10 v10.4.1 h1:pH2c5ADXtd66mxoE0Zm9SUhxE20r7aM3F26W0hOn+GE=
 | 
					 | 
				
			||||||
github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4=
 | 
					 | 
				
			||||||
github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
 | 
					github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
 | 
				
			||||||
 | 
					github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE=
 | 
				
			||||||
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
 | 
					github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
 | 
				
			||||||
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
 | 
					github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
 | 
				
			||||||
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
 | 
					github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
 | 
				
			||||||
@@ -80,13 +71,14 @@ github.com/gofrs/uuid v4.0.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRx
 | 
				
			|||||||
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
 | 
					github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
 | 
				
			||||||
github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
 | 
					github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
 | 
				
			||||||
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
 | 
					github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
 | 
				
			||||||
 | 
					github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY=
 | 
				
			||||||
 | 
					github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
 | 
				
			||||||
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0=
 | 
					github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0=
 | 
				
			||||||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
 | 
					github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
 | 
				
			||||||
github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
 | 
					github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
 | 
				
			||||||
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
 | 
					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.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
 | 
				
			||||||
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
 | 
					github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
 | 
				
			||||||
github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
 | 
					 | 
				
			||||||
github.com/golang/protobuf v1.3.5/go.mod h1:6O5/vntMXwX2lRkT1hjjk0nAC1IDOTvTlVgjlRvqsdk=
 | 
					github.com/golang/protobuf v1.3.5/go.mod h1:6O5/vntMXwX2lRkT1hjjk0nAC1IDOTvTlVgjlRvqsdk=
 | 
				
			||||||
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
 | 
					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=
 | 
					github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
 | 
				
			||||||
@@ -94,7 +86,6 @@ github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrU
 | 
				
			|||||||
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
 | 
					github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
 | 
				
			||||||
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
 | 
					github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
 | 
				
			||||||
github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
 | 
					github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
 | 
				
			||||||
github.com/golang/protobuf v1.5.0 h1:LUVKkCeviFUMKqHa4tXIIij/lbhnMbP7Fn5wKdKkRh4=
 | 
					 | 
				
			||||||
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
 | 
					github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
 | 
				
			||||||
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
 | 
					github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
 | 
				
			||||||
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
 | 
					github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
 | 
				
			||||||
@@ -102,9 +93,7 @@ github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw
 | 
				
			|||||||
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
 | 
					github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
 | 
				
			||||||
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
 | 
					github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
 | 
				
			||||||
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
 | 
					github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
 | 
				
			||||||
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
 | 
					 | 
				
			||||||
github.com/google/go-cmp v0.5.5/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/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
 | 
					 | 
				
			||||||
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
 | 
					github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
 | 
				
			||||||
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=
 | 
					github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=
 | 
				
			||||||
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
 | 
					github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
 | 
				
			||||||
@@ -165,8 +154,6 @@ github.com/jackc/puddle v0.0.0-20190608224051-11cab39313c9/go.mod h1:m4B5Dj62Y0f
 | 
				
			|||||||
github.com/jackc/puddle v1.1.3/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
 | 
					github.com/jackc/puddle v1.1.3/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
 | 
				
			||||||
github.com/jmoiron/sqlx v1.2.0/go.mod h1:1FEQNm3xlJgrMD+FBdI9+xvCksHtbpVBBw5dYhBSsks=
 | 
					github.com/jmoiron/sqlx v1.2.0/go.mod h1:1FEQNm3xlJgrMD+FBdI9+xvCksHtbpVBBw5dYhBSsks=
 | 
				
			||||||
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
 | 
					github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
 | 
				
			||||||
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/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
 | 
					github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
 | 
				
			||||||
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
 | 
					github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
 | 
				
			||||||
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
 | 
					github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
 | 
				
			||||||
@@ -175,14 +162,14 @@ github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxv
 | 
				
			|||||||
github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
 | 
					github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
 | 
				
			||||||
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
 | 
					github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
 | 
				
			||||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
 | 
					github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
 | 
				
			||||||
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
 | 
					 | 
				
			||||||
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
 | 
					github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
 | 
				
			||||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
 | 
					github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
 | 
				
			||||||
github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw=
 | 
					github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw=
 | 
				
			||||||
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
 | 
					 | 
				
			||||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
 | 
					github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
 | 
				
			||||||
github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y=
 | 
					github.com/labstack/echo/v4 v4.8.0 h1:wdc6yKVaHxkNOEdz4cRZs1pQkwSXPiRjq69yWP4QQS8=
 | 
				
			||||||
github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=
 | 
					github.com/labstack/echo/v4 v4.8.0/go.mod h1:xkCDAdFCIf8jsFQ5NnbK7oqaF/yU1A1X20Ltm0OvSks=
 | 
				
			||||||
 | 
					github.com/labstack/gommon v0.3.1 h1:OomWaJXm7xR6L1HmEtGyQf26TEn7V6X88mktX9kee9o=
 | 
				
			||||||
 | 
					github.com/labstack/gommon v0.3.1/go.mod h1:uW6kP17uPlLJsD3ijUYn3/M5bAxtlZhMI6m3MFxTMTM=
 | 
				
			||||||
github.com/lib/pq v0.0.0-20180327071824-d34b9ff171c2/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
 | 
					github.com/lib/pq v0.0.0-20180327071824-d34b9ff171c2/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
 | 
				
			||||||
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
 | 
					github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
 | 
				
			||||||
github.com/lib/pq v1.1.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
 | 
					github.com/lib/pq v1.1.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
 | 
				
			||||||
@@ -195,10 +182,13 @@ github.com/matryer/is v1.4.0 h1:sosSmIWwkYITGrxZ25ULNDeKiMNzFSr4V/eqBQP0PeE=
 | 
				
			|||||||
github.com/matryer/is v1.4.0/go.mod h1:8I/i5uYgLzgsgEloJE1U6xx5HkBQpAZvepWuujKwMRU=
 | 
					github.com/matryer/is v1.4.0/go.mod h1:8I/i5uYgLzgsgEloJE1U6xx5HkBQpAZvepWuujKwMRU=
 | 
				
			||||||
github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ=
 | 
					github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ=
 | 
				
			||||||
github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
 | 
					github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
 | 
				
			||||||
 | 
					github.com/mattn/go-colorable v0.1.11 h1:nQ+aFkoE2TMGc0b68U2OKSexC+eq46+XwZzWXHRmPYs=
 | 
				
			||||||
 | 
					github.com/mattn/go-colorable v0.1.11/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
 | 
				
			||||||
github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
 | 
					github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
 | 
				
			||||||
github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
 | 
					github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
 | 
				
			||||||
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
 | 
					 | 
				
			||||||
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
 | 
					github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
 | 
				
			||||||
 | 
					github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
 | 
				
			||||||
 | 
					github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
 | 
				
			||||||
github.com/mattn/go-sqlite3 v1.9.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
 | 
					github.com/mattn/go-sqlite3 v1.9.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
 | 
				
			||||||
github.com/mattn/go-sqlite3 v1.14.8 h1:gDp86IdQsN/xWjIEmr9MF6o9mpksUgh0fu+9ByFxzIU=
 | 
					github.com/mattn/go-sqlite3 v1.14.8 h1:gDp86IdQsN/xWjIEmr9MF6o9mpksUgh0fu+9ByFxzIU=
 | 
				
			||||||
github.com/mattn/go-sqlite3 v1.14.8/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
 | 
					github.com/mattn/go-sqlite3 v1.14.8/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
 | 
				
			||||||
@@ -208,10 +198,6 @@ github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh
 | 
				
			|||||||
github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
 | 
					github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
 | 
				
			||||||
github.com/moby/sys/mountinfo v0.4.1/go.mod h1:rEr8tzG/lsIZHBtN/JjGG+LMYx9eXgW2JI+6q0qou+A=
 | 
					github.com/moby/sys/mountinfo v0.4.1/go.mod h1:rEr8tzG/lsIZHBtN/JjGG+LMYx9eXgW2JI+6q0qou+A=
 | 
				
			||||||
github.com/moby/term v0.0.0-20201216013528-df9cb8a40635/go.mod h1:FBS0z0QWA44HXygs7VXDUOGoN/1TV3RuWkLO04am3wc=
 | 
					github.com/moby/term v0.0.0-20201216013528-df9cb8a40635/go.mod h1:FBS0z0QWA44HXygs7VXDUOGoN/1TV3RuWkLO04am3wc=
 | 
				
			||||||
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=
 | 
					 | 
				
			||||||
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
 | 
					 | 
				
			||||||
github.com/mrunalp/fileutils v0.5.0/go.mod h1:M1WthSahJixYnrXQl/DFQuteStB1weuxD2QJNHXfbSQ=
 | 
					github.com/mrunalp/fileutils v0.5.0/go.mod h1:M1WthSahJixYnrXQl/DFQuteStB1weuxD2QJNHXfbSQ=
 | 
				
			||||||
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
 | 
					github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
 | 
				
			||||||
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
 | 
					github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
 | 
				
			||||||
@@ -280,11 +266,11 @@ github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635/go.mod h1:hkRG
 | 
				
			|||||||
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
 | 
					github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
 | 
				
			||||||
github.com/tv42/httpunix v0.0.0-20191220191345-2ba4b9c3382c/go.mod h1:hzIxponao9Kjc7aWznkXaL4U4TWaDSs8zcsY4Ka08nM=
 | 
					github.com/tv42/httpunix v0.0.0-20191220191345-2ba4b9c3382c/go.mod h1:hzIxponao9Kjc7aWznkXaL4U4TWaDSs8zcsY4Ka08nM=
 | 
				
			||||||
github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc=
 | 
					github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc=
 | 
				
			||||||
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 v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
 | 
					github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
 | 
				
			||||||
 | 
					github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
 | 
				
			||||||
 | 
					github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
 | 
				
			||||||
 | 
					github.com/valyala/fasttemplate v1.2.1 h1:TVEnxayobAdVkhQfrfes2IzOB6o+z4roRkPF52WA1u4=
 | 
				
			||||||
 | 
					github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
 | 
				
			||||||
github.com/vishvananda/netlink v1.1.0/go.mod h1:cTgwzPIzzgDAYoQrMm0EdrjRUBkTqKYppBueQtXaqoE=
 | 
					github.com/vishvananda/netlink v1.1.0/go.mod h1:cTgwzPIzzgDAYoQrMm0EdrjRUBkTqKYppBueQtXaqoE=
 | 
				
			||||||
github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df/go.mod h1:JP3t17pCcGlemwknint6hfoeCVQrEMVwxRLRjXpq+BU=
 | 
					github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df/go.mod h1:JP3t17pCcGlemwknint6hfoeCVQrEMVwxRLRjXpq+BU=
 | 
				
			||||||
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
 | 
					github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
 | 
				
			||||||
@@ -319,6 +305,7 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh
 | 
				
			|||||||
golang.org/x/crypto v0.0.0-20201203163018-be400aefbc4c/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
 | 
					golang.org/x/crypto v0.0.0-20201203163018-be400aefbc4c/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
 | 
				
			||||||
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
 | 
					golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
 | 
				
			||||||
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
 | 
					golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
 | 
				
			||||||
 | 
					golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
 | 
				
			||||||
golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa h1:idItI2DDfCokpg0N51B2VtiLdJ4vAuXC9fnCb2gACo4=
 | 
					golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa h1:idItI2DDfCokpg0N51B2VtiLdJ4vAuXC9fnCb2gACo4=
 | 
				
			||||||
golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
 | 
					golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
 | 
				
			||||||
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
 | 
					golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
 | 
				
			||||||
@@ -340,6 +327,7 @@ golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLL
 | 
				
			|||||||
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
 | 
					golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
 | 
				
			||||||
golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
 | 
					golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
 | 
				
			||||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
 | 
					golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
 | 
				
			||||||
 | 
					golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f h1:OfiFi4JbukWwe3lzw+xunroH1mnC1e2Gy5cxNJApiSY=
 | 
				
			||||||
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
 | 
					golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
 | 
				
			||||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
 | 
					golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
 | 
				
			||||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 | 
					golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 | 
				
			||||||
@@ -373,17 +361,23 @@ golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7w
 | 
				
			|||||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 | 
					golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 | 
				
			||||||
golang.org/x/sys v0.0.0-20210426230700-d19ff857e887/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 | 
					golang.org/x/sys v0.0.0-20210426230700-d19ff857e887/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 | 
				
			||||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 | 
					golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 | 
				
			||||||
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22 h1:RqytpXGR1iVNX7psjB3ff8y7sNFinVFvkx1c8SjBkio=
 | 
					 | 
				
			||||||
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 | 
					golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 | 
				
			||||||
 | 
					golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 | 
				
			||||||
 | 
					golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 | 
				
			||||||
 | 
					golang.org/x/sys v0.0.0-20211103235746-7861aae1554b h1:1VkfZQv42XQlA/jchYumAnv1UPo6RgF9rJFkTgZIxO4=
 | 
				
			||||||
 | 
					golang.org/x/sys v0.0.0-20211103235746-7861aae1554b/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 | 
				
			||||||
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
 | 
					golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
 | 
				
			||||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
 | 
					golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
 | 
				
			||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
 | 
					golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
 | 
				
			||||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
 | 
					golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
 | 
				
			||||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
 | 
					golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
 | 
				
			||||||
golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
 | 
					golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
 | 
				
			||||||
golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
 | 
					 | 
				
			||||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
 | 
					golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
 | 
				
			||||||
 | 
					golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
 | 
				
			||||||
 | 
					golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
 | 
				
			||||||
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
 | 
					golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
 | 
				
			||||||
 | 
					golang.org/x/time v0.0.0-20201208040808-7e3f01d25324 h1:Hir2P/De0WpUhtrKGGjvSb2YxUgyZ7EFOSLIcSSpiwE=
 | 
				
			||||||
 | 
					golang.org/x/time v0.0.0-20201208040808-7e3f01d25324/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
 | 
				
			||||||
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
 | 
					golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
 | 
				
			||||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
 | 
					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-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
 | 
				
			||||||
@@ -403,7 +397,6 @@ golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522/go.mod h1:I/5z698sn9Ka8T
 | 
				
			|||||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
 | 
					golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
 | 
				
			||||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
 | 
					golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
 | 
				
			||||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
 | 
					golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
 | 
				
			||||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
 | 
					 | 
				
			||||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
 | 
					golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
 | 
				
			||||||
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
 | 
					google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
 | 
				
			||||||
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
 | 
					google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
 | 
				
			||||||
@@ -416,11 +409,9 @@ google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miE
 | 
				
			|||||||
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
 | 
					google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
 | 
				
			||||||
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
 | 
					google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
 | 
				
			||||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
 | 
					google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
 | 
				
			||||||
google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk=
 | 
					 | 
				
			||||||
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
 | 
					google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
 | 
				
			||||||
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
 | 
					gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
 | 
				
			||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
 | 
					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-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
 | 
				
			||||||
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
 | 
					gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
 | 
				
			||||||
gopkg.in/inconshreveable/log15.v2 v2.0.0-20180818164646-67afb5ed74ec/go.mod h1:aPpfJ7XW+gOuirDoZ8gHhLh3kZ1B08FtV2bbmy7Jv3s=
 | 
					gopkg.in/inconshreveable/log15.v2 v2.0.0-20180818164646-67afb5ed74ec/go.mod h1:aPpfJ7XW+gOuirDoZ8gHhLh3kZ1B08FtV2bbmy7Jv3s=
 | 
				
			||||||
@@ -428,11 +419,10 @@ gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
 | 
				
			|||||||
gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74=
 | 
					gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74=
 | 
				
			||||||
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
 | 
					gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
 | 
				
			||||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
 | 
					gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
 | 
				
			||||||
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=
 | 
					gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
 | 
				
			||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
 | 
					 | 
				
			||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
 | 
					gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
 | 
				
			||||||
 | 
					gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
 | 
				
			||||||
 | 
					gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
 | 
				
			||||||
gotest.tools/v3 v3.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk=
 | 
					gotest.tools/v3 v3.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk=
 | 
				
			||||||
gotest.tools/v3 v3.0.3/go.mod h1:Z7Lb0S5l+klDB31fvDQX8ss/FlKDxtlFlw3Oa8Ymbl8=
 | 
					gotest.tools/v3 v3.0.3/go.mod h1:Z7Lb0S5l+klDB31fvDQX8ss/FlKDxtlFlw3Oa8Ymbl8=
 | 
				
			||||||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
 | 
					honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,54 +0,0 @@
 | 
				
			|||||||
package http
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import (
 | 
					 | 
				
			||||||
	"net/http"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	"git.javil.eu/jacob1123/budgeteer/postgres"
 | 
					 | 
				
			||||||
	"github.com/gin-gonic/gin"
 | 
					 | 
				
			||||||
	"github.com/google/uuid"
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type AccountData struct {
 | 
					 | 
				
			||||||
	AlwaysNeededData
 | 
					 | 
				
			||||||
	Account      *postgres.Account
 | 
					 | 
				
			||||||
	Categories   []postgres.GetCategoriesRow
 | 
					 | 
				
			||||||
	Transactions []postgres.GetTransactionsForAccountRow
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (h *Handler) account(c *gin.Context) {
 | 
					 | 
				
			||||||
	data := c.MustGet("data").(AlwaysNeededData)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	accountID := c.Param("accountid")
 | 
					 | 
				
			||||||
	accountUUID, err := uuid.Parse(accountID)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		c.Redirect(http.StatusTemporaryRedirect, "/login")
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	account, err := h.Service.GetAccount(c.Request.Context(), accountUUID)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		c.AbortWithError(http.StatusNotFound, err)
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	categories, err := h.Service.GetCategories(c.Request.Context(), data.Budget.ID)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		c.AbortWithError(http.StatusNotFound, err)
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	transactions, err := h.Service.GetTransactionsForAccount(c.Request.Context(), accountUUID)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		c.AbortWithError(http.StatusNotFound, err)
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	d := AccountData{
 | 
					 | 
				
			||||||
		data,
 | 
					 | 
				
			||||||
		&account,
 | 
					 | 
				
			||||||
		categories,
 | 
					 | 
				
			||||||
		transactions,
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	c.HTML(http.StatusOK, "account.html", d)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,19 +0,0 @@
 | 
				
			|||||||
package http
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import (
 | 
					 | 
				
			||||||
	"net/http"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	"github.com/gin-gonic/gin"
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type AccountsData struct {
 | 
					 | 
				
			||||||
	AlwaysNeededData
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (h *Handler) accounts(c *gin.Context) {
 | 
					 | 
				
			||||||
	d := AccountsData{
 | 
					 | 
				
			||||||
		c.MustGet("data").(AlwaysNeededData),
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	c.HTML(http.StatusOK, "accounts.html", d)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
							
								
								
									
										117
									
								
								http/admin.go
									
									
									
									
									
								
							
							
						
						
									
										117
									
								
								http/admin.go
									
									
									
									
									
								
							@@ -1,117 +0,0 @@
 | 
				
			|||||||
package http
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import (
 | 
					 | 
				
			||||||
	"fmt"
 | 
					 | 
				
			||||||
	"net/http"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	"github.com/gin-gonic/gin"
 | 
					 | 
				
			||||||
	"github.com/google/uuid"
 | 
					 | 
				
			||||||
	"github.com/pressly/goose/v3"
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type AdminData struct {
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (h *Handler) admin(c *gin.Context) {
 | 
					 | 
				
			||||||
	d := AdminData{}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	c.HTML(http.StatusOK, "admin.html", d)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (h *Handler) clearDatabase(c *gin.Context) {
 | 
					 | 
				
			||||||
	d := AdminData{}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if err := goose.Reset(h.Service.DB, "schema"); err != nil {
 | 
					 | 
				
			||||||
		c.AbortWithError(http.StatusInternalServerError, err)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if err := goose.Up(h.Service.DB, "schema"); err != nil {
 | 
					 | 
				
			||||||
		c.AbortWithError(http.StatusInternalServerError, err)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	c.HTML(http.StatusOK, "admin.html", d)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type SettingsData struct {
 | 
					 | 
				
			||||||
	AlwaysNeededData
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (h *Handler) settings(c *gin.Context) {
 | 
					 | 
				
			||||||
	d := SettingsData{
 | 
					 | 
				
			||||||
		c.MustGet("data").(AlwaysNeededData),
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	c.HTML(http.StatusOK, "settings.html", d)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (h *Handler) clearBudget(c *gin.Context) {
 | 
					 | 
				
			||||||
	budgetID := c.Param("budgetid")
 | 
					 | 
				
			||||||
	budgetUUID, err := uuid.Parse(budgetID)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		c.Redirect(http.StatusTemporaryRedirect, "/login")
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	rows, err := h.Service.DeleteAllAssignments(c.Request.Context(), budgetUUID)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		c.AbortWithError(http.StatusInternalServerError, err)
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	fmt.Printf("Deleted %d assignments\n", rows)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	rows, err = h.Service.DeleteAllTransactions(c.Request.Context(), budgetUUID)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		c.AbortWithError(http.StatusInternalServerError, err)
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	fmt.Printf("Deleted %d transactions\n", rows)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (h *Handler) cleanNegativeBudget(c *gin.Context) {
 | 
					 | 
				
			||||||
	/*budgetID := c.Param("budgetid")
 | 
					 | 
				
			||||||
	budgetUUID, err := uuid.Parse(budgetID)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		c.Redirect(http.StatusTemporaryRedirect, "/login")
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}*/
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/*min_date, err := h.Service.GetFirstActivity(c.Request.Context(), budgetUUID)
 | 
					 | 
				
			||||||
	date := getFirstOfMonthTime(min_date)
 | 
					 | 
				
			||||||
	for {
 | 
					 | 
				
			||||||
		nextDate := date.AddDate(0, 1, 0)
 | 
					 | 
				
			||||||
		params := postgres.GetCategoriesWithBalanceParams{
 | 
					 | 
				
			||||||
			BudgetID: budgetUUID,
 | 
					 | 
				
			||||||
			ToDate:   nextDate,
 | 
					 | 
				
			||||||
			FromDate: date,
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		categories, err := h.Service.GetCategoriesWithBalance(c.Request.Context(), params)
 | 
					 | 
				
			||||||
		if err != nil {
 | 
					 | 
				
			||||||
			c.AbortWithError(http.StatusInternalServerError, err)
 | 
					 | 
				
			||||||
			return
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		for _, category := range categories {
 | 
					 | 
				
			||||||
			available := category.Available.GetFloat64()
 | 
					 | 
				
			||||||
			if available >= 0 {
 | 
					 | 
				
			||||||
				continue
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			var negativeAvailable postgres.Numeric
 | 
					 | 
				
			||||||
			negativeAvailable.Set(-available)
 | 
					 | 
				
			||||||
			createAssignment := postgres.CreateAssignmentParams{
 | 
					 | 
				
			||||||
				Date:       nextDate.AddDate(0, 0, -1),
 | 
					 | 
				
			||||||
				Amount:     negativeAvailable,
 | 
					 | 
				
			||||||
				CategoryID: category.ID,
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			h.Service.CreateAssignment(c.Request.Context(), createAssignment)
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		if nextDate.Before(time.Now()) {
 | 
					 | 
				
			||||||
			date = nextDate
 | 
					 | 
				
			||||||
		} else {
 | 
					 | 
				
			||||||
			break
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}*/
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,57 +0,0 @@
 | 
				
			|||||||
package http
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import (
 | 
					 | 
				
			||||||
	"net/http"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	"git.javil.eu/jacob1123/budgeteer/postgres"
 | 
					 | 
				
			||||||
	"github.com/gin-gonic/gin"
 | 
					 | 
				
			||||||
	"github.com/google/uuid"
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type AlwaysNeededData struct {
 | 
					 | 
				
			||||||
	Budget            postgres.Budget
 | 
					 | 
				
			||||||
	Accounts          []postgres.GetAccountsWithBalanceRow
 | 
					 | 
				
			||||||
	OnBudgetAccounts  []postgres.GetAccountsWithBalanceRow
 | 
					 | 
				
			||||||
	OffBudgetAccounts []postgres.GetAccountsWithBalanceRow
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (h *Handler) getImportantData(c *gin.Context) {
 | 
					 | 
				
			||||||
	budgetID := c.Param("budgetid")
 | 
					 | 
				
			||||||
	budgetUUID, err := uuid.Parse(budgetID)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		c.Redirect(http.StatusTemporaryRedirect, "/login")
 | 
					 | 
				
			||||||
		c.Abort()
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	budget, err := h.Service.GetBudget(c.Request.Context(), budgetUUID)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		c.AbortWithError(http.StatusNotFound, err)
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	accounts, err := h.Service.GetAccountsWithBalance(c.Request.Context(), budgetUUID)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		c.AbortWithError(http.StatusInternalServerError, err)
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	var onBudgetAccounts, offBudgetAccounts []postgres.GetAccountsWithBalanceRow
 | 
					 | 
				
			||||||
	for _, account := range accounts {
 | 
					 | 
				
			||||||
		if account.OnBudget {
 | 
					 | 
				
			||||||
			onBudgetAccounts = append(onBudgetAccounts, account)
 | 
					 | 
				
			||||||
		} else {
 | 
					 | 
				
			||||||
			offBudgetAccounts = append(offBudgetAccounts, account)
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	base := AlwaysNeededData{
 | 
					 | 
				
			||||||
		Accounts:          accounts,
 | 
					 | 
				
			||||||
		OnBudgetAccounts:  onBudgetAccounts,
 | 
					 | 
				
			||||||
		OffBudgetAccounts: offBudgetAccounts,
 | 
					 | 
				
			||||||
		Budget:            budget,
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	c.Set("data", base)
 | 
					 | 
				
			||||||
	c.Next()
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,64 +0,0 @@
 | 
				
			|||||||
package http
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import (
 | 
					 | 
				
			||||||
	"net/http"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	"git.javil.eu/jacob1123/budgeteer"
 | 
					 | 
				
			||||||
	"git.javil.eu/jacob1123/budgeteer/postgres"
 | 
					 | 
				
			||||||
	"github.com/gin-gonic/gin"
 | 
					 | 
				
			||||||
	"github.com/google/uuid"
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type AllAccountsData struct {
 | 
					 | 
				
			||||||
	AlwaysNeededData
 | 
					 | 
				
			||||||
	Account      *postgres.Account
 | 
					 | 
				
			||||||
	Categories   []postgres.GetCategoriesRow
 | 
					 | 
				
			||||||
	Transactions []postgres.GetTransactionsForBudgetRow
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (h *Handler) allAccounts(c *gin.Context) {
 | 
					 | 
				
			||||||
	budgetID := c.Param("budgetid")
 | 
					 | 
				
			||||||
	budgetUUID, err := uuid.Parse(budgetID)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		c.Redirect(http.StatusTemporaryRedirect, "/login")
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	categories, err := h.Service.GetCategories(c.Request.Context(), budgetUUID)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		c.AbortWithError(http.StatusNotFound, err)
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	transactions, err := h.Service.GetTransactionsForBudget(c.Request.Context(), budgetUUID)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		c.AbortWithError(http.StatusInternalServerError, err)
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	d := AllAccountsData{
 | 
					 | 
				
			||||||
		c.MustGet("data").(AlwaysNeededData),
 | 
					 | 
				
			||||||
		&postgres.Account{
 | 
					 | 
				
			||||||
			Name: "All accounts",
 | 
					 | 
				
			||||||
		},
 | 
					 | 
				
			||||||
		categories,
 | 
					 | 
				
			||||||
		transactions,
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	c.HTML(http.StatusOK, "account.html", d)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (h *Handler) newBudget(c *gin.Context) {
 | 
					 | 
				
			||||||
	budgetName, succ := c.GetPostForm("name")
 | 
					 | 
				
			||||||
	if !succ {
 | 
					 | 
				
			||||||
		c.AbortWithStatus(http.StatusNotAcceptable)
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	userID := c.MustGet("token").(budgeteer.Token).GetID()
 | 
					 | 
				
			||||||
	_, err := h.Service.NewBudget(c.Request.Context(), budgetName, userID)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		c.AbortWithError(http.StatusInternalServerError, err)
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,182 +0,0 @@
 | 
				
			|||||||
package http
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import (
 | 
					 | 
				
			||||||
	"fmt"
 | 
					 | 
				
			||||||
	"net/http"
 | 
					 | 
				
			||||||
	"strconv"
 | 
					 | 
				
			||||||
	"time"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	"git.javil.eu/jacob1123/budgeteer/postgres"
 | 
					 | 
				
			||||||
	"github.com/gin-gonic/gin"
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type BudgetingData struct {
 | 
					 | 
				
			||||||
	AlwaysNeededData
 | 
					 | 
				
			||||||
	Categories       []CategoryWithBalance
 | 
					 | 
				
			||||||
	AvailableBalance float64
 | 
					 | 
				
			||||||
	Date             time.Time
 | 
					 | 
				
			||||||
	Next             time.Time
 | 
					 | 
				
			||||||
	Previous         time.Time
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func getFirstOfMonth(year, month int, location *time.Location) time.Time {
 | 
					 | 
				
			||||||
	return time.Date(year, time.Month(month), 1, 0, 0, 0, 0, location)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func getFirstOfMonthTime(date time.Time) time.Time {
 | 
					 | 
				
			||||||
	var monthM time.Month
 | 
					 | 
				
			||||||
	year, monthM, _ := date.Date()
 | 
					 | 
				
			||||||
	month := int(monthM)
 | 
					 | 
				
			||||||
	return getFirstOfMonth(year, month, date.Location())
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type CategoryWithBalance struct {
 | 
					 | 
				
			||||||
	*postgres.GetCategoriesRow
 | 
					 | 
				
			||||||
	Available          float64
 | 
					 | 
				
			||||||
	AvailableLastMonth float64
 | 
					 | 
				
			||||||
	Activity           float64
 | 
					 | 
				
			||||||
	Assigned           float64
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func getDate(c *gin.Context) (time.Time, error) {
 | 
					 | 
				
			||||||
	var year, month int
 | 
					 | 
				
			||||||
	yearString := c.Param("year")
 | 
					 | 
				
			||||||
	monthString := c.Param("month")
 | 
					 | 
				
			||||||
	if yearString == "" && monthString == "" {
 | 
					 | 
				
			||||||
		return getFirstOfMonthTime(time.Now()), nil
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	year, err := strconv.Atoi(yearString)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		return time.Time{}, fmt.Errorf("parse year: %w", err)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	month, err = strconv.Atoi(monthString)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		return time.Time{}, fmt.Errorf("parse month: %w", err)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	return getFirstOfMonth(year, month, time.Now().Location()), nil
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (h *Handler) budgeting(c *gin.Context) {
 | 
					 | 
				
			||||||
	alwaysNeededData := c.MustGet("data").(AlwaysNeededData)
 | 
					 | 
				
			||||||
	budgetUUID := alwaysNeededData.Budget.ID
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	firstOfMonth, err := getDate(c)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		c.Redirect(http.StatusTemporaryRedirect, "/budget/"+budgetUUID.String())
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	firstOfNextMonth := firstOfMonth.AddDate(0, 1, 0)
 | 
					 | 
				
			||||||
	firstOfPreviousMonth := firstOfMonth.AddDate(0, -1, 0)
 | 
					 | 
				
			||||||
	d := BudgetingData{
 | 
					 | 
				
			||||||
		AlwaysNeededData: alwaysNeededData,
 | 
					 | 
				
			||||||
		Date:             firstOfMonth,
 | 
					 | 
				
			||||||
		Next:             firstOfNextMonth,
 | 
					 | 
				
			||||||
		Previous:         firstOfPreviousMonth,
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	categories, err := h.Service.GetCategories(c.Request.Context(), budgetUUID)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	cumultativeBalances, err := h.Service.GetCumultativeBalances(c.Request.Context(), budgetUUID)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("load balances: %w", err))
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// skip everything in the future
 | 
					 | 
				
			||||||
	categoriesWithBalance, moneyUsed, err := h.calculateBalances(c, alwaysNeededData.Budget, firstOfNextMonth, firstOfMonth, categories, cumultativeBalances)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	d.Categories = categoriesWithBalance
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	data := c.MustGet("data").(AlwaysNeededData)
 | 
					 | 
				
			||||||
	var availableBalance float64 = 0
 | 
					 | 
				
			||||||
	for _, cat := range categories {
 | 
					 | 
				
			||||||
		if cat.ID != data.Budget.IncomeCategoryID {
 | 
					 | 
				
			||||||
			continue
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		availableBalance = moneyUsed
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		for _, bal := range cumultativeBalances {
 | 
					 | 
				
			||||||
			if bal.CategoryID != cat.ID {
 | 
					 | 
				
			||||||
				continue
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			if !bal.Date.Before(firstOfNextMonth) {
 | 
					 | 
				
			||||||
				continue
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			availableBalance += bal.Transactions.GetFloat64()
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	d.AvailableBalance = availableBalance
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	c.HTML(http.StatusOK, "budgeting.html", d)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (h *Handler) calculateBalances(c *gin.Context, budget postgres.Budget, firstOfNextMonth time.Time, firstOfMonth time.Time, categories []postgres.GetCategoriesRow, cumultativeBalances []postgres.GetCumultativeBalancesRow) ([]CategoryWithBalance, float64, error) {
 | 
					 | 
				
			||||||
	categoriesWithBalance := []CategoryWithBalance{}
 | 
					 | 
				
			||||||
	hiddenCategory := CategoryWithBalance{
 | 
					 | 
				
			||||||
		GetCategoriesRow: &postgres.GetCategoriesRow{
 | 
					 | 
				
			||||||
			Name:  "",
 | 
					 | 
				
			||||||
			Group: "Hidden Categories",
 | 
					 | 
				
			||||||
		},
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	var moneyUsed float64 = 0
 | 
					 | 
				
			||||||
	for i := range categories {
 | 
					 | 
				
			||||||
		cat := &categories[i]
 | 
					 | 
				
			||||||
		categoryWithBalance := CategoryWithBalance{
 | 
					 | 
				
			||||||
			GetCategoriesRow: cat,
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		for _, bal := range cumultativeBalances {
 | 
					 | 
				
			||||||
			if bal.CategoryID != cat.ID {
 | 
					 | 
				
			||||||
				continue
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			if !bal.Date.Before(firstOfNextMonth) {
 | 
					 | 
				
			||||||
				continue
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			moneyUsed -= bal.Assignments.GetFloat64()
 | 
					 | 
				
			||||||
			categoryWithBalance.Available += bal.Assignments.GetFloat64()
 | 
					 | 
				
			||||||
			categoryWithBalance.Available += bal.Transactions.GetFloat64()
 | 
					 | 
				
			||||||
			if categoryWithBalance.Available < 0 && bal.Date.Before(firstOfMonth) {
 | 
					 | 
				
			||||||
				moneyUsed += categoryWithBalance.Available
 | 
					 | 
				
			||||||
				categoryWithBalance.Available = 0
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			if bal.Date.Before(firstOfMonth) {
 | 
					 | 
				
			||||||
				categoryWithBalance.AvailableLastMonth = categoryWithBalance.Available
 | 
					 | 
				
			||||||
			} else if bal.Date.Before(firstOfNextMonth) {
 | 
					 | 
				
			||||||
				categoryWithBalance.Activity = bal.Transactions.GetFloat64()
 | 
					 | 
				
			||||||
				categoryWithBalance.Assigned = bal.Assignments.GetFloat64()
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		// do not show hidden categories
 | 
					 | 
				
			||||||
		if cat.Group == "Hidden Categories" {
 | 
					 | 
				
			||||||
			hiddenCategory.Available += categoryWithBalance.Available
 | 
					 | 
				
			||||||
			hiddenCategory.AvailableLastMonth += categoryWithBalance.AvailableLastMonth
 | 
					 | 
				
			||||||
			hiddenCategory.Activity += categoryWithBalance.Activity
 | 
					 | 
				
			||||||
			hiddenCategory.Assigned += categoryWithBalance.Assigned
 | 
					 | 
				
			||||||
			continue
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		if cat.ID == budget.IncomeCategoryID {
 | 
					 | 
				
			||||||
			continue
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		categoriesWithBalance = append(categoriesWithBalance, categoryWithBalance)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	categoriesWithBalance = append(categoriesWithBalance, hiddenCategory)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	return categoriesWithBalance, moneyUsed, nil
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,26 +0,0 @@
 | 
				
			|||||||
package http
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import (
 | 
					 | 
				
			||||||
	"net/http"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	"git.javil.eu/jacob1123/budgeteer"
 | 
					 | 
				
			||||||
	"git.javil.eu/jacob1123/budgeteer/postgres"
 | 
					 | 
				
			||||||
	"github.com/gin-gonic/gin"
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (h *Handler) dashboard(c *gin.Context) {
 | 
					 | 
				
			||||||
	userID := c.MustGet("token").(budgeteer.Token).GetID()
 | 
					 | 
				
			||||||
	budgets, err := h.Service.GetBudgetsForUser(c.Request.Context(), userID)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	d := DashboardData{
 | 
					 | 
				
			||||||
		Budgets: budgets,
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	c.HTML(http.StatusOK, "dashboard.html", d)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type DashboardData struct {
 | 
					 | 
				
			||||||
	Budgets []postgres.Budget
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
							
								
								
									
										101
									
								
								http/http.go
									
									
									
									
									
								
							
							
						
						
									
										101
									
								
								http/http.go
									
									
									
									
									
								
							@@ -1,101 +0,0 @@
 | 
				
			|||||||
package http
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import (
 | 
					 | 
				
			||||||
	"io/fs"
 | 
					 | 
				
			||||||
	"net/http"
 | 
					 | 
				
			||||||
	"strings"
 | 
					 | 
				
			||||||
	"time"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	"git.javil.eu/jacob1123/budgeteer"
 | 
					 | 
				
			||||||
	"git.javil.eu/jacob1123/budgeteer/bcrypt"
 | 
					 | 
				
			||||||
	"git.javil.eu/jacob1123/budgeteer/postgres"
 | 
					 | 
				
			||||||
	"git.javil.eu/jacob1123/budgeteer/web"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	"github.com/gin-gonic/gin"
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// Handler handles incoming requests
 | 
					 | 
				
			||||||
type Handler struct {
 | 
					 | 
				
			||||||
	Service             *postgres.Database
 | 
					 | 
				
			||||||
	TokenVerifier       budgeteer.TokenVerifier
 | 
					 | 
				
			||||||
	CredentialsVerifier *bcrypt.Verifier
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
const (
 | 
					 | 
				
			||||||
	expiration = 72
 | 
					 | 
				
			||||||
	authCookie = "authentication"
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// Serve starts the HTTP Server
 | 
					 | 
				
			||||||
func (h *Handler) Serve() {
 | 
					 | 
				
			||||||
	router := gin.Default()
 | 
					 | 
				
			||||||
	router.FuncMap["now"] = time.Now
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	templates, err := NewTemplates(router.FuncMap)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		panic(err)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	router.HTMLRender = templates
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	static, err := fs.Sub(web.Static, "static")
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		panic("couldn't open static files")
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	router.Use(enableCachingForStaticFiles())
 | 
					 | 
				
			||||||
	router.StaticFS("/static", http.FS(static))
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	router.GET("/", func(c *gin.Context) { c.HTML(http.StatusOK, "index.html", nil) })
 | 
					 | 
				
			||||||
	router.GET("/login", h.login)
 | 
					 | 
				
			||||||
	router.GET("/register", h.register)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	withLogin := router.Group("")
 | 
					 | 
				
			||||||
	withLogin.Use(h.verifyLoginWithRedirect)
 | 
					 | 
				
			||||||
	withLogin.GET("/dashboard", h.dashboard)
 | 
					 | 
				
			||||||
	withLogin.GET("/admin", h.admin)
 | 
					 | 
				
			||||||
	withLogin.GET("/admin/clear-database", h.clearDatabase)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	withBudget := router.Group("")
 | 
					 | 
				
			||||||
	withBudget.Use(h.verifyLoginWithRedirect)
 | 
					 | 
				
			||||||
	withBudget.Use(h.getImportantData)
 | 
					 | 
				
			||||||
	withBudget.GET("/budget/:budgetid", h.budgeting)
 | 
					 | 
				
			||||||
	withBudget.GET("/budget/:budgetid/:year/:month", h.budgeting)
 | 
					 | 
				
			||||||
	withBudget.GET("/budget/:budgetid/all-accounts", h.allAccounts)
 | 
					 | 
				
			||||||
	withBudget.GET("/budget/:budgetid/accounts", h.accounts)
 | 
					 | 
				
			||||||
	withBudget.GET("/budget/:budgetid/account/:accountid", h.account)
 | 
					 | 
				
			||||||
	withBudget.GET("/budget/:budgetid/settings", h.settings)
 | 
					 | 
				
			||||||
	withBudget.GET("/budget/:budgetid/settings/clear", h.clearBudget)
 | 
					 | 
				
			||||||
	withBudget.GET("/budget/:budgetid/settings/clean-negative", h.cleanNegativeBudget)
 | 
					 | 
				
			||||||
	withBudget.GET("/budget/:budgetid/transaction/:transactionid", h.transaction)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	api := router.Group("/api/v1")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	unauthenticated := api.Group("/user")
 | 
					 | 
				
			||||||
	unauthenticated.GET("/login", func(c *gin.Context) { c.Redirect(http.StatusPermanentRedirect, "/login") })
 | 
					 | 
				
			||||||
	unauthenticated.POST("/login", h.loginPost)
 | 
					 | 
				
			||||||
	unauthenticated.POST("/register", h.registerPost)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	authenticated := api.Group("")
 | 
					 | 
				
			||||||
	authenticated.Use(h.verifyLoginWithRedirect)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	user := authenticated.Group("/user")
 | 
					 | 
				
			||||||
	user.GET("/logout", logout)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	budget := authenticated.Group("/budget")
 | 
					 | 
				
			||||||
	budget.POST("/new", h.newBudget)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	transaction := authenticated.Group("/transaction")
 | 
					 | 
				
			||||||
	transaction.POST("/new", h.newTransaction)
 | 
					 | 
				
			||||||
	transaction.POST("/:transactionid", h.newTransaction)
 | 
					 | 
				
			||||||
	transaction.POST("/import/ynab", h.importYNAB)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	router.Run(":1323")
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func enableCachingForStaticFiles() gin.HandlerFunc {
 | 
					 | 
				
			||||||
	return func(c *gin.Context) {
 | 
					 | 
				
			||||||
		if strings.HasPrefix(c.Request.RequestURI, "/static/") {
 | 
					 | 
				
			||||||
			c.Header("Cache-Control", "max-age=86400")
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
							
								
								
									
										122
									
								
								http/session.go
									
									
									
									
									
								
							
							
						
						
									
										122
									
								
								http/session.go
									
									
									
									
									
								
							@@ -1,122 +0,0 @@
 | 
				
			|||||||
package http
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import (
 | 
					 | 
				
			||||||
	"context"
 | 
					 | 
				
			||||||
	"fmt"
 | 
					 | 
				
			||||||
	"net/http"
 | 
					 | 
				
			||||||
	"time"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	"git.javil.eu/jacob1123/budgeteer"
 | 
					 | 
				
			||||||
	"git.javil.eu/jacob1123/budgeteer/postgres"
 | 
					 | 
				
			||||||
	"github.com/gin-gonic/gin"
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (h *Handler) verifyLogin(c *gin.Context) (budgeteer.Token, error) {
 | 
					 | 
				
			||||||
	tokenString, err := c.Cookie(authCookie)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		return nil, fmt.Errorf("get cookie: %w", err)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	token, err := h.TokenVerifier.VerifyToken(tokenString)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		c.SetCookie(authCookie, "", -1, "", "", false, false)
 | 
					 | 
				
			||||||
		return nil, fmt.Errorf("verify token '%s': %w", tokenString, err)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	return token, nil
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (h *Handler) verifyLoginWithRedirect(c *gin.Context) {
 | 
					 | 
				
			||||||
	token, err := h.verifyLogin(c)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		c.Redirect(http.StatusTemporaryRedirect, "/login")
 | 
					 | 
				
			||||||
		c.Abort()
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	c.Set("token", token)
 | 
					 | 
				
			||||||
	c.Next()
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (h *Handler) login(c *gin.Context) {
 | 
					 | 
				
			||||||
	if _, err := h.verifyLogin(c); err == nil {
 | 
					 | 
				
			||||||
		c.Redirect(http.StatusTemporaryRedirect, "/dashboard")
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	c.HTML(http.StatusOK, "login.html", nil)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (h *Handler) register(c *gin.Context) {
 | 
					 | 
				
			||||||
	if _, err := h.verifyLogin(c); err == nil {
 | 
					 | 
				
			||||||
		c.Redirect(http.StatusTemporaryRedirect, "/dashboard")
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	c.HTML(http.StatusOK, "register.html", nil)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func logout(c *gin.Context) {
 | 
					 | 
				
			||||||
	clearLogin(c)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func clearLogin(c *gin.Context) {
 | 
					 | 
				
			||||||
	c.SetCookie(authCookie, "", -1, "", "", false, true)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (h *Handler) loginPost(c *gin.Context) {
 | 
					 | 
				
			||||||
	username, _ := c.GetPostForm("username")
 | 
					 | 
				
			||||||
	password, _ := c.GetPostForm("password")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	user, err := h.Service.GetUserByUsername(c.Request.Context(), username)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		c.AbortWithError(http.StatusUnauthorized, err)
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if err = h.CredentialsVerifier.Verify(password, user.Password); err != nil {
 | 
					 | 
				
			||||||
		c.AbortWithError(http.StatusUnauthorized, err)
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	t, err := h.TokenVerifier.CreateToken(&user)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		c.AbortWithError(http.StatusUnauthorized, err)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	go h.Service.UpdateLastLogin(context.Background(), user.ID)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	maxAge := (int)((expiration * time.Hour).Seconds())
 | 
					 | 
				
			||||||
	c.SetCookie(authCookie, t, maxAge, "", "", false, true)
 | 
					 | 
				
			||||||
	c.JSON(http.StatusOK, map[string]string{
 | 
					 | 
				
			||||||
		"token": t,
 | 
					 | 
				
			||||||
	})
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (h *Handler) registerPost(c *gin.Context) {
 | 
					 | 
				
			||||||
	email, _ := c.GetPostForm("email")
 | 
					 | 
				
			||||||
	password, _ := c.GetPostForm("password")
 | 
					 | 
				
			||||||
	name, _ := c.GetPostForm("name")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	_, err := h.Service.GetUserByUsername(c.Request.Context(), email)
 | 
					 | 
				
			||||||
	if err == nil {
 | 
					 | 
				
			||||||
		c.AbortWithStatus(http.StatusUnauthorized)
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	hash, err := h.CredentialsVerifier.Hash(password)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		c.AbortWithError(http.StatusUnauthorized, err)
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	createUser := postgres.CreateUserParams{
 | 
					 | 
				
			||||||
		Name:     name,
 | 
					 | 
				
			||||||
		Password: hash,
 | 
					 | 
				
			||||||
		Email:    email,
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	_, err = h.Service.CreateUser(c.Request.Context(), createUser)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		c.AbortWithError(http.StatusInternalServerError, err)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,45 +0,0 @@
 | 
				
			|||||||
package http
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import (
 | 
					 | 
				
			||||||
	"fmt"
 | 
					 | 
				
			||||||
	"html/template"
 | 
					 | 
				
			||||||
	"io/fs"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	"git.javil.eu/jacob1123/budgeteer/web"
 | 
					 | 
				
			||||||
	"github.com/gin-gonic/gin/render"
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type Templates struct {
 | 
					 | 
				
			||||||
	templates map[string]*template.Template
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func NewTemplates(funcMap template.FuncMap) (*Templates, error) {
 | 
					 | 
				
			||||||
	templates, err := fs.Glob(web.Templates, "*.tpl")
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		return nil, fmt.Errorf("glob: %w", err)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	result := &Templates{
 | 
					 | 
				
			||||||
		templates: make(map[string]*template.Template, 0),
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	pages, err := fs.Glob(web.Templates, "*.html")
 | 
					 | 
				
			||||||
	for _, page := range pages {
 | 
					 | 
				
			||||||
		allTemplates := append(templates, page)
 | 
					 | 
				
			||||||
		tpl, err := template.New(page).Funcs(funcMap).ParseFS(web.Templates, allTemplates...)
 | 
					 | 
				
			||||||
		fmt.Printf("page: %s, templates: %v\n", page, templates)
 | 
					 | 
				
			||||||
		if err != nil {
 | 
					 | 
				
			||||||
			return nil, err
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		result.templates[page] = tpl
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	return result, nil
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (tpl *Templates) Instance(name string, obj interface{}) render.Render {
 | 
					 | 
				
			||||||
	return render.HTML{
 | 
					 | 
				
			||||||
		Template: tpl.templates[name],
 | 
					 | 
				
			||||||
		Name:     name,
 | 
					 | 
				
			||||||
		Data:     obj,
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,62 +0,0 @@
 | 
				
			|||||||
package http
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import (
 | 
					 | 
				
			||||||
	"net/http"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	"git.javil.eu/jacob1123/budgeteer/postgres"
 | 
					 | 
				
			||||||
	"github.com/gin-gonic/gin"
 | 
					 | 
				
			||||||
	"github.com/google/uuid"
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type TransactionData struct {
 | 
					 | 
				
			||||||
	AlwaysNeededData
 | 
					 | 
				
			||||||
	Transaction *postgres.Transaction
 | 
					 | 
				
			||||||
	Account     *postgres.Account
 | 
					 | 
				
			||||||
	Categories  []postgres.GetCategoriesRow
 | 
					 | 
				
			||||||
	Payees      []postgres.Payee
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (h *Handler) transaction(c *gin.Context) {
 | 
					 | 
				
			||||||
	data := c.MustGet("data").(AlwaysNeededData)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	transactionID := c.Param("transactionid")
 | 
					 | 
				
			||||||
	transactionUUID, err := uuid.Parse(transactionID)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		c.Redirect(http.StatusTemporaryRedirect, "/login")
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	transaction, err := h.Service.GetTransaction(c.Request.Context(), transactionUUID)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		c.AbortWithError(http.StatusNotFound, err)
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	account, err := h.Service.GetAccount(c.Request.Context(), transaction.AccountID)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		c.AbortWithError(http.StatusNotFound, err)
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	categories, err := h.Service.GetCategories(c.Request.Context(), data.Budget.ID)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		c.AbortWithError(http.StatusNotFound, err)
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	payees, err := h.Service.GetPayees(c.Request.Context(), data.Budget.ID)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		c.AbortWithError(http.StatusNotFound, err)
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	d := TransactionData{
 | 
					 | 
				
			||||||
		data,
 | 
					 | 
				
			||||||
		&transaction,
 | 
					 | 
				
			||||||
		&account,
 | 
					 | 
				
			||||||
		categories,
 | 
					 | 
				
			||||||
		payees,
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	c.HTML(http.StatusOK, "transaction.html", d)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,98 +0,0 @@
 | 
				
			|||||||
package http
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import (
 | 
					 | 
				
			||||||
	"fmt"
 | 
					 | 
				
			||||||
	"net/http"
 | 
					 | 
				
			||||||
	"time"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	"git.javil.eu/jacob1123/budgeteer/postgres"
 | 
					 | 
				
			||||||
	"github.com/gin-gonic/gin"
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (h *Handler) newTransaction(c *gin.Context) {
 | 
					 | 
				
			||||||
	transactionMemo, _ := c.GetPostForm("memo")
 | 
					 | 
				
			||||||
	transactionAccountID, err := getUUID(c, "account_id")
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		c.AbortWithError(http.StatusNotAcceptable, fmt.Errorf("account_id: %w", err))
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	transactionCategoryID, err := getNullUUIDFromForm(c, "category_id")
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		c.AbortWithError(http.StatusNotAcceptable, fmt.Errorf("category_id: %w", err))
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	transactionPayeeID, err := getNullUUIDFromForm(c, "payee_id")
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		c.AbortWithError(http.StatusNotAcceptable, fmt.Errorf("payee_id: %w", err))
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	transactionDate, succ := c.GetPostForm("date")
 | 
					 | 
				
			||||||
	if !succ {
 | 
					 | 
				
			||||||
		c.AbortWithError(http.StatusNotAcceptable, fmt.Errorf("date missing"))
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	transactionDateValue, err := time.Parse("2006-01-02", transactionDate)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		c.AbortWithError(http.StatusNotAcceptable, fmt.Errorf("date is not a valid date"))
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	transactionAmount, succ := c.GetPostForm("amount")
 | 
					 | 
				
			||||||
	if !succ {
 | 
					 | 
				
			||||||
		c.AbortWithError(http.StatusNotAcceptable, fmt.Errorf("amount missing"))
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	amount := postgres.Numeric{}
 | 
					 | 
				
			||||||
	amount.Set(transactionAmount)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	transactionUUID, err := getNullUUIDFromParam(c, "transactionid")
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("parse transaction id: %w", err))
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if !transactionUUID.Valid {
 | 
					 | 
				
			||||||
		new := postgres.CreateTransactionParams{
 | 
					 | 
				
			||||||
			Memo:       transactionMemo,
 | 
					 | 
				
			||||||
			Date:       transactionDateValue,
 | 
					 | 
				
			||||||
			Amount:     amount,
 | 
					 | 
				
			||||||
			AccountID:  transactionAccountID,
 | 
					 | 
				
			||||||
			PayeeID:    transactionPayeeID,
 | 
					 | 
				
			||||||
			CategoryID: transactionCategoryID,
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		_, err = h.Service.CreateTransaction(c.Request.Context(), new)
 | 
					 | 
				
			||||||
		if err != nil {
 | 
					 | 
				
			||||||
			c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("create transaction: %w", err))
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	_, delete := c.GetPostForm("delete")
 | 
					 | 
				
			||||||
	if delete {
 | 
					 | 
				
			||||||
		err = h.Service.DeleteTransaction(c.Request.Context(), transactionUUID.UUID)
 | 
					 | 
				
			||||||
		if err != nil {
 | 
					 | 
				
			||||||
			c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("delete transaction: %w", err))
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	update := postgres.UpdateTransactionParams{
 | 
					 | 
				
			||||||
		ID:         transactionUUID.UUID,
 | 
					 | 
				
			||||||
		Memo:       transactionMemo,
 | 
					 | 
				
			||||||
		Date:       transactionDateValue,
 | 
					 | 
				
			||||||
		Amount:     amount,
 | 
					 | 
				
			||||||
		AccountID:  transactionAccountID,
 | 
					 | 
				
			||||||
		PayeeID:    transactionPayeeID,
 | 
					 | 
				
			||||||
		CategoryID: transactionCategoryID,
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	err = h.Service.UpdateTransaction(c.Request.Context(), update)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("update transaction: %w", err))
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
							
								
								
									
										56
									
								
								http/util.go
									
									
									
									
									
								
							
							
						
						
									
										56
									
								
								http/util.go
									
									
									
									
									
								
							@@ -1,56 +0,0 @@
 | 
				
			|||||||
package http
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import (
 | 
					 | 
				
			||||||
	"fmt"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	"github.com/gin-gonic/gin"
 | 
					 | 
				
			||||||
	"github.com/google/uuid"
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func getUUID(c *gin.Context, name string) (uuid.UUID, error) {
 | 
					 | 
				
			||||||
	value, succ := c.GetPostForm(name)
 | 
					 | 
				
			||||||
	if !succ {
 | 
					 | 
				
			||||||
		return uuid.UUID{}, fmt.Errorf("not set")
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	id, err := uuid.Parse(value)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		return uuid.UUID{}, fmt.Errorf("not a valid uuid: %w", err)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	return id, nil
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func getNullUUIDFromParam(c *gin.Context, name string) (uuid.NullUUID, error) {
 | 
					 | 
				
			||||||
	value := c.Param(name)
 | 
					 | 
				
			||||||
	if value == "" {
 | 
					 | 
				
			||||||
		return uuid.NullUUID{}, nil
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	id, err := uuid.Parse(value)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		return uuid.NullUUID{}, fmt.Errorf("not a valid uuid: %w", err)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	return uuid.NullUUID{
 | 
					 | 
				
			||||||
		UUID:  id,
 | 
					 | 
				
			||||||
		Valid: true,
 | 
					 | 
				
			||||||
	}, nil
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func getNullUUIDFromForm(c *gin.Context, name string) (uuid.NullUUID, error) {
 | 
					 | 
				
			||||||
	value, succ := c.GetPostForm(name)
 | 
					 | 
				
			||||||
	if !succ || value == "" {
 | 
					 | 
				
			||||||
		return uuid.NullUUID{}, nil
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	id, err := uuid.Parse(value)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		return uuid.NullUUID{}, fmt.Errorf("not a valid uuid: %w", err)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	return uuid.NullUUID{
 | 
					 | 
				
			||||||
		UUID:  id,
 | 
					 | 
				
			||||||
		Valid: true,
 | 
					 | 
				
			||||||
	}, nil
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,66 +0,0 @@
 | 
				
			|||||||
package http
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import (
 | 
					 | 
				
			||||||
	"fmt"
 | 
					 | 
				
			||||||
	"net/http"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	"git.javil.eu/jacob1123/budgeteer/postgres"
 | 
					 | 
				
			||||||
	"github.com/gin-gonic/gin"
 | 
					 | 
				
			||||||
	"github.com/google/uuid"
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (h *Handler) importYNAB(c *gin.Context) {
 | 
					 | 
				
			||||||
	budgetID, succ := c.GetPostForm("budget_id")
 | 
					 | 
				
			||||||
	if !succ {
 | 
					 | 
				
			||||||
		c.AbortWithError(http.StatusBadRequest, fmt.Errorf("no budget_id specified"))
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	budgetUUID, err := uuid.Parse(budgetID)
 | 
					 | 
				
			||||||
	if !succ {
 | 
					 | 
				
			||||||
		c.AbortWithError(http.StatusBadRequest, err)
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	ynab, err := postgres.NewYNABImport(c.Request.Context(), h.Service.Queries, budgetUUID)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		c.AbortWithError(http.StatusInternalServerError, err)
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	transactionsFile, err := c.FormFile("transactions")
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		c.AbortWithError(http.StatusInternalServerError, err)
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	transactions, err := transactionsFile.Open()
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		c.AbortWithError(http.StatusInternalServerError, err)
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	err = ynab.ImportTransactions(transactions)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		c.AbortWithError(http.StatusInternalServerError, err)
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	assignmentsFile, err := c.FormFile("assignments")
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		c.AbortWithError(http.StatusInternalServerError, err)
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	assignments, err := assignmentsFile.Open()
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		c.AbortWithError(http.StatusInternalServerError, err)
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	err = ynab.ImportAssignments(assignments)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		c.AbortWithError(http.StatusInternalServerError, err)
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
							
								
								
									
										105
									
								
								jwt/login.go
									
									
									
									
									
								
							
							
						
						
									
										105
									
								
								jwt/login.go
									
									
									
									
									
								
							@@ -1,105 +0,0 @@
 | 
				
			|||||||
package jwt
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import (
 | 
					 | 
				
			||||||
	"fmt"
 | 
					 | 
				
			||||||
	"time"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	"git.javil.eu/jacob1123/budgeteer"
 | 
					 | 
				
			||||||
	"git.javil.eu/jacob1123/budgeteer/postgres"
 | 
					 | 
				
			||||||
	"github.com/dgrijalva/jwt-go"
 | 
					 | 
				
			||||||
	"github.com/google/uuid"
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// TokenVerifier verifies Tokens
 | 
					 | 
				
			||||||
type TokenVerifier struct {
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// Token contains everything to authenticate a user
 | 
					 | 
				
			||||||
type Token struct {
 | 
					 | 
				
			||||||
	username string
 | 
					 | 
				
			||||||
	name     string
 | 
					 | 
				
			||||||
	expiry   float64
 | 
					 | 
				
			||||||
	id       uuid.UUID
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
const (
 | 
					 | 
				
			||||||
	expiration = 72
 | 
					 | 
				
			||||||
	secret     = "uditapbzuditagscwxuqdflgzpbu´ßiaefnlmzeßtrubiadern"
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// CreateToken creates a new token from username and name
 | 
					 | 
				
			||||||
func (tv *TokenVerifier) CreateToken(user *postgres.User) (string, error) {
 | 
					 | 
				
			||||||
	token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{
 | 
					 | 
				
			||||||
		"usr":  user.Email,
 | 
					 | 
				
			||||||
		"name": user.Name,
 | 
					 | 
				
			||||||
		"exp":  time.Now().Add(time.Hour * expiration).Unix(),
 | 
					 | 
				
			||||||
		"id":   user.ID,
 | 
					 | 
				
			||||||
	})
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// Generate encoded token and send it as response.
 | 
					 | 
				
			||||||
	t, err := token.SignedString([]byte(secret))
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		return "", err
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	return t, nil
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// VerifyToken verifys a given string-token
 | 
					 | 
				
			||||||
func (tv *TokenVerifier) VerifyToken(tokenString string) (budgeteer.Token, error) {
 | 
					 | 
				
			||||||
	token, err := jwt.Parse(tokenString, func(token *jwt.Token) (interface{}, error) {
 | 
					 | 
				
			||||||
		if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok {
 | 
					 | 
				
			||||||
			return nil, fmt.Errorf("Unexpected signing method: %v", token.Header["alg"])
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		return []byte(secret), nil
 | 
					 | 
				
			||||||
	})
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		return nil, fmt.Errorf("parse jwt: %w", err)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	claims, err := verifyToken(token)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		return nil, fmt.Errorf("verify jwt: %w", err)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	tkn := &Token{
 | 
					 | 
				
			||||||
		username: claims["usr"].(string),
 | 
					 | 
				
			||||||
		name:     claims["name"].(string),
 | 
					 | 
				
			||||||
		expiry:   claims["exp"].(float64),
 | 
					 | 
				
			||||||
		id:       uuid.MustParse(claims["id"].(string)),
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return tkn, nil
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func verifyToken(token *jwt.Token) (jwt.MapClaims, error) {
 | 
					 | 
				
			||||||
	if !token.Valid {
 | 
					 | 
				
			||||||
		return nil, fmt.Errorf("Token is not valid")
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	claims, ok := token.Claims.(jwt.MapClaims)
 | 
					 | 
				
			||||||
	if !ok {
 | 
					 | 
				
			||||||
		return nil, fmt.Errorf("Claims are not of Type MapClaims")
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if !claims.VerifyExpiresAt(time.Now().Unix(), true) {
 | 
					 | 
				
			||||||
		return nil, fmt.Errorf("Claims have expired")
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	return claims, nil
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (t *Token) GetName() string {
 | 
					 | 
				
			||||||
	return t.name
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (t *Token) GetUsername() string {
 | 
					 | 
				
			||||||
	return t.username
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (t *Token) GetExpiry() float64 {
 | 
					 | 
				
			||||||
	return t.expiry
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (t *Token) GetID() uuid.UUID {
 | 
					 | 
				
			||||||
	return t.id
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
							
								
								
									
										89
									
								
								jwt/token-verifier.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										89
									
								
								jwt/token-verifier.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,89 @@
 | 
				
			|||||||
 | 
					package jwt
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"git.javil.eu/jacob1123/budgeteer"
 | 
				
			||||||
 | 
						"git.javil.eu/jacob1123/budgeteer/postgres"
 | 
				
			||||||
 | 
						"github.com/dgrijalva/jwt-go"
 | 
				
			||||||
 | 
						"github.com/google/uuid"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// TokenVerifier verifies Tokens.
 | 
				
			||||||
 | 
					type TokenVerifier struct {
 | 
				
			||||||
 | 
						Expiration time.Duration
 | 
				
			||||||
 | 
						secret     string
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const DefaultExpiration = time.Hour * time.Duration(72)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func NewTokenVerifier(secret string) (*TokenVerifier, error) {
 | 
				
			||||||
 | 
						if secret == "" {
 | 
				
			||||||
 | 
							return nil, ErrEmptySecret
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return &TokenVerifier{
 | 
				
			||||||
 | 
							Expiration: DefaultExpiration,
 | 
				
			||||||
 | 
							secret:     secret,
 | 
				
			||||||
 | 
						}, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var (
 | 
				
			||||||
 | 
						ErrUnexpectedSigningMethod = fmt.Errorf("unexpected signing method")
 | 
				
			||||||
 | 
						ErrInvalidToken            = fmt.Errorf("token is invalid")
 | 
				
			||||||
 | 
						ErrTokenExpired            = fmt.Errorf("token has expired")
 | 
				
			||||||
 | 
						ErrEmptySecret             = fmt.Errorf("secret is required")
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// CreateToken creates a new token from username and name.
 | 
				
			||||||
 | 
					func (tv *TokenVerifier) CreateToken(user *postgres.User) (string, error) {
 | 
				
			||||||
 | 
						if tv.secret == "" {
 | 
				
			||||||
 | 
							return "", ErrEmptySecret
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{
 | 
				
			||||||
 | 
							"usr":  user.Email,
 | 
				
			||||||
 | 
							"name": user.Name,
 | 
				
			||||||
 | 
							"exp":  time.Now().Add(tv.Expiration).Unix(),
 | 
				
			||||||
 | 
							"id":   user.ID,
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Generate encoded token and send it as response.
 | 
				
			||||||
 | 
						t, err := token.SignedString([]byte(tv.secret))
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return "", fmt.Errorf("create token: %w", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return t, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// VerifyToken verifies a given string-token.
 | 
				
			||||||
 | 
					func (tv *TokenVerifier) VerifyToken(tokenString string) (budgeteer.Token, error) { //nolint:ireturn
 | 
				
			||||||
 | 
						if tv.secret == "" {
 | 
				
			||||||
 | 
							return nil, ErrEmptySecret
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						token, err := jwt.Parse(tokenString, func(token *jwt.Token) (interface{}, error) {
 | 
				
			||||||
 | 
							if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok {
 | 
				
			||||||
 | 
								return nil, fmt.Errorf("method '%v': %w", token.Header["alg"], ErrUnexpectedSigningMethod)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							return []byte(tv.secret), nil
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, fmt.Errorf("parse jwt: %w", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						claims, err := verifyToken(token)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, fmt.Errorf("verify jwt: %w", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						tkn := &Token{ //nolint:forcetypeassert
 | 
				
			||||||
 | 
							username: claims["usr"].(string),
 | 
				
			||||||
 | 
							name:     claims["name"].(string),
 | 
				
			||||||
 | 
							expiry:   claims["exp"].(float64),
 | 
				
			||||||
 | 
							id:       uuid.MustParse(claims["id"].(string)),
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return tkn, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										49
									
								
								jwt/token.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										49
									
								
								jwt/token.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,49 @@
 | 
				
			|||||||
 | 
					package jwt
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/dgrijalva/jwt-go"
 | 
				
			||||||
 | 
						"github.com/google/uuid"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Token contains everything to authenticate a user.
 | 
				
			||||||
 | 
					type Token struct {
 | 
				
			||||||
 | 
						username string
 | 
				
			||||||
 | 
						name     string
 | 
				
			||||||
 | 
						expiry   float64
 | 
				
			||||||
 | 
						id       uuid.UUID
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func verifyToken(token *jwt.Token) (jwt.MapClaims, error) {
 | 
				
			||||||
 | 
						if !token.Valid {
 | 
				
			||||||
 | 
							return nil, ErrInvalidToken
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						claims, ok := token.Claims.(jwt.MapClaims)
 | 
				
			||||||
 | 
						if !ok {
 | 
				
			||||||
 | 
							return nil, ErrInvalidToken
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if !claims.VerifyExpiresAt(time.Now().Unix(), true) {
 | 
				
			||||||
 | 
							return nil, ErrTokenExpired
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return claims, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (t *Token) GetName() string {
 | 
				
			||||||
 | 
						return t.name
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (t *Token) GetUsername() string {
 | 
				
			||||||
 | 
						return t.username
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (t *Token) GetExpiry() float64 {
 | 
				
			||||||
 | 
						return t.expiry
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (t *Token) GetID() uuid.UUID {
 | 
				
			||||||
 | 
						return t.id
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -1,11 +1,15 @@
 | 
				
			|||||||
// Code generated by sqlc. DO NOT EDIT.
 | 
					// Code generated by sqlc. DO NOT EDIT.
 | 
				
			||||||
 | 
					// versions:
 | 
				
			||||||
 | 
					//   sqlc v1.13.0
 | 
				
			||||||
// source: accounts.sql
 | 
					// source: accounts.sql
 | 
				
			||||||
 | 
					
 | 
				
			||||||
package postgres
 | 
					package postgres
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"context"
 | 
						"context"
 | 
				
			||||||
 | 
						"database/sql"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"git.javil.eu/jacob1123/budgeteer/postgres/numeric"
 | 
				
			||||||
	"github.com/google/uuid"
 | 
						"github.com/google/uuid"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -13,7 +17,7 @@ const createAccount = `-- name: CreateAccount :one
 | 
				
			|||||||
INSERT INTO accounts
 | 
					INSERT INTO accounts
 | 
				
			||||||
(name, budget_id)
 | 
					(name, budget_id)
 | 
				
			||||||
VALUES ($1, $2)
 | 
					VALUES ($1, $2)
 | 
				
			||||||
RETURNING id, budget_id, name, on_budget
 | 
					RETURNING id, budget_id, name, on_budget, is_open, last_reconciled
 | 
				
			||||||
`
 | 
					`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type CreateAccountParams struct {
 | 
					type CreateAccountParams struct {
 | 
				
			||||||
@@ -29,12 +33,14 @@ func (q *Queries) CreateAccount(ctx context.Context, arg CreateAccountParams) (A
 | 
				
			|||||||
		&i.BudgetID,
 | 
							&i.BudgetID,
 | 
				
			||||||
		&i.Name,
 | 
							&i.Name,
 | 
				
			||||||
		&i.OnBudget,
 | 
							&i.OnBudget,
 | 
				
			||||||
 | 
							&i.IsOpen,
 | 
				
			||||||
 | 
							&i.LastReconciled,
 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
	return i, err
 | 
						return i, err
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const getAccount = `-- name: GetAccount :one
 | 
					const getAccount = `-- name: GetAccount :one
 | 
				
			||||||
SELECT accounts.id, accounts.budget_id, accounts.name, accounts.on_budget FROM accounts
 | 
					SELECT accounts.id, accounts.budget_id, accounts.name, accounts.on_budget, accounts.is_open, accounts.last_reconciled FROM accounts
 | 
				
			||||||
WHERE accounts.id = $1
 | 
					WHERE accounts.id = $1
 | 
				
			||||||
`
 | 
					`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -46,13 +52,16 @@ func (q *Queries) GetAccount(ctx context.Context, id uuid.UUID) (Account, error)
 | 
				
			|||||||
		&i.BudgetID,
 | 
							&i.BudgetID,
 | 
				
			||||||
		&i.Name,
 | 
							&i.Name,
 | 
				
			||||||
		&i.OnBudget,
 | 
							&i.OnBudget,
 | 
				
			||||||
 | 
							&i.IsOpen,
 | 
				
			||||||
 | 
							&i.LastReconciled,
 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
	return i, err
 | 
						return i, err
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const getAccounts = `-- name: GetAccounts :many
 | 
					const getAccounts = `-- name: GetAccounts :many
 | 
				
			||||||
SELECT accounts.id, accounts.budget_id, accounts.name, accounts.on_budget FROM accounts
 | 
					SELECT accounts.id, accounts.budget_id, accounts.name, accounts.on_budget, accounts.is_open, accounts.last_reconciled FROM accounts
 | 
				
			||||||
WHERE accounts.budget_id = $1
 | 
					WHERE accounts.budget_id = $1
 | 
				
			||||||
 | 
					AND accounts.is_open = TRUE
 | 
				
			||||||
ORDER BY accounts.name
 | 
					ORDER BY accounts.name
 | 
				
			||||||
`
 | 
					`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -70,6 +79,8 @@ func (q *Queries) GetAccounts(ctx context.Context, budgetID uuid.UUID) ([]Accoun
 | 
				
			|||||||
			&i.BudgetID,
 | 
								&i.BudgetID,
 | 
				
			||||||
			&i.Name,
 | 
								&i.Name,
 | 
				
			||||||
			&i.OnBudget,
 | 
								&i.OnBudget,
 | 
				
			||||||
 | 
								&i.IsOpen,
 | 
				
			||||||
 | 
								&i.LastReconciled,
 | 
				
			||||||
		); err != nil {
 | 
							); err != nil {
 | 
				
			||||||
			return nil, err
 | 
								return nil, err
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@@ -85,12 +96,13 @@ func (q *Queries) GetAccounts(ctx context.Context, budgetID uuid.UUID) ([]Accoun
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const getAccountsWithBalance = `-- name: GetAccountsWithBalance :many
 | 
					const getAccountsWithBalance = `-- name: GetAccountsWithBalance :many
 | 
				
			||||||
SELECT accounts.id, accounts.name, accounts.on_budget, SUM(transactions.amount)::decimal(12,2) as balance
 | 
					SELECT accounts.id, accounts.name, accounts.on_budget, accounts.is_open, accounts.last_reconciled,
 | 
				
			||||||
 | 
					        (SELECT SUM(transactions.amount) FROM transactions WHERE transactions.account_id = accounts.id AND transactions.date < NOW())::decimal(12,2) as working_balance,
 | 
				
			||||||
 | 
					        (SELECT SUM(transactions.amount) FROM transactions WHERE transactions.account_id = accounts.id AND transactions.date < NOW() AND transactions.status IN ('Cleared', 'Reconciled'))::decimal(12,2) as cleared_balance,
 | 
				
			||||||
 | 
					        (SELECT SUM(transactions.amount) FROM transactions WHERE transactions.account_id = accounts.id AND transactions.date < NOW() AND transactions.status = 'Reconciled')::decimal(12,2) as reconciled_balance
 | 
				
			||||||
FROM accounts
 | 
					FROM accounts
 | 
				
			||||||
LEFT JOIN transactions ON transactions.account_id = accounts.id
 | 
					 | 
				
			||||||
WHERE accounts.budget_id = $1
 | 
					WHERE accounts.budget_id = $1
 | 
				
			||||||
AND transactions.date < NOW()
 | 
					AND accounts.is_open = TRUE
 | 
				
			||||||
GROUP BY accounts.id, accounts.name
 | 
					 | 
				
			||||||
ORDER BY accounts.name
 | 
					ORDER BY accounts.name
 | 
				
			||||||
`
 | 
					`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -98,7 +110,11 @@ type GetAccountsWithBalanceRow struct {
 | 
				
			|||||||
	ID                uuid.UUID
 | 
						ID                uuid.UUID
 | 
				
			||||||
	Name              string
 | 
						Name              string
 | 
				
			||||||
	OnBudget          bool
 | 
						OnBudget          bool
 | 
				
			||||||
	Balance  Numeric
 | 
						IsOpen            bool
 | 
				
			||||||
 | 
						LastReconciled    sql.NullTime
 | 
				
			||||||
 | 
						WorkingBalance    numeric.Numeric
 | 
				
			||||||
 | 
						ClearedBalance    numeric.Numeric
 | 
				
			||||||
 | 
						ReconciledBalance numeric.Numeric
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (q *Queries) GetAccountsWithBalance(ctx context.Context, budgetID uuid.UUID) ([]GetAccountsWithBalanceRow, error) {
 | 
					func (q *Queries) GetAccountsWithBalance(ctx context.Context, budgetID uuid.UUID) ([]GetAccountsWithBalanceRow, error) {
 | 
				
			||||||
@@ -114,7 +130,11 @@ func (q *Queries) GetAccountsWithBalance(ctx context.Context, budgetID uuid.UUID
 | 
				
			|||||||
			&i.ID,
 | 
								&i.ID,
 | 
				
			||||||
			&i.Name,
 | 
								&i.Name,
 | 
				
			||||||
			&i.OnBudget,
 | 
								&i.OnBudget,
 | 
				
			||||||
			&i.Balance,
 | 
								&i.IsOpen,
 | 
				
			||||||
 | 
								&i.LastReconciled,
 | 
				
			||||||
 | 
								&i.WorkingBalance,
 | 
				
			||||||
 | 
								&i.ClearedBalance,
 | 
				
			||||||
 | 
								&i.ReconciledBalance,
 | 
				
			||||||
		); err != nil {
 | 
							); err != nil {
 | 
				
			||||||
			return nil, err
 | 
								return nil, err
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@@ -128,3 +148,97 @@ func (q *Queries) GetAccountsWithBalance(ctx context.Context, budgetID uuid.UUID
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
	return items, nil
 | 
						return items, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const searchAccounts = `-- name: SearchAccounts :many
 | 
				
			||||||
 | 
					SELECT accounts.id, accounts.budget_id, accounts.name, 'account' as type FROM accounts
 | 
				
			||||||
 | 
					WHERE accounts.budget_id = $1
 | 
				
			||||||
 | 
					AND accounts.is_open = TRUE
 | 
				
			||||||
 | 
					AND accounts.name ILIKE $2
 | 
				
			||||||
 | 
					ORDER BY accounts.name
 | 
				
			||||||
 | 
					`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type SearchAccountsParams struct {
 | 
				
			||||||
 | 
						BudgetID uuid.UUID
 | 
				
			||||||
 | 
						Search   string
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type SearchAccountsRow struct {
 | 
				
			||||||
 | 
						ID       uuid.UUID
 | 
				
			||||||
 | 
						BudgetID uuid.UUID
 | 
				
			||||||
 | 
						Name     string
 | 
				
			||||||
 | 
						Type     interface{}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (q *Queries) SearchAccounts(ctx context.Context, arg SearchAccountsParams) ([]SearchAccountsRow, error) {
 | 
				
			||||||
 | 
						rows, err := q.db.QueryContext(ctx, searchAccounts, arg.BudgetID, arg.Search)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						defer rows.Close()
 | 
				
			||||||
 | 
						var items []SearchAccountsRow
 | 
				
			||||||
 | 
						for rows.Next() {
 | 
				
			||||||
 | 
							var i SearchAccountsRow
 | 
				
			||||||
 | 
							if err := rows.Scan(
 | 
				
			||||||
 | 
								&i.ID,
 | 
				
			||||||
 | 
								&i.BudgetID,
 | 
				
			||||||
 | 
								&i.Name,
 | 
				
			||||||
 | 
								&i.Type,
 | 
				
			||||||
 | 
							); err != nil {
 | 
				
			||||||
 | 
								return nil, err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							items = append(items, i)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if err := rows.Close(); err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if err := rows.Err(); err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return items, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const setLastReconciled = `-- name: SetLastReconciled :exec
 | 
				
			||||||
 | 
					UPDATE accounts
 | 
				
			||||||
 | 
					SET last_reconciled = NOW()
 | 
				
			||||||
 | 
					WHERE accounts.id = $1
 | 
				
			||||||
 | 
					`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (q *Queries) SetLastReconciled(ctx context.Context, id uuid.UUID) error {
 | 
				
			||||||
 | 
						_, err := q.db.ExecContext(ctx, setLastReconciled, id)
 | 
				
			||||||
 | 
						return err
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const updateAccount = `-- name: UpdateAccount :one
 | 
				
			||||||
 | 
					UPDATE accounts
 | 
				
			||||||
 | 
					SET name = $1,
 | 
				
			||||||
 | 
					    on_budget = $2,
 | 
				
			||||||
 | 
					    is_open = $3
 | 
				
			||||||
 | 
					WHERE accounts.id = $4
 | 
				
			||||||
 | 
					RETURNING id, budget_id, name, on_budget, is_open, last_reconciled
 | 
				
			||||||
 | 
					`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type UpdateAccountParams struct {
 | 
				
			||||||
 | 
						Name     string
 | 
				
			||||||
 | 
						OnBudget bool
 | 
				
			||||||
 | 
						IsOpen   bool
 | 
				
			||||||
 | 
						ID       uuid.UUID
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (q *Queries) UpdateAccount(ctx context.Context, arg UpdateAccountParams) (Account, error) {
 | 
				
			||||||
 | 
						row := q.db.QueryRowContext(ctx, updateAccount,
 | 
				
			||||||
 | 
							arg.Name,
 | 
				
			||||||
 | 
							arg.OnBudget,
 | 
				
			||||||
 | 
							arg.IsOpen,
 | 
				
			||||||
 | 
							arg.ID,
 | 
				
			||||||
 | 
						)
 | 
				
			||||||
 | 
						var i Account
 | 
				
			||||||
 | 
						err := row.Scan(
 | 
				
			||||||
 | 
							&i.ID,
 | 
				
			||||||
 | 
							&i.BudgetID,
 | 
				
			||||||
 | 
							&i.Name,
 | 
				
			||||||
 | 
							&i.OnBudget,
 | 
				
			||||||
 | 
							&i.IsOpen,
 | 
				
			||||||
 | 
							&i.LastReconciled,
 | 
				
			||||||
 | 
						)
 | 
				
			||||||
 | 
						return i, err
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,4 +1,6 @@
 | 
				
			|||||||
// Code generated by sqlc. DO NOT EDIT.
 | 
					// Code generated by sqlc. DO NOT EDIT.
 | 
				
			||||||
 | 
					// versions:
 | 
				
			||||||
 | 
					//   sqlc v1.13.0
 | 
				
			||||||
// source: assignments.sql
 | 
					// source: assignments.sql
 | 
				
			||||||
 | 
					
 | 
				
			||||||
package postgres
 | 
					package postgres
 | 
				
			||||||
@@ -7,6 +9,7 @@ import (
 | 
				
			|||||||
	"context"
 | 
						"context"
 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"git.javil.eu/jacob1123/budgeteer/postgres/numeric"
 | 
				
			||||||
	"github.com/google/uuid"
 | 
						"github.com/google/uuid"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -16,12 +19,12 @@ INSERT INTO assignments (
 | 
				
			|||||||
) VALUES (
 | 
					) VALUES (
 | 
				
			||||||
        $1, $2, $3
 | 
					        $1, $2, $3
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
RETURNING id, category_id, date, memo, amount
 | 
					RETURNING category_id, date, memo, amount
 | 
				
			||||||
`
 | 
					`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type CreateAssignmentParams struct {
 | 
					type CreateAssignmentParams struct {
 | 
				
			||||||
	Date       time.Time
 | 
						Date       time.Time
 | 
				
			||||||
	Amount     Numeric
 | 
						Amount     numeric.Numeric
 | 
				
			||||||
	CategoryID uuid.UUID
 | 
						CategoryID uuid.UUID
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -29,7 +32,6 @@ func (q *Queries) CreateAssignment(ctx context.Context, arg CreateAssignmentPara
 | 
				
			|||||||
	row := q.db.QueryRowContext(ctx, createAssignment, arg.Date, arg.Amount, arg.CategoryID)
 | 
						row := q.db.QueryRowContext(ctx, createAssignment, arg.Date, arg.Amount, arg.CategoryID)
 | 
				
			||||||
	var i Assignment
 | 
						var i Assignment
 | 
				
			||||||
	err := row.Scan(
 | 
						err := row.Scan(
 | 
				
			||||||
		&i.ID,
 | 
					 | 
				
			||||||
		&i.CategoryID,
 | 
							&i.CategoryID,
 | 
				
			||||||
		&i.Date,
 | 
							&i.Date,
 | 
				
			||||||
		&i.Memo,
 | 
							&i.Memo,
 | 
				
			||||||
@@ -53,6 +55,49 @@ func (q *Queries) DeleteAllAssignments(ctx context.Context, budgetID uuid.UUID)
 | 
				
			|||||||
	return result.RowsAffected()
 | 
						return result.RowsAffected()
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const getAllAssignments = `-- name: GetAllAssignments :many
 | 
				
			||||||
 | 
					SELECT assignments.date, categories.name as category, category_groups.name as group, assignments.amount
 | 
				
			||||||
 | 
					FROM assignments
 | 
				
			||||||
 | 
					INNER JOIN categories ON categories.id = assignments.category_id
 | 
				
			||||||
 | 
					INNER JOIN category_groups ON categories.category_group_id = category_groups.id
 | 
				
			||||||
 | 
					WHERE category_groups.budget_id = $1
 | 
				
			||||||
 | 
					`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type GetAllAssignmentsRow struct {
 | 
				
			||||||
 | 
						Date     time.Time
 | 
				
			||||||
 | 
						Category string
 | 
				
			||||||
 | 
						Group    string
 | 
				
			||||||
 | 
						Amount   numeric.Numeric
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (q *Queries) GetAllAssignments(ctx context.Context, budgetID uuid.UUID) ([]GetAllAssignmentsRow, error) {
 | 
				
			||||||
 | 
						rows, err := q.db.QueryContext(ctx, getAllAssignments, budgetID)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						defer rows.Close()
 | 
				
			||||||
 | 
						var items []GetAllAssignmentsRow
 | 
				
			||||||
 | 
						for rows.Next() {
 | 
				
			||||||
 | 
							var i GetAllAssignmentsRow
 | 
				
			||||||
 | 
							if err := rows.Scan(
 | 
				
			||||||
 | 
								&i.Date,
 | 
				
			||||||
 | 
								&i.Category,
 | 
				
			||||||
 | 
								&i.Group,
 | 
				
			||||||
 | 
								&i.Amount,
 | 
				
			||||||
 | 
							); err != nil {
 | 
				
			||||||
 | 
								return nil, err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							items = append(items, i)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if err := rows.Close(); err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if err := rows.Err(); err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return items, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const getAssignmentsByMonthAndCategory = `-- name: GetAssignmentsByMonthAndCategory :many
 | 
					const getAssignmentsByMonthAndCategory = `-- name: GetAssignmentsByMonthAndCategory :many
 | 
				
			||||||
SELECT date, category_id, budget_id, amount
 | 
					SELECT date, category_id, budget_id, amount
 | 
				
			||||||
FROM assignments_by_month
 | 
					FROM assignments_by_month
 | 
				
			||||||
@@ -86,3 +131,41 @@ func (q *Queries) GetAssignmentsByMonthAndCategory(ctx context.Context, budgetID
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
	return items, nil
 | 
						return items, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const updateAssignment = `-- name: UpdateAssignment :exec
 | 
				
			||||||
 | 
					INSERT INTO assignments (category_id, date, amount)
 | 
				
			||||||
 | 
					VALUES($1, $2, $3) 
 | 
				
			||||||
 | 
					ON CONFLICT (category_id, date) 
 | 
				
			||||||
 | 
					DO 
 | 
				
			||||||
 | 
					   UPDATE SET amount = $3
 | 
				
			||||||
 | 
					`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type UpdateAssignmentParams struct {
 | 
				
			||||||
 | 
						CategoryID uuid.UUID
 | 
				
			||||||
 | 
						Date       time.Time
 | 
				
			||||||
 | 
						Amount     numeric.Numeric
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (q *Queries) UpdateAssignment(ctx context.Context, arg UpdateAssignmentParams) error {
 | 
				
			||||||
 | 
						_, err := q.db.ExecContext(ctx, updateAssignment, arg.CategoryID, arg.Date, arg.Amount)
 | 
				
			||||||
 | 
						return err
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const updateAssignmentWithDifference = `-- name: UpdateAssignmentWithDifference :exec
 | 
				
			||||||
 | 
					INSERT INTO assignments (category_id, date, amount)
 | 
				
			||||||
 | 
					VALUES($1, $2, $3) 
 | 
				
			||||||
 | 
					ON CONFLICT (category_id, date) 
 | 
				
			||||||
 | 
					DO 
 | 
				
			||||||
 | 
					   UPDATE SET amount = assignments.amount + $3
 | 
				
			||||||
 | 
					`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type UpdateAssignmentWithDifferenceParams struct {
 | 
				
			||||||
 | 
						CategoryID uuid.UUID
 | 
				
			||||||
 | 
						Date       time.Time
 | 
				
			||||||
 | 
						Amount     numeric.Numeric
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (q *Queries) UpdateAssignmentWithDifference(ctx context.Context, arg UpdateAssignmentWithDifferenceParams) error {
 | 
				
			||||||
 | 
						_, err := q.db.ExecContext(ctx, updateAssignmentWithDifference, arg.CategoryID, arg.Date, arg.Amount)
 | 
				
			||||||
 | 
						return err
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,4 +1,6 @@
 | 
				
			|||||||
// Code generated by sqlc. DO NOT EDIT.
 | 
					// Code generated by sqlc. DO NOT EDIT.
 | 
				
			||||||
 | 
					// versions:
 | 
				
			||||||
 | 
					//   sqlc v1.13.0
 | 
				
			||||||
// source: budgets.sql
 | 
					// source: budgets.sql
 | 
				
			||||||
 | 
					
 | 
				
			||||||
package postgres
 | 
					package postgres
 | 
				
			||||||
@@ -34,6 +36,15 @@ func (q *Queries) CreateBudget(ctx context.Context, arg CreateBudgetParams) (Bud
 | 
				
			|||||||
	return i, err
 | 
						return i, err
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const deleteBudget = `-- name: DeleteBudget :exec
 | 
				
			||||||
 | 
					DELETE FROM budgets WHERE id = $1
 | 
				
			||||||
 | 
					`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (q *Queries) DeleteBudget(ctx context.Context, id uuid.UUID) error {
 | 
				
			||||||
 | 
						_, err := q.db.ExecContext(ctx, deleteBudget, id)
 | 
				
			||||||
 | 
						return err
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const getBudget = `-- name: GetBudget :one
 | 
					const getBudget = `-- name: GetBudget :one
 | 
				
			||||||
SELECT id, name, last_modification, income_category_id FROM budgets 
 | 
					SELECT id, name, last_modification, income_category_id FROM budgets 
 | 
				
			||||||
WHERE id = $1
 | 
					WHERE id = $1
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -8,11 +8,15 @@ import (
 | 
				
			|||||||
	"github.com/google/uuid"
 | 
						"github.com/google/uuid"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// NewBudget creates a budget and adds it to the current user
 | 
					// NewBudget creates a budget and adds it to the current user.
 | 
				
			||||||
func (s *Database) NewBudget(context context.Context, name string, userID uuid.UUID) (*Budget, error) {
 | 
					func (s *Database) NewBudget(context context.Context, name string, userID uuid.UUID) (*Budget, error) {
 | 
				
			||||||
	tx, err := s.BeginTx(context, &sql.TxOptions{})
 | 
						tx, err := s.BeginTx(context, &sql.TxOptions{})
 | 
				
			||||||
	q := s.WithTx(tx)
 | 
						if err != nil {
 | 
				
			||||||
	budget, err := q.CreateBudget(context, CreateBudgetParams{
 | 
							return nil, fmt.Errorf("begin transaction: %w", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						transaction := s.WithTx(tx)
 | 
				
			||||||
 | 
						budget, err := transaction.CreateBudget(context, CreateBudgetParams{
 | 
				
			||||||
		Name:             name,
 | 
							Name:             name,
 | 
				
			||||||
		IncomeCategoryID: uuid.New(),
 | 
							IncomeCategoryID: uuid.New(),
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
@@ -21,12 +25,12 @@ func (s *Database) NewBudget(context context.Context, name string, userID uuid.U
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ub := LinkBudgetToUserParams{UserID: userID, BudgetID: budget.ID}
 | 
						ub := LinkBudgetToUserParams{UserID: userID, BudgetID: budget.ID}
 | 
				
			||||||
	_, err = q.LinkBudgetToUser(context, ub)
 | 
						_, err = transaction.LinkBudgetToUser(context, ub)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, fmt.Errorf("link budget to user: %w", err)
 | 
							return nil, fmt.Errorf("link budget to user: %w", err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	group, err := q.CreateCategoryGroup(context, CreateCategoryGroupParams{
 | 
						group, err := transaction.CreateCategoryGroup(context, CreateCategoryGroupParams{
 | 
				
			||||||
		Name:     "Inflow",
 | 
							Name:     "Inflow",
 | 
				
			||||||
		BudgetID: budget.ID,
 | 
							BudgetID: budget.ID,
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
@@ -34,7 +38,7 @@ func (s *Database) NewBudget(context context.Context, name string, userID uuid.U
 | 
				
			|||||||
		return nil, fmt.Errorf("create inflow category_group: %w", err)
 | 
							return nil, fmt.Errorf("create inflow category_group: %w", err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	cat, err := q.CreateCategory(context, CreateCategoryParams{
 | 
						cat, err := transaction.CreateCategory(context, CreateCategoryParams{
 | 
				
			||||||
		Name:            "Ready to Assign",
 | 
							Name:            "Ready to Assign",
 | 
				
			||||||
		CategoryGroupID: group.ID,
 | 
							CategoryGroupID: group.ID,
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
@@ -42,7 +46,7 @@ func (s *Database) NewBudget(context context.Context, name string, userID uuid.U
 | 
				
			|||||||
		return nil, fmt.Errorf("create ready to assign category: %w", err)
 | 
							return nil, fmt.Errorf("create ready to assign category: %w", err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	err = q.SetInflowCategory(context, SetInflowCategoryParams{
 | 
						err = transaction.SetInflowCategory(context, SetInflowCategoryParams{
 | 
				
			||||||
		IncomeCategoryID: cat.ID,
 | 
							IncomeCategoryID: cat.ID,
 | 
				
			||||||
		ID:               budget.ID,
 | 
							ID:               budget.ID,
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
@@ -50,7 +54,11 @@ func (s *Database) NewBudget(context context.Context, name string, userID uuid.U
 | 
				
			|||||||
		return nil, fmt.Errorf("set inflow category: %w", err)
 | 
							return nil, fmt.Errorf("set inflow category: %w", err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	tx.Commit()
 | 
						err = tx.Commit()
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, fmt.Errorf("commit: %w", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						budget.IncomeCategoryID = cat.ID
 | 
				
			||||||
	return &budget, nil
 | 
						return &budget, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,4 +1,6 @@
 | 
				
			|||||||
// Code generated by sqlc. DO NOT EDIT.
 | 
					// Code generated by sqlc. DO NOT EDIT.
 | 
				
			||||||
 | 
					// versions:
 | 
				
			||||||
 | 
					//   sqlc v1.13.0
 | 
				
			||||||
// source: categories.sql
 | 
					// source: categories.sql
 | 
				
			||||||
 | 
					
 | 
				
			||||||
package postgres
 | 
					package postgres
 | 
				
			||||||
@@ -89,6 +91,24 @@ func (q *Queries) GetCategories(ctx context.Context, budgetID uuid.UUID) ([]GetC
 | 
				
			|||||||
	return items, nil
 | 
						return items, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const getCategoryGroupByName = `-- name: GetCategoryGroupByName :one
 | 
				
			||||||
 | 
					SELECT category_groups.id, category_groups.budget_id, category_groups.name FROM category_groups 
 | 
				
			||||||
 | 
					WHERE category_groups.budget_id = $1
 | 
				
			||||||
 | 
					AND category_groups.name = $2
 | 
				
			||||||
 | 
					`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type GetCategoryGroupByNameParams struct {
 | 
				
			||||||
 | 
						BudgetID uuid.UUID
 | 
				
			||||||
 | 
						Name     string
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (q *Queries) GetCategoryGroupByName(ctx context.Context, arg GetCategoryGroupByNameParams) (CategoryGroup, error) {
 | 
				
			||||||
 | 
						row := q.db.QueryRowContext(ctx, getCategoryGroupByName, arg.BudgetID, arg.Name)
 | 
				
			||||||
 | 
						var i CategoryGroup
 | 
				
			||||||
 | 
						err := row.Scan(&i.ID, &i.BudgetID, &i.Name)
 | 
				
			||||||
 | 
						return i, err
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const getCategoryGroups = `-- name: GetCategoryGroups :many
 | 
					const getCategoryGroups = `-- name: GetCategoryGroups :many
 | 
				
			||||||
SELECT category_groups.id, category_groups.budget_id, category_groups.name FROM category_groups 
 | 
					SELECT category_groups.id, category_groups.budget_id, category_groups.name FROM category_groups 
 | 
				
			||||||
WHERE category_groups.budget_id = $1
 | 
					WHERE category_groups.budget_id = $1
 | 
				
			||||||
@@ -116,3 +136,47 @@ func (q *Queries) GetCategoryGroups(ctx context.Context, budgetID uuid.UUID) ([]
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
	return items, nil
 | 
						return items, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const searchCategories = `-- name: SearchCategories :many
 | 
				
			||||||
 | 
					SELECT CONCAT(category_groups.name, ' : ', categories.name) as name, categories.id, 'category' as type
 | 
				
			||||||
 | 
					FROM categories
 | 
				
			||||||
 | 
					INNER JOIN category_groups ON categories.category_group_id = category_groups.id
 | 
				
			||||||
 | 
					WHERE category_groups.budget_id = $1
 | 
				
			||||||
 | 
					AND categories.name ILIKE $2
 | 
				
			||||||
 | 
					AND category_groups.name != 'Hidden Categories'
 | 
				
			||||||
 | 
					ORDER BY category_groups.name, categories.name
 | 
				
			||||||
 | 
					`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type SearchCategoriesParams struct {
 | 
				
			||||||
 | 
						BudgetID uuid.UUID
 | 
				
			||||||
 | 
						Search   string
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type SearchCategoriesRow struct {
 | 
				
			||||||
 | 
						Name interface{}
 | 
				
			||||||
 | 
						ID   uuid.UUID
 | 
				
			||||||
 | 
						Type interface{}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (q *Queries) SearchCategories(ctx context.Context, arg SearchCategoriesParams) ([]SearchCategoriesRow, error) {
 | 
				
			||||||
 | 
						rows, err := q.db.QueryContext(ctx, searchCategories, arg.BudgetID, arg.Search)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						defer rows.Close()
 | 
				
			||||||
 | 
						var items []SearchCategoriesRow
 | 
				
			||||||
 | 
						for rows.Next() {
 | 
				
			||||||
 | 
							var i SearchCategoriesRow
 | 
				
			||||||
 | 
							if err := rows.Scan(&i.Name, &i.ID, &i.Type); err != nil {
 | 
				
			||||||
 | 
								return nil, err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							items = append(items, i)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if err := rows.Close(); err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if err := rows.Err(); err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return items, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,7 +5,7 @@ import (
 | 
				
			|||||||
	"embed"
 | 
						"embed"
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	_ "github.com/jackc/pgx/v4/stdlib"
 | 
						_ "github.com/jackc/pgx/v4/stdlib" // needed for pg connection
 | 
				
			||||||
	"github.com/pressly/goose/v3"
 | 
						"github.com/pressly/goose/v3"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -17,10 +17,9 @@ type Database struct {
 | 
				
			|||||||
	*sql.DB
 | 
						*sql.DB
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Connect to a database
 | 
					// Connect connects to a database.
 | 
				
			||||||
func Connect(server string, user string, password string, database string) (*Database, error) {
 | 
					func Connect(typ string, connString string) (*Database, error) {
 | 
				
			||||||
	connString := fmt.Sprintf("postgres://%s:%s@%s/%s", user, password, server, database)
 | 
						conn, err := sql.Open(typ, connString)
 | 
				
			||||||
	conn, err := sql.Open("pgx", connString)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, fmt.Errorf("open connection: %w", err)
 | 
							return nil, fmt.Errorf("open connection: %w", err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,4 +1,6 @@
 | 
				
			|||||||
// Code generated by sqlc. DO NOT EDIT.
 | 
					// Code generated by sqlc. DO NOT EDIT.
 | 
				
			||||||
 | 
					// versions:
 | 
				
			||||||
 | 
					//   sqlc v1.13.0
 | 
				
			||||||
// source: cumultative-balances.sql
 | 
					// source: cumultative-balances.sql
 | 
				
			||||||
 | 
					
 | 
				
			||||||
package postgres
 | 
					package postgres
 | 
				
			||||||
@@ -7,26 +9,25 @@ import (
 | 
				
			|||||||
	"context"
 | 
						"context"
 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"git.javil.eu/jacob1123/budgeteer/postgres/numeric"
 | 
				
			||||||
	"github.com/google/uuid"
 | 
						"github.com/google/uuid"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const getCumultativeBalances = `-- name: GetCumultativeBalances :many
 | 
					const getCumultativeBalances = `-- name: GetCumultativeBalances :many
 | 
				
			||||||
SELECT COALESCE(ass.date, tra.date), COALESCE(ass.category_id, tra.category_id),
 | 
					SELECT COALESCE(ass.date, tra.date), COALESCE(ass.category_id, tra.category_id),
 | 
				
			||||||
       COALESCE(ass.amount, 0)::decimal(12,2) as assignments, SUM(ass.amount) OVER (PARTITION BY ass.category_id ORDER BY ass.date)::decimal(12,2) as assignments_cum,
 | 
					       COALESCE(ass.amount, 0)::decimal(12,2) as assignments,
 | 
				
			||||||
       COALESCE(tra.amount, 0)::decimal(12,2) as transactions, SUM(tra.amount) OVER (PARTITION BY tra.category_id ORDER BY tra.date)::decimal(12,2) as transactions_cum
 | 
					       COALESCE(tra.amount, 0)::decimal(12,2) as transactions
 | 
				
			||||||
FROM assignments_by_month as ass
 | 
					FROM assignments_by_month as ass
 | 
				
			||||||
FULL OUTER JOIN transactions_by_month as tra ON ass.date = tra.date AND ass.category_id = tra.category_id
 | 
					FULL OUTER JOIN transactions_by_month as tra ON ass.date = tra.date AND ass.category_id = tra.category_id
 | 
				
			||||||
WHERE (ass.budget_id IS NULL OR ass.budget_id = $1) AND (tra.budget_id IS NULL OR tra.budget_id = $1)
 | 
					WHERE COALESCE(ass.budget_id, tra.budget_id) = $1
 | 
				
			||||||
ORDER BY COALESCE(ass.date, tra.date), COALESCE(ass.category_id, tra.category_id)
 | 
					ORDER BY COALESCE(ass.date, tra.date), COALESCE(ass.amount, tra.amount)
 | 
				
			||||||
`
 | 
					`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type GetCumultativeBalancesRow struct {
 | 
					type GetCumultativeBalancesRow struct {
 | 
				
			||||||
	Date         time.Time
 | 
						Date         time.Time
 | 
				
			||||||
	CategoryID   uuid.UUID
 | 
						CategoryID   uuid.UUID
 | 
				
			||||||
	Assignments     Numeric
 | 
						Assignments  numeric.Numeric
 | 
				
			||||||
	AssignmentsCum  Numeric
 | 
						Transactions numeric.Numeric
 | 
				
			||||||
	Transactions    Numeric
 | 
					 | 
				
			||||||
	TransactionsCum Numeric
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (q *Queries) GetCumultativeBalances(ctx context.Context, budgetID uuid.UUID) ([]GetCumultativeBalancesRow, error) {
 | 
					func (q *Queries) GetCumultativeBalances(ctx context.Context, budgetID uuid.UUID) ([]GetCumultativeBalancesRow, error) {
 | 
				
			||||||
@@ -42,9 +43,7 @@ func (q *Queries) GetCumultativeBalances(ctx context.Context, budgetID uuid.UUID
 | 
				
			|||||||
			&i.Date,
 | 
								&i.Date,
 | 
				
			||||||
			&i.CategoryID,
 | 
								&i.CategoryID,
 | 
				
			||||||
			&i.Assignments,
 | 
								&i.Assignments,
 | 
				
			||||||
			&i.AssignmentsCum,
 | 
					 | 
				
			||||||
			&i.Transactions,
 | 
								&i.Transactions,
 | 
				
			||||||
			&i.TransactionsCum,
 | 
					 | 
				
			||||||
		); err != nil {
 | 
							); err != nil {
 | 
				
			||||||
			return nil, err
 | 
								return nil, err
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,4 +1,6 @@
 | 
				
			|||||||
// Code generated by sqlc. DO NOT EDIT.
 | 
					// Code generated by sqlc. DO NOT EDIT.
 | 
				
			||||||
 | 
					// versions:
 | 
				
			||||||
 | 
					//   sqlc v1.13.0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
package postgres
 | 
					package postgres
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,27 +1,52 @@
 | 
				
			|||||||
// Code generated by sqlc. DO NOT EDIT.
 | 
					// Code generated by sqlc. DO NOT EDIT.
 | 
				
			||||||
 | 
					// versions:
 | 
				
			||||||
 | 
					//   sqlc v1.13.0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
package postgres
 | 
					package postgres
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"database/sql"
 | 
						"database/sql"
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"git.javil.eu/jacob1123/budgeteer/postgres/numeric"
 | 
				
			||||||
	"github.com/google/uuid"
 | 
						"github.com/google/uuid"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type TransactionStatus string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const (
 | 
				
			||||||
 | 
						TransactionStatusReconciled TransactionStatus = "Reconciled"
 | 
				
			||||||
 | 
						TransactionStatusCleared    TransactionStatus = "Cleared"
 | 
				
			||||||
 | 
						TransactionStatusUncleared  TransactionStatus = "Uncleared"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (e *TransactionStatus) Scan(src interface{}) error {
 | 
				
			||||||
 | 
						switch s := src.(type) {
 | 
				
			||||||
 | 
						case []byte:
 | 
				
			||||||
 | 
							*e = TransactionStatus(s)
 | 
				
			||||||
 | 
						case string:
 | 
				
			||||||
 | 
							*e = TransactionStatus(s)
 | 
				
			||||||
 | 
						default:
 | 
				
			||||||
 | 
							return fmt.Errorf("unsupported scan type for TransactionStatus: %T", src)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type Account struct {
 | 
					type Account struct {
 | 
				
			||||||
	ID             uuid.UUID
 | 
						ID             uuid.UUID
 | 
				
			||||||
	BudgetID       uuid.UUID
 | 
						BudgetID       uuid.UUID
 | 
				
			||||||
	Name           string
 | 
						Name           string
 | 
				
			||||||
	OnBudget       bool
 | 
						OnBudget       bool
 | 
				
			||||||
 | 
						IsOpen         bool
 | 
				
			||||||
 | 
						LastReconciled sql.NullTime
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type Assignment struct {
 | 
					type Assignment struct {
 | 
				
			||||||
	ID         uuid.UUID
 | 
					 | 
				
			||||||
	CategoryID uuid.UUID
 | 
						CategoryID uuid.UUID
 | 
				
			||||||
	Date       time.Time
 | 
						Date       time.Time
 | 
				
			||||||
	Memo       sql.NullString
 | 
						Memo       sql.NullString
 | 
				
			||||||
	Amount     Numeric
 | 
						Amount     numeric.Numeric
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type AssignmentsByMonth struct {
 | 
					type AssignmentsByMonth struct {
 | 
				
			||||||
@@ -50,6 +75,24 @@ type CategoryGroup struct {
 | 
				
			|||||||
	Name     string
 | 
						Name     string
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type DisplayTransaction struct {
 | 
				
			||||||
 | 
						ID              uuid.UUID
 | 
				
			||||||
 | 
						Date            time.Time
 | 
				
			||||||
 | 
						Memo            string
 | 
				
			||||||
 | 
						Amount          numeric.Numeric
 | 
				
			||||||
 | 
						GroupID         uuid.NullUUID
 | 
				
			||||||
 | 
						Status          TransactionStatus
 | 
				
			||||||
 | 
						Account         string
 | 
				
			||||||
 | 
						PayeeID         uuid.NullUUID
 | 
				
			||||||
 | 
						CategoryID      uuid.NullUUID
 | 
				
			||||||
 | 
						Payee           string
 | 
				
			||||||
 | 
						CategoryGroup   string
 | 
				
			||||||
 | 
						Category        string
 | 
				
			||||||
 | 
						TransferAccount string
 | 
				
			||||||
 | 
						BudgetID        uuid.UUID
 | 
				
			||||||
 | 
						AccountID       uuid.UUID
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type Payee struct {
 | 
					type Payee struct {
 | 
				
			||||||
	ID       uuid.UUID
 | 
						ID       uuid.UUID
 | 
				
			||||||
	BudgetID uuid.UUID
 | 
						BudgetID uuid.UUID
 | 
				
			||||||
@@ -60,11 +103,12 @@ type Transaction struct {
 | 
				
			|||||||
	ID         uuid.UUID
 | 
						ID         uuid.UUID
 | 
				
			||||||
	Date       time.Time
 | 
						Date       time.Time
 | 
				
			||||||
	Memo       string
 | 
						Memo       string
 | 
				
			||||||
	Amount     Numeric
 | 
						Amount     numeric.Numeric
 | 
				
			||||||
	AccountID  uuid.UUID
 | 
						AccountID  uuid.UUID
 | 
				
			||||||
	CategoryID uuid.NullUUID
 | 
						CategoryID uuid.NullUUID
 | 
				
			||||||
	PayeeID    uuid.NullUUID
 | 
						PayeeID    uuid.NullUUID
 | 
				
			||||||
	GroupID    uuid.NullUUID
 | 
						GroupID    uuid.NullUUID
 | 
				
			||||||
 | 
						Status     TransactionStatus
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type TransactionsByMonth struct {
 | 
					type TransactionsByMonth struct {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,35 +0,0 @@
 | 
				
			|||||||
package postgres
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import "github.com/jackc/pgtype"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type Numeric struct {
 | 
					 | 
				
			||||||
	pgtype.Numeric
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (n Numeric) GetFloat64() float64 {
 | 
					 | 
				
			||||||
	if n.Status != pgtype.Present {
 | 
					 | 
				
			||||||
		return 0
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	var balance float64
 | 
					 | 
				
			||||||
	err := n.AssignTo(&balance)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		panic(err)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return balance
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (n Numeric) IsPositive() bool {
 | 
					 | 
				
			||||||
	if n.Status != pgtype.Present {
 | 
					 | 
				
			||||||
		return true
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	float := n.GetFloat64()
 | 
					 | 
				
			||||||
	return float >= 0
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (n Numeric) IsZero() bool {
 | 
					 | 
				
			||||||
	if n.Status != pgtype.Present {
 | 
					 | 
				
			||||||
		return true
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	float := n.GetFloat64()
 | 
					 | 
				
			||||||
	return float == 0
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
							
								
								
									
										272
									
								
								postgres/numeric/numeric.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										272
									
								
								postgres/numeric/numeric.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,272 @@
 | 
				
			|||||||
 | 
					package numeric
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
						"math/big"
 | 
				
			||||||
 | 
						"strings"
 | 
				
			||||||
 | 
						"unicode/utf8"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/jackc/pgtype"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type Numeric struct {
 | 
				
			||||||
 | 
						pgtype.Numeric
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func Zero() Numeric {
 | 
				
			||||||
 | 
						return Numeric{pgtype.Numeric{Exp: 0, Int: big.NewInt(0), Status: pgtype.Present, NaN: false}}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func FromInt64(value int64) Numeric {
 | 
				
			||||||
 | 
						return Numeric{Numeric: pgtype.Numeric{Int: big.NewInt(value), Status: pgtype.Present}}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func FromInt64WithExp(value int64, exp int32) Numeric {
 | 
				
			||||||
 | 
						return Numeric{Numeric: pgtype.Numeric{Int: big.NewInt(value), Exp: exp, Status: pgtype.Present}}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (n *Numeric) SetZero() {
 | 
				
			||||||
 | 
						n.Exp = 0
 | 
				
			||||||
 | 
						n.Int = big.NewInt(0)
 | 
				
			||||||
 | 
						n.Status = pgtype.Present
 | 
				
			||||||
 | 
						n.NaN = false
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (n Numeric) GetFloat64() float64 {
 | 
				
			||||||
 | 
						if n.Status != pgtype.Present {
 | 
				
			||||||
 | 
							return 0
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						var balance float64
 | 
				
			||||||
 | 
						err := n.AssignTo(&balance)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							panic(err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return balance
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (n Numeric) IsPositive() bool {
 | 
				
			||||||
 | 
						if n.Status != pgtype.Present {
 | 
				
			||||||
 | 
							return true
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						float := n.GetFloat64()
 | 
				
			||||||
 | 
						return float >= 0
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (n Numeric) IsZero() bool {
 | 
				
			||||||
 | 
						if n.Status != pgtype.Present {
 | 
				
			||||||
 | 
							return true
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						float := n.GetFloat64()
 | 
				
			||||||
 | 
						return float == 0
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (n *Numeric) MatchExpI(exp int32) {
 | 
				
			||||||
 | 
						diffExp := n.Exp - exp
 | 
				
			||||||
 | 
						factor := big.NewInt(0).Exp(big.NewInt(10), big.NewInt(int64(diffExp)), nil) //nolint:gomnd
 | 
				
			||||||
 | 
						n.Exp = exp
 | 
				
			||||||
 | 
						n.Int = big.NewInt(0).Mul(n.Int, factor)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (n Numeric) MatchExp(exp int32) Numeric {
 | 
				
			||||||
 | 
						diffExp := n.Exp - exp
 | 
				
			||||||
 | 
						factor := big.NewInt(0).Exp(big.NewInt(10), big.NewInt(int64(diffExp)), nil) //nolint:gomnd
 | 
				
			||||||
 | 
						return Numeric{pgtype.Numeric{
 | 
				
			||||||
 | 
							Exp:    exp,
 | 
				
			||||||
 | 
							Int:    big.NewInt(0).Mul(n.Int, factor),
 | 
				
			||||||
 | 
							Status: n.Status,
 | 
				
			||||||
 | 
							NaN:    n.NaN,
 | 
				
			||||||
 | 
						}}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (n *Numeric) SubI(other Numeric) *Numeric {
 | 
				
			||||||
 | 
						right := other
 | 
				
			||||||
 | 
						if n.Exp < other.Exp {
 | 
				
			||||||
 | 
							right = other.MatchExp(n.Exp)
 | 
				
			||||||
 | 
						} else if n.Exp > other.Exp {
 | 
				
			||||||
 | 
							n.MatchExpI(other.Exp)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if n.Exp == right.Exp {
 | 
				
			||||||
 | 
							n.Int = big.NewInt(0).Sub(n.Int, right.Int)
 | 
				
			||||||
 | 
							return n
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						panic("Cannot subtract with different exponents")
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (n Numeric) Sub(other Numeric) Numeric {
 | 
				
			||||||
 | 
						left := n
 | 
				
			||||||
 | 
						right := other
 | 
				
			||||||
 | 
						if n.Exp < other.Exp {
 | 
				
			||||||
 | 
							right = other.MatchExp(n.Exp)
 | 
				
			||||||
 | 
						} else if n.Exp > other.Exp {
 | 
				
			||||||
 | 
							left = n.MatchExp(other.Exp)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if left.Exp == right.Exp {
 | 
				
			||||||
 | 
							return Numeric{pgtype.Numeric{
 | 
				
			||||||
 | 
								Exp: left.Exp,
 | 
				
			||||||
 | 
								Int: big.NewInt(0).Sub(left.Int, right.Int),
 | 
				
			||||||
 | 
							}}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						panic("Cannot subtract with different exponents")
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (n Numeric) Neg() Numeric {
 | 
				
			||||||
 | 
						return Numeric{pgtype.Numeric{Exp: n.Exp, Int: big.NewInt(-1 * n.Int.Int64()), Status: n.Status}}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (n Numeric) Add(other Numeric) Numeric {
 | 
				
			||||||
 | 
						left := n
 | 
				
			||||||
 | 
						right := other
 | 
				
			||||||
 | 
						if n.Exp < other.Exp {
 | 
				
			||||||
 | 
							right = other.MatchExp(n.Exp)
 | 
				
			||||||
 | 
						} else if n.Exp > other.Exp {
 | 
				
			||||||
 | 
							left = n.MatchExp(other.Exp)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if left.Exp == right.Exp {
 | 
				
			||||||
 | 
							return Numeric{pgtype.Numeric{
 | 
				
			||||||
 | 
								Exp: left.Exp,
 | 
				
			||||||
 | 
								Int: big.NewInt(0).Add(left.Int, right.Int),
 | 
				
			||||||
 | 
							}}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						panic("Cannot add with different exponents")
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (n *Numeric) AddI(other Numeric) *Numeric {
 | 
				
			||||||
 | 
						right := other
 | 
				
			||||||
 | 
						if n.Exp < other.Exp {
 | 
				
			||||||
 | 
							right = other.MatchExp(n.Exp)
 | 
				
			||||||
 | 
						} else if n.Exp > other.Exp {
 | 
				
			||||||
 | 
							n.MatchExpI(other.Exp)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if n.Exp == right.Exp {
 | 
				
			||||||
 | 
							n.Int = big.NewInt(0).Add(n.Int, right.Int)
 | 
				
			||||||
 | 
							return n
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						panic("Cannot add with different exponents")
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (n Numeric) String() string {
 | 
				
			||||||
 | 
						if n.Int == nil || n.Int.Int64() == 0 {
 | 
				
			||||||
 | 
							return "0"
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						s := fmt.Sprintf("%d", n.Int)
 | 
				
			||||||
 | 
						bytes := []byte(s)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						exp := n.Exp
 | 
				
			||||||
 | 
						for exp > 0 {
 | 
				
			||||||
 | 
							bytes = append(bytes, byte('0'))
 | 
				
			||||||
 | 
							exp--
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if exp == 0 {
 | 
				
			||||||
 | 
							return string(bytes)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						length := int32(len(bytes))
 | 
				
			||||||
 | 
						var bytesWithSeparator []byte
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						exp = -exp
 | 
				
			||||||
 | 
						for length <= exp {
 | 
				
			||||||
 | 
							if n.Int.Int64() < 0 {
 | 
				
			||||||
 | 
								bytes = append([]byte{bytes[0], byte('0')}, bytes[1:]...)
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								bytes = append([]byte{byte('0')}, bytes...)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							length++
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						split := length - exp
 | 
				
			||||||
 | 
						bytesWithSeparator = append(bytesWithSeparator, bytes[:split]...)
 | 
				
			||||||
 | 
						if split == 1 && n.Int.Int64() < 0 {
 | 
				
			||||||
 | 
							bytesWithSeparator = append(bytesWithSeparator, byte('0'))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						bytesWithSeparator = append(bytesWithSeparator, byte('.'))
 | 
				
			||||||
 | 
						bytesWithSeparator = append(bytesWithSeparator, bytes[split:]...)
 | 
				
			||||||
 | 
						return string(bytesWithSeparator)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (n Numeric) MarshalJSON() ([]byte, error) {
 | 
				
			||||||
 | 
						if n.Int == nil || n.Int.Int64() == 0 {
 | 
				
			||||||
 | 
							return []byte("0"), nil
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						s := fmt.Sprintf("%d", n.Int)
 | 
				
			||||||
 | 
						bytes := []byte(s)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						exp := n.Exp
 | 
				
			||||||
 | 
						for exp > 0 {
 | 
				
			||||||
 | 
							bytes = append(bytes, byte('0'))
 | 
				
			||||||
 | 
							exp--
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if exp == 0 {
 | 
				
			||||||
 | 
							return bytes, nil
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						length := int32(len(bytes))
 | 
				
			||||||
 | 
						var bytesWithSeparator []byte
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						exp = -exp
 | 
				
			||||||
 | 
						for length <= exp {
 | 
				
			||||||
 | 
							if n.Int.Int64() < 0 {
 | 
				
			||||||
 | 
								bytes = append([]byte{bytes[0], byte('0')}, bytes[1:]...)
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								bytes = append([]byte{byte('0')}, bytes...)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							length++
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						split := length - exp
 | 
				
			||||||
 | 
						bytesWithSeparator = append(bytesWithSeparator, bytes[:split]...)
 | 
				
			||||||
 | 
						if split == 1 && n.Int.Int64() < 0 {
 | 
				
			||||||
 | 
							bytesWithSeparator = append(bytesWithSeparator, byte('0'))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						bytesWithSeparator = append(bytesWithSeparator, byte('.'))
 | 
				
			||||||
 | 
						bytesWithSeparator = append(bytesWithSeparator, bytes[split:]...)
 | 
				
			||||||
 | 
						return bytesWithSeparator, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func MustParse(text string) Numeric {
 | 
				
			||||||
 | 
						num, err := Parse(text)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							panic(err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return num
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func Parse(text string) (Numeric, error) {
 | 
				
			||||||
 | 
						// Unify decimal separator
 | 
				
			||||||
 | 
						text = strings.Replace(text, ",", ".", 1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						num := Numeric{}
 | 
				
			||||||
 | 
						err := num.Set(text)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return num, fmt.Errorf("parse numeric %s: %w", text, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return num, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func ParseCurrency(text string) (Numeric, error) {
 | 
				
			||||||
 | 
						// Remove trailing currency
 | 
				
			||||||
 | 
						text = trimLastChar(text)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return Parse(text)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func trimLastChar(s string) string {
 | 
				
			||||||
 | 
						r, size := utf8.DecodeLastRuneInString(s)
 | 
				
			||||||
 | 
						if r == utf8.RuneError && (size == 0 || size == 1) {
 | 
				
			||||||
 | 
							size = 0
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return s[:len(s)-size]
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										118
									
								
								postgres/numeric/numeric_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										118
									
								
								postgres/numeric/numeric_test.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,118 @@
 | 
				
			|||||||
 | 
					package numeric_test
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"testing"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"git.javil.eu/jacob1123/budgeteer/postgres/numeric"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type TestCaseMarshalJSON struct {
 | 
				
			||||||
 | 
						Value  numeric.Numeric
 | 
				
			||||||
 | 
						Result string
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestMarshalJSON(t *testing.T) {
 | 
				
			||||||
 | 
						t.Parallel()
 | 
				
			||||||
 | 
						tests := []TestCaseMarshalJSON{
 | 
				
			||||||
 | 
							{numeric.Zero(), `0`},
 | 
				
			||||||
 | 
							{numeric.MustParse("1.23"), "1.23"},
 | 
				
			||||||
 | 
							{numeric.MustParse("1,24"), "1.24"},
 | 
				
			||||||
 | 
							{numeric.MustParse("1"), "1"},
 | 
				
			||||||
 | 
							{numeric.MustParse("10"), "10"},
 | 
				
			||||||
 | 
							{numeric.MustParse("100"), "100"},
 | 
				
			||||||
 | 
							{numeric.MustParse("1000"), "1000"},
 | 
				
			||||||
 | 
							{numeric.MustParse("0.1"), "0.1"},
 | 
				
			||||||
 | 
							{numeric.MustParse("0.01"), "0.01"},
 | 
				
			||||||
 | 
							{numeric.MustParse("0.001"), "0.001"},
 | 
				
			||||||
 | 
							{numeric.MustParse("0.0001"), "0.0001"},
 | 
				
			||||||
 | 
							{numeric.MustParse("-1"), "-1"},
 | 
				
			||||||
 | 
							{numeric.MustParse("-10"), "-10"},
 | 
				
			||||||
 | 
							{numeric.MustParse("-100"), "-100"},
 | 
				
			||||||
 | 
							{numeric.MustParse("-1000"), "-1000"},
 | 
				
			||||||
 | 
							{numeric.MustParse("-0.1"), "-0.1"},
 | 
				
			||||||
 | 
							{numeric.MustParse("-0.01"), "-0.01"},
 | 
				
			||||||
 | 
							{numeric.MustParse("-0.001"), "-0.001"},
 | 
				
			||||||
 | 
							{numeric.MustParse("-0.0001"), "-0.0001"},
 | 
				
			||||||
 | 
							{numeric.MustParse("123456789.12345"), "123456789.12345"},
 | 
				
			||||||
 | 
							{numeric.MustParse("123456789.12345"), "123456789.12345"},
 | 
				
			||||||
 | 
							{numeric.MustParse("-1.23"), "-1.23"},
 | 
				
			||||||
 | 
							{numeric.MustParse("-1,24"), "-1.24"},
 | 
				
			||||||
 | 
							{numeric.MustParse("-123456789.12345"), "-123456789.12345"},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						for i := range tests {
 | 
				
			||||||
 | 
							test := tests[i]
 | 
				
			||||||
 | 
							t.Run(test.Result, func(t *testing.T) {
 | 
				
			||||||
 | 
								t.Parallel()
 | 
				
			||||||
 | 
								z := test.Value
 | 
				
			||||||
 | 
								result, err := z.MarshalJSON()
 | 
				
			||||||
 | 
								if err != nil {
 | 
				
			||||||
 | 
									t.Error(err)
 | 
				
			||||||
 | 
									return
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								if string(result) != test.Result {
 | 
				
			||||||
 | 
									t.Errorf("Expected %s, got %s", test.Result, string(result))
 | 
				
			||||||
 | 
									return
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							})
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type TestCaseParse struct {
 | 
				
			||||||
 | 
						Result numeric.Numeric
 | 
				
			||||||
 | 
						Value  string
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestParse(t *testing.T) {
 | 
				
			||||||
 | 
						t.Parallel()
 | 
				
			||||||
 | 
						tests := []TestCaseParse{
 | 
				
			||||||
 | 
							{numeric.FromInt64WithExp(0, 0), `0`},
 | 
				
			||||||
 | 
							{numeric.FromInt64WithExp(1, 0), `1`},
 | 
				
			||||||
 | 
							{numeric.FromInt64WithExp(1, 1), `10`},
 | 
				
			||||||
 | 
							{numeric.FromInt64WithExp(1, 2), `100`},
 | 
				
			||||||
 | 
							{numeric.FromInt64WithExp(1, 3), `1000`},
 | 
				
			||||||
 | 
							{numeric.FromInt64WithExp(1, -1), `0.1`},
 | 
				
			||||||
 | 
							{numeric.FromInt64WithExp(1, -2), `0.01`},
 | 
				
			||||||
 | 
							{numeric.FromInt64WithExp(1, -3), `0.001`},
 | 
				
			||||||
 | 
							{numeric.FromInt64WithExp(1, -4), `0.0001`},
 | 
				
			||||||
 | 
							{numeric.FromInt64WithExp(-1, 0), `-1`},
 | 
				
			||||||
 | 
							{numeric.FromInt64WithExp(-1, 1), `-10`},
 | 
				
			||||||
 | 
							{numeric.FromInt64WithExp(-1, 2), `-100`},
 | 
				
			||||||
 | 
							{numeric.FromInt64WithExp(-1, 3), `-1000`},
 | 
				
			||||||
 | 
							{numeric.FromInt64WithExp(-1, -1), `-0.1`},
 | 
				
			||||||
 | 
							{numeric.FromInt64WithExp(-1, -2), `-0.01`},
 | 
				
			||||||
 | 
							{numeric.FromInt64WithExp(-1, -3), `-0.001`},
 | 
				
			||||||
 | 
							{numeric.FromInt64WithExp(-1, -4), `-0.0001`},
 | 
				
			||||||
 | 
							{numeric.FromInt64WithExp(123, -2), "1.23"},
 | 
				
			||||||
 | 
							{numeric.FromInt64WithExp(124, -2), "1,24"},
 | 
				
			||||||
 | 
							{numeric.FromInt64WithExp(12345678912345, -5), "123456789.12345"},
 | 
				
			||||||
 | 
							{numeric.FromInt64WithExp(0, 0), `-0`},
 | 
				
			||||||
 | 
							{numeric.FromInt64WithExp(-1, 0), `-1`},
 | 
				
			||||||
 | 
							{numeric.FromInt64WithExp(-1, 1), `-10`},
 | 
				
			||||||
 | 
							{numeric.FromInt64WithExp(-1, 2), `-100`},
 | 
				
			||||||
 | 
							{numeric.FromInt64WithExp(-123, -2), "-1.23"},
 | 
				
			||||||
 | 
							{numeric.FromInt64WithExp(-124, -2), "-1,24"},
 | 
				
			||||||
 | 
							{numeric.FromInt64WithExp(-12345678912345, -5), "-123456789.12345"},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						for i := range tests {
 | 
				
			||||||
 | 
							test := tests[i]
 | 
				
			||||||
 | 
							t.Run(test.Value, func(t *testing.T) {
 | 
				
			||||||
 | 
								t.Parallel()
 | 
				
			||||||
 | 
								result, err := numeric.Parse(test.Value)
 | 
				
			||||||
 | 
								if err != nil {
 | 
				
			||||||
 | 
									t.Error(err)
 | 
				
			||||||
 | 
									return
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								if test.Result.Int.Int64() != result.Int.Int64() {
 | 
				
			||||||
 | 
									t.Errorf("Expected int %d, got %d", test.Result.Int, result.Int)
 | 
				
			||||||
 | 
									return
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								if test.Result.Exp != result.Exp {
 | 
				
			||||||
 | 
									t.Errorf("Expected exp %d, got %d", test.Result.Exp, result.Exp)
 | 
				
			||||||
 | 
									return
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							})
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -1,4 +1,6 @@
 | 
				
			|||||||
// Code generated by sqlc. DO NOT EDIT.
 | 
					// Code generated by sqlc. DO NOT EDIT.
 | 
				
			||||||
 | 
					// versions:
 | 
				
			||||||
 | 
					//   sqlc v1.13.0
 | 
				
			||||||
// source: payees.sql
 | 
					// source: payees.sql
 | 
				
			||||||
 | 
					
 | 
				
			||||||
package postgres
 | 
					package postgres
 | 
				
			||||||
@@ -22,6 +24,9 @@ type CreatePayeeParams struct {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (q *Queries) CreatePayee(ctx context.Context, arg CreatePayeeParams) (Payee, error) {
 | 
					func (q *Queries) CreatePayee(ctx context.Context, arg CreatePayeeParams) (Payee, error) {
 | 
				
			||||||
 | 
						if len(arg.Name) > 50 {
 | 
				
			||||||
 | 
							arg.Name = arg.Name[:50]
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	row := q.db.QueryRowContext(ctx, createPayee, arg.Name, arg.BudgetID)
 | 
						row := q.db.QueryRowContext(ctx, createPayee, arg.Name, arg.BudgetID)
 | 
				
			||||||
	var i Payee
 | 
						var i Payee
 | 
				
			||||||
	err := row.Scan(&i.ID, &i.BudgetID, &i.Name)
 | 
						err := row.Scan(&i.ID, &i.BudgetID, &i.Name)
 | 
				
			||||||
@@ -56,3 +61,50 @@ func (q *Queries) GetPayees(ctx context.Context, budgetID uuid.UUID) ([]Payee, e
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
	return items, nil
 | 
						return items, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const searchPayees = `-- name: SearchPayees :many
 | 
				
			||||||
 | 
					SELECT payees.id, payees.budget_id, payees.name, 'payee' as type FROM payees 
 | 
				
			||||||
 | 
					WHERE payees.budget_id = $1
 | 
				
			||||||
 | 
					AND payees.name ILIKE $2
 | 
				
			||||||
 | 
					ORDER BY payees.name
 | 
				
			||||||
 | 
					`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type SearchPayeesParams struct {
 | 
				
			||||||
 | 
						BudgetID uuid.UUID
 | 
				
			||||||
 | 
						Search   string
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type SearchPayeesRow struct {
 | 
				
			||||||
 | 
						ID       uuid.UUID
 | 
				
			||||||
 | 
						BudgetID uuid.UUID
 | 
				
			||||||
 | 
						Name     string
 | 
				
			||||||
 | 
						Type     interface{}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (q *Queries) SearchPayees(ctx context.Context, arg SearchPayeesParams) ([]SearchPayeesRow, error) {
 | 
				
			||||||
 | 
						rows, err := q.db.QueryContext(ctx, searchPayees, arg.BudgetID, arg.Search)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						defer rows.Close()
 | 
				
			||||||
 | 
						var items []SearchPayeesRow
 | 
				
			||||||
 | 
						for rows.Next() {
 | 
				
			||||||
 | 
							var i SearchPayeesRow
 | 
				
			||||||
 | 
							if err := rows.Scan(
 | 
				
			||||||
 | 
								&i.ID,
 | 
				
			||||||
 | 
								&i.BudgetID,
 | 
				
			||||||
 | 
								&i.Name,
 | 
				
			||||||
 | 
								&i.Type,
 | 
				
			||||||
 | 
							); err != nil {
 | 
				
			||||||
 | 
								return nil, err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							items = append(items, i)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if err := rows.Close(); err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if err := rows.Err(); err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return items, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -11,13 +11,35 @@ WHERE accounts.id = $1;
 | 
				
			|||||||
-- name: GetAccounts :many
 | 
					-- name: GetAccounts :many
 | 
				
			||||||
SELECT accounts.* FROM accounts
 | 
					SELECT accounts.* FROM accounts
 | 
				
			||||||
WHERE accounts.budget_id = $1
 | 
					WHERE accounts.budget_id = $1
 | 
				
			||||||
 | 
					AND accounts.is_open = TRUE
 | 
				
			||||||
ORDER BY accounts.name;
 | 
					ORDER BY accounts.name;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
-- name: GetAccountsWithBalance :many
 | 
					-- name: GetAccountsWithBalance :many
 | 
				
			||||||
SELECT accounts.id, accounts.name, accounts.on_budget, SUM(transactions.amount)::decimal(12,2) as balance
 | 
					SELECT accounts.id, accounts.name, accounts.on_budget, accounts.is_open, accounts.last_reconciled,
 | 
				
			||||||
 | 
					        (SELECT SUM(transactions.amount) FROM transactions WHERE transactions.account_id = accounts.id AND transactions.date < NOW())::decimal(12,2) as working_balance,
 | 
				
			||||||
 | 
					        (SELECT SUM(transactions.amount) FROM transactions WHERE transactions.account_id = accounts.id AND transactions.date < NOW() AND transactions.status IN ('Cleared', 'Reconciled'))::decimal(12,2) as cleared_balance,
 | 
				
			||||||
 | 
					        (SELECT SUM(transactions.amount) FROM transactions WHERE transactions.account_id = accounts.id AND transactions.date < NOW() AND transactions.status = 'Reconciled')::decimal(12,2) as reconciled_balance
 | 
				
			||||||
FROM accounts
 | 
					FROM accounts
 | 
				
			||||||
LEFT JOIN transactions ON transactions.account_id = accounts.id
 | 
					 | 
				
			||||||
WHERE accounts.budget_id = $1
 | 
					WHERE accounts.budget_id = $1
 | 
				
			||||||
AND transactions.date < NOW()
 | 
					AND accounts.is_open = TRUE
 | 
				
			||||||
GROUP BY accounts.id, accounts.name
 | 
					 | 
				
			||||||
ORDER BY accounts.name;
 | 
					ORDER BY accounts.name;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					-- name: SearchAccounts :many
 | 
				
			||||||
 | 
					SELECT accounts.id, accounts.budget_id, accounts.name, 'account' as type FROM accounts
 | 
				
			||||||
 | 
					WHERE accounts.budget_id = @budget_id
 | 
				
			||||||
 | 
					AND accounts.is_open = TRUE
 | 
				
			||||||
 | 
					AND accounts.name ILIKE @search
 | 
				
			||||||
 | 
					ORDER BY accounts.name;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					-- name: UpdateAccount :one
 | 
				
			||||||
 | 
					UPDATE accounts
 | 
				
			||||||
 | 
					SET name = $1,
 | 
				
			||||||
 | 
					    on_budget = $2,
 | 
				
			||||||
 | 
					    is_open = $3
 | 
				
			||||||
 | 
					WHERE accounts.id = $4
 | 
				
			||||||
 | 
					RETURNING *;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					-- name: SetLastReconciled :exec
 | 
				
			||||||
 | 
					UPDATE accounts
 | 
				
			||||||
 | 
					SET last_reconciled = NOW()
 | 
				
			||||||
 | 
					WHERE accounts.id = $1;
 | 
				
			||||||
@@ -16,3 +16,24 @@ WHERE categories.id = assignments.category_id AND category_groups.budget_id = @b
 | 
				
			|||||||
SELECT *
 | 
					SELECT *
 | 
				
			||||||
FROM assignments_by_month
 | 
					FROM assignments_by_month
 | 
				
			||||||
WHERE assignments_by_month.budget_id = @budget_id;
 | 
					WHERE assignments_by_month.budget_id = @budget_id;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					-- name: GetAllAssignments :many
 | 
				
			||||||
 | 
					SELECT assignments.date, categories.name as category, category_groups.name as group, assignments.amount
 | 
				
			||||||
 | 
					FROM assignments
 | 
				
			||||||
 | 
					INNER JOIN categories ON categories.id = assignments.category_id
 | 
				
			||||||
 | 
					INNER JOIN category_groups ON categories.category_group_id = category_groups.id
 | 
				
			||||||
 | 
					WHERE category_groups.budget_id = @budget_id;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					-- name: UpdateAssignment :exec
 | 
				
			||||||
 | 
					INSERT INTO assignments (category_id, date, amount)
 | 
				
			||||||
 | 
					VALUES($1, $2, $3) 
 | 
				
			||||||
 | 
					ON CONFLICT (category_id, date) 
 | 
				
			||||||
 | 
					DO 
 | 
				
			||||||
 | 
					   UPDATE SET amount = $3;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					-- name: UpdateAssignmentWithDifference :exec
 | 
				
			||||||
 | 
					INSERT INTO assignments (category_id, date, amount)
 | 
				
			||||||
 | 
					VALUES($1, $2, $3) 
 | 
				
			||||||
 | 
					ON CONFLICT (category_id, date) 
 | 
				
			||||||
 | 
					DO 
 | 
				
			||||||
 | 
					   UPDATE SET amount = assignments.amount + $3;
 | 
				
			||||||
@@ -32,3 +32,6 @@ FROM (
 | 
				
			|||||||
        INNER JOIN accounts ON accounts.id = transactions.account_id
 | 
					        INNER JOIN accounts ON accounts.id = transactions.account_id
 | 
				
			||||||
        WHERE accounts.budget_id = @budget_id
 | 
					        WHERE accounts.budget_id = @budget_id
 | 
				
			||||||
) dates;
 | 
					) dates;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					-- name: DeleteBudget :exec
 | 
				
			||||||
 | 
					DELETE FROM budgets WHERE id = $1;
 | 
				
			||||||
@@ -8,6 +8,11 @@ RETURNING *;
 | 
				
			|||||||
SELECT category_groups.* FROM category_groups 
 | 
					SELECT category_groups.* FROM category_groups 
 | 
				
			||||||
WHERE category_groups.budget_id = $1;
 | 
					WHERE category_groups.budget_id = $1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					-- name: GetCategoryGroupByName :one
 | 
				
			||||||
 | 
					SELECT category_groups.* FROM category_groups 
 | 
				
			||||||
 | 
					WHERE category_groups.budget_id = $1
 | 
				
			||||||
 | 
					AND category_groups.name = $2;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
-- name: CreateCategory :one
 | 
					-- name: CreateCategory :one
 | 
				
			||||||
INSERT INTO categories
 | 
					INSERT INTO categories
 | 
				
			||||||
(name, category_group_id)
 | 
					(name, category_group_id)
 | 
				
			||||||
@@ -19,3 +24,13 @@ SELECT categories.*, category_groups.name as group FROM categories
 | 
				
			|||||||
INNER JOIN category_groups ON categories.category_group_id = category_groups.id
 | 
					INNER JOIN category_groups ON categories.category_group_id = category_groups.id
 | 
				
			||||||
WHERE category_groups.budget_id = $1
 | 
					WHERE category_groups.budget_id = $1
 | 
				
			||||||
ORDER BY category_groups.name, categories.name;
 | 
					ORDER BY category_groups.name, categories.name;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					-- name: SearchCategories :many
 | 
				
			||||||
 | 
					SELECT CONCAT(category_groups.name, ' : ', categories.name) as name, categories.id, 'category' as type
 | 
				
			||||||
 | 
					FROM categories
 | 
				
			||||||
 | 
					INNER JOIN category_groups ON categories.category_group_id = category_groups.id
 | 
				
			||||||
 | 
					WHERE category_groups.budget_id = @budget_id
 | 
				
			||||||
 | 
					AND categories.name ILIKE @search
 | 
				
			||||||
 | 
					AND category_groups.name != 'Hidden Categories'
 | 
				
			||||||
 | 
					ORDER BY category_groups.name, categories.name;
 | 
				
			||||||
 | 
					--ORDER BY levenshtein(payees.name, $2);
 | 
				
			||||||
@@ -1,8 +1,8 @@
 | 
				
			|||||||
-- name: GetCumultativeBalances :many
 | 
					-- name: GetCumultativeBalances :many
 | 
				
			||||||
SELECT COALESCE(ass.date, tra.date), COALESCE(ass.category_id, tra.category_id),
 | 
					SELECT COALESCE(ass.date, tra.date), COALESCE(ass.category_id, tra.category_id),
 | 
				
			||||||
       COALESCE(ass.amount, 0)::decimal(12,2) as assignments, SUM(ass.amount) OVER (PARTITION BY ass.category_id ORDER BY ass.date)::decimal(12,2) as assignments_cum,
 | 
					       COALESCE(ass.amount, 0)::decimal(12,2) as assignments,
 | 
				
			||||||
       COALESCE(tra.amount, 0)::decimal(12,2) as transactions, SUM(tra.amount) OVER (PARTITION BY tra.category_id ORDER BY tra.date)::decimal(12,2) as transactions_cum
 | 
					       COALESCE(tra.amount, 0)::decimal(12,2) as transactions
 | 
				
			||||||
FROM assignments_by_month as ass
 | 
					FROM assignments_by_month as ass
 | 
				
			||||||
FULL OUTER JOIN transactions_by_month as tra ON ass.date = tra.date AND ass.category_id = tra.category_id
 | 
					FULL OUTER JOIN transactions_by_month as tra ON ass.date = tra.date AND ass.category_id = tra.category_id
 | 
				
			||||||
WHERE (ass.budget_id IS NULL OR ass.budget_id = @budget_id) AND (tra.budget_id IS NULL OR tra.budget_id = @budget_id)
 | 
					WHERE COALESCE(ass.budget_id, tra.budget_id) = @budget_id
 | 
				
			||||||
ORDER BY COALESCE(ass.date, tra.date), COALESCE(ass.category_id, tra.category_id);
 | 
					ORDER BY COALESCE(ass.date, tra.date), COALESCE(ass.amount, tra.amount);
 | 
				
			||||||
@@ -8,3 +8,10 @@ RETURNING *;
 | 
				
			|||||||
SELECT payees.* FROM payees 
 | 
					SELECT payees.* FROM payees 
 | 
				
			||||||
WHERE payees.budget_id = $1
 | 
					WHERE payees.budget_id = $1
 | 
				
			||||||
ORDER BY name;
 | 
					ORDER BY name;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					-- name: SearchPayees :many
 | 
				
			||||||
 | 
					SELECT payees.*, 'payee' as type FROM payees 
 | 
				
			||||||
 | 
					WHERE payees.budget_id = @budget_id
 | 
				
			||||||
 | 
					AND payees.name ILIKE @search
 | 
				
			||||||
 | 
					ORDER BY payees.name;
 | 
				
			||||||
 | 
					--ORDER BY levenshtein(payees.name, $2);
 | 
				
			||||||
@@ -1,50 +1,40 @@
 | 
				
			|||||||
-- name: GetTransaction :one
 | 
					-- name: GetTransaction :one
 | 
				
			||||||
SELECT * FROM transactions
 | 
					SELECT * FROM display_transactions
 | 
				
			||||||
WHERE id = $1;
 | 
					WHERE id = $1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
-- name: CreateTransaction :one
 | 
					-- name: CreateTransaction :one
 | 
				
			||||||
INSERT INTO transactions
 | 
					INSERT INTO transactions
 | 
				
			||||||
(date, memo, amount, account_id, payee_id, category_id, group_id)
 | 
					(date, memo, amount, account_id, payee_id, category_id, group_id, status)
 | 
				
			||||||
VALUES ($1, $2, $3, $4, $5, $6, $7)
 | 
					VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
 | 
				
			||||||
RETURNING *;
 | 
					RETURNING id;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
-- name: UpdateTransaction :exec
 | 
					-- name: UpdateTransaction :exec
 | 
				
			||||||
UPDATE transactions
 | 
					UPDATE transactions
 | 
				
			||||||
SET date = $1,
 | 
					SET date = $1,
 | 
				
			||||||
  memo = $2,
 | 
					  memo = $2,
 | 
				
			||||||
  amount = $3,
 | 
					  amount = $3,
 | 
				
			||||||
    account_id = $4,
 | 
					  payee_id = $4,
 | 
				
			||||||
    payee_id = $5,
 | 
					  category_id = $5
 | 
				
			||||||
    category_id = $6
 | 
					WHERE id = $6;
 | 
				
			||||||
WHERE id = $7;
 | 
					
 | 
				
			||||||
 | 
					-- name: SetTransactionReconciled :exec
 | 
				
			||||||
 | 
					UPDATE transactions
 | 
				
			||||||
 | 
					SET status = 'Reconciled'
 | 
				
			||||||
 | 
					WHERE id = $1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
-- name: DeleteTransaction :exec
 | 
					-- name: DeleteTransaction :exec
 | 
				
			||||||
DELETE FROM transactions
 | 
					DELETE FROM transactions
 | 
				
			||||||
WHERE id = $1;
 | 
					WHERE id = $1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
-- name: GetTransactionsForBudget :many
 | 
					-- name: GetAllTransactionsForBudget :many
 | 
				
			||||||
SELECT  transactions.id, transactions.date, transactions.memo, transactions.amount, transactions.group_id,
 | 
					SELECT  t.*
 | 
				
			||||||
        accounts.name as account, COALESCE(payees.name, '') as payee, COALESCE(category_groups.name, '') as category_group, COALESCE(categories.name, '') as category
 | 
					FROM display_transactions AS t
 | 
				
			||||||
FROM transactions 
 | 
					WHERE t.budget_id = $1;
 | 
				
			||||||
INNER JOIN accounts ON accounts.id = transactions.account_id
 | 
					 | 
				
			||||||
LEFT JOIN payees ON payees.id = transactions.payee_id
 | 
					 | 
				
			||||||
LEFT JOIN categories ON categories.id = transactions.category_id
 | 
					 | 
				
			||||||
LEFT JOIN category_groups ON category_groups.id = categories.category_group_id
 | 
					 | 
				
			||||||
WHERE accounts.budget_id = $1
 | 
					 | 
				
			||||||
ORDER BY transactions.date DESC
 | 
					 | 
				
			||||||
LIMIT 200;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
-- name: GetTransactionsForAccount :many
 | 
					-- name: GetTransactionsForAccount :many
 | 
				
			||||||
SELECT  transactions.id, transactions.date, transactions.memo, transactions.amount, transactions.group_id,
 | 
					SELECT  t.*
 | 
				
			||||||
        accounts.name as account, COALESCE(payees.name, '') as payee, COALESCE(category_groups.name, '') as category_group, COALESCE(categories.name, '') as category
 | 
					FROM display_transactions AS t
 | 
				
			||||||
FROM transactions 
 | 
					WHERE t.account_id = $1;
 | 
				
			||||||
INNER JOIN accounts ON accounts.id = transactions.account_id
 | 
					 | 
				
			||||||
LEFT JOIN payees ON payees.id = transactions.payee_id
 | 
					 | 
				
			||||||
LEFT JOIN categories ON categories.id = transactions.category_id
 | 
					 | 
				
			||||||
LEFT JOIN category_groups ON category_groups.id = categories.category_group_id
 | 
					 | 
				
			||||||
WHERE transactions.account_id = $1
 | 
					 | 
				
			||||||
ORDER BY transactions.date DESC
 | 
					 | 
				
			||||||
LIMIT 200;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
-- name: DeleteAllTransactions :execrows
 | 
					-- name: DeleteAllTransactions :execrows
 | 
				
			||||||
DELETE FROM transactions
 | 
					DELETE FROM transactions
 | 
				
			||||||
@@ -56,3 +46,28 @@ AND accounts.id = transactions.account_id;
 | 
				
			|||||||
SELECT *
 | 
					SELECT *
 | 
				
			||||||
FROM transactions_by_month
 | 
					FROM transactions_by_month
 | 
				
			||||||
WHERE transactions_by_month.budget_id = @budget_id;
 | 
					WHERE transactions_by_month.budget_id = @budget_id;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					-- name: GetProblematicTransactions :many
 | 
				
			||||||
 | 
					SELECT transactions.*
 | 
				
			||||||
 | 
					FROM display_transactions AS transactions
 | 
				
			||||||
 | 
					LEFT JOIN accounts 
 | 
				
			||||||
 | 
					        ON transactions.account_id = accounts.id
 | 
				
			||||||
 | 
					LEFT JOIN transactions AS otherGroupTransaction 
 | 
				
			||||||
 | 
					        ON transactions.group_id = otherGroupTransaction.group_id 
 | 
				
			||||||
 | 
					        AND transactions.id != otherGroupTransaction.id 
 | 
				
			||||||
 | 
					        AND transactions.account_id != otherGroupTransaction.account_id
 | 
				
			||||||
 | 
					LEFT JOIn accounts AS otherGroupAccount 
 | 
				
			||||||
 | 
					        ON otherGroupTransaction.account_id = otherGroupAccount.id
 | 
				
			||||||
 | 
					WHERE transactions.category_id IS NULL
 | 
				
			||||||
 | 
					AND accounts.on_budget
 | 
				
			||||||
 | 
					AND (otherGroupAccount.id IS NULL OR NOT otherGroupAccount.on_budget)
 | 
				
			||||||
 | 
					AND accounts.budget_id = $1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					-- name: GetFilteredTransactions :many
 | 
				
			||||||
 | 
					SELECT transactions.*
 | 
				
			||||||
 | 
					FROM display_transactions AS transactions
 | 
				
			||||||
 | 
					WHERE (NOT @filter_category::boolean OR transactions.category_id = @category_id) 
 | 
				
			||||||
 | 
					AND (NOT @filter_account::boolean OR transactions.account_id = @account_id) 
 | 
				
			||||||
 | 
					AND (NOT @filter_payee::boolean OR transactions.payee_id = @payee_id)
 | 
				
			||||||
 | 
					AND transactions.date BETWEEN @from_date AND @to_date
 | 
				
			||||||
 | 
					AND transactions.budget_id = @budget_id;
 | 
				
			||||||
							
								
								
									
										12
									
								
								postgres/schema/0013_add-transaction-status.sql
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								postgres/schema/0013_add-transaction-status.sql
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,12 @@
 | 
				
			|||||||
 | 
					-- +goose Up
 | 
				
			||||||
 | 
					CREATE TYPE transaction_status AS ENUM (
 | 
				
			||||||
 | 
					  'Reconciled',
 | 
				
			||||||
 | 
					  'Cleared',
 | 
				
			||||||
 | 
					  'Uncleared'
 | 
				
			||||||
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ALTER TABLE transactions ADD COLUMN status transaction_status NOT NULL DEFAULT 'Uncleared';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					-- +goose Down
 | 
				
			||||||
 | 
					ALTER TABLE transactions DROP COLUMN status;
 | 
				
			||||||
 | 
					DROP TYPE transaction_status;
 | 
				
			||||||
							
								
								
									
										5
									
								
								postgres/schema/0014_enable-fuzzy-match-module.sql
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								postgres/schema/0014_enable-fuzzy-match-module.sql
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,5 @@
 | 
				
			|||||||
 | 
					-- +goose Up
 | 
				
			||||||
 | 
					CREATE EXTENSION IF NOT EXISTS "fuzzystrmatch";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					-- +goose Down
 | 
				
			||||||
 | 
					DROP EXTENSION "fuzzystrmatch";
 | 
				
			||||||
							
								
								
									
										25
									
								
								postgres/schema/0015_transactions-view.sql
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								postgres/schema/0015_transactions-view.sql
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,25 @@
 | 
				
			|||||||
 | 
					-- +goose Up
 | 
				
			||||||
 | 
					CREATE VIEW display_transactions AS 
 | 
				
			||||||
 | 
					        SELECT  transactions.id, transactions.date, transactions.memo, 
 | 
				
			||||||
 | 
					                transactions.amount, transactions.group_id, transactions.status,
 | 
				
			||||||
 | 
					                accounts.name as account, transactions.payee_id, transactions.category_id,
 | 
				
			||||||
 | 
					                COALESCE(payees.name, '') as payee, 
 | 
				
			||||||
 | 
					                COALESCE(category_groups.name, '') as category_group, 
 | 
				
			||||||
 | 
					                COALESCE(categories.name, '') as category,
 | 
				
			||||||
 | 
					                COALESCE((
 | 
				
			||||||
 | 
					                SELECT CONCAT(otherAccounts.name) 
 | 
				
			||||||
 | 
					                FROM transactions otherTransactions 
 | 
				
			||||||
 | 
					                LEFT JOIN accounts otherAccounts ON otherAccounts.id = otherTransactions.account_id
 | 
				
			||||||
 | 
					                WHERE otherTransactions.group_id = transactions.group_id 
 | 
				
			||||||
 | 
					                AND otherTransactions.id != transactions.id
 | 
				
			||||||
 | 
					                ), '')::text as transfer_account,
 | 
				
			||||||
 | 
					                accounts.budget_id, transactions.account_id
 | 
				
			||||||
 | 
					        FROM transactions 
 | 
				
			||||||
 | 
					        INNER JOIN accounts ON accounts.id = transactions.account_id
 | 
				
			||||||
 | 
					        LEFT JOIN payees ON payees.id = transactions.payee_id
 | 
				
			||||||
 | 
					        LEFT JOIN categories ON categories.id = transactions.category_id
 | 
				
			||||||
 | 
					        LEFT JOIN category_groups ON category_groups.id = categories.category_group_id
 | 
				
			||||||
 | 
					        ORDER BY transactions.date DESC;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					-- +goose Down
 | 
				
			||||||
 | 
					DROP VIEW display_transactions;
 | 
				
			||||||
							
								
								
									
										5
									
								
								postgres/schema/0016_closed-accounts.sql
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								postgres/schema/0016_closed-accounts.sql
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,5 @@
 | 
				
			|||||||
 | 
					-- +goose Up
 | 
				
			||||||
 | 
					ALTER TABLE accounts ADD COLUMN is_open BOOLEAN NOT NULL DEFAULT TRUE;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					-- +goose Down
 | 
				
			||||||
 | 
					ALTER TABLE accounts DROP COLUMN is_open;
 | 
				
			||||||
							
								
								
									
										6
									
								
								postgres/schema/0017_natural-key-assignments.sql
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								postgres/schema/0017_natural-key-assignments.sql
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,6 @@
 | 
				
			|||||||
 | 
					-- +goose Up
 | 
				
			||||||
 | 
					ALTER TABLE assignments DROP id;
 | 
				
			||||||
 | 
					ALTER TABLE assignments ADD PRIMARY KEY (category_id, date);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					-- +goose Down
 | 
				
			||||||
 | 
					ALTER TABLE assignments ADD COLUMN id uuid DEFAULT uuid_generate_v4() PRIMARY KEY;
 | 
				
			||||||
							
								
								
									
										12
									
								
								postgres/schema/0018_reconciled-on.sql
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								postgres/schema/0018_reconciled-on.sql
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,12 @@
 | 
				
			|||||||
 | 
					-- +goose Up
 | 
				
			||||||
 | 
					ALTER TABLE accounts ADD COLUMN last_reconciled date NULL;
 | 
				
			||||||
 | 
					UPDATE accounts
 | 
				
			||||||
 | 
					SET last_reconciled = (
 | 
				
			||||||
 | 
					    SELECT MAX(transactions.date)
 | 
				
			||||||
 | 
					    FROM transactions
 | 
				
			||||||
 | 
					    WHERE transactions.account_id = accounts.id
 | 
				
			||||||
 | 
					    AND transactions.status = 'Reconciled'
 | 
				
			||||||
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					-- +goose Down
 | 
				
			||||||
 | 
					ALTER TABLE accounts DROP COLUMN last_reconciled;
 | 
				
			||||||
@@ -0,0 +1,13 @@
 | 
				
			|||||||
 | 
					-- +goose Up
 | 
				
			||||||
 | 
					CREATE OR REPLACE VIEW transactions_by_month AS 
 | 
				
			||||||
 | 
					        SELECT date_trunc('month', transactions.date)::date as date, transactions.category_id, accounts.budget_id, SUM(amount) as amount
 | 
				
			||||||
 | 
					        FROM transactions
 | 
				
			||||||
 | 
					        INNER JOIN accounts ON accounts.id = transactions.account_id AND accounts.on_budget
 | 
				
			||||||
 | 
					        GROUP BY date_trunc('month', transactions.date), transactions.category_id, accounts.budget_id;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					-- +goose Down
 | 
				
			||||||
 | 
					CREATE OR REPLACE VIEW transactions_by_month AS 
 | 
				
			||||||
 | 
					        SELECT date_trunc('month', transactions.date)::date as date, transactions.category_id, accounts.budget_id, SUM(amount) as amount
 | 
				
			||||||
 | 
					        FROM transactions
 | 
				
			||||||
 | 
					        INNER JOIN accounts ON accounts.id = transactions.account_id
 | 
				
			||||||
 | 
					        GROUP BY date_trunc('month', transactions.date), transactions.category_id, accounts.budget_id;
 | 
				
			||||||
@@ -1,4 +1,6 @@
 | 
				
			|||||||
// Code generated by sqlc. DO NOT EDIT.
 | 
					// Code generated by sqlc. DO NOT EDIT.
 | 
				
			||||||
 | 
					// versions:
 | 
				
			||||||
 | 
					//   sqlc v1.13.0
 | 
				
			||||||
// source: transactions.sql
 | 
					// source: transactions.sql
 | 
				
			||||||
 | 
					
 | 
				
			||||||
package postgres
 | 
					package postgres
 | 
				
			||||||
@@ -7,27 +9,29 @@ import (
 | 
				
			|||||||
	"context"
 | 
						"context"
 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"git.javil.eu/jacob1123/budgeteer/postgres/numeric"
 | 
				
			||||||
	"github.com/google/uuid"
 | 
						"github.com/google/uuid"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const createTransaction = `-- name: CreateTransaction :one
 | 
					const createTransaction = `-- name: CreateTransaction :one
 | 
				
			||||||
INSERT INTO transactions
 | 
					INSERT INTO transactions
 | 
				
			||||||
(date, memo, amount, account_id, payee_id, category_id, group_id)
 | 
					(date, memo, amount, account_id, payee_id, category_id, group_id, status)
 | 
				
			||||||
VALUES ($1, $2, $3, $4, $5, $6, $7)
 | 
					VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
 | 
				
			||||||
RETURNING id, date, memo, amount, account_id, category_id, payee_id, group_id
 | 
					RETURNING id
 | 
				
			||||||
`
 | 
					`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type CreateTransactionParams struct {
 | 
					type CreateTransactionParams struct {
 | 
				
			||||||
	Date       time.Time
 | 
						Date       time.Time
 | 
				
			||||||
	Memo       string
 | 
						Memo       string
 | 
				
			||||||
	Amount     Numeric
 | 
						Amount     numeric.Numeric
 | 
				
			||||||
	AccountID  uuid.UUID
 | 
						AccountID  uuid.UUID
 | 
				
			||||||
	PayeeID    uuid.NullUUID
 | 
						PayeeID    uuid.NullUUID
 | 
				
			||||||
	CategoryID uuid.NullUUID
 | 
						CategoryID uuid.NullUUID
 | 
				
			||||||
	GroupID    uuid.NullUUID
 | 
						GroupID    uuid.NullUUID
 | 
				
			||||||
 | 
						Status     TransactionStatus
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (q *Queries) CreateTransaction(ctx context.Context, arg CreateTransactionParams) (Transaction, error) {
 | 
					func (q *Queries) CreateTransaction(ctx context.Context, arg CreateTransactionParams) (uuid.UUID, error) {
 | 
				
			||||||
	row := q.db.QueryRowContext(ctx, createTransaction,
 | 
						row := q.db.QueryRowContext(ctx, createTransaction,
 | 
				
			||||||
		arg.Date,
 | 
							arg.Date,
 | 
				
			||||||
		arg.Memo,
 | 
							arg.Memo,
 | 
				
			||||||
@@ -36,19 +40,11 @@ func (q *Queries) CreateTransaction(ctx context.Context, arg CreateTransactionPa
 | 
				
			|||||||
		arg.PayeeID,
 | 
							arg.PayeeID,
 | 
				
			||||||
		arg.CategoryID,
 | 
							arg.CategoryID,
 | 
				
			||||||
		arg.GroupID,
 | 
							arg.GroupID,
 | 
				
			||||||
 | 
							arg.Status,
 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
	var i Transaction
 | 
						var id uuid.UUID
 | 
				
			||||||
	err := row.Scan(
 | 
						err := row.Scan(&id)
 | 
				
			||||||
		&i.ID,
 | 
						return id, err
 | 
				
			||||||
		&i.Date,
 | 
					 | 
				
			||||||
		&i.Memo,
 | 
					 | 
				
			||||||
		&i.Amount,
 | 
					 | 
				
			||||||
		&i.AccountID,
 | 
					 | 
				
			||||||
		&i.CategoryID,
 | 
					 | 
				
			||||||
		&i.PayeeID,
 | 
					 | 
				
			||||||
		&i.GroupID,
 | 
					 | 
				
			||||||
	)
 | 
					 | 
				
			||||||
	return i, err
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const deleteAllTransactions = `-- name: DeleteAllTransactions :execrows
 | 
					const deleteAllTransactions = `-- name: DeleteAllTransactions :execrows
 | 
				
			||||||
@@ -76,23 +72,202 @@ func (q *Queries) DeleteTransaction(ctx context.Context, id uuid.UUID) error {
 | 
				
			|||||||
	return err
 | 
						return err
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const getAllTransactionsForBudget = `-- name: GetAllTransactionsForBudget :many
 | 
				
			||||||
 | 
					SELECT  t.id, t.date, t.memo, t.amount, t.group_id, t.status, t.account, t.payee_id, t.category_id, t.payee, t.category_group, t.category, t.transfer_account, t.budget_id, t.account_id
 | 
				
			||||||
 | 
					FROM display_transactions AS t
 | 
				
			||||||
 | 
					WHERE t.budget_id = $1
 | 
				
			||||||
 | 
					`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (q *Queries) GetAllTransactionsForBudget(ctx context.Context, budgetID uuid.UUID) ([]DisplayTransaction, error) {
 | 
				
			||||||
 | 
						rows, err := q.db.QueryContext(ctx, getAllTransactionsForBudget, budgetID)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						defer rows.Close()
 | 
				
			||||||
 | 
						var items []DisplayTransaction
 | 
				
			||||||
 | 
						for rows.Next() {
 | 
				
			||||||
 | 
							var i DisplayTransaction
 | 
				
			||||||
 | 
							if err := rows.Scan(
 | 
				
			||||||
 | 
								&i.ID,
 | 
				
			||||||
 | 
								&i.Date,
 | 
				
			||||||
 | 
								&i.Memo,
 | 
				
			||||||
 | 
								&i.Amount,
 | 
				
			||||||
 | 
								&i.GroupID,
 | 
				
			||||||
 | 
								&i.Status,
 | 
				
			||||||
 | 
								&i.Account,
 | 
				
			||||||
 | 
								&i.PayeeID,
 | 
				
			||||||
 | 
								&i.CategoryID,
 | 
				
			||||||
 | 
								&i.Payee,
 | 
				
			||||||
 | 
								&i.CategoryGroup,
 | 
				
			||||||
 | 
								&i.Category,
 | 
				
			||||||
 | 
								&i.TransferAccount,
 | 
				
			||||||
 | 
								&i.BudgetID,
 | 
				
			||||||
 | 
								&i.AccountID,
 | 
				
			||||||
 | 
							); err != nil {
 | 
				
			||||||
 | 
								return nil, err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							items = append(items, i)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if err := rows.Close(); err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if err := rows.Err(); err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return items, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const getFilteredTransactions = `-- name: GetFilteredTransactions :many
 | 
				
			||||||
 | 
					SELECT transactions.id, transactions.date, transactions.memo, transactions.amount, transactions.group_id, transactions.status, transactions.account, transactions.payee_id, transactions.category_id, transactions.payee, transactions.category_group, transactions.category, transactions.transfer_account, transactions.budget_id, transactions.account_id
 | 
				
			||||||
 | 
					FROM display_transactions AS transactions
 | 
				
			||||||
 | 
					WHERE (NOT $1::boolean OR transactions.category_id = $2) 
 | 
				
			||||||
 | 
					AND (NOT $3::boolean OR transactions.account_id = $4) 
 | 
				
			||||||
 | 
					AND (NOT $5::boolean OR transactions.payee_id = $6)
 | 
				
			||||||
 | 
					AND transactions.date BETWEEN $7 AND $8
 | 
				
			||||||
 | 
					AND transactions.budget_id = $9
 | 
				
			||||||
 | 
					`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type GetFilteredTransactionsParams struct {
 | 
				
			||||||
 | 
						FilterCategory bool
 | 
				
			||||||
 | 
						CategoryID     uuid.NullUUID
 | 
				
			||||||
 | 
						FilterAccount  bool
 | 
				
			||||||
 | 
						AccountID      uuid.UUID
 | 
				
			||||||
 | 
						FilterPayee    bool
 | 
				
			||||||
 | 
						PayeeID        uuid.NullUUID
 | 
				
			||||||
 | 
						FromDate       time.Time
 | 
				
			||||||
 | 
						ToDate         time.Time
 | 
				
			||||||
 | 
						BudgetID       uuid.UUID
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (q *Queries) GetFilteredTransactions(ctx context.Context, arg GetFilteredTransactionsParams) ([]DisplayTransaction, error) {
 | 
				
			||||||
 | 
						rows, err := q.db.QueryContext(ctx, getFilteredTransactions,
 | 
				
			||||||
 | 
							arg.FilterCategory,
 | 
				
			||||||
 | 
							arg.CategoryID,
 | 
				
			||||||
 | 
							arg.FilterAccount,
 | 
				
			||||||
 | 
							arg.AccountID,
 | 
				
			||||||
 | 
							arg.FilterPayee,
 | 
				
			||||||
 | 
							arg.PayeeID,
 | 
				
			||||||
 | 
							arg.FromDate,
 | 
				
			||||||
 | 
							arg.ToDate,
 | 
				
			||||||
 | 
							arg.BudgetID,
 | 
				
			||||||
 | 
						)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						defer rows.Close()
 | 
				
			||||||
 | 
						var items []DisplayTransaction
 | 
				
			||||||
 | 
						for rows.Next() {
 | 
				
			||||||
 | 
							var i DisplayTransaction
 | 
				
			||||||
 | 
							if err := rows.Scan(
 | 
				
			||||||
 | 
								&i.ID,
 | 
				
			||||||
 | 
								&i.Date,
 | 
				
			||||||
 | 
								&i.Memo,
 | 
				
			||||||
 | 
								&i.Amount,
 | 
				
			||||||
 | 
								&i.GroupID,
 | 
				
			||||||
 | 
								&i.Status,
 | 
				
			||||||
 | 
								&i.Account,
 | 
				
			||||||
 | 
								&i.PayeeID,
 | 
				
			||||||
 | 
								&i.CategoryID,
 | 
				
			||||||
 | 
								&i.Payee,
 | 
				
			||||||
 | 
								&i.CategoryGroup,
 | 
				
			||||||
 | 
								&i.Category,
 | 
				
			||||||
 | 
								&i.TransferAccount,
 | 
				
			||||||
 | 
								&i.BudgetID,
 | 
				
			||||||
 | 
								&i.AccountID,
 | 
				
			||||||
 | 
							); err != nil {
 | 
				
			||||||
 | 
								return nil, err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							items = append(items, i)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if err := rows.Close(); err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if err := rows.Err(); err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return items, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const getProblematicTransactions = `-- name: GetProblematicTransactions :many
 | 
				
			||||||
 | 
					SELECT transactions.id, transactions.date, transactions.memo, transactions.amount, transactions.group_id, transactions.status, transactions.account, transactions.payee_id, transactions.category_id, transactions.payee, transactions.category_group, transactions.category, transactions.transfer_account, transactions.budget_id, transactions.account_id
 | 
				
			||||||
 | 
					FROM display_transactions AS transactions
 | 
				
			||||||
 | 
					LEFT JOIN accounts 
 | 
				
			||||||
 | 
					        ON transactions.account_id = accounts.id
 | 
				
			||||||
 | 
					LEFT JOIN transactions AS otherGroupTransaction 
 | 
				
			||||||
 | 
					        ON transactions.group_id = otherGroupTransaction.group_id 
 | 
				
			||||||
 | 
					        AND transactions.id != otherGroupTransaction.id 
 | 
				
			||||||
 | 
					        AND transactions.account_id != otherGroupTransaction.account_id
 | 
				
			||||||
 | 
					LEFT JOIn accounts AS otherGroupAccount 
 | 
				
			||||||
 | 
					        ON otherGroupTransaction.account_id = otherGroupAccount.id
 | 
				
			||||||
 | 
					WHERE transactions.category_id IS NULL
 | 
				
			||||||
 | 
					AND accounts.on_budget
 | 
				
			||||||
 | 
					AND (otherGroupAccount.id IS NULL OR NOT otherGroupAccount.on_budget)
 | 
				
			||||||
 | 
					AND accounts.budget_id = $1
 | 
				
			||||||
 | 
					`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (q *Queries) GetProblematicTransactions(ctx context.Context, budgetID uuid.UUID) ([]DisplayTransaction, error) {
 | 
				
			||||||
 | 
						rows, err := q.db.QueryContext(ctx, getProblematicTransactions, budgetID)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						defer rows.Close()
 | 
				
			||||||
 | 
						var items []DisplayTransaction
 | 
				
			||||||
 | 
						for rows.Next() {
 | 
				
			||||||
 | 
							var i DisplayTransaction
 | 
				
			||||||
 | 
							if err := rows.Scan(
 | 
				
			||||||
 | 
								&i.ID,
 | 
				
			||||||
 | 
								&i.Date,
 | 
				
			||||||
 | 
								&i.Memo,
 | 
				
			||||||
 | 
								&i.Amount,
 | 
				
			||||||
 | 
								&i.GroupID,
 | 
				
			||||||
 | 
								&i.Status,
 | 
				
			||||||
 | 
								&i.Account,
 | 
				
			||||||
 | 
								&i.PayeeID,
 | 
				
			||||||
 | 
								&i.CategoryID,
 | 
				
			||||||
 | 
								&i.Payee,
 | 
				
			||||||
 | 
								&i.CategoryGroup,
 | 
				
			||||||
 | 
								&i.Category,
 | 
				
			||||||
 | 
								&i.TransferAccount,
 | 
				
			||||||
 | 
								&i.BudgetID,
 | 
				
			||||||
 | 
								&i.AccountID,
 | 
				
			||||||
 | 
							); err != nil {
 | 
				
			||||||
 | 
								return nil, err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							items = append(items, i)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if err := rows.Close(); err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if err := rows.Err(); err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return items, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const getTransaction = `-- name: GetTransaction :one
 | 
					const getTransaction = `-- name: GetTransaction :one
 | 
				
			||||||
SELECT id, date, memo, amount, account_id, category_id, payee_id, group_id FROM transactions
 | 
					SELECT id, date, memo, amount, group_id, status, account, payee_id, category_id, payee, category_group, category, transfer_account, budget_id, account_id FROM display_transactions
 | 
				
			||||||
WHERE id = $1
 | 
					WHERE id = $1
 | 
				
			||||||
`
 | 
					`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (q *Queries) GetTransaction(ctx context.Context, id uuid.UUID) (Transaction, error) {
 | 
					func (q *Queries) GetTransaction(ctx context.Context, id uuid.UUID) (DisplayTransaction, error) {
 | 
				
			||||||
	row := q.db.QueryRowContext(ctx, getTransaction, id)
 | 
						row := q.db.QueryRowContext(ctx, getTransaction, id)
 | 
				
			||||||
	var i Transaction
 | 
						var i DisplayTransaction
 | 
				
			||||||
	err := row.Scan(
 | 
						err := row.Scan(
 | 
				
			||||||
		&i.ID,
 | 
							&i.ID,
 | 
				
			||||||
		&i.Date,
 | 
							&i.Date,
 | 
				
			||||||
		&i.Memo,
 | 
							&i.Memo,
 | 
				
			||||||
		&i.Amount,
 | 
							&i.Amount,
 | 
				
			||||||
		&i.AccountID,
 | 
					 | 
				
			||||||
		&i.CategoryID,
 | 
					 | 
				
			||||||
		&i.PayeeID,
 | 
					 | 
				
			||||||
		&i.GroupID,
 | 
							&i.GroupID,
 | 
				
			||||||
 | 
							&i.Status,
 | 
				
			||||||
 | 
							&i.Account,
 | 
				
			||||||
 | 
							&i.PayeeID,
 | 
				
			||||||
 | 
							&i.CategoryID,
 | 
				
			||||||
 | 
							&i.Payee,
 | 
				
			||||||
 | 
							&i.CategoryGroup,
 | 
				
			||||||
 | 
							&i.Category,
 | 
				
			||||||
 | 
							&i.TransferAccount,
 | 
				
			||||||
 | 
							&i.BudgetID,
 | 
				
			||||||
 | 
							&i.AccountID,
 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
	return i, err
 | 
						return i, err
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -132,49 +307,36 @@ func (q *Queries) GetTransactionsByMonthAndCategory(ctx context.Context, budgetI
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const getTransactionsForAccount = `-- name: GetTransactionsForAccount :many
 | 
					const getTransactionsForAccount = `-- name: GetTransactionsForAccount :many
 | 
				
			||||||
SELECT  transactions.id, transactions.date, transactions.memo, transactions.amount, transactions.group_id,
 | 
					SELECT  t.id, t.date, t.memo, t.amount, t.group_id, t.status, t.account, t.payee_id, t.category_id, t.payee, t.category_group, t.category, t.transfer_account, t.budget_id, t.account_id
 | 
				
			||||||
        accounts.name as account, COALESCE(payees.name, '') as payee, COALESCE(category_groups.name, '') as category_group, COALESCE(categories.name, '') as category
 | 
					FROM display_transactions AS t
 | 
				
			||||||
FROM transactions 
 | 
					WHERE t.account_id = $1
 | 
				
			||||||
INNER JOIN accounts ON accounts.id = transactions.account_id
 | 
					 | 
				
			||||||
LEFT JOIN payees ON payees.id = transactions.payee_id
 | 
					 | 
				
			||||||
LEFT JOIN categories ON categories.id = transactions.category_id
 | 
					 | 
				
			||||||
LEFT JOIN category_groups ON category_groups.id = categories.category_group_id
 | 
					 | 
				
			||||||
WHERE transactions.account_id = $1
 | 
					 | 
				
			||||||
ORDER BY transactions.date DESC
 | 
					 | 
				
			||||||
LIMIT 200
 | 
					 | 
				
			||||||
`
 | 
					`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type GetTransactionsForAccountRow struct {
 | 
					func (q *Queries) GetTransactionsForAccount(ctx context.Context, accountID uuid.UUID) ([]DisplayTransaction, error) {
 | 
				
			||||||
	ID            uuid.UUID
 | 
					 | 
				
			||||||
	Date          time.Time
 | 
					 | 
				
			||||||
	Memo          string
 | 
					 | 
				
			||||||
	Amount        Numeric
 | 
					 | 
				
			||||||
	GroupID       uuid.NullUUID
 | 
					 | 
				
			||||||
	Account       string
 | 
					 | 
				
			||||||
	Payee         string
 | 
					 | 
				
			||||||
	CategoryGroup string
 | 
					 | 
				
			||||||
	Category      string
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (q *Queries) GetTransactionsForAccount(ctx context.Context, accountID uuid.UUID) ([]GetTransactionsForAccountRow, error) {
 | 
					 | 
				
			||||||
	rows, err := q.db.QueryContext(ctx, getTransactionsForAccount, accountID)
 | 
						rows, err := q.db.QueryContext(ctx, getTransactionsForAccount, accountID)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, err
 | 
							return nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	defer rows.Close()
 | 
						defer rows.Close()
 | 
				
			||||||
	var items []GetTransactionsForAccountRow
 | 
						var items []DisplayTransaction
 | 
				
			||||||
	for rows.Next() {
 | 
						for rows.Next() {
 | 
				
			||||||
		var i GetTransactionsForAccountRow
 | 
							var i DisplayTransaction
 | 
				
			||||||
		if err := rows.Scan(
 | 
							if err := rows.Scan(
 | 
				
			||||||
			&i.ID,
 | 
								&i.ID,
 | 
				
			||||||
			&i.Date,
 | 
								&i.Date,
 | 
				
			||||||
			&i.Memo,
 | 
								&i.Memo,
 | 
				
			||||||
			&i.Amount,
 | 
								&i.Amount,
 | 
				
			||||||
			&i.GroupID,
 | 
								&i.GroupID,
 | 
				
			||||||
 | 
								&i.Status,
 | 
				
			||||||
			&i.Account,
 | 
								&i.Account,
 | 
				
			||||||
 | 
								&i.PayeeID,
 | 
				
			||||||
 | 
								&i.CategoryID,
 | 
				
			||||||
			&i.Payee,
 | 
								&i.Payee,
 | 
				
			||||||
			&i.CategoryGroup,
 | 
								&i.CategoryGroup,
 | 
				
			||||||
			&i.Category,
 | 
								&i.Category,
 | 
				
			||||||
 | 
								&i.TransferAccount,
 | 
				
			||||||
 | 
								&i.BudgetID,
 | 
				
			||||||
 | 
								&i.AccountID,
 | 
				
			||||||
		); err != nil {
 | 
							); err != nil {
 | 
				
			||||||
			return nil, err
 | 
								return nil, err
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@@ -189,62 +351,15 @@ func (q *Queries) GetTransactionsForAccount(ctx context.Context, accountID uuid.
 | 
				
			|||||||
	return items, nil
 | 
						return items, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const getTransactionsForBudget = `-- name: GetTransactionsForBudget :many
 | 
					const setTransactionReconciled = `-- name: SetTransactionReconciled :exec
 | 
				
			||||||
SELECT  transactions.id, transactions.date, transactions.memo, transactions.amount, transactions.group_id,
 | 
					UPDATE transactions
 | 
				
			||||||
        accounts.name as account, COALESCE(payees.name, '') as payee, COALESCE(category_groups.name, '') as category_group, COALESCE(categories.name, '') as category
 | 
					SET status = 'Reconciled'
 | 
				
			||||||
FROM transactions 
 | 
					WHERE id = $1
 | 
				
			||||||
INNER JOIN accounts ON accounts.id = transactions.account_id
 | 
					 | 
				
			||||||
LEFT JOIN payees ON payees.id = transactions.payee_id
 | 
					 | 
				
			||||||
LEFT JOIN categories ON categories.id = transactions.category_id
 | 
					 | 
				
			||||||
LEFT JOIN category_groups ON category_groups.id = categories.category_group_id
 | 
					 | 
				
			||||||
WHERE accounts.budget_id = $1
 | 
					 | 
				
			||||||
ORDER BY transactions.date DESC
 | 
					 | 
				
			||||||
LIMIT 200
 | 
					 | 
				
			||||||
`
 | 
					`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type GetTransactionsForBudgetRow struct {
 | 
					func (q *Queries) SetTransactionReconciled(ctx context.Context, id uuid.UUID) error {
 | 
				
			||||||
	ID            uuid.UUID
 | 
						_, err := q.db.ExecContext(ctx, setTransactionReconciled, id)
 | 
				
			||||||
	Date          time.Time
 | 
						return err
 | 
				
			||||||
	Memo          string
 | 
					 | 
				
			||||||
	Amount        Numeric
 | 
					 | 
				
			||||||
	GroupID       uuid.NullUUID
 | 
					 | 
				
			||||||
	Account       string
 | 
					 | 
				
			||||||
	Payee         string
 | 
					 | 
				
			||||||
	CategoryGroup string
 | 
					 | 
				
			||||||
	Category      string
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (q *Queries) GetTransactionsForBudget(ctx context.Context, budgetID uuid.UUID) ([]GetTransactionsForBudgetRow, error) {
 | 
					 | 
				
			||||||
	rows, err := q.db.QueryContext(ctx, getTransactionsForBudget, budgetID)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		return nil, err
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	defer rows.Close()
 | 
					 | 
				
			||||||
	var items []GetTransactionsForBudgetRow
 | 
					 | 
				
			||||||
	for rows.Next() {
 | 
					 | 
				
			||||||
		var i GetTransactionsForBudgetRow
 | 
					 | 
				
			||||||
		if err := rows.Scan(
 | 
					 | 
				
			||||||
			&i.ID,
 | 
					 | 
				
			||||||
			&i.Date,
 | 
					 | 
				
			||||||
			&i.Memo,
 | 
					 | 
				
			||||||
			&i.Amount,
 | 
					 | 
				
			||||||
			&i.GroupID,
 | 
					 | 
				
			||||||
			&i.Account,
 | 
					 | 
				
			||||||
			&i.Payee,
 | 
					 | 
				
			||||||
			&i.CategoryGroup,
 | 
					 | 
				
			||||||
			&i.Category,
 | 
					 | 
				
			||||||
		); err != nil {
 | 
					 | 
				
			||||||
			return nil, err
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		items = append(items, i)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if err := rows.Close(); err != nil {
 | 
					 | 
				
			||||||
		return nil, err
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if err := rows.Err(); err != nil {
 | 
					 | 
				
			||||||
		return nil, err
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return items, nil
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const updateTransaction = `-- name: UpdateTransaction :exec
 | 
					const updateTransaction = `-- name: UpdateTransaction :exec
 | 
				
			||||||
@@ -252,17 +367,15 @@ UPDATE transactions
 | 
				
			|||||||
SET date = $1,
 | 
					SET date = $1,
 | 
				
			||||||
  memo = $2,
 | 
					  memo = $2,
 | 
				
			||||||
  amount = $3,
 | 
					  amount = $3,
 | 
				
			||||||
    account_id = $4,
 | 
					  payee_id = $4,
 | 
				
			||||||
    payee_id = $5,
 | 
					  category_id = $5
 | 
				
			||||||
    category_id = $6
 | 
					WHERE id = $6
 | 
				
			||||||
WHERE id = $7
 | 
					 | 
				
			||||||
`
 | 
					`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type UpdateTransactionParams struct {
 | 
					type UpdateTransactionParams struct {
 | 
				
			||||||
	Date       time.Time
 | 
						Date       time.Time
 | 
				
			||||||
	Memo       string
 | 
						Memo       string
 | 
				
			||||||
	Amount     Numeric
 | 
						Amount     numeric.Numeric
 | 
				
			||||||
	AccountID  uuid.UUID
 | 
					 | 
				
			||||||
	PayeeID    uuid.NullUUID
 | 
						PayeeID    uuid.NullUUID
 | 
				
			||||||
	CategoryID uuid.NullUUID
 | 
						CategoryID uuid.NullUUID
 | 
				
			||||||
	ID         uuid.UUID
 | 
						ID         uuid.UUID
 | 
				
			||||||
@@ -273,7 +386,6 @@ func (q *Queries) UpdateTransaction(ctx context.Context, arg UpdateTransactionPa
 | 
				
			|||||||
		arg.Date,
 | 
							arg.Date,
 | 
				
			||||||
		arg.Memo,
 | 
							arg.Memo,
 | 
				
			||||||
		arg.Amount,
 | 
							arg.Amount,
 | 
				
			||||||
		arg.AccountID,
 | 
					 | 
				
			||||||
		arg.PayeeID,
 | 
							arg.PayeeID,
 | 
				
			||||||
		arg.CategoryID,
 | 
							arg.CategoryID,
 | 
				
			||||||
		arg.ID,
 | 
							arg.ID,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,4 +1,6 @@
 | 
				
			|||||||
// Code generated by sqlc. DO NOT EDIT.
 | 
					// Code generated by sqlc. DO NOT EDIT.
 | 
				
			||||||
 | 
					// versions:
 | 
				
			||||||
 | 
					//   sqlc v1.13.0
 | 
				
			||||||
// source: user_budgets.sql
 | 
					// source: user_budgets.sql
 | 
				
			||||||
 | 
					
 | 
				
			||||||
package postgres
 | 
					package postgres
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,4 +1,6 @@
 | 
				
			|||||||
// Code generated by sqlc. DO NOT EDIT.
 | 
					// Code generated by sqlc. DO NOT EDIT.
 | 
				
			||||||
 | 
					// versions:
 | 
				
			||||||
 | 
					//   sqlc v1.13.0
 | 
				
			||||||
// source: users.sql
 | 
					// source: users.sql
 | 
				
			||||||
 | 
					
 | 
				
			||||||
package postgres
 | 
					package postgres
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										144
									
								
								postgres/ynab-export.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										144
									
								
								postgres/ynab-export.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,144 @@
 | 
				
			|||||||
 | 
					package postgres
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"context"
 | 
				
			||||||
 | 
						"encoding/csv"
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
						"io"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"git.javil.eu/jacob1123/budgeteer/postgres/numeric"
 | 
				
			||||||
 | 
						"github.com/google/uuid"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type YNABExport struct {
 | 
				
			||||||
 | 
						queries  *Queries
 | 
				
			||||||
 | 
						budgetID uuid.UUID
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func NewYNABExport(context context.Context, queries *Queries, budgetID uuid.UUID) (*YNABExport, error) {
 | 
				
			||||||
 | 
						return &YNABExport{
 | 
				
			||||||
 | 
							queries:  queries,
 | 
				
			||||||
 | 
							budgetID: budgetID,
 | 
				
			||||||
 | 
						}, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// ImportAssignments expects a TSV-file as exported by YNAB in the following format:
 | 
				
			||||||
 | 
					// "Month"	"Category Group/Category"	"Category Group"	"Category"	"Budgeted"	"Activity"	"Available"
 | 
				
			||||||
 | 
					// "Apr 2019"	"Income: Next Month"	"Income"	"Next Month"	0,00€	0,00€	0,00€
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					// Activity and Available are not imported, since they are determined by the transactions and historic assignments.
 | 
				
			||||||
 | 
					func (ynab *YNABExport) ExportAssignments(context context.Context, w io.Writer) error {
 | 
				
			||||||
 | 
						csv := csv.NewWriter(w)
 | 
				
			||||||
 | 
						csv.Comma = '\t'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						assignments, err := ynab.queries.GetAllAssignments(context, ynab.budgetID)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return fmt.Errorf("load assignments: %w", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						count := 0
 | 
				
			||||||
 | 
						for _, assignment := range assignments {
 | 
				
			||||||
 | 
							row := []string{
 | 
				
			||||||
 | 
								assignment.Date.Format("Jan 2006"),
 | 
				
			||||||
 | 
								assignment.Group + ": " + assignment.Category,
 | 
				
			||||||
 | 
								assignment.Group,
 | 
				
			||||||
 | 
								assignment.Category,
 | 
				
			||||||
 | 
								assignment.Amount.String() + "€",
 | 
				
			||||||
 | 
								numeric.Zero().String() + "€",
 | 
				
			||||||
 | 
								numeric.Zero().String() + "€",
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							err := csv.Write(row)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								return fmt.Errorf("write assignment: %w", err)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							count++
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						csv.Flush()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						fmt.Printf("Exported %d assignments\n", count)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// ImportTransactions expects a TSV-file as exported by YNAB in the following format:
 | 
				
			||||||
 | 
					// "Account"	"Flag"	"Date"	"Payee"	"Category Group/Category"	"Category Group"	"Category"	"Memo"	"Outflow"	"Inflow"	"Cleared"
 | 
				
			||||||
 | 
					// "Cash"	""	"11.12.2021"	"Transfer : Checking"	""	""	""	"Brought to bank"	500,00€	0,00€	"Cleared".
 | 
				
			||||||
 | 
					func (ynab *YNABExport) ExportTransactions(context context.Context, w io.Writer) error {
 | 
				
			||||||
 | 
						csv := csv.NewWriter(w)
 | 
				
			||||||
 | 
						csv.Comma = '\t'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						transactions, err := ynab.queries.GetAllTransactionsForBudget(context, ynab.budgetID)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return fmt.Errorf("load transactions: %w", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						header := []string{
 | 
				
			||||||
 | 
							"Account",
 | 
				
			||||||
 | 
							"Flag",
 | 
				
			||||||
 | 
							"Date",
 | 
				
			||||||
 | 
							"Payee",
 | 
				
			||||||
 | 
							"Category Group/Category",
 | 
				
			||||||
 | 
							"Category Group",
 | 
				
			||||||
 | 
							"Category",
 | 
				
			||||||
 | 
							"Memo",
 | 
				
			||||||
 | 
							"Outflow",
 | 
				
			||||||
 | 
							"Inflow",
 | 
				
			||||||
 | 
							"Cleared",
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						err = csv.Write(header)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return fmt.Errorf("write transaction: %w", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						count := 0
 | 
				
			||||||
 | 
						for _, transaction := range transactions {
 | 
				
			||||||
 | 
							row := GetTransactionRow(transaction)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							err := csv.Write(row)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								return fmt.Errorf("write transaction: %w", err)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							count++
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						csv.Flush()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						fmt.Printf("Exported %d transactions\n", count)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func GetTransactionRow(transaction DisplayTransaction) []string {
 | 
				
			||||||
 | 
						row := []string{
 | 
				
			||||||
 | 
							transaction.Account,
 | 
				
			||||||
 | 
							"", // Flag
 | 
				
			||||||
 | 
							transaction.Date.Format("02.01.2006"),
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if transaction.TransferAccount != "" {
 | 
				
			||||||
 | 
							row = append(row, "Transfer : "+transaction.TransferAccount)
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							row = append(row, transaction.Payee)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if transaction.CategoryGroup != "" && transaction.Category != "" {
 | 
				
			||||||
 | 
							row = append(row,
 | 
				
			||||||
 | 
								transaction.CategoryGroup+": "+transaction.Category,
 | 
				
			||||||
 | 
								transaction.CategoryGroup,
 | 
				
			||||||
 | 
								transaction.Category)
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							row = append(row, "", "", "")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						row = append(row, transaction.Memo)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if transaction.Amount.IsPositive() {
 | 
				
			||||||
 | 
							row = append(row, numeric.Zero().String()+"€", transaction.Amount.String()+"€")
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							row = append(row, transaction.Amount.String()[1:]+"€", numeric.Zero().String()+"€")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return append(row, string(transaction.Status))
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -7,13 +7,12 @@ import (
 | 
				
			|||||||
	"io"
 | 
						"io"
 | 
				
			||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
	"unicode/utf8"
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"git.javil.eu/jacob1123/budgeteer/postgres/numeric"
 | 
				
			||||||
	"github.com/google/uuid"
 | 
						"github.com/google/uuid"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type YNABImport struct {
 | 
					type YNABImport struct {
 | 
				
			||||||
	Context        context.Context
 | 
					 | 
				
			||||||
	accounts       []Account
 | 
						accounts       []Account
 | 
				
			||||||
	payees         []Payee
 | 
						payees         []Payee
 | 
				
			||||||
	categories     []GetCategoriesRow
 | 
						categories     []GetCategoriesRow
 | 
				
			||||||
@@ -22,87 +21,84 @@ type YNABImport struct {
 | 
				
			|||||||
	budgetID       uuid.UUID
 | 
						budgetID       uuid.UUID
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func NewYNABImport(context context.Context, q *Queries, budgetID uuid.UUID) (*YNABImport, error) {
 | 
					func NewYNABImport(context context.Context, queries *Queries, budgetID uuid.UUID) (*YNABImport, error) {
 | 
				
			||||||
	accounts, err := q.GetAccounts(context, budgetID)
 | 
						accounts, err := queries.GetAccounts(context, budgetID)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, err
 | 
							return nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	payees, err := q.GetPayees(context, budgetID)
 | 
						payees, err := queries.GetPayees(context, budgetID)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, err
 | 
							return nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	categories, err := q.GetCategories(context, budgetID)
 | 
						categories, err := queries.GetCategories(context, budgetID)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, err
 | 
							return nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	categoryGroups, err := q.GetCategoryGroups(context, budgetID)
 | 
						categoryGroups, err := queries.GetCategoryGroups(context, budgetID)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, err
 | 
							return nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return &YNABImport{
 | 
						return &YNABImport{
 | 
				
			||||||
		Context:        context,
 | 
					 | 
				
			||||||
		accounts:       accounts,
 | 
							accounts:       accounts,
 | 
				
			||||||
		payees:         payees,
 | 
							payees:         payees,
 | 
				
			||||||
		categories:     categories,
 | 
							categories:     categories,
 | 
				
			||||||
		categoryGroups: categoryGroups,
 | 
							categoryGroups: categoryGroups,
 | 
				
			||||||
		queries:        q,
 | 
							queries:        queries,
 | 
				
			||||||
		budgetID:       budgetID,
 | 
							budgetID:       budgetID,
 | 
				
			||||||
	}, nil
 | 
						}, nil
 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// ImportAssignments expects a TSV-file as exported by YNAB in the following format:
 | 
					// ImportAssignments expects a TSV-file as exported by YNAB in the following format:
 | 
				
			||||||
//"Month"	"Category Group/Category"	"Category Group"	"Category"	"Budgeted"	"Activity"	"Available"
 | 
					// "Month"	"Category Group/Category"	"Category Group"	"Category"	"Budgeted"	"Activity"	"Available"
 | 
				
			||||||
//"Apr 2019"	"Income: Next Month"	"Income"	"Next Month"	0,00€	0,00€	0,00€
 | 
					// "Apr 2019"	"Income: Next Month"	"Income"	"Next Month"	0,00€	0,00€	0,00€
 | 
				
			||||||
//
 | 
					//
 | 
				
			||||||
// Activity and Available are not imported, since they are determined by the transactions and historic assignments
 | 
					// Activity and Available are not imported, since they are determined by the transactions and historic assignments.
 | 
				
			||||||
func (ynab *YNABImport) ImportAssignments(r io.Reader) error {
 | 
					func (ynab *YNABImport) ImportAssignments(context context.Context, r io.Reader) error {
 | 
				
			||||||
	csv := csv.NewReader(r)
 | 
						csv := csv.NewReader(r)
 | 
				
			||||||
	csv.Comma = '\t'
 | 
						csv.Comma = '\t'
 | 
				
			||||||
	csv.LazyQuotes = true
 | 
						csv.LazyQuotes = true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	csvData, err := csv.ReadAll()
 | 
						csvData, err := csv.ReadAll()
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return fmt.Errorf("could not read from tsv: %w", err)
 | 
							return fmt.Errorf("read from tsv: %w", err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	count := 0
 | 
						count := 0
 | 
				
			||||||
	for _, record := range csvData[1:] {
 | 
						for _, record := range csvData[1:] {
 | 
				
			||||||
 | 
					 | 
				
			||||||
		dateString := record[0]
 | 
							dateString := record[0]
 | 
				
			||||||
		date, err := time.Parse("Jan 2006", dateString)
 | 
							date, err := time.Parse("Jan 2006", dateString)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			return fmt.Errorf("could not parse date %s: %w", dateString, err)
 | 
								return fmt.Errorf("parse date %s: %w", dateString, err)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		categoryGroup, categoryName := record[2], record[3] //also in 1 joined by :
 | 
							categoryGroup, categoryName := record[2], record[3] // also in 1 joined by :
 | 
				
			||||||
		category, err := ynab.GetCategory(categoryGroup, categoryName)
 | 
							category, err := ynab.GetCategory(context, categoryGroup, categoryName)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			return fmt.Errorf("could not get category %s/%s: %w", categoryGroup, categoryName, err)
 | 
								return fmt.Errorf("get category %s/%s: %w", categoryGroup, categoryName, err)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		amountString := record[4]
 | 
							amountString := record[4]
 | 
				
			||||||
		amount, err := GetAmount(amountString, "0,00€")
 | 
							amount, err := GetAmount(amountString, "0,00€")
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			return fmt.Errorf("could not parse amount %s: %w", amountString, err)
 | 
								return fmt.Errorf("parse amount %s: %w", amountString, err)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if amount.Int.Int64() == 0 {
 | 
							if amount.Int.Int64() == 0 {
 | 
				
			||||||
			continue
 | 
								continue
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		assignment := CreateAssignmentParams{
 | 
							assignment := UpdateAssignmentWithDifferenceParams{
 | 
				
			||||||
			Date:       date,
 | 
								Date:       date,
 | 
				
			||||||
			CategoryID: category.UUID,
 | 
								CategoryID: category.UUID,
 | 
				
			||||||
			Amount:     amount,
 | 
								Amount:     amount,
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		_, err = ynab.queries.CreateAssignment(ynab.Context, assignment)
 | 
							err = ynab.queries.UpdateAssignmentWithDifference(context, assignment)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			return fmt.Errorf("could not save assignment %v: %w", assignment, err)
 | 
								return fmt.Errorf("save assignment %v: %w", assignment, err)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		count++
 | 
							count++
 | 
				
			||||||
@@ -121,39 +117,80 @@ type Transfer struct {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// ImportTransactions expects a TSV-file as exported by YNAB in the following format:
 | 
					// ImportTransactions expects a TSV-file as exported by YNAB in the following format:
 | 
				
			||||||
 | 
					// "Account"	"Flag"	"Date"	"Payee"	"Category Group/Category"	"Category Group"	"Category"	"Memo"	"Outflow"	"Inflow"	"Cleared"
 | 
				
			||||||
func (ynab *YNABImport) ImportTransactions(r io.Reader) error {
 | 
					// "Cash"	""	"11.12.2021"	"Transfer : Checking"	""	""	""	"Brought to bank"	500,00€	0,00€	"Cleared".
 | 
				
			||||||
 | 
					func (ynab *YNABImport) ImportTransactions(context context.Context, r io.Reader) error {
 | 
				
			||||||
	csv := csv.NewReader(r)
 | 
						csv := csv.NewReader(r)
 | 
				
			||||||
	csv.Comma = '\t'
 | 
						csv.Comma = '\t'
 | 
				
			||||||
	csv.LazyQuotes = true
 | 
						csv.LazyQuotes = true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	csvData, err := csv.ReadAll()
 | 
						csvData, err := csv.ReadAll()
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return fmt.Errorf("could not read from tsv: %w", err)
 | 
							return fmt.Errorf("read from tsv: %w", err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var openTransfers []Transfer
 | 
						var openTransfers []Transfer
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	count := 0
 | 
						count := 0
 | 
				
			||||||
	for _, record := range csvData[1:] {
 | 
						for _, record := range csvData[1:] {
 | 
				
			||||||
		accountName := record[0]
 | 
							transaction, err := ynab.GetTransaction(context, record)
 | 
				
			||||||
		account, err := ynab.GetAccount(accountName)
 | 
					 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			return fmt.Errorf("could not get account %s: %w", accountName, err)
 | 
								return err
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		//flag := record[1]
 | 
							payeeName := record[3]
 | 
				
			||||||
 | 
							// Transaction is a transfer
 | 
				
			||||||
 | 
							if strings.HasPrefix(payeeName, "Transfer : ") {
 | 
				
			||||||
 | 
								err = ynab.ImportTransferTransaction(context, payeeName, transaction.CreateTransactionParams,
 | 
				
			||||||
 | 
									&openTransfers, transaction.Account, transaction.Amount)
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								err = ynab.ImportRegularTransaction(context, payeeName, transaction.CreateTransactionParams)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								return err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							count++
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for _, openTransfer := range openTransfers {
 | 
				
			||||||
 | 
							fmt.Printf("Saving unmatched transfer from %s to %s on %s over %f as regular transaction\n",
 | 
				
			||||||
 | 
								openTransfer.FromAccount, openTransfer.ToAccount, openTransfer.Date, openTransfer.Amount.GetFloat64())
 | 
				
			||||||
 | 
							_, err = ynab.queries.CreateTransaction(context, openTransfer.CreateTransactionParams)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								return fmt.Errorf("save transaction %v: %w", openTransfer.CreateTransactionParams, err)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						fmt.Printf("Imported %d transactions\n", count)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type NewTransaction struct {
 | 
				
			||||||
 | 
						CreateTransactionParams
 | 
				
			||||||
 | 
						Account *Account
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (ynab *YNABImport) GetTransaction(context context.Context, record []string) (NewTransaction, error) {
 | 
				
			||||||
 | 
						accountName := record[0]
 | 
				
			||||||
 | 
						account, err := ynab.GetAccount(context, accountName)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return NewTransaction{}, fmt.Errorf("get account %s: %w", accountName, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// flag := record[1]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	dateString := record[2]
 | 
						dateString := record[2]
 | 
				
			||||||
	date, err := time.Parse("02.01.2006", dateString)
 | 
						date, err := time.Parse("02.01.2006", dateString)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
			return fmt.Errorf("could not parse date %s: %w", dateString, err)
 | 
							return NewTransaction{}, fmt.Errorf("parse date %s: %w", dateString, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		categoryGroup, categoryName := record[5], record[6] //also in 4 joined by :
 | 
						categoryGroup, categoryName := record[5], record[6] // also in 4 joined by :
 | 
				
			||||||
		category, err := ynab.GetCategory(categoryGroup, categoryName)
 | 
						category, err := ynab.GetCategory(context, categoryGroup, categoryName)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
			return fmt.Errorf("could not get category %s/%s: %w", categoryGroup, categoryName, err)
 | 
							return NewTransaction{}, fmt.Errorf("get category %s/%s: %w", categoryGroup, categoryName, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	memo := record[7]
 | 
						memo := record[7]
 | 
				
			||||||
@@ -162,35 +199,67 @@ func (ynab *YNABImport) ImportTransactions(r io.Reader) error {
 | 
				
			|||||||
	inflow := record[9]
 | 
						inflow := record[9]
 | 
				
			||||||
	amount, err := GetAmount(inflow, outflow)
 | 
						amount, err := GetAmount(inflow, outflow)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
			return fmt.Errorf("could not parse amount from (%s/%s): %w", inflow, outflow, err)
 | 
							return NewTransaction{}, fmt.Errorf("parse amount from (%s/%s): %w", inflow, outflow, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		transaction := CreateTransactionParams{
 | 
						statusEnum := TransactionStatusUncleared
 | 
				
			||||||
 | 
						status := record[10]
 | 
				
			||||||
 | 
						switch status {
 | 
				
			||||||
 | 
						case "Cleared":
 | 
				
			||||||
 | 
							statusEnum = TransactionStatusCleared
 | 
				
			||||||
 | 
						case "Reconciled":
 | 
				
			||||||
 | 
							statusEnum = TransactionStatusReconciled
 | 
				
			||||||
 | 
						case "Uncleared":
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return NewTransaction{
 | 
				
			||||||
 | 
							CreateTransactionParams: CreateTransactionParams{
 | 
				
			||||||
			Date:       date,
 | 
								Date:       date,
 | 
				
			||||||
			Memo:       memo,
 | 
								Memo:       memo,
 | 
				
			||||||
			AccountID:  account.ID,
 | 
								AccountID:  account.ID,
 | 
				
			||||||
			CategoryID: category,
 | 
								CategoryID: category,
 | 
				
			||||||
			Amount:     amount,
 | 
								Amount:     amount,
 | 
				
			||||||
		}
 | 
								Status:     statusEnum,
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
							Account: account,
 | 
				
			||||||
 | 
						}, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		payeeName := record[3]
 | 
					func (ynab *YNABImport) ImportRegularTransaction(context context.Context, payeeName string,
 | 
				
			||||||
		if strings.HasPrefix(payeeName, "Transfer : ") {
 | 
						transaction CreateTransactionParams,
 | 
				
			||||||
			// Transaction is a transfer to
 | 
					) error {
 | 
				
			||||||
			transferToAccountName := payeeName[11:]
 | 
						payeeID, err := ynab.GetPayee(context, payeeName)
 | 
				
			||||||
			transferToAccount, err := ynab.GetAccount(transferToAccountName)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
				return fmt.Errorf("Could not get transfer account %s: %w", transferToAccountName, err)
 | 
							return fmt.Errorf("get payee %s: %w", payeeName, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						transaction.PayeeID = payeeID
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						_, err = ynab.queries.CreateTransaction(context, transaction)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return fmt.Errorf("save transaction %v: %w", transaction, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (ynab *YNABImport) ImportTransferTransaction(context context.Context, payeeName string,
 | 
				
			||||||
 | 
						transaction CreateTransactionParams, openTransfers *[]Transfer,
 | 
				
			||||||
 | 
						account *Account, amount numeric.Numeric,
 | 
				
			||||||
 | 
					) error {
 | 
				
			||||||
 | 
						transferToAccountName := payeeName[11:]
 | 
				
			||||||
 | 
						transferToAccount, err := ynab.GetAccount(context, transferToAccountName)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return fmt.Errorf("get transfer account %s: %w", transferToAccountName, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	transfer := Transfer{
 | 
						transfer := Transfer{
 | 
				
			||||||
		transaction,
 | 
							transaction,
 | 
				
			||||||
		transferToAccount,
 | 
							transferToAccount,
 | 
				
			||||||
				accountName,
 | 
							account.Name,
 | 
				
			||||||
		transferToAccountName,
 | 
							transferToAccountName,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	found := false
 | 
						found := false
 | 
				
			||||||
			for i, openTransfer := range openTransfers {
 | 
						for i, openTransfer := range *openTransfers {
 | 
				
			||||||
		if openTransfer.TransferToAccount.ID != transfer.AccountID {
 | 
							if openTransfer.TransferToAccount.ID != transfer.AccountID {
 | 
				
			||||||
			continue
 | 
								continue
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@@ -202,98 +271,58 @@ func (ynab *YNABImport) ImportTransactions(r io.Reader) error {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		fmt.Printf("Matched transfers from %s to %s over %f\n", account.Name, transferToAccount.Name, amount.GetFloat64())
 | 
							fmt.Printf("Matched transfers from %s to %s over %f\n", account.Name, transferToAccount.Name, amount.GetFloat64())
 | 
				
			||||||
				openTransfers[i] = openTransfers[len(openTransfers)-1]
 | 
							transfers := *openTransfers
 | 
				
			||||||
				openTransfers = openTransfers[:len(openTransfers)-1]
 | 
							transfers[i] = transfers[len(transfers)-1]
 | 
				
			||||||
 | 
							*openTransfers = transfers[:len(transfers)-1]
 | 
				
			||||||
		found = true
 | 
							found = true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		groupID := uuid.New()
 | 
							groupID := uuid.New()
 | 
				
			||||||
		transfer.GroupID = uuid.NullUUID{UUID: groupID, Valid: true}
 | 
							transfer.GroupID = uuid.NullUUID{UUID: groupID, Valid: true}
 | 
				
			||||||
		openTransfer.GroupID = uuid.NullUUID{UUID: groupID, Valid: true}
 | 
							openTransfer.GroupID = uuid.NullUUID{UUID: groupID, Valid: true}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				_, err = ynab.queries.CreateTransaction(ynab.Context, transfer.CreateTransactionParams)
 | 
							_, err = ynab.queries.CreateTransaction(context, transfer.CreateTransactionParams)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
					return fmt.Errorf("could not save transaction %v: %w", transfer.CreateTransactionParams, err)
 | 
								return fmt.Errorf("save transaction %v: %w", transfer.CreateTransactionParams, err)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
				_, err = ynab.queries.CreateTransaction(ynab.Context, openTransfer.CreateTransactionParams)
 | 
							_, err = ynab.queries.CreateTransaction(context, openTransfer.CreateTransactionParams)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
					return fmt.Errorf("could not save transaction %v: %w", openTransfer.CreateTransactionParams, err)
 | 
								return fmt.Errorf("save transaction %v: %w", openTransfer.CreateTransactionParams, err)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		break
 | 
							break
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if !found {
 | 
						if !found {
 | 
				
			||||||
				openTransfers = append(openTransfers, transfer)
 | 
							*openTransfers = append(*openTransfers, transfer)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
		} else {
 | 
					 | 
				
			||||||
			payeeID, err := ynab.GetPayee(payeeName)
 | 
					 | 
				
			||||||
			if err != nil {
 | 
					 | 
				
			||||||
				return fmt.Errorf("could not get payee %s: %w", payeeName, err)
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			transaction.PayeeID = payeeID
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			_, err = ynab.queries.CreateTransaction(ynab.Context, transaction)
 | 
					 | 
				
			||||||
			if err != nil {
 | 
					 | 
				
			||||||
				return fmt.Errorf("could not save transaction %v: %w", transaction, err)
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		//status := record[10]
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		count++
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	for _, openTransfer := range openTransfers {
 | 
					 | 
				
			||||||
		fmt.Printf("Saving unmatched transfer from %s to %s on %s over %f as regular transaction\n", openTransfer.FromAccount, openTransfer.ToAccount, openTransfer.Date, openTransfer.Amount.GetFloat64())
 | 
					 | 
				
			||||||
		_, err = ynab.queries.CreateTransaction(ynab.Context, openTransfer.CreateTransactionParams)
 | 
					 | 
				
			||||||
		if err != nil {
 | 
					 | 
				
			||||||
			return fmt.Errorf("could not save transaction %v: %w", openTransfer.CreateTransactionParams, err)
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	fmt.Printf("Imported %d transactions\n", count)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	return nil
 | 
						return nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func trimLastChar(s string) string {
 | 
					func GetAmount(inflow string, outflow string) (numeric.Numeric, error) {
 | 
				
			||||||
	r, size := utf8.DecodeLastRuneInString(s)
 | 
						in, err := numeric.ParseCurrency(inflow)
 | 
				
			||||||
	if r == utf8.RuneError && (size == 0 || size == 1) {
 | 
					 | 
				
			||||||
		size = 0
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return s[:len(s)-size]
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func GetAmount(inflow string, outflow string) (Numeric, error) {
 | 
					 | 
				
			||||||
	// Remove trailing currency
 | 
					 | 
				
			||||||
	inflow = strings.Replace(trimLastChar(inflow), ",", ".", 1)
 | 
					 | 
				
			||||||
	outflow = strings.Replace(trimLastChar(outflow), ",", ".", 1)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	num := Numeric{}
 | 
					 | 
				
			||||||
	err := num.Set(inflow)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return num, fmt.Errorf("Could not parse inflow %s: %w", inflow, err)
 | 
							return in, fmt.Errorf("parse inflow: %w", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if !in.IsZero() {
 | 
				
			||||||
 | 
							return in, nil
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// if inflow is zero, use outflow
 | 
						// if inflow is zero, use outflow
 | 
				
			||||||
	if num.Int.Int64() != 0 {
 | 
						out, err := numeric.ParseCurrency("-" + outflow)
 | 
				
			||||||
		return num, nil
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	err = num.Set("-" + outflow)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return num, fmt.Errorf("Could not parse outflow %s: %w", inflow, err)
 | 
							return out, fmt.Errorf("parse outflow: %w", err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return num, nil
 | 
						return out, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (ynab *YNABImport) GetAccount(name string) (*Account, error) {
 | 
					func (ynab *YNABImport) GetAccount(context context.Context, name string) (*Account, error) {
 | 
				
			||||||
	for _, acc := range ynab.accounts {
 | 
						for _, acc := range ynab.accounts {
 | 
				
			||||||
		if acc.Name == name {
 | 
							if acc.Name == name {
 | 
				
			||||||
			return &acc, nil
 | 
								return &acc, nil
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	account, err := ynab.queries.CreateAccount(ynab.Context, CreateAccountParams{Name: name, BudgetID: ynab.budgetID})
 | 
						account, err := ynab.queries.CreateAccount(context, CreateAccountParams{Name: name, BudgetID: ynab.budgetID})
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, err
 | 
							return nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -302,7 +331,7 @@ func (ynab *YNABImport) GetAccount(name string) (*Account, error) {
 | 
				
			|||||||
	return &account, nil
 | 
						return &account, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (ynab *YNABImport) GetPayee(name string) (uuid.NullUUID, error) {
 | 
					func (ynab *YNABImport) GetPayee(context context.Context, name string) (uuid.NullUUID, error) {
 | 
				
			||||||
	if name == "" {
 | 
						if name == "" {
 | 
				
			||||||
		return uuid.NullUUID{}, nil
 | 
							return uuid.NullUUID{}, nil
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -313,7 +342,7 @@ func (ynab *YNABImport) GetPayee(name string) (uuid.NullUUID, error) {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	payee, err := ynab.queries.CreatePayee(ynab.Context, CreatePayeeParams{Name: name, BudgetID: ynab.budgetID})
 | 
						payee, err := ynab.queries.CreatePayee(context, CreatePayeeParams{Name: name, BudgetID: ynab.budgetID})
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return uuid.NullUUID{}, err
 | 
							return uuid.NullUUID{}, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -322,7 +351,7 @@ func (ynab *YNABImport) GetPayee(name string) (uuid.NullUUID, error) {
 | 
				
			|||||||
	return uuid.NullUUID{UUID: payee.ID, Valid: true}, nil
 | 
						return uuid.NullUUID{UUID: payee.ID, Valid: true}, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (ynab *YNABImport) GetCategory(group string, name string) (uuid.NullUUID, error) {
 | 
					func (ynab *YNABImport) GetCategory(context context.Context, group string, name string) (uuid.NullUUID, error) { //nolint
 | 
				
			||||||
	if group == "" || name == "" {
 | 
						if group == "" || name == "" {
 | 
				
			||||||
		return uuid.NullUUID{}, nil
 | 
							return uuid.NullUUID{}, nil
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -333,32 +362,25 @@ func (ynab *YNABImport) GetCategory(group string, name string) (uuid.NullUUID, e
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for _, categoryGroup := range ynab.categoryGroups {
 | 
						var categoryGroup CategoryGroup
 | 
				
			||||||
		if categoryGroup.Name == group {
 | 
						for _, existingGroup := range ynab.categoryGroups {
 | 
				
			||||||
			createCategory := CreateCategoryParams{Name: name, CategoryGroupID: categoryGroup.ID}
 | 
							if existingGroup.Name == group {
 | 
				
			||||||
			category, err := ynab.queries.CreateCategory(ynab.Context, createCategory)
 | 
								categoryGroup = existingGroup
 | 
				
			||||||
			if err != nil {
 | 
					 | 
				
			||||||
				return uuid.NullUUID{}, err
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			getCategory := GetCategoriesRow{
 | 
					 | 
				
			||||||
				ID:              category.ID,
 | 
					 | 
				
			||||||
				CategoryGroupID: category.CategoryGroupID,
 | 
					 | 
				
			||||||
				Name:            category.Name,
 | 
					 | 
				
			||||||
				Group:           categoryGroup.Name,
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			ynab.categories = append(ynab.categories, getCategory)
 | 
					 | 
				
			||||||
			return uuid.NullUUID{UUID: category.ID, Valid: true}, nil
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	categoryGroup, err := ynab.queries.CreateCategoryGroup(ynab.Context, CreateCategoryGroupParams{Name: group, BudgetID: ynab.budgetID})
 | 
						if categoryGroup.Name == "" {
 | 
				
			||||||
 | 
							newGroup := CreateCategoryGroupParams{Name: group, BudgetID: ynab.budgetID}
 | 
				
			||||||
 | 
							var err error
 | 
				
			||||||
 | 
							categoryGroup, err = ynab.queries.CreateCategoryGroup(context, newGroup)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			return uuid.NullUUID{}, err
 | 
								return uuid.NullUUID{}, err
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		ynab.categoryGroups = append(ynab.categoryGroups, categoryGroup)
 | 
							ynab.categoryGroups = append(ynab.categoryGroups, categoryGroup)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	category, err := ynab.queries.CreateCategory(ynab.Context, CreateCategoryParams{Name: name, CategoryGroupID: categoryGroup.ID})
 | 
						newCategory := CreateCategoryParams{Name: name, CategoryGroupID: categoryGroup.ID}
 | 
				
			||||||
 | 
						category, err := ynab.queries.CreateCategory(context, newCategory)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return uuid.NullUUID{}, err
 | 
							return uuid.NullUUID{}, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										135
									
								
								server/account.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										135
									
								
								server/account.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,135 @@
 | 
				
			|||||||
 | 
					package server
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"net/http"
 | 
				
			||||||
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"git.javil.eu/jacob1123/budgeteer/postgres"
 | 
				
			||||||
 | 
						"github.com/google/uuid"
 | 
				
			||||||
 | 
						"github.com/labstack/echo/v4"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type FilterTransactionsRequest struct {
 | 
				
			||||||
 | 
						CategoryID string    `json:"categoryId"`
 | 
				
			||||||
 | 
						PayeeID    string    `json:"payeeId"`
 | 
				
			||||||
 | 
						AccountID  string    `json:"accountId"`
 | 
				
			||||||
 | 
						FromDate   time.Time `json:"fromDate"`
 | 
				
			||||||
 | 
						ToDate     time.Time `json:"toDate"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (h *Handler) filteredTransactions(c echo.Context) error {
 | 
				
			||||||
 | 
						budgetID := c.Param("budgetid")
 | 
				
			||||||
 | 
						budgetUUID, err := uuid.Parse(budgetID)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return echo.NewHTTPError(http.StatusBadRequest, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var request FilterTransactionsRequest
 | 
				
			||||||
 | 
						err = c.Bind(&request)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return echo.NewHTTPError(http.StatusBadRequest, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						params := postgres.GetFilteredTransactionsParams{
 | 
				
			||||||
 | 
							BudgetID: budgetUUID,
 | 
				
			||||||
 | 
							FromDate: request.FromDate,
 | 
				
			||||||
 | 
							ToDate:   request.ToDate,
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						params.CategoryID, params.FilterCategory = parseEmptyUUID(request.CategoryID)
 | 
				
			||||||
 | 
						accountID, filterAccount := parseEmptyUUID(request.AccountID)
 | 
				
			||||||
 | 
						params.AccountID, params.FilterAccount = accountID.UUID, filterAccount
 | 
				
			||||||
 | 
						params.PayeeID, params.FilterPayee = parseEmptyUUID(request.PayeeID)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						transactions, err := h.Service.GetFilteredTransactions(c.Request().Context(), params)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return echo.NewHTTPError(http.StatusInternalServerError, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return c.JSON(http.StatusOK, TransactionsResponse{nil, transactions})
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func parseEmptyUUID(value string) (uuid.NullUUID, bool) {
 | 
				
			||||||
 | 
						if value == "" {
 | 
				
			||||||
 | 
							return uuid.NullUUID{}, false
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						val, err := uuid.Parse(value)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return uuid.NullUUID{}, false
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return uuid.NullUUID{UUID: val, Valid: true}, true
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (h *Handler) problematicTransactions(c echo.Context) error {
 | 
				
			||||||
 | 
						budgetID := c.Param("budgetid")
 | 
				
			||||||
 | 
						budgetUUID, err := uuid.Parse(budgetID)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return echo.NewHTTPError(http.StatusBadRequest, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						transactions, err := h.Service.GetProblematicTransactions(c.Request().Context(), budgetUUID)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return c.JSON(http.StatusOK, TransactionsResponse{nil, transactions})
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (h *Handler) transactionsForAccount(c echo.Context) error {
 | 
				
			||||||
 | 
						accountID := c.Param("accountid")
 | 
				
			||||||
 | 
						accountUUID, err := uuid.Parse(accountID)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return echo.NewHTTPError(http.StatusBadRequest, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						account, err := h.Service.GetAccount(c.Request().Context(), accountUUID)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return echo.NewHTTPError(http.StatusNotFound, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						transactions, err := h.Service.GetTransactionsForAccount(c.Request().Context(), accountUUID)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return echo.NewHTTPError(http.StatusNotFound, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return c.JSON(http.StatusOK, TransactionsResponse{&account, transactions})
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type TransactionsResponse struct {
 | 
				
			||||||
 | 
						Account      *postgres.Account
 | 
				
			||||||
 | 
						Transactions []postgres.DisplayTransaction
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type EditAccountRequest struct {
 | 
				
			||||||
 | 
						Name     string `json:"name"`
 | 
				
			||||||
 | 
						OnBudget bool   `json:"onBudget"`
 | 
				
			||||||
 | 
						IsOpen   bool   `json:"isOpen"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (h *Handler) editAccount(c echo.Context) error {
 | 
				
			||||||
 | 
						accountID := c.Param("accountid")
 | 
				
			||||||
 | 
						accountUUID, err := uuid.Parse(accountID)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return echo.NewHTTPError(http.StatusBadRequest, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var request EditAccountRequest
 | 
				
			||||||
 | 
						err = c.Bind(&request)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return echo.NewHTTPError(http.StatusBadRequest, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						updateParams := postgres.UpdateAccountParams{
 | 
				
			||||||
 | 
							Name:     request.Name,
 | 
				
			||||||
 | 
							OnBudget: request.OnBudget,
 | 
				
			||||||
 | 
							IsOpen:   request.IsOpen,
 | 
				
			||||||
 | 
							ID:       accountUUID,
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						account, err := h.Service.UpdateAccount(c.Request().Context(), updateParams)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return echo.NewHTTPError(http.StatusNotFound, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return h.getBudget(c, account.BudgetID)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										71
									
								
								server/account_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										71
									
								
								server/account_test.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,71 @@
 | 
				
			|||||||
 | 
					package server
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"context"
 | 
				
			||||||
 | 
						"encoding/json"
 | 
				
			||||||
 | 
						"net/http"
 | 
				
			||||||
 | 
						"net/http/httptest"
 | 
				
			||||||
 | 
						"strings"
 | 
				
			||||||
 | 
						"testing"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"git.javil.eu/jacob1123/budgeteer/bcrypt"
 | 
				
			||||||
 | 
						"git.javil.eu/jacob1123/budgeteer/jwt"
 | 
				
			||||||
 | 
						"git.javil.eu/jacob1123/budgeteer/postgres"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/labstack/echo/v4"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestRegisterUser(t *testing.T) {
 | 
				
			||||||
 | 
						t.Parallel()
 | 
				
			||||||
 | 
						database, err := postgres.Connect("pgtx", cfg.DatabaseConnection)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Errorf("connect to DB: %v", err)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						tokenVerifier, _ := jwt.NewTokenVerifier(cfg.SessionSecret)
 | 
				
			||||||
 | 
						h := Handler{
 | 
				
			||||||
 | 
							Service:             database,
 | 
				
			||||||
 | 
							TokenVerifier:       tokenVerifier,
 | 
				
			||||||
 | 
							CredentialsVerifier: &bcrypt.Verifier{},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						recorder := httptest.NewRecorder()
 | 
				
			||||||
 | 
						engine := echo.New()
 | 
				
			||||||
 | 
						h.LoadRoutes(engine)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						t.Run("RegisterUser", func(t *testing.T) {
 | 
				
			||||||
 | 
							t.Parallel()
 | 
				
			||||||
 | 
							request, err := http.NewRequestWithContext(context.Background(),
 | 
				
			||||||
 | 
								http.MethodPost,
 | 
				
			||||||
 | 
								"/api/v1/user/register",
 | 
				
			||||||
 | 
								strings.NewReader(`{"password":"pass","email":"info@example.com","name":"Test"}`))
 | 
				
			||||||
 | 
							request.Header.Set("Content-Type", "application/json")
 | 
				
			||||||
 | 
							context := engine.NewContext(request, recorder)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								t.Errorf("error creating request: %s", err)
 | 
				
			||||||
 | 
								return
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							err = h.registerPost(context)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								t.Error(err.Error())
 | 
				
			||||||
 | 
								t.Error("Error registering")
 | 
				
			||||||
 | 
								return
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if recorder.Code != http.StatusOK {
 | 
				
			||||||
 | 
								t.Errorf("handler returned wrong status code: got %v want %v", recorder.Code, http.StatusOK)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							var response LoginResponse
 | 
				
			||||||
 | 
							err = json.NewDecoder(recorder.Body).Decode(&response)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								t.Error(err.Error())
 | 
				
			||||||
 | 
								t.Error("Error registering")
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if len(response.Token) == 0 {
 | 
				
			||||||
 | 
								t.Error("Did not get a token")
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										69
									
								
								server/admin.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										69
									
								
								server/admin.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,69 @@
 | 
				
			|||||||
 | 
					package server
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
						"net/http"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/google/uuid"
 | 
				
			||||||
 | 
						"github.com/labstack/echo/v4"
 | 
				
			||||||
 | 
						"github.com/pressly/goose/v3"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (h *Handler) clearDatabase(c echo.Context) error {
 | 
				
			||||||
 | 
						if err := goose.Reset(h.Service.DB, "schema"); err != nil {
 | 
				
			||||||
 | 
							return echo.NewHTTPError(http.StatusInternalServerError, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err := goose.Up(h.Service.DB, "schema"); err != nil {
 | 
				
			||||||
 | 
							return echo.NewHTTPError(http.StatusInternalServerError, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (h *Handler) deleteBudget(c echo.Context) error {
 | 
				
			||||||
 | 
						budgetID := c.Param("budgetid")
 | 
				
			||||||
 | 
						budgetUUID, err := uuid.Parse(budgetID)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return echo.NewHTTPError(http.StatusBadRequest, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						err = h.clearBudgetData(c, budgetUUID)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						err = h.Service.DeleteBudget(c.Request().Context(), budgetUUID)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (h *Handler) clearBudgetData(c echo.Context, budgetUUID uuid.UUID) error {
 | 
				
			||||||
 | 
						rows, err := h.Service.DeleteAllAssignments(c.Request().Context(), budgetUUID)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						fmt.Printf("Deleted %d assignments\n", rows)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						rows, err = h.Service.DeleteAllTransactions(c.Request().Context(), budgetUUID)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						fmt.Printf("Deleted %d transactions\n", rows)
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (h *Handler) clearBudget(c echo.Context) error {
 | 
				
			||||||
 | 
						budgetID := c.Param("budgetid")
 | 
				
			||||||
 | 
						budgetUUID, err := uuid.Parse(budgetID)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return echo.NewHTTPError(http.StatusBadRequest, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return h.clearBudgetData(c, budgetUUID)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										87
									
								
								server/autocomplete.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										87
									
								
								server/autocomplete.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,87 @@
 | 
				
			|||||||
 | 
					package server
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"net/http"
 | 
				
			||||||
 | 
						"strings"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"git.javil.eu/jacob1123/budgeteer/postgres"
 | 
				
			||||||
 | 
						"github.com/google/uuid"
 | 
				
			||||||
 | 
						"github.com/labstack/echo/v4"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (h *Handler) autocompleteAccounts(c echo.Context) error {
 | 
				
			||||||
 | 
						budgetID := c.Param("budgetid")
 | 
				
			||||||
 | 
						budgetUUID, err := uuid.Parse(budgetID)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return echo.NewHTTPError(http.StatusBadRequest, "budgetid missing from URL")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						query := c.Request().URL.Query().Get("s")
 | 
				
			||||||
 | 
						searchParams := postgres.SearchAccountsParams{
 | 
				
			||||||
 | 
							BudgetID: budgetUUID,
 | 
				
			||||||
 | 
							Search:   "%" + query + "%",
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						categories, err := h.Service.SearchAccounts(c.Request().Context(), searchParams)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return c.JSON(http.StatusOK, categories)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (h *Handler) autocompleteCategories(c echo.Context) error {
 | 
				
			||||||
 | 
						budgetID := c.Param("budgetid")
 | 
				
			||||||
 | 
						budgetUUID, err := uuid.Parse(budgetID)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return echo.NewHTTPError(http.StatusBadRequest, "budgetid missing from URL")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						query := c.Request().URL.Query().Get("s")
 | 
				
			||||||
 | 
						searchParams := postgres.SearchCategoriesParams{
 | 
				
			||||||
 | 
							BudgetID: budgetUUID,
 | 
				
			||||||
 | 
							Search:   "%" + query + "%",
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						categories, err := h.Service.SearchCategories(c.Request().Context(), searchParams)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return echo.NewHTTPError(http.StatusInternalServerError, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return c.JSON(http.StatusOK, categories)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (h *Handler) autocompletePayee(c echo.Context) error {
 | 
				
			||||||
 | 
						budgetID := c.Param("budgetid")
 | 
				
			||||||
 | 
						budgetUUID, err := uuid.Parse(budgetID)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return echo.NewHTTPError(http.StatusBadRequest, "budgetid missing from URL")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						query := c.Request().URL.Query().Get("s")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						transferPrefix := "Transfer"
 | 
				
			||||||
 | 
						if strings.HasPrefix(query, transferPrefix) {
 | 
				
			||||||
 | 
							searchParams := postgres.SearchAccountsParams{
 | 
				
			||||||
 | 
								BudgetID: budgetUUID,
 | 
				
			||||||
 | 
								Search:   "%" + strings.Trim(query[len(transferPrefix):], " \t\n:") + "%",
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							accounts, err := h.Service.SearchAccounts(c.Request().Context(), searchParams)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								return err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							return c.JSON(http.StatusOK, accounts)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						searchParams := postgres.SearchPayeesParams{
 | 
				
			||||||
 | 
							BudgetID: budgetUUID,
 | 
				
			||||||
 | 
							Search:   query + "%",
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						payees, err := h.Service.SearchPayees(c.Request().Context(), searchParams)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return c.JSON(http.StatusOK, payees)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										30
									
								
								server/budget.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								server/budget.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,30 @@
 | 
				
			|||||||
 | 
					package server
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"net/http"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/labstack/echo/v4"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type newBudgetInformation struct {
 | 
				
			||||||
 | 
						Name string `json:"name"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (h *Handler) newBudget(c echo.Context) error {
 | 
				
			||||||
 | 
						var newBudget newBudgetInformation
 | 
				
			||||||
 | 
						if err := c.Bind(&newBudget); err != nil {
 | 
				
			||||||
 | 
							return echo.NewHTTPError(http.StatusNotAcceptable, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if newBudget.Name == "" {
 | 
				
			||||||
 | 
							return echo.NewHTTPError(http.StatusBadRequest, "budget name is required")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						userID := MustGetToken(c).GetID()
 | 
				
			||||||
 | 
						budget, err := h.Service.NewBudget(c.Request().Context(), newBudget.Name, userID)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return c.JSON(http.StatusOK, budget)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										182
									
								
								server/budgeting.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										182
									
								
								server/budgeting.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,182 @@
 | 
				
			|||||||
 | 
					package server
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"context"
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
						"net/http"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"git.javil.eu/jacob1123/budgeteer/postgres"
 | 
				
			||||||
 | 
						"git.javil.eu/jacob1123/budgeteer/postgres/numeric"
 | 
				
			||||||
 | 
						"github.com/google/uuid"
 | 
				
			||||||
 | 
						"github.com/labstack/echo/v4"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type CategoryWithBalance struct {
 | 
				
			||||||
 | 
						*postgres.GetCategoriesRow
 | 
				
			||||||
 | 
						AvailableLastMonth numeric.Numeric
 | 
				
			||||||
 | 
						Activity           numeric.Numeric
 | 
				
			||||||
 | 
						Assigned           numeric.Numeric
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func NewCategoryWithBalance(category *postgres.GetCategoriesRow) CategoryWithBalance {
 | 
				
			||||||
 | 
						return CategoryWithBalance{
 | 
				
			||||||
 | 
							GetCategoriesRow:   category,
 | 
				
			||||||
 | 
							AvailableLastMonth: numeric.Zero(),
 | 
				
			||||||
 | 
							Activity:           numeric.Zero(),
 | 
				
			||||||
 | 
							Assigned:           numeric.Zero(),
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (h *Handler) budgetingForMonth(c echo.Context) error {
 | 
				
			||||||
 | 
						budgetID := c.Param("budgetid")
 | 
				
			||||||
 | 
						budgetUUID, err := uuid.Parse(budgetID)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return echo.NewHTTPError(http.StatusBadRequest, "budgetid missing from URL")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						budget, err := h.Service.GetBudget(c.Request().Context(), budgetUUID)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return echo.NewHTTPError(http.StatusBadRequest, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						month, err := getDate(c)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return c.Redirect(http.StatusTemporaryRedirect, "/budget/"+budget.ID.String())
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						data, err := h.getBudgetingViewForMonth(c.Request().Context(), budget, month)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return c.JSON(http.StatusOK, data)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (h *Handler) getBudgetingViewForMonth(ctx context.Context, budget postgres.Budget, month Month) (BudgetingForMonthResponse, error) {
 | 
				
			||||||
 | 
						categories, err := h.Service.GetCategories(ctx, budget.ID)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return BudgetingForMonthResponse{}, fmt.Errorf("error loading categories: %w", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						cumultativeBalances, err := h.Service.GetCumultativeBalances(ctx, budget.ID)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return BudgetingForMonthResponse{}, fmt.Errorf("error loading balances: %w", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						categoriesWithBalance, moneyUsed, overspentLastMonth := h.calculateBalances(budget, month, categories, cumultativeBalances)
 | 
				
			||||||
 | 
						availableBalance := h.getAvailableBalance(budget, month, moneyUsed, cumultativeBalances)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						data := BudgetingForMonthResponse{categoriesWithBalance, availableBalance, overspentLastMonth}
 | 
				
			||||||
 | 
						return data, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type BudgetingForMonthResponse struct {
 | 
				
			||||||
 | 
						Categories         []CategoryWithBalance
 | 
				
			||||||
 | 
						AvailableBalance   numeric.Numeric
 | 
				
			||||||
 | 
						OverspentLastMonth numeric.Numeric
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (*Handler) getAvailableBalance(budget postgres.Budget, month Month,
 | 
				
			||||||
 | 
						moneyUsed numeric.Numeric, cumultativeBalances []postgres.GetCumultativeBalancesRow,
 | 
				
			||||||
 | 
					) numeric.Numeric {
 | 
				
			||||||
 | 
						availableBalance := moneyUsed
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for _, bal := range cumultativeBalances {
 | 
				
			||||||
 | 
							if bal.CategoryID != budget.IncomeCategoryID {
 | 
				
			||||||
 | 
								continue
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if month.InFuture(bal.Date) {
 | 
				
			||||||
 | 
								continue
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							availableBalance.AddI(bal.Transactions)
 | 
				
			||||||
 | 
							availableBalance.AddI(bal.Assignments) // should be zero, but who knows
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return availableBalance
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type BudgetingResponse struct {
 | 
				
			||||||
 | 
						Accounts []postgres.GetAccountsWithBalanceRow
 | 
				
			||||||
 | 
						Budget   postgres.Budget
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (h *Handler) budget(c echo.Context) error {
 | 
				
			||||||
 | 
						budgetID := c.Param("budgetid")
 | 
				
			||||||
 | 
						budgetUUID, err := uuid.Parse(budgetID)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return echo.NewHTTPError(http.StatusBadRequest, "budgetid missing from URL")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return h.getBudget(c, budgetUUID)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (h *Handler) getBudget(c echo.Context, budgetUUID uuid.UUID) error {
 | 
				
			||||||
 | 
						budget, err := h.Service.GetBudget(c.Request().Context(), budgetUUID)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return echo.NewHTTPError(http.StatusNotFound, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						accounts, err := h.Service.GetAccountsWithBalance(c.Request().Context(), budgetUUID)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						data := BudgetingResponse{accounts, budget}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return c.JSON(http.StatusOK, data)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (h *Handler) calculateBalances(budget postgres.Budget, month Month,
 | 
				
			||||||
 | 
						categories []postgres.GetCategoriesRow, cumultativeBalances []postgres.GetCumultativeBalancesRow,
 | 
				
			||||||
 | 
					) ([]CategoryWithBalance, numeric.Numeric, numeric.Numeric) {
 | 
				
			||||||
 | 
						categoriesWithBalance := []CategoryWithBalance{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						moneyUsed := numeric.Zero()
 | 
				
			||||||
 | 
						overspentLastMonth := numeric.Zero()
 | 
				
			||||||
 | 
						categories = append(categories, postgres.GetCategoriesRow{
 | 
				
			||||||
 | 
							Group: "Income",
 | 
				
			||||||
 | 
							Name:  "No Category",
 | 
				
			||||||
 | 
							ID:    uuid.UUID{},
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
						for i := range categories {
 | 
				
			||||||
 | 
							cat := &categories[i]
 | 
				
			||||||
 | 
							if cat.ID == budget.IncomeCategoryID {
 | 
				
			||||||
 | 
								continue
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							categoryWithBalance := NewCategoryWithBalance(cat)
 | 
				
			||||||
 | 
							for _, bal := range cumultativeBalances {
 | 
				
			||||||
 | 
								if bal.CategoryID != cat.ID {
 | 
				
			||||||
 | 
									continue
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								// skip everything in the future
 | 
				
			||||||
 | 
								if month.InFuture(bal.Date) {
 | 
				
			||||||
 | 
									continue
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								moneyUsed.SubI(bal.Assignments)
 | 
				
			||||||
 | 
								if month.InPresent(bal.Date) {
 | 
				
			||||||
 | 
									categoryWithBalance.Activity = bal.Transactions
 | 
				
			||||||
 | 
									categoryWithBalance.Assigned = bal.Assignments
 | 
				
			||||||
 | 
									continue
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								categoryWithBalance.AvailableLastMonth.AddI(bal.Assignments)
 | 
				
			||||||
 | 
								categoryWithBalance.AvailableLastMonth.AddI(bal.Transactions)
 | 
				
			||||||
 | 
								if !categoryWithBalance.AvailableLastMonth.IsPositive() {
 | 
				
			||||||
 | 
									moneyUsed.AddI(categoryWithBalance.AvailableLastMonth)
 | 
				
			||||||
 | 
									if month.Previous().InPresent(bal.Date) {
 | 
				
			||||||
 | 
										overspentLastMonth.AddI(categoryWithBalance.AvailableLastMonth)
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									categoryWithBalance.AvailableLastMonth = numeric.Zero()
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							categoriesWithBalance = append(categoriesWithBalance, categoryWithBalance)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return categoriesWithBalance, moneyUsed, overspentLastMonth
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										52
									
								
								server/category.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										52
									
								
								server/category.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,52 @@
 | 
				
			|||||||
 | 
					package server
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
						"net/http"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"git.javil.eu/jacob1123/budgeteer/postgres"
 | 
				
			||||||
 | 
						"git.javil.eu/jacob1123/budgeteer/postgres/numeric"
 | 
				
			||||||
 | 
						"github.com/google/uuid"
 | 
				
			||||||
 | 
						"github.com/labstack/echo/v4"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type SetCategoryAssignmentRequest struct {
 | 
				
			||||||
 | 
						Assigned float64
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (h *Handler) setCategoryAssignment(c echo.Context) error {
 | 
				
			||||||
 | 
						categoryID := c.Param("categoryid")
 | 
				
			||||||
 | 
						categoryUUID, err := uuid.Parse(categoryID)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return echo.NewHTTPError(http.StatusBadRequest, "categoryid missing from URL")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var request SetCategoryAssignmentRequest
 | 
				
			||||||
 | 
						err = c.Bind(&request)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return echo.NewHTTPError(http.StatusBadRequest, fmt.Errorf("invalid payload: %w", err))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						date, err := getDate(c)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return echo.NewHTTPError(http.StatusBadRequest, fmt.Errorf("date invalid: %w", err))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var amount numeric.Numeric
 | 
				
			||||||
 | 
						err = amount.Set(request.Assigned)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return echo.NewHTTPError(http.StatusBadRequest, fmt.Errorf("parse amount: %w", err))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						updateArgs := postgres.UpdateAssignmentParams{
 | 
				
			||||||
 | 
							CategoryID: categoryUUID,
 | 
				
			||||||
 | 
							Date:       date.FirstOfMonth(),
 | 
				
			||||||
 | 
							Amount:     amount,
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						err = h.Service.UpdateAssignment(c.Request().Context(), updateArgs)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return fmt.Errorf("update assignment: %w", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										35
									
								
								server/category_group_new.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								server/category_group_new.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,35 @@
 | 
				
			|||||||
 | 
					package server
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"net/http"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"git.javil.eu/jacob1123/budgeteer/postgres"
 | 
				
			||||||
 | 
						"github.com/google/uuid"
 | 
				
			||||||
 | 
						"github.com/labstack/echo/v4"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type newCategoryGroupInformation struct {
 | 
				
			||||||
 | 
						BudgetID uuid.UUID `json:"budgetId"`
 | 
				
			||||||
 | 
						Group    string    `json:"group"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (h *Handler) newCategoryGroup(c echo.Context) error {
 | 
				
			||||||
 | 
						var newCategory newCategoryGroupInformation
 | 
				
			||||||
 | 
						if err := c.Bind(&newCategory); err != nil {
 | 
				
			||||||
 | 
							return echo.NewHTTPError(http.StatusNotAcceptable, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if newCategory.Group == "" {
 | 
				
			||||||
 | 
							return echo.NewHTTPError(http.StatusBadRequest, "category group is required")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						categoryGroup, err := h.Service.CreateCategoryGroup(c.Request().Context(), postgres.CreateCategoryGroupParams{
 | 
				
			||||||
 | 
							BudgetID: newCategory.BudgetID,
 | 
				
			||||||
 | 
							Name:     newCategory.Group,
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return c.JSON(http.StatusOK, categoryGroup)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										48
									
								
								server/category_new.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								server/category_new.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,48 @@
 | 
				
			|||||||
 | 
					package server
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"net/http"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"git.javil.eu/jacob1123/budgeteer/postgres"
 | 
				
			||||||
 | 
						"github.com/google/uuid"
 | 
				
			||||||
 | 
						"github.com/labstack/echo/v4"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type newCategoryInformation struct {
 | 
				
			||||||
 | 
						BudgetID uuid.UUID `json:"budgetId"`
 | 
				
			||||||
 | 
						Name     string    `json:"name"`
 | 
				
			||||||
 | 
						Group    string    `json:"group"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (h *Handler) newCategory(c echo.Context) error {
 | 
				
			||||||
 | 
						var newCategory newCategoryInformation
 | 
				
			||||||
 | 
						if err := c.Bind(&newCategory); err != nil {
 | 
				
			||||||
 | 
							return echo.NewHTTPError(http.StatusNotAcceptable, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if newCategory.Name == "" {
 | 
				
			||||||
 | 
							return echo.NewHTTPError(http.StatusBadRequest, "category name is required")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if newCategory.Group == "" {
 | 
				
			||||||
 | 
							return echo.NewHTTPError(http.StatusBadRequest, "category group is required")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						categoryGroup, err := h.Service.GetCategoryGroupByName(c.Request().Context(), postgres.GetCategoryGroupByNameParams{
 | 
				
			||||||
 | 
							BudgetID: newCategory.BudgetID,
 | 
				
			||||||
 | 
							Name:     newCategory.Group,
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						category, err := h.Service.CreateCategory(c.Request().Context(), postgres.CreateCategoryParams{
 | 
				
			||||||
 | 
							CategoryGroupID: categoryGroup.ID,
 | 
				
			||||||
 | 
							Name:            newCategory.Name,
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return c.JSON(http.StatusOK, category)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										104
									
								
								server/http.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										104
									
								
								server/http.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,104 @@
 | 
				
			|||||||
 | 
					package server
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
						"net/http"
 | 
				
			||||||
 | 
						"strings"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"git.javil.eu/jacob1123/budgeteer"
 | 
				
			||||||
 | 
						"git.javil.eu/jacob1123/budgeteer/bcrypt"
 | 
				
			||||||
 | 
						"git.javil.eu/jacob1123/budgeteer/postgres"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/labstack/echo/v4"
 | 
				
			||||||
 | 
						"github.com/labstack/echo/v4/middleware"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Handler handles incoming requests.
 | 
				
			||||||
 | 
					type Handler struct {
 | 
				
			||||||
 | 
						Service             *postgres.Database
 | 
				
			||||||
 | 
						TokenVerifier       budgeteer.TokenVerifier
 | 
				
			||||||
 | 
						CredentialsVerifier *bcrypt.Verifier
 | 
				
			||||||
 | 
						StaticFS            http.FileSystem
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Serve starts the http server.
 | 
				
			||||||
 | 
					func (h *Handler) Serve() {
 | 
				
			||||||
 | 
						router := echo.New()
 | 
				
			||||||
 | 
						h.LoadRoutes(router)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err := router.Start(":1323"); err != nil {
 | 
				
			||||||
 | 
							panic(err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// LoadRoutes initializes all the routes.
 | 
				
			||||||
 | 
					func (h *Handler) LoadRoutes(router *echo.Echo) {
 | 
				
			||||||
 | 
						router.Use(middleware.Logger())
 | 
				
			||||||
 | 
						router.Use(enableCachingForStaticFiles())
 | 
				
			||||||
 | 
						router.Use(middleware.StaticWithConfig(middleware.StaticConfig{
 | 
				
			||||||
 | 
							Filesystem: h.StaticFS,
 | 
				
			||||||
 | 
							HTML5:      true,
 | 
				
			||||||
 | 
						}))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						api := router.Group("/api/v1")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						anonymous := api.Group("/user")
 | 
				
			||||||
 | 
						anonymous.POST("/login", h.loginPost)
 | 
				
			||||||
 | 
						anonymous.POST("/register", h.registerPost)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						authenticated := api.Group("")
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							authenticated.Use(h.verifyLoginWithForbidden)
 | 
				
			||||||
 | 
							account := authenticated.Group("/account")
 | 
				
			||||||
 | 
							account.GET("/:accountid/transactions", h.transactionsForAccount)
 | 
				
			||||||
 | 
							account.POST("/:accountid/reconcile", h.reconcileTransactions)
 | 
				
			||||||
 | 
							account.POST("/:accountid", h.editAccount)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							category := authenticated.Group("/category")
 | 
				
			||||||
 | 
							category.POST("/new", h.newCategory)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							categoryGroup := authenticated.Group("/category-group")
 | 
				
			||||||
 | 
							categoryGroup.POST("/new", h.newCategoryGroup)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							budget := authenticated.Group("/budget")
 | 
				
			||||||
 | 
							budget.POST("/new", h.newBudget)
 | 
				
			||||||
 | 
							budget.GET("/:budgetid", h.budget)
 | 
				
			||||||
 | 
							budget.GET("/:budgetid/:year/:month", h.budgetingForMonth)
 | 
				
			||||||
 | 
							budget.POST("/:budgetid/category/:categoryid/:year/:month", h.setCategoryAssignment)
 | 
				
			||||||
 | 
							budget.GET("/:budgetid/autocomplete/payees", h.autocompletePayee)
 | 
				
			||||||
 | 
							budget.GET("/:budgetid/autocomplete/accounts", h.autocompleteAccounts)
 | 
				
			||||||
 | 
							budget.GET("/:budgetid/autocomplete/categories", h.autocompleteCategories)
 | 
				
			||||||
 | 
							budget.GET("/:budgetid/problematic-transactions", h.problematicTransactions)
 | 
				
			||||||
 | 
							budget.POST("/:budgetid/filtered-transactions", h.filteredTransactions)
 | 
				
			||||||
 | 
							budget.DELETE("/:budgetid", h.deleteBudget)
 | 
				
			||||||
 | 
							budget.POST("/:budgetid/import/ynab", h.importYNAB)
 | 
				
			||||||
 | 
							budget.POST("/:budgetid/export/ynab/transactions", h.exportYNABTransactions)
 | 
				
			||||||
 | 
							budget.POST("/:budgetid/export/ynab/assignments", h.exportYNABAssignments)
 | 
				
			||||||
 | 
							budget.POST("/:budgetid/settings/clear", h.clearBudget)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							transaction := authenticated.Group("/transaction")
 | 
				
			||||||
 | 
							transaction.POST("/new", h.newTransaction)
 | 
				
			||||||
 | 
							transaction.POST("/:transactionid", h.updateTransaction)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							authenticated.GET("/admin/clear-database", h.clearDatabase)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						api.Any("/*", h.notFound)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (h *Handler) notFound(c echo.Context) error {
 | 
				
			||||||
 | 
						fmt.Println("not found?")
 | 
				
			||||||
 | 
						return echo.NewHTTPError(http.StatusNotImplemented, "not found")
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func enableCachingForStaticFiles() echo.MiddlewareFunc {
 | 
				
			||||||
 | 
						return func(next echo.HandlerFunc) echo.HandlerFunc {
 | 
				
			||||||
 | 
							return func(c echo.Context) error {
 | 
				
			||||||
 | 
								if strings.HasPrefix(c.Path(), "/static/") {
 | 
				
			||||||
 | 
									c.Response().Header().Set("Cache-Control", "max-age=86400")
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								return next(c)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										37
									
								
								server/json-date.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								server/json-date.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,37 @@
 | 
				
			|||||||
 | 
					package server
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"encoding/json"
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
						"strings"
 | 
				
			||||||
 | 
						"time"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type JSONDate time.Time
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// UnmarshalJSON parses the JSONDate from a JSON input.
 | 
				
			||||||
 | 
					func (j *JSONDate) UnmarshalJSON(b []byte) error {
 | 
				
			||||||
 | 
						s := strings.Trim(string(b), "\"")
 | 
				
			||||||
 | 
						t, err := time.Parse("2006-01-02", s)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return fmt.Errorf("parse date: %w", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						*j = JSONDate(t)
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// MarshalJSON converts the JSONDate to a JSON in ISO format.
 | 
				
			||||||
 | 
					func (j JSONDate) MarshalJSON() ([]byte, error) {
 | 
				
			||||||
 | 
						result, err := json.Marshal(time.Time(j))
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, fmt.Errorf("marshal date: %w", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return result, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Format formats the time using the regular time.Time mechanics..
 | 
				
			||||||
 | 
					func (j JSONDate) Format(s string) string {
 | 
				
			||||||
 | 
						t := time.Time(j)
 | 
				
			||||||
 | 
						return t.Format(s)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										305
									
								
								server/main_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										305
									
								
								server/main_test.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,305 @@
 | 
				
			|||||||
 | 
					package server
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"context"
 | 
				
			||||||
 | 
						"encoding/json"
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
						"io/fs"
 | 
				
			||||||
 | 
						"net/http"
 | 
				
			||||||
 | 
						"os"
 | 
				
			||||||
 | 
						"path/filepath"
 | 
				
			||||||
 | 
						"strconv"
 | 
				
			||||||
 | 
						"strings"
 | 
				
			||||||
 | 
						"testing"
 | 
				
			||||||
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"git.javil.eu/jacob1123/budgeteer/bcrypt"
 | 
				
			||||||
 | 
						"git.javil.eu/jacob1123/budgeteer/config"
 | 
				
			||||||
 | 
						"git.javil.eu/jacob1123/budgeteer/jwt"
 | 
				
			||||||
 | 
						"git.javil.eu/jacob1123/budgeteer/postgres"
 | 
				
			||||||
 | 
						"git.javil.eu/jacob1123/budgeteer/web"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						txdb "github.com/DATA-DOG/go-txdb"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var cfg = config.Config{ //nolint:gochecknoglobals
 | 
				
			||||||
 | 
						DatabaseConnection: "postgres://budgeteer:budgeteer@db:5432/budgeteer_test",
 | 
				
			||||||
 | 
						SessionSecret:      "this_is_my_demo_secret_for_unit_tests",
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func init() { //nolint:gochecknoinits
 | 
				
			||||||
 | 
						_, err := postgres.Connect("pgx", cfg.DatabaseConnection)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							panic("failed connecting to DB for migrations: " + err.Error())
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						txdb.Register("pgtx", "pgx", cfg.DatabaseConnection)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestMain(t *testing.T) {
 | 
				
			||||||
 | 
						t.Parallel()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						queries, err := postgres.Connect("pgtx", cfg.DatabaseConnection)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Errorf("connect to DB: %v", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						static, err := fs.Sub(web.Static, "dist")
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							panic("couldn't open static files")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						tokenVerifier, err := jwt.NewTokenVerifier(cfg.SessionSecret)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							panic(fmt.Errorf("couldn't create token verifier: %w", err))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						handler := &Handler{
 | 
				
			||||||
 | 
							Service:             queries,
 | 
				
			||||||
 | 
							TokenVerifier:       tokenVerifier,
 | 
				
			||||||
 | 
							CredentialsVerifier: &bcrypt.Verifier{},
 | 
				
			||||||
 | 
							StaticFS:            http.FS(static),
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						ctx := context.Background()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						createUserParams := postgres.CreateUserParams{
 | 
				
			||||||
 | 
							Email:    "test@example.com",
 | 
				
			||||||
 | 
							Name:     "test@example.com",
 | 
				
			||||||
 | 
							Password: "this is my dumb password",
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						user, err := handler.Service.CreateUser(ctx, createUserParams)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							fmt.Println(err)
 | 
				
			||||||
 | 
							t.Fail()
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						budget, err := handler.Service.NewBudget(ctx, "My nice Budget", user.ID)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							fmt.Println(err)
 | 
				
			||||||
 | 
							t.Fail()
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						handler.DoYNABImport(ctx, t, budget)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						loc := time.Now().Location()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						AssertCategoriesAndAvailableEqual(ctx, t, loc, handler, budget)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						AssertAccountsEqual(ctx, t, handler, budget)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func AssertAccountsEqual(ctx context.Context, t *testing.T, handler *Handler, budget *postgres.Budget) {
 | 
				
			||||||
 | 
						t.Helper()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						t.Run("account balances", func(t *testing.T) {
 | 
				
			||||||
 | 
							t.Parallel()
 | 
				
			||||||
 | 
							resultDir := "../testdata/production-export/results"
 | 
				
			||||||
 | 
							files, err := os.ReadDir(resultDir)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								t.Errorf("could not load results: %s", err)
 | 
				
			||||||
 | 
								return
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							for _, file := range files {
 | 
				
			||||||
 | 
								if file.IsDir() {
 | 
				
			||||||
 | 
									continue
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								name := file.Name()[0 : len(file.Name())-5]
 | 
				
			||||||
 | 
								if name != "accounts" {
 | 
				
			||||||
 | 
									continue
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								testCaseFile := filepath.Join(resultDir, file.Name())
 | 
				
			||||||
 | 
								handler.CheckAccountBalance(ctx, t, testCaseFile, budget)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (h Handler) CheckAccountBalance(ctx context.Context, t *testing.T, testCaseFile string, budget *postgres.Budget) {
 | 
				
			||||||
 | 
						t.Helper()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						accounts, err := h.Service.GetAccountsWithBalance(ctx, budget.ID)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Errorf("get accounts: %s", err)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						testDataFile, err := os.Open(testCaseFile)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Errorf("could not load category test data: %s", err)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var testData map[string]float64
 | 
				
			||||||
 | 
						dec := json.NewDecoder(testDataFile)
 | 
				
			||||||
 | 
						err = dec.Decode(&testData)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Errorf("could not decode category test data: %s", err)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for accountName, accountBalance := range testData {
 | 
				
			||||||
 | 
							found := false
 | 
				
			||||||
 | 
							for _, account := range accounts {
 | 
				
			||||||
 | 
								if account.Name == accountName {
 | 
				
			||||||
 | 
									assertEqual(t, accountBalance, account.WorkingBalance.GetFloat64(), "balance for "+accountName)
 | 
				
			||||||
 | 
									found = true
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if !found {
 | 
				
			||||||
 | 
								t.Errorf("account " + accountName + " was not found in result")
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func AssertCategoriesAndAvailableEqual(ctx context.Context, t *testing.T, loc *time.Location, handler *Handler, budget *postgres.Budget) {
 | 
				
			||||||
 | 
						t.Helper()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						t.Run("Categories and available balance", func(t *testing.T) {
 | 
				
			||||||
 | 
							t.Parallel()
 | 
				
			||||||
 | 
							resultDir := "../testdata/production-export/results"
 | 
				
			||||||
 | 
							files, err := os.ReadDir(resultDir)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								t.Errorf("could not load results: %s", err)
 | 
				
			||||||
 | 
								return
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							for _, file := range files {
 | 
				
			||||||
 | 
								if file.IsDir() {
 | 
				
			||||||
 | 
									continue
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								name := file.Name()[0 : len(file.Name())-5]
 | 
				
			||||||
 | 
								parts := strings.Split(name, "-")
 | 
				
			||||||
 | 
								if len(parts) != 2 {
 | 
				
			||||||
 | 
									continue
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								year, _ := strconv.Atoi(parts[0])
 | 
				
			||||||
 | 
								month, _ := strconv.Atoi(parts[1])
 | 
				
			||||||
 | 
								testCaseFile := filepath.Join(resultDir, file.Name())
 | 
				
			||||||
 | 
								handler.CheckAvailableBalance(ctx, t, testCaseFile, budget, Month{year, month})
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type TestData struct {
 | 
				
			||||||
 | 
						AvailableBalance float64
 | 
				
			||||||
 | 
						Categories       map[string]CategoryTestData
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type CategoryTestData struct {
 | 
				
			||||||
 | 
						Available float64
 | 
				
			||||||
 | 
						Activity  float64
 | 
				
			||||||
 | 
						Assigned  float64
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (h Handler) CheckAvailableBalance(ctx context.Context, t *testing.T, testCaseFile string, budget *postgres.Budget, month Month) {
 | 
				
			||||||
 | 
						t.Helper()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						t.Run(month.String(), func(t *testing.T) {
 | 
				
			||||||
 | 
							t.Parallel()
 | 
				
			||||||
 | 
							data, err := h.getBudgetingViewForMonth(ctx, *budget, month)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								t.Errorf("prepare budgeting: %s", err)
 | 
				
			||||||
 | 
								return
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							testDataFile, err := os.Open(testCaseFile)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								t.Errorf("could not load category test data: %s", err)
 | 
				
			||||||
 | 
								return
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							var testData TestData
 | 
				
			||||||
 | 
							dec := json.NewDecoder(testDataFile)
 | 
				
			||||||
 | 
							err = dec.Decode(&testData)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								t.Errorf("could not decode category test data: %s", err)
 | 
				
			||||||
 | 
								return
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							assertEqual(t, testData.AvailableBalance, data.AvailableBalance.GetFloat64(), "available balance")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							for categoryName, categoryTestData := range testData.Categories {
 | 
				
			||||||
 | 
								found := false
 | 
				
			||||||
 | 
								for _, category := range data.Categories {
 | 
				
			||||||
 | 
									name := category.Group + " : " + category.Name
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									if name == categoryName {
 | 
				
			||||||
 | 
										assertEqual(t, categoryTestData.Activity, category.Activity.GetFloat64(), "activity for "+categoryName)
 | 
				
			||||||
 | 
										assertEqual(t, categoryTestData.Assigned, category.Assigned.GetFloat64(), "assigned for "+categoryName)
 | 
				
			||||||
 | 
										available := category.AvailableLastMonth
 | 
				
			||||||
 | 
										available.AddI(category.Activity).AddI(category.Assigned)
 | 
				
			||||||
 | 
										assertEqual(t, categoryTestData.Available, available.GetFloat64(), "available for "+categoryName)
 | 
				
			||||||
 | 
										found = true
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								if !found {
 | 
				
			||||||
 | 
									t.Errorf("category " + categoryName + " was not found in result")
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func AssertEqualBool(t *testing.T, expected, actual bool, message string) {
 | 
				
			||||||
 | 
						t.Helper()
 | 
				
			||||||
 | 
						if expected == actual {
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						t.Errorf("%s: expected %v, got %v", message, expected, actual)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func assertEqual(t *testing.T, expected, actual float64, message string) {
 | 
				
			||||||
 | 
						t.Helper()
 | 
				
			||||||
 | 
						if expected == actual {
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						t.Errorf("%s: expected %f, got %f", message, expected, actual)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (h Handler) DoYNABImport(ctx context.Context, t *testing.T, budget *postgres.Budget) {
 | 
				
			||||||
 | 
						t.Helper()
 | 
				
			||||||
 | 
						budgetID := budget.ID
 | 
				
			||||||
 | 
						ynab, err := postgres.NewYNABImport(ctx, h.Service.Queries, budgetID)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							fmt.Println(err)
 | 
				
			||||||
 | 
							t.Fail()
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						transactions, err := os.Open("../testdata/production-export/Register.tsv")
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							fmt.Println(err)
 | 
				
			||||||
 | 
							t.Fail()
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						assignments, err := os.Open("../testdata/production-export/Budget.tsv")
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							fmt.Println(err)
 | 
				
			||||||
 | 
							t.Fail()
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						err = ynab.ImportTransactions(ctx, transactions)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							fmt.Println(err)
 | 
				
			||||||
 | 
							t.Fail()
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						err = ynab.ImportAssignments(ctx, assignments)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							fmt.Println(err)
 | 
				
			||||||
 | 
							t.Fail()
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										71
									
								
								server/month.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										71
									
								
								server/month.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,71 @@
 | 
				
			|||||||
 | 
					package server
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
						"time"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type Month struct {
 | 
				
			||||||
 | 
						Year  int
 | 
				
			||||||
 | 
						Month int
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func NewFromTime(date time.Time) Month {
 | 
				
			||||||
 | 
						return Month{date.Year(), int(date.Month())}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (m Month) String() string {
 | 
				
			||||||
 | 
						return fmt.Sprintf("%d-%d", m.Year, m.Month)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (m Month) FirstOfMonth() time.Time {
 | 
				
			||||||
 | 
						return time.Date(m.Year, time.Month(m.Month), 1, 0, 0, 0, 0, time.Now().Location())
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (m Month) Previous() Month {
 | 
				
			||||||
 | 
						if m.Month == int(time.January) {
 | 
				
			||||||
 | 
							return Month{Year: m.Year - 1, Month: int(time.December)}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return Month{Year: m.Year, Month: m.Month - 1}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (m Month) Next() Month {
 | 
				
			||||||
 | 
						if m.Month == int(time.December) {
 | 
				
			||||||
 | 
							return Month{Year: m.Year + 1, Month: int(time.January)}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return Month{Year: m.Year, Month: m.Month + 1}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (m Month) InFuture(date time.Time) bool {
 | 
				
			||||||
 | 
						if m.Year < date.Year() {
 | 
				
			||||||
 | 
							return true
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if m.Year > date.Year() {
 | 
				
			||||||
 | 
							return false
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return time.Month(m.Month) < date.Month()
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (m Month) InPast(date time.Time) bool {
 | 
				
			||||||
 | 
						if m.Year > date.Year() {
 | 
				
			||||||
 | 
							return true
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if m.Year < date.Year() {
 | 
				
			||||||
 | 
							return false
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return time.Month(m.Month) > date.Month()
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (m Month) InPresent(date time.Time) bool {
 | 
				
			||||||
 | 
						if date.Year() != m.Year {
 | 
				
			||||||
 | 
							return false
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return date.Month() == time.Month(m.Month)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										46
									
								
								server/month_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								server/month_test.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,46 @@
 | 
				
			|||||||
 | 
					package server_test
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"testing"
 | 
				
			||||||
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"git.javil.eu/jacob1123/budgeteer/server"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type TestCaseCompare struct {
 | 
				
			||||||
 | 
						Value     server.Month
 | 
				
			||||||
 | 
						Date      time.Time
 | 
				
			||||||
 | 
						InPast    bool
 | 
				
			||||||
 | 
						InPresent bool
 | 
				
			||||||
 | 
						InFuture  bool
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestComparisons(t *testing.T) {
 | 
				
			||||||
 | 
						t.Parallel()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						loc := time.Now().Location()
 | 
				
			||||||
 | 
						tests := []TestCaseCompare{
 | 
				
			||||||
 | 
							{server.Month{2022, 2}, time.Date(2022, 3, 1, 0, 0, 0, 0, loc), false, false, true},
 | 
				
			||||||
 | 
							{server.Month{2022, 3}, time.Date(2022, 3, 1, 0, 0, 0, 0, loc), false, true, false},
 | 
				
			||||||
 | 
							{server.Month{2022, 4}, time.Date(2022, 3, 1, 0, 0, 0, 0, loc), true, false, false},
 | 
				
			||||||
 | 
							{server.Month{2022, 2}, time.Date(2022, 3, 31, 0, 0, 0, 0, loc), false, false, true},
 | 
				
			||||||
 | 
							{server.Month{2022, 3}, time.Date(2022, 3, 31, 0, 0, 0, 0, loc), false, true, false},
 | 
				
			||||||
 | 
							{server.Month{2022, 4}, time.Date(2022, 3, 31, 0, 0, 0, 0, loc), true, false, false},
 | 
				
			||||||
 | 
							{server.Month{2021, 2}, time.Date(2022, 3, 31, 0, 0, 0, 0, loc), false, false, true},
 | 
				
			||||||
 | 
							{server.Month{2021, 3}, time.Date(2022, 3, 31, 0, 0, 0, 0, loc), false, false, true},
 | 
				
			||||||
 | 
							{server.Month{2021, 4}, time.Date(2022, 3, 31, 0, 0, 0, 0, loc), false, false, true},
 | 
				
			||||||
 | 
							{server.Month{2023, 2}, time.Date(2022, 3, 31, 0, 0, 0, 0, loc), true, false, false},
 | 
				
			||||||
 | 
							{server.Month{2023, 3}, time.Date(2022, 3, 31, 0, 0, 0, 0, loc), true, false, false},
 | 
				
			||||||
 | 
							{server.Month{2023, 4}, time.Date(2022, 3, 31, 0, 0, 0, 0, loc), true, false, false},
 | 
				
			||||||
 | 
							{server.Month{2021, 11}, time.Date(2021, 12, 1, 0, 0, 0, 0, loc), false, false, true},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						for i := range tests { //nolint:paralleltest
 | 
				
			||||||
 | 
							test := tests[i]
 | 
				
			||||||
 | 
							t.Run(test.Date.Format("2006-01-02")+" is in of "+test.Value.String(), func(t *testing.T) {
 | 
				
			||||||
 | 
								t.Parallel()
 | 
				
			||||||
 | 
								server.AssertEqualBool(t, test.InPast, test.Value.InPast(test.Date), "in past")
 | 
				
			||||||
 | 
								server.AssertEqualBool(t, test.InPresent, test.Value.InPresent(test.Date), "in present")
 | 
				
			||||||
 | 
								server.AssertEqualBool(t, test.InFuture, test.Value.InFuture(test.Date), "in future")
 | 
				
			||||||
 | 
							})
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										101
									
								
								server/reconcile.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										101
									
								
								server/reconcile.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,101 @@
 | 
				
			|||||||
 | 
					package server
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"database/sql"
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
						"net/http"
 | 
				
			||||||
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"git.javil.eu/jacob1123/budgeteer/postgres"
 | 
				
			||||||
 | 
						"git.javil.eu/jacob1123/budgeteer/postgres/numeric"
 | 
				
			||||||
 | 
						"github.com/google/uuid"
 | 
				
			||||||
 | 
						"github.com/labstack/echo/v4"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type ReconcileTransactionsRequest struct {
 | 
				
			||||||
 | 
						TransactionIDs                 []uuid.UUID `json:"transactionIds"`
 | 
				
			||||||
 | 
						ReconcilationTransactionAmount string      `json:"reconciliationTransactionAmount"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type ReconcileTransactionsResponse struct {
 | 
				
			||||||
 | 
						Message                   string
 | 
				
			||||||
 | 
						ReconciliationTransaction *postgres.DisplayTransaction
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (h *Handler) reconcileTransactions(c echo.Context) error {
 | 
				
			||||||
 | 
						accountID := c.Param("accountid")
 | 
				
			||||||
 | 
						accountUUID, err := uuid.Parse(accountID)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return echo.NewHTTPError(http.StatusBadRequest, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var request ReconcileTransactionsRequest
 | 
				
			||||||
 | 
						err = c.Bind(&request)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return echo.NewHTTPError(http.StatusBadRequest, fmt.Errorf("parse request: %w", err))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var amount numeric.Numeric
 | 
				
			||||||
 | 
						err = amount.Set(request.ReconcilationTransactionAmount)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return echo.NewHTTPError(http.StatusBadRequest, fmt.Errorf("parse request: %w", err))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						tx, err := h.Service.BeginTx(c.Request().Context(), &sql.TxOptions{})
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return fmt.Errorf("begin tx: %w", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						db := h.Service.WithTx(tx)
 | 
				
			||||||
 | 
						for _, transactionID := range request.TransactionIDs {
 | 
				
			||||||
 | 
							err := db.SetTransactionReconciled(c.Request().Context(), transactionID)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								return fmt.Errorf("update transaction: %w", err)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						reconciliationTransaction, err := h.CreateReconcilationTransaction(amount, accountUUID, db, c)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return fmt.Errorf("insert new transaction: %w", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						err = h.Service.SetLastReconciled(c.Request().Context(), accountUUID)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return fmt.Errorf("set last reconciled: %w", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						err = tx.Commit()
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return fmt.Errorf("commit: %w", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return c.JSON(http.StatusOK, ReconcileTransactionsResponse{
 | 
				
			||||||
 | 
							Message:                   fmt.Sprintf("Set status for %d transactions", len(request.TransactionIDs)),
 | 
				
			||||||
 | 
							ReconciliationTransaction: reconciliationTransaction,
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (*Handler) CreateReconcilationTransaction(amount numeric.Numeric, accountUUID uuid.UUID, db *postgres.Queries, c echo.Context) (*postgres.DisplayTransaction, error) {
 | 
				
			||||||
 | 
						if amount.IsZero() {
 | 
				
			||||||
 | 
							return nil, nil //nolint: nilnil
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						createTransaction := postgres.CreateTransactionParams{
 | 
				
			||||||
 | 
							Date:      time.Now(),
 | 
				
			||||||
 | 
							Memo:      "Reconciliation Transaction",
 | 
				
			||||||
 | 
							Amount:    amount,
 | 
				
			||||||
 | 
							AccountID: accountUUID,
 | 
				
			||||||
 | 
							Status:    "Reconciled",
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						transactionUUID, err := db.CreateTransaction(c.Request().Context(), createTransaction)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, fmt.Errorf("insert new transaction: %w", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						transaction, err := db.GetTransaction(c.Request().Context(), transactionUUID)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, fmt.Errorf("get created transaction: %w", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return &transaction, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										156
									
								
								server/session.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										156
									
								
								server/session.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,156 @@
 | 
				
			|||||||
 | 
					package server
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"context"
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
						"net/http"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"git.javil.eu/jacob1123/budgeteer"
 | 
				
			||||||
 | 
						"git.javil.eu/jacob1123/budgeteer/postgres"
 | 
				
			||||||
 | 
						"github.com/google/uuid"
 | 
				
			||||||
 | 
						"github.com/labstack/echo/v4"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const (
 | 
				
			||||||
 | 
						HeaderName = "Authorization"
 | 
				
			||||||
 | 
						Bearer     = "Bearer "
 | 
				
			||||||
 | 
						ParamName  = "token"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func MustGetToken(c echo.Context) budgeteer.Token { //nolint:ireturn
 | 
				
			||||||
 | 
						token := c.Get(ParamName)
 | 
				
			||||||
 | 
						if token, ok := token.(budgeteer.Token); ok {
 | 
				
			||||||
 | 
							return token
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						panic("Token is not a valid Token")
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (h *Handler) verifyLogin(c echo.Context) (budgeteer.Token, error) { //nolint:ireturn
 | 
				
			||||||
 | 
						tokenString := c.Request().Header.Get(HeaderName)
 | 
				
			||||||
 | 
						if len(tokenString) <= len(Bearer) {
 | 
				
			||||||
 | 
							return nil, echo.NewHTTPError(http.StatusUnauthorized, "no authorization header supplied")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						tokenString = tokenString[7:]
 | 
				
			||||||
 | 
						token, err := h.TokenVerifier.VerifyToken(tokenString)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, fmt.Errorf("verify token '%s': %w", tokenString, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return token, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (h *Handler) verifyLoginWithForbidden(next echo.HandlerFunc) echo.HandlerFunc {
 | 
				
			||||||
 | 
						return func(c echo.Context) error {
 | 
				
			||||||
 | 
							token, err := h.verifyLogin(c)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								// c.Header("WWW-Authenticate", "Bearer")
 | 
				
			||||||
 | 
								return echo.NewHTTPError(http.StatusForbidden, err)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							c.Set(ParamName, token)
 | 
				
			||||||
 | 
							return next(c)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type loginInformation struct {
 | 
				
			||||||
 | 
						Password string `json:"password"`
 | 
				
			||||||
 | 
						User     string `json:"user"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (h *Handler) loginPost(c echo.Context) error {
 | 
				
			||||||
 | 
						var login loginInformation
 | 
				
			||||||
 | 
						err := c.Bind(&login)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return fmt.Errorf("parse payload: %w", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						user, err := h.Service.GetUserByUsername(c.Request().Context(), login.User)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err = h.CredentialsVerifier.Verify(login.Password, user.Password); err != nil {
 | 
				
			||||||
 | 
							return fmt.Errorf("verify password: %w", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						token, err := h.TokenVerifier.CreateToken(&user)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return fmt.Errorf("create token: %w", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						go h.UpdateLastLogin(user.ID)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						budgets, err := h.Service.GetBudgetsForUser(c.Request().Context(), user.ID)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return c.JSON(http.StatusOK, LoginResponse{token, user, budgets})
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type LoginResponse struct {
 | 
				
			||||||
 | 
						Token   string
 | 
				
			||||||
 | 
						User    postgres.User
 | 
				
			||||||
 | 
						Budgets []postgres.Budget
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type registerInformation struct {
 | 
				
			||||||
 | 
						Password string `json:"password"`
 | 
				
			||||||
 | 
						Email    string `json:"email"`
 | 
				
			||||||
 | 
						Name     string `json:"name"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (h *Handler) registerPost(c echo.Context) error {
 | 
				
			||||||
 | 
						var register registerInformation
 | 
				
			||||||
 | 
						err := c.Bind(®ister)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return echo.NewHTTPError(http.StatusBadRequest, "error parsing body")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if register.Email == "" || register.Password == "" || register.Name == "" {
 | 
				
			||||||
 | 
							return echo.NewHTTPError(http.StatusBadRequest, "e-mail, password and name are required")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						_, err = h.Service.GetUserByUsername(c.Request().Context(), register.Email)
 | 
				
			||||||
 | 
						if err == nil {
 | 
				
			||||||
 | 
							return echo.NewHTTPError(http.StatusBadRequest, "email is already taken")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						hash, err := h.CredentialsVerifier.Hash(register.Password)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return fmt.Errorf("hash password: %w", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						createUser := postgres.CreateUserParams{
 | 
				
			||||||
 | 
							Name:     register.Name,
 | 
				
			||||||
 | 
							Password: hash,
 | 
				
			||||||
 | 
							Email:    register.Email,
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						user, err := h.Service.CreateUser(c.Request().Context(), createUser)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						token, err := h.TokenVerifier.CreateToken(&user)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return fmt.Errorf("create token: %w", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						go h.UpdateLastLogin(user.ID)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						budgets, err := h.Service.GetBudgetsForUser(c.Request().Context(), user.ID)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return c.JSON(http.StatusOK, LoginResponse{token, user, budgets})
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (h *Handler) UpdateLastLogin(userID uuid.UUID) {
 | 
				
			||||||
 | 
						_, err := h.Service.UpdateLastLogin(context.Background(), userID)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							fmt.Printf("Error updating last login: %s", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										166
									
								
								server/transaction.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										166
									
								
								server/transaction.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,166 @@
 | 
				
			|||||||
 | 
					package server
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"context"
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
						"net/http"
 | 
				
			||||||
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"git.javil.eu/jacob1123/budgeteer/postgres"
 | 
				
			||||||
 | 
						"git.javil.eu/jacob1123/budgeteer/postgres/numeric"
 | 
				
			||||||
 | 
						"github.com/google/uuid"
 | 
				
			||||||
 | 
						"github.com/labstack/echo/v4"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type NewTransactionPayload struct {
 | 
				
			||||||
 | 
						Date  JSONDate `json:"date"`
 | 
				
			||||||
 | 
						Payee struct {
 | 
				
			||||||
 | 
							ID   uuid.NullUUID
 | 
				
			||||||
 | 
							Name string
 | 
				
			||||||
 | 
							Type string
 | 
				
			||||||
 | 
						} `json:"payee"`
 | 
				
			||||||
 | 
						CategoryID uuid.NullUUID `json:"categoryId"`
 | 
				
			||||||
 | 
						Memo       string        `json:"memo"`
 | 
				
			||||||
 | 
						Amount     string        `json:"amount"`
 | 
				
			||||||
 | 
						BudgetID   uuid.UUID     `json:"budgetId"`
 | 
				
			||||||
 | 
						AccountID  uuid.UUID     `json:"accountId"`
 | 
				
			||||||
 | 
						State      string        `json:"state"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (h *Handler) updateTransaction(c echo.Context) error {
 | 
				
			||||||
 | 
						var payload NewTransactionPayload
 | 
				
			||||||
 | 
						err := c.Bind(&payload)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return echo.NewHTTPError(http.StatusBadRequest, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						amount, err := numeric.Parse(payload.Amount)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return echo.NewHTTPError(http.StatusBadRequest, fmt.Errorf("amount: %w", err))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						transactionID := c.Param("transactionid")
 | 
				
			||||||
 | 
						transactionUUID, err := uuid.Parse(transactionID)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return echo.NewHTTPError(http.StatusBadRequest, "transactionid missing from URL")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return h.UpdateTransaction(payload, amount, transactionUUID, c)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (h *Handler) newTransaction(c echo.Context) error {
 | 
				
			||||||
 | 
						var payload NewTransactionPayload
 | 
				
			||||||
 | 
						err := c.Bind(&payload)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return echo.NewHTTPError(http.StatusBadRequest, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						amount, err := numeric.Parse(payload.Amount)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return echo.NewHTTPError(http.StatusBadRequest, fmt.Errorf("amount: %w", err))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						newTransaction := postgres.CreateTransactionParams{
 | 
				
			||||||
 | 
							Memo:       payload.Memo,
 | 
				
			||||||
 | 
							Date:       time.Time(payload.Date),
 | 
				
			||||||
 | 
							Amount:     amount,
 | 
				
			||||||
 | 
							Status:     postgres.TransactionStatus(payload.State),
 | 
				
			||||||
 | 
							CategoryID: payload.CategoryID,
 | 
				
			||||||
 | 
							AccountID:  payload.AccountID,
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if payload.Payee.Type == "account" {
 | 
				
			||||||
 | 
							groupID, err := h.CreateTransferForOtherAccount(newTransaction, amount, payload, c)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								return echo.NewHTTPError(http.StatusInternalServerError, err)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							newTransaction.GroupID = groupID
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							payeeID, err := GetPayeeID(c.Request().Context(), payload, h)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								return echo.NewHTTPError(http.StatusInternalServerError, fmt.Errorf("create payee: %w", err))
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							newTransaction.PayeeID = payeeID
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						transactionUUID, err := h.Service.CreateTransaction(c.Request().Context(), newTransaction)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return echo.NewHTTPError(http.StatusInternalServerError, fmt.Errorf("create transaction: %w", err))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						transaction, err := h.Service.GetTransaction(c.Request().Context(), transactionUUID)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return echo.NewHTTPError(http.StatusInternalServerError, fmt.Errorf("get transaction: %w", err))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return c.JSON(http.StatusOK, transaction)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (h *Handler) UpdateTransaction(payload NewTransactionPayload, amount numeric.Numeric, transactionUUID uuid.UUID, c echo.Context) error {
 | 
				
			||||||
 | 
						if amount.IsZero() {
 | 
				
			||||||
 | 
							err := h.Service.DeleteTransaction(c.Request().Context(), transactionUUID)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								return echo.NewHTTPError(http.StatusInternalServerError, fmt.Errorf("delete transaction: %w", err))
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							return nil
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						editTransaction := postgres.UpdateTransactionParams{
 | 
				
			||||||
 | 
							Memo:       payload.Memo,
 | 
				
			||||||
 | 
							Date:       time.Time(payload.Date),
 | 
				
			||||||
 | 
							Amount:     amount,
 | 
				
			||||||
 | 
							PayeeID:    payload.Payee.ID,
 | 
				
			||||||
 | 
							CategoryID: payload.CategoryID,
 | 
				
			||||||
 | 
							ID:         transactionUUID,
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						err := h.Service.UpdateTransaction(c.Request().Context(), editTransaction)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return echo.NewHTTPError(http.StatusInternalServerError, fmt.Errorf("edit transaction: %w", err))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						transaction, err := h.Service.GetTransaction(c.Request().Context(), transactionUUID)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return echo.NewHTTPError(http.StatusInternalServerError, fmt.Errorf("get transaction: %w", err))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return c.JSON(http.StatusOK, transaction)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (h *Handler) CreateTransferForOtherAccount(newTransaction postgres.CreateTransactionParams, amount numeric.Numeric, payload NewTransactionPayload, c echo.Context) (uuid.NullUUID, error) {
 | 
				
			||||||
 | 
						newTransaction.GroupID = uuid.NullUUID{UUID: uuid.New(), Valid: true}
 | 
				
			||||||
 | 
						newTransaction.Amount = amount.Neg()
 | 
				
			||||||
 | 
						newTransaction.AccountID = payload.Payee.ID.UUID
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// transfer does not need category. Either it's account is off-budget or no category was supplied.
 | 
				
			||||||
 | 
						newTransaction.CategoryID = uuid.NullUUID{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						_, err := h.Service.CreateTransaction(c.Request().Context(), newTransaction)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return uuid.NullUUID{}, fmt.Errorf("create transfer transaction: %w", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return newTransaction.GroupID, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func GetPayeeID(context context.Context, payload NewTransactionPayload, h *Handler) (uuid.NullUUID, error) {
 | 
				
			||||||
 | 
						payeeID := payload.Payee.ID
 | 
				
			||||||
 | 
						if payeeID.Valid {
 | 
				
			||||||
 | 
							return payeeID, nil
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if payload.Payee.Name == "" {
 | 
				
			||||||
 | 
							return uuid.NullUUID{}, nil
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						newPayee := postgres.CreatePayeeParams{
 | 
				
			||||||
 | 
							Name:     payload.Payee.Name,
 | 
				
			||||||
 | 
							BudgetID: payload.BudgetID,
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						payee, err := h.Service.CreatePayee(context, newPayee)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return uuid.NullUUID{}, fmt.Errorf("create payee: %w", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return uuid.NullUUID{UUID: payee.ID, Valid: true}, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										37
									
								
								server/util.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								server/util.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,37 @@
 | 
				
			|||||||
 | 
					package server
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
						"strconv"
 | 
				
			||||||
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/labstack/echo/v4"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func getDate(c echo.Context) (Month, error) {
 | 
				
			||||||
 | 
						var year, month int
 | 
				
			||||||
 | 
						yearString := c.Param("year")
 | 
				
			||||||
 | 
						monthString := c.Param("month")
 | 
				
			||||||
 | 
						if yearString == "" && monthString == "" {
 | 
				
			||||||
 | 
							return getFirstOfMonthTime(time.Now()), nil
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						year, err := strconv.Atoi(yearString)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return Month{}, fmt.Errorf("parse year: %w", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						month, err = strconv.Atoi(monthString)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return Month{}, fmt.Errorf("parse month: %w", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return Month{year, month}, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func getFirstOfMonthTime(date time.Time) Month {
 | 
				
			||||||
 | 
						var monthM time.Month
 | 
				
			||||||
 | 
						year, monthM, _ := date.Date()
 | 
				
			||||||
 | 
						month := int(monthM)
 | 
				
			||||||
 | 
						return Month{year, month}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										107
									
								
								server/ynab-import.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										107
									
								
								server/ynab-import.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,107 @@
 | 
				
			|||||||
 | 
					package server
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
						"net/http"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"git.javil.eu/jacob1123/budgeteer/postgres"
 | 
				
			||||||
 | 
						"github.com/google/uuid"
 | 
				
			||||||
 | 
						"github.com/labstack/echo/v4"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (h *Handler) importYNAB(c echo.Context) error {
 | 
				
			||||||
 | 
						budgetID := c.Param("budgetid")
 | 
				
			||||||
 | 
						if budgetID == "" {
 | 
				
			||||||
 | 
							return echo.NewHTTPError(http.StatusBadRequest, "no budget_id specified")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						budgetUUID, err := uuid.Parse(budgetID)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return echo.NewHTTPError(http.StatusBadRequest, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						ynab, err := postgres.NewYNABImport(c.Request().Context(), h.Service.Queries, budgetUUID)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						transactionsFile, err := c.FormFile("transactions")
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return fmt.Errorf("get transactions: %w", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						transactions, err := transactionsFile.Open()
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return fmt.Errorf("open transactions: %w", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						err = ynab.ImportTransactions(c.Request().Context(), transactions)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						assignmentsFile, err := c.FormFile("assignments")
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return fmt.Errorf("get assignments: %w", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						assignments, err := assignmentsFile.Open()
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return fmt.Errorf("open assignments: %w", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						err = ynab.ImportAssignments(c.Request().Context(), assignments)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (h *Handler) exportYNABTransactions(c echo.Context) error {
 | 
				
			||||||
 | 
						budgetID := c.Param("budgetid")
 | 
				
			||||||
 | 
						if budgetID == "" {
 | 
				
			||||||
 | 
							return echo.NewHTTPError(http.StatusBadRequest, "no budget_id specified")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						budgetUUID, err := uuid.Parse(budgetID)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return echo.NewHTTPError(http.StatusBadRequest, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						ynab, err := postgres.NewYNABExport(c.Request().Context(), h.Service.Queries, budgetUUID)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						err = ynab.ExportTransactions(c.Request().Context(), c.Response().Writer)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (h *Handler) exportYNABAssignments(c echo.Context) error {
 | 
				
			||||||
 | 
						budgetID := c.Param("budgetid")
 | 
				
			||||||
 | 
						if budgetID == "" {
 | 
				
			||||||
 | 
							return echo.NewHTTPError(http.StatusBadRequest, "no budget_id specified")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						budgetUUID, err := uuid.Parse(budgetID)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return echo.NewHTTPError(http.StatusBadRequest, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						ynab, err := postgres.NewYNABExport(c.Request().Context(), h.Service.Queries, budgetUUID)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return echo.NewHTTPError(http.StatusInternalServerError, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						err = ynab.ExportAssignments(c.Request().Context(), c.Response().Writer)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return echo.NewHTTPError(http.StatusInternalServerError, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -7,9 +7,11 @@ packages:
 | 
				
			|||||||
    queries: "postgres/queries/"
 | 
					    queries: "postgres/queries/"
 | 
				
			||||||
overrides:
 | 
					overrides:
 | 
				
			||||||
  - go_type: 
 | 
					  - go_type: 
 | 
				
			||||||
      type: "Numeric"
 | 
					      import: "git.javil.eu/jacob1123/budgeteer/postgres/numeric"
 | 
				
			||||||
 | 
					      type: Numeric
 | 
				
			||||||
    db_type: "pg_catalog.numeric"
 | 
					    db_type: "pg_catalog.numeric"
 | 
				
			||||||
  - go_type: 
 | 
					  - go_type: 
 | 
				
			||||||
      type: "Numeric"
 | 
					      import: "git.javil.eu/jacob1123/budgeteer/postgres/numeric"
 | 
				
			||||||
 | 
					      type: Numeric
 | 
				
			||||||
    db_type: "pg_catalog.numeric"
 | 
					    db_type: "pg_catalog.numeric"
 | 
				
			||||||
    nullable: true
 | 
					    nullable: true
 | 
				
			||||||
							
								
								
									
										1
									
								
								testdata
									
									
									
									
									
										Submodule
									
								
							
							
								
								
								
								
								
							
						
						
									
										1
									
								
								testdata
									
									
									
									
									
										Submodule
									
								
							 Submodule testdata added at 8de369b17a
									
								
							
							
								
								
									
										4
									
								
								token.go
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								token.go
									
									
									
									
									
								
							@@ -5,7 +5,7 @@ import (
 | 
				
			|||||||
	"github.com/google/uuid"
 | 
						"github.com/google/uuid"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Token contains data that authenticates a user
 | 
					// Token contains data that authenticates a user.
 | 
				
			||||||
type Token interface {
 | 
					type Token interface {
 | 
				
			||||||
	GetUsername() string
 | 
						GetUsername() string
 | 
				
			||||||
	GetName() string
 | 
						GetName() string
 | 
				
			||||||
@@ -13,7 +13,7 @@ type Token interface {
 | 
				
			|||||||
	GetID() uuid.UUID
 | 
						GetID() uuid.UUID
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// TokenVerifier verifies a Token
 | 
					// TokenVerifier verifies a Token.
 | 
				
			||||||
type TokenVerifier interface {
 | 
					type TokenVerifier interface {
 | 
				
			||||||
	VerifyToken(string) (Token, error)
 | 
						VerifyToken(string) (Token, error)
 | 
				
			||||||
	CreateToken(*postgres.User) (string, error)
 | 
						CreateToken(*postgres.User) (string, error)
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										21
									
								
								web/.eslintrc.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								web/.eslintrc.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,21 @@
 | 
				
			|||||||
 | 
					module.exports = {
 | 
				
			||||||
 | 
					    extends: [
 | 
				
			||||||
 | 
					        // add more generic rulesets here, such as:
 | 
				
			||||||
 | 
					        // 'eslint:recommended',
 | 
				
			||||||
 | 
					        "plugin:vue/vue3-recommended",
 | 
				
			||||||
 | 
					        // 'plugin:vue/recommended' // Use this if you are using Vue.js 2.x.
 | 
				
			||||||
 | 
					    ],
 | 
				
			||||||
 | 
					    rules: {
 | 
				
			||||||
 | 
					        // override/add rules settings here, such as:
 | 
				
			||||||
 | 
					        'vue/max-attributes-per-line': 'off',
 | 
				
			||||||
 | 
					        'vue/singleline-html-element-content-newline': 'off',
 | 
				
			||||||
 | 
					        'vue/first-attribute-linebreak': 'off',
 | 
				
			||||||
 | 
					        'vue/html-closing-bracket-newline': 'off',
 | 
				
			||||||
 | 
					        // 'vue/no-unused-vars': 'error'
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    parser: "vue-eslint-parser",
 | 
				
			||||||
 | 
					    parserOptions: {
 | 
				
			||||||
 | 
					        parser: "@typescript-eslint/parser",
 | 
				
			||||||
 | 
					        sourceType: "module",
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
@@ -1,39 +0,0 @@
 | 
				
			|||||||
{{template "base" .}}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
{{define "title"}}{{.Account.Name}}{{end}}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
{{define "new"}}
 | 
					 | 
				
			||||||
    {{template "transaction-new" .}}
 | 
					 | 
				
			||||||
{{end}}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
{{define "main"}}
 | 
					 | 
				
			||||||
<div class="budget-item">
 | 
					 | 
				
			||||||
    <a href="#newtransactionmodal" data-bs-toggle="modal" data-bs-target="#newtransactionmodal">New Transaction</a>
 | 
					 | 
				
			||||||
    <span class="time"></span>
 | 
					 | 
				
			||||||
</div>
 | 
					 | 
				
			||||||
<table class="container col-lg-12" id="content">
 | 
					 | 
				
			||||||
    {{range .Transactions}}
 | 
					 | 
				
			||||||
    <tr class="{{if .Date.After now}}future{{end}}">
 | 
					 | 
				
			||||||
        <td>{{.Date.Format "02.01.2006"}}</td>
 | 
					 | 
				
			||||||
        <td>
 | 
					 | 
				
			||||||
            {{.Account}}
 | 
					 | 
				
			||||||
        </td>
 | 
					 | 
				
			||||||
        <td>
 | 
					 | 
				
			||||||
            {{.Payee}}
 | 
					 | 
				
			||||||
        </td>
 | 
					 | 
				
			||||||
        <td>
 | 
					 | 
				
			||||||
            {{if .CategoryGroup}}
 | 
					 | 
				
			||||||
                {{.CategoryGroup}} : {{.Category}}
 | 
					 | 
				
			||||||
            {{end}}
 | 
					 | 
				
			||||||
        </td>
 | 
					 | 
				
			||||||
        <td>
 | 
					 | 
				
			||||||
            {{if .GroupID.Valid}}☀{{end}}
 | 
					 | 
				
			||||||
        </td>
 | 
					 | 
				
			||||||
        <td>
 | 
					 | 
				
			||||||
            <a href="/budget/{{$.Budget.ID}}/transaction/{{.ID}}">{{.Memo}}</a>
 | 
					 | 
				
			||||||
        </td>
 | 
					 | 
				
			||||||
        {{template "amount-cell" .Amount}}
 | 
					 | 
				
			||||||
    </tr>
 | 
					 | 
				
			||||||
    {{end}}
 | 
					 | 
				
			||||||
</table>
 | 
					 | 
				
			||||||
{{end}}
 | 
					 | 
				
			||||||
@@ -1,17 +0,0 @@
 | 
				
			|||||||
{{define "title"}}
 | 
					 | 
				
			||||||
    Accounts
 | 
					 | 
				
			||||||
{{end}}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
{{define "new"}}
 | 
					 | 
				
			||||||
{{end}}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
{{template "base" .}}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
{{define "main"}}
 | 
					 | 
				
			||||||
    {{range .Accounts}}
 | 
					 | 
				
			||||||
    <div class="budget-item">
 | 
					 | 
				
			||||||
        <a href="/budget/{{$.Budget.ID}}/account/{{.ID}}">{{.Name}}</a>
 | 
					 | 
				
			||||||
        <span class="time">{{printf "%.2f" .Balance.GetFloat64}}</span>
 | 
					 | 
				
			||||||
    </div>
 | 
					 | 
				
			||||||
    {{end}}
 | 
					 | 
				
			||||||
{{end}}
 | 
					 | 
				
			||||||
@@ -1,18 +0,0 @@
 | 
				
			|||||||
 | 
					 | 
				
			||||||
{{define "title"}}
 | 
					 | 
				
			||||||
    Admin
 | 
					 | 
				
			||||||
{{end}}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
{{define "sidebar"}}
 | 
					 | 
				
			||||||
    Settings for all Budgets
 | 
					 | 
				
			||||||
{{end}}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
{{template "base" .}}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
{{define "main"}}
 | 
					 | 
				
			||||||
    <h1>Danger Zone</h1>
 | 
					 | 
				
			||||||
    <div class="budget-item">
 | 
					 | 
				
			||||||
        <button>Clear database</button>
 | 
					 | 
				
			||||||
        <p>This removes all data and starts from scratch. Not undoable!</p>
 | 
					 | 
				
			||||||
    </div>
 | 
					 | 
				
			||||||
{{end}}
 | 
					 | 
				
			||||||
@@ -1,23 +0,0 @@
 | 
				
			|||||||
{{define "amount"}}
 | 
					 | 
				
			||||||
        <span class="right {{if .IsZero}}zero{{else if not .IsPositive}}negative{{end}}">
 | 
					 | 
				
			||||||
            {{printf "%.2f" .GetFloat64}}
 | 
					 | 
				
			||||||
        </span>
 | 
					 | 
				
			||||||
{{end}}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
{{define "amount-cell"}}
 | 
					 | 
				
			||||||
        <td class="right {{if .IsZero}}zero{{else if not .IsPositive}}negative{{end}}">
 | 
					 | 
				
			||||||
            {{printf "%.2f" .GetFloat64}}
 | 
					 | 
				
			||||||
        </td>
 | 
					 | 
				
			||||||
{{end}}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
{{define "amountf64"}}
 | 
					 | 
				
			||||||
        <span class="right {{if eq . 0.0}}zero{{else if lt . 0.0}}negative{{end}}">
 | 
					 | 
				
			||||||
            {{printf "%.2f" .}}
 | 
					 | 
				
			||||||
        </span>
 | 
					 | 
				
			||||||
{{end}}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
{{define "amountf64-cell"}}
 | 
					 | 
				
			||||||
        <td class="right {{if eq . 0.0}}zero{{else if lt . 0.0}}negative{{end}}">
 | 
					 | 
				
			||||||
            {{printf "%.2f" .}}
 | 
					 | 
				
			||||||
        </td>
 | 
					 | 
				
			||||||
{{end}}
 | 
					 | 
				
			||||||
							
								
								
									
										39
									
								
								web/base.tpl
									
									
									
									
									
								
							
							
						
						
									
										39
									
								
								web/base.tpl
									
									
									
									
									
								
							@@ -1,39 +0,0 @@
 | 
				
			|||||||
{{define "base"}}
 | 
					 | 
				
			||||||
<!DOCTYPE html>
 | 
					 | 
				
			||||||
<html>
 | 
					 | 
				
			||||||
    <head>
 | 
					 | 
				
			||||||
        <meta charset="utf-8">
 | 
					 | 
				
			||||||
	    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	    <link href="/static/css/bootstrap.min.css" rel="stylesheet" />
 | 
					 | 
				
			||||||
	    <link href="/static/css/main.css" rel="stylesheet" />
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script> 
 | 
					 | 
				
			||||||
	    <script src="https://malsup.github.io/jquery.form.js"></script> 
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	    <script src="/static/js/bootstrap.min.js"></script> 
 | 
					 | 
				
			||||||
	    <script src="/static/js/main.js"></script> 
 | 
					 | 
				
			||||||
        <title>{{template "title" .}} - Budgeteer</title>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        {{block "more-head" .}}{{end}}
 | 
					 | 
				
			||||||
    </head>
 | 
					 | 
				
			||||||
    <body>
 | 
					 | 
				
			||||||
        <div id="wrapper">
 | 
					 | 
				
			||||||
            <div id="sidebar">
 | 
					 | 
				
			||||||
                {{block "sidebar" .}}
 | 
					 | 
				
			||||||
                    {{template "budget-sidebar" .}}
 | 
					 | 
				
			||||||
                {{end}}
 | 
					 | 
				
			||||||
            </div>
 | 
					 | 
				
			||||||
            <div id="content">
 | 
					 | 
				
			||||||
                <div class="container" id="head">
 | 
					 | 
				
			||||||
                    {{template "title" .}}
 | 
					 | 
				
			||||||
                </div>
 | 
					 | 
				
			||||||
                <div class="container col-lg-12" id="content">
 | 
					 | 
				
			||||||
                        {{template "main" .}}
 | 
					 | 
				
			||||||
                </div>
 | 
					 | 
				
			||||||
                {{block "new" .}}{{end}}
 | 
					 | 
				
			||||||
            </div>
 | 
					 | 
				
			||||||
        </div>
 | 
					 | 
				
			||||||
    </body>
 | 
					 | 
				
			||||||
</html>
 | 
					 | 
				
			||||||
{{end}}
 | 
					 | 
				
			||||||
@@ -1,40 +0,0 @@
 | 
				
			|||||||
{{define "budget-new"}}
 | 
					 | 
				
			||||||
    <div id="newbudgetmodal" class="modal fade" role="dialog">
 | 
					 | 
				
			||||||
        <div class="modal-dialog" role="document">
 | 
					 | 
				
			||||||
            <script>        
 | 
					 | 
				
			||||||
                $(document).ready(function () {
 | 
					 | 
				
			||||||
                    $('#errorcreatingbudget').hide();
 | 
					 | 
				
			||||||
                    $('#newbudgetform').ajaxForm({
 | 
					 | 
				
			||||||
                        error: function() {
 | 
					 | 
				
			||||||
                            $('#errorcreatingbudget').show();
 | 
					 | 
				
			||||||
                        }
 | 
					 | 
				
			||||||
                    }); 
 | 
					 | 
				
			||||||
                }); 
 | 
					 | 
				
			||||||
            </script>
 | 
					 | 
				
			||||||
            <div class="modal-content">
 | 
					 | 
				
			||||||
                <div class="modal-header">
 | 
					 | 
				
			||||||
                    <h5 class="modal-title">New Budget</h5>
 | 
					 | 
				
			||||||
                    <button type="button" class="close" data-bs-dismiss="modal" aria-label="Close">
 | 
					 | 
				
			||||||
                        <span aria-hidden="true">×</span>
 | 
					 | 
				
			||||||
                    </button>
 | 
					 | 
				
			||||||
                </div>
 | 
					 | 
				
			||||||
                <form id="newbudgetform" action="/api/v1/budget/new" method="POST">
 | 
					 | 
				
			||||||
                    <div class="modal-body">
 | 
					 | 
				
			||||||
                        <div class="form-group">
 | 
					 | 
				
			||||||
                            <label for="name">Name</label>
 | 
					 | 
				
			||||||
                            <input type="text" name="name" class="form-control" placeholder="Name" />
 | 
					 | 
				
			||||||
                        </div>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                        <div id="errorcreatingbudget">
 | 
					 | 
				
			||||||
                            Error creating budget.
 | 
					 | 
				
			||||||
                        </div>
 | 
					 | 
				
			||||||
                    </div>
 | 
					 | 
				
			||||||
                    <div class="modal-footer">
 | 
					 | 
				
			||||||
                        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
 | 
					 | 
				
			||||||
                        <input type="submit" class="btn btn-primary" value="Create" class="form-control" />
 | 
					 | 
				
			||||||
                    </div>
 | 
					 | 
				
			||||||
                </form>
 | 
					 | 
				
			||||||
            </div>
 | 
					 | 
				
			||||||
        </div>
 | 
					 | 
				
			||||||
    </div>
 | 
					 | 
				
			||||||
{{end}}
 | 
					 | 
				
			||||||
Some files were not shown because too many files have changed in this diff Show More
		Reference in New Issue
	
	Block a user