commit 531b5dabe2ea809fd002bdcd5c5f6819ab9c25a7 Author: Declan Teevan Date: Tue Apr 16 22:27:52 2024 +0100 chore: initial commit diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..2125666 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text=auto \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9692111 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +*.exe +*.exe~ +*.dll +*.so +*.dylib +*.test +*.out +go.work +*.env \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..a8032f9 --- /dev/null +++ b/LICENSE @@ -0,0 +1,660 @@ + GNU AFFERO GENERAL PUBLIC LICENSE + Version 3, 19 November 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU Affero General Public License is a free, copyleft license for +software and other kinds of works, specifically designed to ensure +cooperation with the community in the case of network server software. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +our General Public Licenses are intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + Developers that use our General Public Licenses protect your rights +with two steps: (1) assert copyright on the software, and (2) offer +you this License which gives you legal permission to copy, distribute +and/or modify the software. + + A secondary benefit of defending all users' freedom is that +improvements made in alternate versions of the program, if they +receive widespread use, become available for other developers to +incorporate. Many developers of free software are heartened and +encouraged by the resulting cooperation. However, in the case of +software used on network servers, this result may fail to come about. +The GNU General Public License permits making a modified version and +letting the public access it on a server without ever releasing its +source code to the public. + + The GNU Affero General Public License is designed specifically to +ensure that, in such cases, the modified source code becomes available +to the community. It requires the operator of a network server to +provide the source code of the modified version running there to the +users of that server. Therefore, public use of a modified version, on +a publicly accessible server, gives the public access to the source +code of the modified version. + + An older license, called the Affero General Public License and +published by Affero, was designed to accomplish similar goals. This is +a different license, not a version of the Affero GPL, but Affero has +released a new version of the Affero GPL which permits relicensing under +this license. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU Affero General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Remote Network Interaction; Use with the GNU General Public License. + + Notwithstanding any other provision of this License, if you modify the +Program, your modified version must prominently offer all users +interacting with it remotely through a computer network (if your version +supports such interaction) an opportunity to receive the Corresponding +Source of your version by providing access to the Corresponding Source +from a network server at no charge, through some standard or customary +means of facilitating copying of software. This Corresponding Source +shall include the Corresponding Source for any work covered by version 3 +of the GNU General Public License that is incorporated pursuant to the +following paragraph. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the work with which it is combined will remain governed by version +3 of the GNU General Public License. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU Affero General Public License from time to time. Such new versions +will be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU Affero General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU Affero General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU Affero General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + Copyright (C) 2024 Declan Teevan + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If your software can interact with users remotely through a computer +network, you should also make sure that it provides a way for users to +get its source. For example, if your program is a web application, its +interface could display a "Source" link that leads users to an archive +of the code. There are many ways you could offer source, and different +solutions will be better for different programs; see section 13 for the +specific requirements. + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU AGPL, see +. \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..73c3bba --- /dev/null +++ b/Makefile @@ -0,0 +1,13 @@ +install-tools: + go install github.com/bufbuild/buf/cmd/buf@v1.27.2 + go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@v4.17.0 + +generate-protobufs: + buf generate + +format: + buf format -w + gofmt -w -s . + +deploy-docker: + docker compose -f deploy/docker/compose.yaml -f deploy/docker/compose.override.yaml up --build \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..fbe550c --- /dev/null +++ b/README.md @@ -0,0 +1,108 @@ +# Stocklet + +An event-driven microservices-based distributed e-commerce example application written in Golang. *(mouthful)* + +## ๐Ÿ“˜ About + +This project was originally built as an experiment with event-driven architecture. But I hope it can future serve as a beneficial demonstration of utilising the architecture and exemplify the implementation of some other miscellaneous microservice patterns. + +Any ideas, suggestions or direct contributions to better conform with general and evolving industry practices are welcome and will be greatly appreciated, as I'd like for this project to evolve to the stage of being somewhat a reflection of a production-ready enterprise application. + +โš ๏ธ The application should be considered in the experimental prototype stage. Breaking changes can be expected between any future commits to this repo, in order to ease the development process and allow for clean refactoring of the project. + +## ๐Ÿ“ Features + +* Monorepository layout +* Microservice architecture +* Event-driven architecture +* Interfacing with services using gRPC +* User-facing RESTful HTTP APIs with gRPC-Gateway +* Distributed tracing with OpenTelemetry +* Transactional outbox pattern with Debezium +* API gateway pattern using Envoy +* Distributed transactions utilising the saga pattern + +## ๐Ÿ—ƒ๏ธ Architecture + +### ๐Ÿ”Ž Overview + +![Architecture Overview](/docs/imgs/overview.svg) + +### ๐Ÿงฐ Technical Stack + +#### Libraries, Frameworks and Tools + +* API Tooling + * [google.golang.org/grpc](https://pkg.go.dev/google.golang.org/grpc) + * [github.com/grpc-ecosystem/grpc-gateway/v2](https://pkg.go.dev/github.com/grpc-ecosystem/grpc-gateway/v2) + +* Client Libraries + * [go.opentelemetry.io/otel](https://pkg.go.dev/go.opentelemetry.io/otel) + * [github.com/twmb/franz-go](https://pkg.go.dev/github.com/twmb/franz-go) + * [github.com/jackc/pgx/v5](https://pkg.go.dev/github.com/jackc/pgx/v5) + +* Protobuf Libraries + * [google.golang.org/protobuf](https://pkg.go.dev/google.golang.org/protobuf) + * [github.com/bufbuild/protovalidate-go](https://pkg.go.dev/github.com/bufbuild/protovalidate-go) + +* Tools + * [plantuml.com](https://plantuml.com/) + * [github.com/bufbuild/buf/cmd/buf](https://buf.build/docs/installation) + * [github.com/golang-migrate/migrate/v4](https://pkg.go.dev/github.com/golang-migrate/migrate/v4#section-readme) + +* Miscellaneous + * [golang.org/x/crypto/bcrypt](https://pkg.go.dev/golang.org/x/crypto/bcrypt) + * [github.com/rs/zerolog](https://pkg.go.dev/github.com/rs/zerolog) + * [github.com/lestrrat-go/jwx/v2](https://pkg.go.dev/github.com/lestrrat-go/jwx/v2) + * [github.com/doug-martin/goqu/v9](https://pkg.go.dev/github.com/doug-martin/goqu/v9) + +#### Infrastructure + +* Message Brokers + * [Kafka](https://hub.docker.com/r/bitnami/kafka) +* Databases + * [PostgreSQL](https://hub.docker.com/_/postgres) +* Miscellaneous + * [OpenTelemetry](https://opentelemetry.io/) + * [Envoy](https://www.envoyproxy.io/) + * [Debezium Connect](https://hub.docker.com/r/debezium/connect) +* Provisioning and Deployment + * [Docker](https://www.docker.com/) and [Docker Compose](https://docs.docker.com/compose/) + +### ๐Ÿงฉ Services + +| Name | gRPC (w/ Gateway) | Produces Events | Consumes Events | +| :-: | :-: | :-: | :-: | +| [auth](/internal/svc/auth/) | โœ”๏ธ | โŒ | โœ”๏ธ | +| [order](/internal/svc/order/) | โœ”๏ธ | โœ”๏ธ | โœ”๏ธ | +| [payment](/internal/svc/payment/) | โœ”๏ธ | โœ”๏ธ | โœ”๏ธ | +| [product](/internal/svc/product/) | โœ”๏ธ | โœ”๏ธ | โœ”๏ธ | +| [shipping](/internal/svc/shipping/) | โœ”๏ธ | โœ”๏ธ | โœ”๏ธ | +| [user](/internal/svc/user/) | โœ”๏ธ | โœ”๏ธ | โŒ | +| [warehouse](/internal/svc/warehouse/) | โœ”๏ธ | โœ”๏ธ | โœ”๏ธ | + +Each service is prepared by a [``service-init``](/cmd/service-init/) container; a deployment responsible for performing any database migrations and configuring Debezium outbox connectors for that service. + +### ๐Ÿ“‡ Events + +The events are schemed and serialised using [protocol buffers](https://protobuf.dev/). They are dispatched using the [transactional outbox pattern](https://microservices.io/patterns/data/transactional-outbox.html), with [Debezium](https://debezium.io/) used as a relay to read and publish events from database outbox tables to the message broker. + +Further documentation on the events can be found at [``/docs/EVENTS.md``](/docs/EVENTS.md) + +## ๐Ÿ’ป Deployment + +### Using Docker + +The application can be deployed using [Docker Compose](https://docs.docker.com/compose/) (with the compose files located in [``/deploy/docker/``](/deploy/docker/)). Ensure the correct configuration is in place by copying and removing ``.example`` from the end of the example environment files located in [``/deploy/configs/``](/deploy/configs/). + +Deploy using the following command: ``docker compose -f deploy/docker/compose.yaml -f deploy/docker/compose.override.yaml up --build`` + +## ๐Ÿงช Contributing + +If you like this project then please leave a โญ to show your support. All forms of feedback and contributions are welcome and greatly appreciated! + +Have any [ideas for improvements?](/docs/ROADMAP.md) Please don't hesistate to [open an issue](https://github.com/hexolan/stocklet/issues/new) to discuss, or a [pull request](https://github.com/hexolan/stocklet/compare) with [enhancements](https://github.com/hexolan/stocklet/fork). + +## ๐Ÿ““ License + +This project is licensed under the [GNU Affero General Public License v3](/LICENSE). diff --git a/buf.gen.yaml b/buf.gen.yaml new file mode 100644 index 0000000..9e24499 --- /dev/null +++ b/buf.gen.yaml @@ -0,0 +1,23 @@ +version: v1 +plugins: + - plugin: buf.build/protocolbuffers/go:v1.31.0 + out: internal/pkg/protogen + opt: + - paths=import + - module=github.com/hexolan/stocklet/internal/pkg/protogen + - plugin: buf.build/grpc/go:v1.3.0 + out: internal/pkg/protogen + opt: + - paths=import + - module=github.com/hexolan/stocklet/internal/pkg/protogen + - plugin: buf.build/grpc-ecosystem/gateway:v2.18.0 + out: internal/pkg/protogen + opt: + - paths=import + - module=github.com/hexolan/stocklet/internal/pkg/protogen + - plugin: buf.build/grpc-ecosystem/openapiv2:v2.18.0 + out: schema/openapi + opt: + - output_format=yaml + - allow_merge=true + - merge_file_name=services \ No newline at end of file diff --git a/buf.work.yaml b/buf.work.yaml new file mode 100644 index 0000000..45dd086 --- /dev/null +++ b/buf.work.yaml @@ -0,0 +1,3 @@ +version: v1 +directories: + - schema/protobufs \ No newline at end of file diff --git a/build/auth-service/Dockerfile b/build/auth-service/Dockerfile new file mode 100644 index 0000000..2557194 --- /dev/null +++ b/build/auth-service/Dockerfile @@ -0,0 +1,16 @@ +FROM golang:1.22 AS build +WORKDIR /app + +# Install required modules +COPY go.mod go.sum ./ +RUN go mod download + +# Build the service +COPY . . +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /bin/auth-service ./cmd/auth-service + +# Runtime Environment +FROM gcr.io/distroless/static-debian12 +COPY --from=build /bin/auth-service . +EXPOSE 90 9090 +CMD ["./auth-service"] \ No newline at end of file diff --git a/build/edge-gateway/Dockerfile b/build/edge-gateway/Dockerfile new file mode 100644 index 0000000..59121bb --- /dev/null +++ b/build/edge-gateway/Dockerfile @@ -0,0 +1,3 @@ +FROM envoyproxy/envoy:v1.28-latest +COPY envoy.yaml /etc/envoy/envoy.yaml +RUN chmod go+r /etc/envoy/envoy.yaml \ No newline at end of file diff --git a/build/edge-gateway/envoy.yaml b/build/edge-gateway/envoy.yaml new file mode 100644 index 0000000..9673bee --- /dev/null +++ b/build/edge-gateway/envoy.yaml @@ -0,0 +1,190 @@ +static_resources: + listeners: + - address: + socket_address: + address: 0.0.0.0 + port_value: 80 + filter_chains: + - filters: + - name: envoy.filters.network.http_connection_manager + typed_config: + "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager + codec_type: AUTO + stat_prefix: ingress_http + generate_request_id: true + tracing: + provider: + name: envoy.tracers.opentelemetry + typed_config: + "@type": type.googleapis.com/envoy.config.trace.v3.OpenTelemetryConfig + grpc_service: + envoy_grpc: + cluster_name: otel_collector + timeout: 0.5s + service_name: edge-gateway + route_config: + name: local_route + virtual_hosts: + - name: services + domains: + - "*" + routes: + - match: + prefix: /v1/auth/ + route: + cluster: auth_service_gw + - match: + prefix: /v1/order/ + route: + cluster: order_service_gw + - match: + prefix: /v1/payment/ + route: + cluster: payment_service_gw + - match: + prefix: /v1/product/ + route: + cluster: product_service_gw + - match: + prefix: /v1/shipping/ + route: + cluster: shipping_service_gw + - match: + prefix: /v1/user/ + route: + cluster: user_service_gw + - match: + prefix: /v1/warehouse/ + route: + cluster: warehouse_service_gw + http_filters: + - name: envoy.filters.http.jwt_authn + typed_config: + "@type": type.googleapis.com/envoy.extensions.filters.http.jwt_authn.v3.JwtAuthentication + providers: + default_provider: + remote_jwks: + http_uri: + uri: http://auth-service:90/v1/auth/jwks + cluster: auth_service_gw + timeout: 1s + cache_duration: + seconds: 300 + from_headers: + - name: Authorization + forward: true + forward_payload_header: x-jwt-payload + rules: + - match: + prefix: / + requires: + requires_any: + requirements: + - provider_name: default_provider + - allow_missing: {} + - name: envoy.filters.http.router + typed_config: + "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router + + clusters: + - name: otel_collector + type: STRICT_DNS + lb_policy: ROUND_ROBIN + typed_extension_protocol_options: + envoy.extensions.upstreams.http.v3.HttpProtocolOptions: + "@type": type.googleapis.com/envoy.extensions.upstreams.http.v3.HttpProtocolOptions + explicit_http_config: + http2_protocol_options: {} + load_assignment: + cluster_name: otel_collector + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: otel-collector + port_value: 4317 + - name: auth_service_gw + type: STRICT_DNS + lb_policy: ROUND_ROBIN + load_assignment: + cluster_name: auth_service_gw + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: auth-service + port_value: 90 + - name: order_service_gw + type: STRICT_DNS + lb_policy: ROUND_ROBIN + load_assignment: + cluster_name: order_service_gw + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: order-service + port_value: 90 + - name: payment_service_gw + type: STRICT_DNS + lb_policy: ROUND_ROBIN + load_assignment: + cluster_name: payment_service_gw + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: payment-service + port_value: 90 + - name: product_service_gw + type: STRICT_DNS + lb_policy: ROUND_ROBIN + load_assignment: + cluster_name: product_service_gw + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: product-service + port_value: 90 + - name: shipping_service_gw + type: STRICT_DNS + lb_policy: ROUND_ROBIN + load_assignment: + cluster_name: shipping_service_gw + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: shipping-service + port_value: 90 + - name: user_service_gw + type: STRICT_DNS + lb_policy: ROUND_ROBIN + load_assignment: + cluster_name: user_service_gw + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: user-service + port_value: 90 + - name: warehouse_service_gw + type: STRICT_DNS + lb_policy: ROUND_ROBIN + load_assignment: + cluster_name: warehouse_service_gw + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: warehouse-service + port_value: 90 \ No newline at end of file diff --git a/build/order-service/Dockerfile b/build/order-service/Dockerfile new file mode 100644 index 0000000..0cf8392 --- /dev/null +++ b/build/order-service/Dockerfile @@ -0,0 +1,16 @@ +FROM golang:1.22 AS build +WORKDIR /app + +# Install required modules +COPY go.mod go.sum ./ +RUN go mod download + +# Build the service +COPY . . +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /bin/order-service ./cmd/order-service + +# Runtime Environment +FROM gcr.io/distroless/static-debian12 +COPY --from=build /bin/order-service . +EXPOSE 90 9090 +CMD ["./order-service"] \ No newline at end of file diff --git a/build/otel-collector/Dockerfile b/build/otel-collector/Dockerfile new file mode 100644 index 0000000..98ef769 --- /dev/null +++ b/build/otel-collector/Dockerfile @@ -0,0 +1,2 @@ +FROM otel/opentelemetry-collector-contrib:0.90.1 +COPY config.yaml /etc/otelcol-contrib/config.yaml \ No newline at end of file diff --git a/build/otel-collector/config.yaml b/build/otel-collector/config.yaml new file mode 100644 index 0000000..22112af --- /dev/null +++ b/build/otel-collector/config.yaml @@ -0,0 +1,23 @@ +receivers: + otlp: + protocols: + grpc: + http: + +exporters: + debug: + verbosity: detailed + +processors: + batch: + +service: + pipelines: + traces: + receivers: [otlp] + processors: [batch] + exporters: [debug] + metrics: + receivers: [otlp] + processors: [batch] + exporters: [debug] diff --git a/build/payment-service/Dockerfile b/build/payment-service/Dockerfile new file mode 100644 index 0000000..51bf73e --- /dev/null +++ b/build/payment-service/Dockerfile @@ -0,0 +1,16 @@ +FROM golang:1.22 AS build +WORKDIR /app + +# Install required modules +COPY go.mod go.sum ./ +RUN go mod download + +# Build the service +COPY . . +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /bin/payment-service ./cmd/payment-service + +# Runtime Environment +FROM gcr.io/distroless/static-debian12 +COPY --from=build /bin/payment-service . +EXPOSE 90 9090 +CMD ["./payment-service"] \ No newline at end of file diff --git a/build/product-service/Dockerfile b/build/product-service/Dockerfile new file mode 100644 index 0000000..b2061a7 --- /dev/null +++ b/build/product-service/Dockerfile @@ -0,0 +1,16 @@ +FROM golang:1.22 AS build +WORKDIR /app + +# Install required modules +COPY go.mod go.sum ./ +RUN go mod download + +# Build the service +COPY . . +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /bin/product-service ./cmd/product-service + +# Runtime Environment +FROM gcr.io/distroless/static-debian12 +COPY --from=build /bin/product-service . +EXPOSE 90 9090 +CMD ["./product-service"] \ No newline at end of file diff --git a/build/service-init/Dockerfile b/build/service-init/Dockerfile new file mode 100644 index 0000000..0edd076 --- /dev/null +++ b/build/service-init/Dockerfile @@ -0,0 +1,15 @@ +FROM golang:1.22 AS build +WORKDIR /app + +# Install required modules +COPY go.mod go.sum ./ +RUN go mod download + +# Build the service +COPY . . +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /bin/service-init ./cmd/service-init + +# Runtime Environment +FROM gcr.io/distroless/static-debian12 +COPY --from=build /bin/service-init . +CMD ["./service-init"] \ No newline at end of file diff --git a/build/shipping-service/Dockerfile b/build/shipping-service/Dockerfile new file mode 100644 index 0000000..e030c57 --- /dev/null +++ b/build/shipping-service/Dockerfile @@ -0,0 +1,16 @@ +FROM golang:1.22 AS build +WORKDIR /app + +# Install required modules +COPY go.mod go.sum ./ +RUN go mod download + +# Build the service +COPY . . +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /bin/shipping-service ./cmd/shipping-service + +# Runtime Environment +FROM gcr.io/distroless/static-debian12 +COPY --from=build /bin/shipping-service . +EXPOSE 90 9090 +CMD ["./shipping-service"] \ No newline at end of file diff --git a/build/user-service/Dockerfile b/build/user-service/Dockerfile new file mode 100644 index 0000000..da98e7b --- /dev/null +++ b/build/user-service/Dockerfile @@ -0,0 +1,16 @@ +FROM golang:1.22 AS build +WORKDIR /app + +# Install required modules +COPY go.mod go.sum ./ +RUN go mod download + +# Build the service +COPY . . +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /bin/user-service ./cmd/user-service + +# Runtime Environment +FROM gcr.io/distroless/static-debian12 +COPY --from=build /bin/user-service . +EXPOSE 90 9090 +CMD ["./user-service"] \ No newline at end of file diff --git a/build/warehouse-service/Dockerfile b/build/warehouse-service/Dockerfile new file mode 100644 index 0000000..ed0b8b6 --- /dev/null +++ b/build/warehouse-service/Dockerfile @@ -0,0 +1,16 @@ +FROM golang:1.22 AS build +WORKDIR /app + +# Install required modules +COPY go.mod go.sum ./ +RUN go mod download + +# Build the service +COPY . . +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /bin/warehouse-service ./cmd/warehouse-service + +# Runtime Environment +FROM gcr.io/distroless/static-debian12 +COPY --from=build /bin/warehouse-service . +EXPOSE 90 9090 +CMD ["./warehouse-service"] \ No newline at end of file diff --git a/cmd/auth-service/main.go b/cmd/auth-service/main.go new file mode 100644 index 0000000..1959e5a --- /dev/null +++ b/cmd/auth-service/main.go @@ -0,0 +1,99 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package main + +import ( + "github.com/jackc/pgx/v5/pgxpool" + "github.com/rs/zerolog/log" + "github.com/twmb/franz-go/pkg/kgo" + + "github.com/hexolan/stocklet/internal/pkg/messaging" + "github.com/hexolan/stocklet/internal/pkg/metrics" + "github.com/hexolan/stocklet/internal/pkg/serve" + "github.com/hexolan/stocklet/internal/pkg/storage" + "github.com/hexolan/stocklet/internal/svc/auth" + "github.com/hexolan/stocklet/internal/svc/auth/api" + "github.com/hexolan/stocklet/internal/svc/auth/controller" +) + +func loadConfig() *auth.ServiceConfig { + // Load the main service configuration + cfg, err := auth.NewServiceConfig() + if err != nil { + log.Panic().Err(err).Msg("") + } + + // Configure metrics (logging and OTEL) + metrics.ConfigureLogger() + metrics.InitTracerProvider(&cfg.Shared.Otel, "auth") + + return cfg +} + +func usePostgresController(cfg *auth.ServiceConfig) (auth.StorageController, *pgxpool.Pool) { + // load the Postgres configuration + if err := cfg.Postgres.Load(); err != nil { + log.Panic().Err(err).Msg("") + } + + // open a Postgres connection + client, err := storage.NewPostgresConn(&cfg.Postgres) + if err != nil { + log.Panic().Err(err).Msg("") + } + + controller := controller.NewPostgresController(client) + return controller, client +} + +func useKafkaController(cfg *auth.ServiceConfig) (auth.ConsumerController, *kgo.Client) { + // load the Kafka configuration + if err := cfg.Kafka.Load(); err != nil { + log.Panic().Err(err).Msg("") + } + + // open a Kafka connection + client, err := messaging.NewKafkaConn(&cfg.Kafka, kgo.ConsumerGroup("auth-service")) + if err != nil { + log.Panic().Err(err).Msg("") + } + + controller := controller.NewKafkaController(client) + return controller, client +} + +func main() { + cfg := loadConfig() + + // Create the storage controller + store, storeCl := usePostgresController(cfg) + defer storeCl.Close() + + // Create the service (& API interfaces) + svc := auth.NewAuthService(cfg, store) + grpcSvr := api.PrepareGrpc(cfg, svc) + gatewayMux := api.PrepareGateway(cfg) + + // Create the consumer + consumer, consCl := useKafkaController(cfg) + defer consCl.Close() + consumer.Attach(svc) + + // Serve the API interfaces + go consumer.Start() + go serve.Gateway(gatewayMux) + serve.Grpc(grpcSvr) +} diff --git a/cmd/order-service/main.go b/cmd/order-service/main.go new file mode 100644 index 0000000..8b27b48 --- /dev/null +++ b/cmd/order-service/main.go @@ -0,0 +1,99 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package main + +import ( + "github.com/jackc/pgx/v5/pgxpool" + "github.com/rs/zerolog/log" + "github.com/twmb/franz-go/pkg/kgo" + + "github.com/hexolan/stocklet/internal/pkg/messaging" + "github.com/hexolan/stocklet/internal/pkg/metrics" + "github.com/hexolan/stocklet/internal/pkg/serve" + "github.com/hexolan/stocklet/internal/pkg/storage" + "github.com/hexolan/stocklet/internal/svc/order" + "github.com/hexolan/stocklet/internal/svc/order/api" + "github.com/hexolan/stocklet/internal/svc/order/controller" +) + +func loadConfig() *order.ServiceConfig { + // Load the core service configuration + cfg, err := order.NewServiceConfig() + if err != nil { + log.Panic().Err(err).Msg("") + } + + // Configure metrics (logging and OTEL) + metrics.ConfigureLogger() + metrics.InitTracerProvider(&cfg.Shared.Otel, "order") + + return cfg +} + +func usePostgresController(cfg *order.ServiceConfig) (order.StorageController, *pgxpool.Pool) { + // load the Postgres configuration + if err := cfg.Postgres.Load(); err != nil { + log.Panic().Err(err).Msg("") + } + + // open a Postgres connection + client, err := storage.NewPostgresConn(&cfg.Postgres) + if err != nil { + log.Panic().Err(err).Msg("") + } + + controller := controller.NewPostgresController(client) + return controller, client +} + +func useKafkaController(cfg *order.ServiceConfig) (order.ConsumerController, *kgo.Client) { + // load the Kafka configuration + if err := cfg.Kafka.Load(); err != nil { + log.Panic().Err(err).Msg("") + } + + // open a Kafka connection + client, err := messaging.NewKafkaConn(&cfg.Kafka, kgo.ConsumerGroup("order-service")) + if err != nil { + log.Panic().Err(err).Msg("") + } + + controller := controller.NewKafkaController(client) + return controller, client +} + +func main() { + cfg := loadConfig() + + // Create the storage controller + store, storeCl := usePostgresController(cfg) + defer storeCl.Close() + + // Create the service (& API interfaces) + svc := order.NewOrderService(cfg, store) + grpcSvr := api.PrepareGrpc(cfg, svc) + gatewayMux := api.PrepareGateway(cfg) + + // Create the consumer + consumer, consCl := useKafkaController(cfg) + defer consCl.Close() + consumer.Attach(svc) + + // Serve/start the interfaces + go consumer.Start() + go serve.Gateway(gatewayMux) + serve.Grpc(grpcSvr) +} diff --git a/cmd/payment-service/main.go b/cmd/payment-service/main.go new file mode 100644 index 0000000..2fdad11 --- /dev/null +++ b/cmd/payment-service/main.go @@ -0,0 +1,99 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package main + +import ( + "github.com/jackc/pgx/v5/pgxpool" + "github.com/rs/zerolog/log" + "github.com/twmb/franz-go/pkg/kgo" + + "github.com/hexolan/stocklet/internal/pkg/messaging" + "github.com/hexolan/stocklet/internal/pkg/metrics" + "github.com/hexolan/stocklet/internal/pkg/serve" + "github.com/hexolan/stocklet/internal/pkg/storage" + "github.com/hexolan/stocklet/internal/svc/payment" + "github.com/hexolan/stocklet/internal/svc/payment/api" + "github.com/hexolan/stocklet/internal/svc/payment/controller" +) + +func loadConfig() *payment.ServiceConfig { + // Load the core service configuration + cfg, err := payment.NewServiceConfig() + if err != nil { + log.Panic().Err(err).Msg("") + } + + // Configure metrics (logging and OTEL) + metrics.ConfigureLogger() + metrics.InitTracerProvider(&cfg.Shared.Otel, "payment") + + return cfg +} + +func usePostgresController(cfg *payment.ServiceConfig) (payment.StorageController, *pgxpool.Pool) { + // load the Postgres configuration + if err := cfg.Postgres.Load(); err != nil { + log.Panic().Err(err).Msg("") + } + + // open a Postgres connection + client, err := storage.NewPostgresConn(&cfg.Postgres) + if err != nil { + log.Panic().Err(err).Msg("") + } + + controller := controller.NewPostgresController(client) + return controller, client +} + +func useKafkaController(cfg *payment.ServiceConfig) (payment.ConsumerController, *kgo.Client) { + // load the Kafka configuration + if err := cfg.Kafka.Load(); err != nil { + log.Panic().Err(err).Msg("") + } + + // open a Kafka connection + client, err := messaging.NewKafkaConn(&cfg.Kafka, kgo.ConsumerGroup("payment-service")) + if err != nil { + log.Panic().Err(err).Msg("") + } + + controller := controller.NewKafkaController(client) + return controller, client +} + +func main() { + cfg := loadConfig() + + // Create the storage controller + store, storeCl := usePostgresController(cfg) + defer storeCl.Close() + + // Create the service (& API interfaces) + svc := payment.NewPaymentService(cfg, store) + grpcSvr := api.PrepareGrpc(cfg, svc) + gatewayMux := api.PrepareGateway(cfg) + + // Create the consumer + consumer, consCl := useKafkaController(cfg) + defer consCl.Close() + consumer.Attach(svc) + + // Serve/start the interfaces + go consumer.Start() + go serve.Gateway(gatewayMux) + serve.Grpc(grpcSvr) +} diff --git a/cmd/product-service/main.go b/cmd/product-service/main.go new file mode 100644 index 0000000..2ec0332 --- /dev/null +++ b/cmd/product-service/main.go @@ -0,0 +1,99 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package main + +import ( + "github.com/jackc/pgx/v5/pgxpool" + "github.com/rs/zerolog/log" + "github.com/twmb/franz-go/pkg/kgo" + + "github.com/hexolan/stocklet/internal/pkg/messaging" + "github.com/hexolan/stocklet/internal/pkg/metrics" + "github.com/hexolan/stocklet/internal/pkg/serve" + "github.com/hexolan/stocklet/internal/pkg/storage" + "github.com/hexolan/stocklet/internal/svc/product" + "github.com/hexolan/stocklet/internal/svc/product/api" + "github.com/hexolan/stocklet/internal/svc/product/controller" +) + +func loadConfig() *product.ServiceConfig { + // Load the core service configuration + cfg, err := product.NewServiceConfig() + if err != nil { + log.Panic().Err(err).Msg("") + } + + // Configure metrics (logging and OTEL) + metrics.ConfigureLogger() + metrics.InitTracerProvider(&cfg.Shared.Otel, "product") + + return cfg +} + +func usePostgresController(cfg *product.ServiceConfig) (product.StorageController, *pgxpool.Pool) { + // load the Postgres configuration + if err := cfg.Postgres.Load(); err != nil { + log.Panic().Err(err).Msg("") + } + + // open a Postgres connection + client, err := storage.NewPostgresConn(&cfg.Postgres) + if err != nil { + log.Panic().Err(err).Msg("") + } + + controller := controller.NewPostgresController(client) + return controller, client +} + +func useKafkaController(cfg *product.ServiceConfig) (product.ConsumerController, *kgo.Client) { + // load the Kafka configuration + if err := cfg.Kafka.Load(); err != nil { + log.Panic().Err(err).Msg("") + } + + // open a Kafka connection + client, err := messaging.NewKafkaConn(&cfg.Kafka, kgo.ConsumerGroup("product-service")) + if err != nil { + log.Panic().Err(err).Msg("") + } + + controller := controller.NewKafkaController(client) + return controller, client +} + +func main() { + cfg := loadConfig() + + // Create the storage controller + store, storeCl := usePostgresController(cfg) + defer storeCl.Close() + + // Create the service (& API interfaces) + svc := product.NewProductService(cfg, store) + grpcSvr := api.PrepareGrpc(cfg, svc) + gatewayMux := api.PrepareGateway(cfg) + + // Create the consumer + consumer, consCl := useKafkaController(cfg) + defer consCl.Close() + consumer.Attach(svc) + + // Serve/start the interfaces + go consumer.Start() + go serve.Gateway(gatewayMux) + serve.Grpc(grpcSvr) +} diff --git a/cmd/service-init/config.go b/cmd/service-init/config.go new file mode 100644 index 0000000..260d8a2 --- /dev/null +++ b/cmd/service-init/config.go @@ -0,0 +1,63 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package main + +import ( + "github.com/hexolan/stocklet/internal/pkg/config" +) + +// Init Container Configuration +type InitConfig struct { + // Name of the service (e.g. 'auth' or 'order') + // + // Env Var: "INIT_SVC_NAME" + ServiceName string + + // Env Var: "INIT_MIGRATIONS" (optional. accepts 'false') + // Defaults to true + ApplyMigrations bool + + // 'ApplyDebezium' will default to false unless + // the debezium host is provided. + // + // Env Var: "INIT_DEBEZIUM_HOST" (optional) + // e.g. "http://debezium:8083" + ApplyDebezium bool + DebeziumHost string +} + +func (opts *InitConfig) Load() error { + // ServiceName + opt, err := config.RequireFromEnv("INIT_SVC_NAME") + if err != nil { + return err + } + opts.ServiceName = opt + + // ApplyMigrations + opts.ApplyMigrations = true + if opt, _ := config.RequireFromEnv("INIT_MIGRATIONS"); opt == "false" { + opts.ApplyMigrations = false + } + + // ApplyDebezium and DebeziumHost + if opt, err := config.RequireFromEnv("INIT_DEBEZIUM_HOST"); err == nil { + opts.ApplyDebezium = true + opts.DebeziumHost = opt + } + + return nil +} diff --git a/cmd/service-init/connectors.go b/cmd/service-init/connectors.go new file mode 100644 index 0000000..5169c5f --- /dev/null +++ b/cmd/service-init/connectors.go @@ -0,0 +1,67 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package main + +import ( + "bytes" + "encoding/json" + "net/http" + + "github.com/rs/zerolog/log" + + "github.com/hexolan/stocklet/internal/pkg/config" +) + +func applyPostgresOutbox(cfg *InitConfig, conf *config.PostgresConfig) { + payloadB, err := json.Marshal(map[string]string{ + "connector.class": "io.debezium.connector.postgresql.PostgresConnector", + "plugin.name": "pgoutput", + "tasks.max": "1", + "table.include.list": "public.event_outbox", + "transforms": "outbox", + "transforms.outbox.type": "io.debezium.transforms.outbox.EventRouter", + "transforms.outbox.route.topic.replacement": "${routedByValue}", + "value.converter": "io.debezium.converters.BinaryDataConverter", + + "topic.prefix": cfg.ServiceName, + "database.hostname": conf.Host, + "database.port": conf.Port, + "database.user": conf.Username, + "database.password": conf.Password, + "database.dbname": conf.Database, + }) + if err != nil { + log.Panic().Err(err).Msg("debezium connect: failed to marshal debezium cfg") + } + + url := cfg.DebeziumHost + "/connectors/" + cfg.ServiceName + "-outbox/config" + log.Info().Str("url", url).Msg("debezium url") + req, err := http.NewRequest( + "PUT", + url, + bytes.NewReader(payloadB), + ) + req.Header.Set("Accept", "application/json") + req.Header.Set("Content-Type", "application/json") + + client := &http.Client{} + res, err := client.Do(req) + if err != nil { + log.Panic().Err(err).Msg("debezium connect: failed to perform debezium request") + } + + log.Info().Str("status", res.Status).Msg("debezium connect: applied outbox config") +} diff --git a/cmd/service-init/main.go b/cmd/service-init/main.go new file mode 100644 index 0000000..918b16a --- /dev/null +++ b/cmd/service-init/main.go @@ -0,0 +1,52 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package main + +import ( + "github.com/rs/zerolog/log" + + "github.com/hexolan/stocklet/internal/pkg/config" +) + +func main() { + // Load the init container cfg options + cfg := InitConfig{} + if err := cfg.Load(); err != nil { + log.Panic().Err(err).Msg("missing required configuration") + } + + // If migrations or debezium are enabled, + // then a database configuration will be required. + if cfg.ApplyMigrations || cfg.ApplyDebezium { + // Support for dynamic loading of configuration + // (e.g. mongo config instead of postgres config) + pgConf := config.PostgresConfig{} + if err := pgConf.Load(); err == nil { + // Using postgres as a database. + if cfg.ApplyMigrations { + applyPostgresMigrations(&pgConf) + } + + if cfg.ApplyDebezium { + applyPostgresOutbox(&cfg, &pgConf) + } + } else { + log.Panic().Msg("unable to load any db configs (unable to perform migrations or apply connector cfgs)") + } + } + + log.Info().Str("svc", cfg.ServiceName).Msg("completed init for service") +} diff --git a/cmd/service-init/migrations.go b/cmd/service-init/migrations.go new file mode 100644 index 0000000..50a0500 --- /dev/null +++ b/cmd/service-init/migrations.go @@ -0,0 +1,43 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package main + +import ( + "github.com/golang-migrate/migrate/v4" + _ "github.com/golang-migrate/migrate/v4/database/postgres" + _ "github.com/golang-migrate/migrate/v4/source/file" + "github.com/rs/zerolog/log" + + "github.com/hexolan/stocklet/internal/pkg/config" +) + +func applyPostgresMigrations(conf *config.PostgresConfig) { + m, err := migrate.New("file:///migrations", conf.GetDSN()) + if err != nil { + log.Panic().Err(err).Msg("migrate: failed to open client") + } + + err = m.Up() + if err != nil { + if err.Error() == "no change" { + log.Info().Err(err).Msg("migrate: migrations up to date") + } else { + log.Panic().Err(err).Msg("migrate: raised when performing db migration") + } + } + + log.Info().Msg("migrate: succesfully performed postgres migrations") +} diff --git a/cmd/shipping-service/main.go b/cmd/shipping-service/main.go new file mode 100644 index 0000000..a155555 --- /dev/null +++ b/cmd/shipping-service/main.go @@ -0,0 +1,99 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package main + +import ( + "github.com/jackc/pgx/v5/pgxpool" + "github.com/rs/zerolog/log" + "github.com/twmb/franz-go/pkg/kgo" + + "github.com/hexolan/stocklet/internal/pkg/messaging" + "github.com/hexolan/stocklet/internal/pkg/metrics" + "github.com/hexolan/stocklet/internal/pkg/serve" + "github.com/hexolan/stocklet/internal/pkg/storage" + "github.com/hexolan/stocklet/internal/svc/shipping" + "github.com/hexolan/stocklet/internal/svc/shipping/api" + "github.com/hexolan/stocklet/internal/svc/shipping/controller" +) + +func loadConfig() *shipping.ServiceConfig { + // Load the core service configuration + cfg, err := shipping.NewServiceConfig() + if err != nil { + log.Panic().Err(err).Msg("") + } + + // Configure metrics (logging and OTEL) + metrics.ConfigureLogger() + metrics.InitTracerProvider(&cfg.Shared.Otel, "shipping") + + return cfg +} + +func usePostgresController(cfg *shipping.ServiceConfig) (shipping.StorageController, *pgxpool.Pool) { + // load the Postgres configuration + if err := cfg.Postgres.Load(); err != nil { + log.Panic().Err(err).Msg("") + } + + // open a Postgres connection + client, err := storage.NewPostgresConn(&cfg.Postgres) + if err != nil { + log.Panic().Err(err).Msg("") + } + + controller := controller.NewPostgresController(client) + return controller, client +} + +func useKafkaController(cfg *shipping.ServiceConfig) (shipping.ConsumerController, *kgo.Client) { + // load the Kafka configuration + if err := cfg.Kafka.Load(); err != nil { + log.Panic().Err(err).Msg("") + } + + // open a Kafka connection + client, err := messaging.NewKafkaConn(&cfg.Kafka, kgo.ConsumerGroup("shipping-service")) + if err != nil { + log.Panic().Err(err).Msg("") + } + + controller := controller.NewKafkaController(client) + return controller, client +} + +func main() { + cfg := loadConfig() + + // Create the storage controller + store, storeCl := usePostgresController(cfg) + defer storeCl.Close() + + // Create the service (& API interfaces) + svc := shipping.NewShippingService(cfg, store) + grpcSvr := api.PrepareGrpc(cfg, svc) + gatewayMux := api.PrepareGateway(cfg) + + // Create the consumer + consumer, consCl := useKafkaController(cfg) + defer consCl.Close() + consumer.Attach(svc) + + // Serve/start the interfaces + go consumer.Start() + go serve.Gateway(gatewayMux) + serve.Grpc(grpcSvr) +} diff --git a/cmd/user-service/main.go b/cmd/user-service/main.go new file mode 100644 index 0000000..e4eb1e4 --- /dev/null +++ b/cmd/user-service/main.go @@ -0,0 +1,75 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package main + +import ( + "github.com/jackc/pgx/v5/pgxpool" + "github.com/rs/zerolog/log" + + "github.com/hexolan/stocklet/internal/pkg/metrics" + "github.com/hexolan/stocklet/internal/pkg/serve" + "github.com/hexolan/stocklet/internal/pkg/storage" + "github.com/hexolan/stocklet/internal/svc/user" + "github.com/hexolan/stocklet/internal/svc/user/api" + "github.com/hexolan/stocklet/internal/svc/user/controller" +) + +func loadConfig() *user.ServiceConfig { + // Load the core service configuration + cfg, err := user.NewServiceConfig() + if err != nil { + log.Panic().Err(err).Msg("") + } + + // Configure metrics (logging and OTEL) + metrics.ConfigureLogger() + metrics.InitTracerProvider(&cfg.Shared.Otel, "user") + + return cfg +} + +func usePostgresController(cfg *user.ServiceConfig) (user.StorageController, *pgxpool.Pool) { + // load the Postgres configuration + if err := cfg.Postgres.Load(); err != nil { + log.Panic().Err(err).Msg("") + } + + // open a Postgres connection + client, err := storage.NewPostgresConn(&cfg.Postgres) + if err != nil { + log.Panic().Err(err).Msg("") + } + + controller := controller.NewPostgresController(client, &cfg.ServiceOpts) + return controller, client +} + +func main() { + cfg := loadConfig() + + // Create the storage controller + store, storeCl := usePostgresController(cfg) + defer storeCl.Close() + + // Create the service (& API interfaces) + svc := user.NewUserService(cfg, store) + grpcSvr := api.PrepareGrpc(cfg, svc) + gatewayMux := api.PrepareGateway(cfg) + + // Serve/start the interfaces + go serve.Gateway(gatewayMux) + serve.Grpc(grpcSvr) +} diff --git a/cmd/warehouse-service/main.go b/cmd/warehouse-service/main.go new file mode 100644 index 0000000..45a0f82 --- /dev/null +++ b/cmd/warehouse-service/main.go @@ -0,0 +1,99 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package main + +import ( + "github.com/jackc/pgx/v5/pgxpool" + "github.com/rs/zerolog/log" + "github.com/twmb/franz-go/pkg/kgo" + + "github.com/hexolan/stocklet/internal/pkg/messaging" + "github.com/hexolan/stocklet/internal/pkg/metrics" + "github.com/hexolan/stocklet/internal/pkg/serve" + "github.com/hexolan/stocklet/internal/pkg/storage" + "github.com/hexolan/stocklet/internal/svc/warehouse" + "github.com/hexolan/stocklet/internal/svc/warehouse/api" + "github.com/hexolan/stocklet/internal/svc/warehouse/controller" +) + +func loadConfig() *warehouse.ServiceConfig { + // Load the core service configuration + cfg, err := warehouse.NewServiceConfig() + if err != nil { + log.Panic().Err(err).Msg("") + } + + // Configure metrics (logging and OTEL) + metrics.ConfigureLogger() + metrics.InitTracerProvider(&cfg.Shared.Otel, "warehouse") + + return cfg +} + +func usePostgresController(cfg *warehouse.ServiceConfig) (warehouse.StorageController, *pgxpool.Pool) { + // load the Postgres configuration + if err := cfg.Postgres.Load(); err != nil { + log.Panic().Err(err).Msg("") + } + + // open a Postgres connection + client, err := storage.NewPostgresConn(&cfg.Postgres) + if err != nil { + log.Panic().Err(err).Msg("") + } + + controller := controller.NewPostgresController(client) + return controller, client +} + +func useKafkaController(cfg *warehouse.ServiceConfig) (warehouse.ConsumerController, *kgo.Client) { + // load the Kafka configuration + if err := cfg.Kafka.Load(); err != nil { + log.Panic().Err(err).Msg("") + } + + // open a Kafka connection + client, err := messaging.NewKafkaConn(&cfg.Kafka, kgo.ConsumerGroup("warehouse-service")) + if err != nil { + log.Panic().Err(err).Msg("") + } + + controller := controller.NewKafkaController(client) + return controller, client +} + +func main() { + cfg := loadConfig() + + // Create the storage controller + store, storeCl := usePostgresController(cfg) + defer storeCl.Close() + + // Create the service (& API interfaces) + svc := warehouse.NewWarehouseService(cfg, store) + grpcSvr := api.PrepareGrpc(cfg, svc) + gatewayMux := api.PrepareGateway(cfg) + + // Create the consumer + consumer, consCl := useKafkaController(cfg) + defer consCl.Close() + consumer.Attach(svc) + + // Serve/start the interfaces + go consumer.Start() + go serve.Gateway(gatewayMux) + serve.Grpc(grpcSvr) +} diff --git a/deploy/configs/auth-init.env.example b/deploy/configs/auth-init.env.example new file mode 100644 index 0000000..1540c14 --- /dev/null +++ b/deploy/configs/auth-init.env.example @@ -0,0 +1,8 @@ +INIT_SVC_NAME=auth +INIT_MIGRATIONS=true + +PG_DB=postgres +PG_USER=postgres +PG_PASS=postgres +PG_HOST=auth-service-postgres +PG_PORT=5432 \ No newline at end of file diff --git a/deploy/configs/auth.env.example b/deploy/configs/auth.env.example new file mode 100644 index 0000000..f9177c3 --- /dev/null +++ b/deploy/configs/auth.env.example @@ -0,0 +1,13 @@ +MODE=dev + +PG_DB=postgres +PG_USER=postgres +PG_PASS=postgres +PG_HOST=auth-service-postgres +PG_PORT=5432 + +KAFKA_BROKERS=kafka:19092 +OTEL_COLLECTOR_GRPC=otel-collector:4317 + +# base64 encoded EC256/EC512 private key +AUTH_PRIVATE_KEY=LS0tLS1CRUdJTiBFQyBQUklWQVRFIEtFWS0tLS0tCk1IY0NBUUVFSUJ5RHBLV1pHS3YxNDdvZGlUR2N4V0l0NWxEbEtRQW5zdDZQQkw3bUNGMFJvQW9HQ0NxR1NNNDkKQXdFSG9VUURRZ0FFbUM0UVdtek1ta3lkT0xMZUxYdHVIa3RqVGtQZzM5djRkSnNFZEhGcGdQM1M0ZXp4a2ZYaApmSVZiQlR6OXA4OFFBSkRsL0ZOVFFjUXFUYlZ2bCsybE9RPT0KLS0tLS1FTkQgRUMgUFJJVkFURSBLRVktLS0tLQ== \ No newline at end of file diff --git a/deploy/configs/order-init.env.example b/deploy/configs/order-init.env.example new file mode 100644 index 0000000..ee18dcb --- /dev/null +++ b/deploy/configs/order-init.env.example @@ -0,0 +1,9 @@ +INIT_SVC_NAME=order +INIT_MIGRATIONS=true +INIT_DEBEZIUM_HOST=http://debezium:8083 + +PG_DB=postgres +PG_USER=postgres +PG_PASS=postgres +PG_HOST=order-service-postgres +PG_PORT=5432 \ No newline at end of file diff --git a/deploy/configs/order.env.example b/deploy/configs/order.env.example new file mode 100644 index 0000000..f2111e4 --- /dev/null +++ b/deploy/configs/order.env.example @@ -0,0 +1,10 @@ +MODE=dev + +PG_DB=postgres +PG_USER=postgres +PG_PASS=postgres +PG_HOST=order-service-postgres +PG_PORT=5432 + +KAFKA_BROKERS=kafka:19092 +OTEL_COLLECTOR_GRPC=otel-collector:4317 \ No newline at end of file diff --git a/deploy/configs/payment-init.env.example b/deploy/configs/payment-init.env.example new file mode 100644 index 0000000..04c2007 --- /dev/null +++ b/deploy/configs/payment-init.env.example @@ -0,0 +1,9 @@ +INIT_SVC_NAME=payment +INIT_MIGRATIONS=true +INIT_DEBEZIUM_HOST=http://debezium:8083 + +PG_DB=postgres +PG_USER=postgres +PG_PASS=postgres +PG_HOST=payment-service-postgres +PG_PORT=5432 \ No newline at end of file diff --git a/deploy/configs/payment.env.example b/deploy/configs/payment.env.example new file mode 100644 index 0000000..b35e18b --- /dev/null +++ b/deploy/configs/payment.env.example @@ -0,0 +1,10 @@ +MODE=dev + +PG_DB=postgres +PG_USER=postgres +PG_PASS=postgres +PG_HOST=payment-service-postgres +PG_PORT=5432 + +KAFKA_BROKERS=kafka:19092 +OTEL_COLLECTOR_GRPC=otel-collector:4317 \ No newline at end of file diff --git a/deploy/configs/product-init.env.example b/deploy/configs/product-init.env.example new file mode 100644 index 0000000..b4e2c49 --- /dev/null +++ b/deploy/configs/product-init.env.example @@ -0,0 +1,9 @@ +INIT_SVC_NAME=product +INIT_MIGRATIONS=true +INIT_DEBEZIUM_HOST=http://debezium:8083 + +PG_DB=postgres +PG_USER=postgres +PG_PASS=postgres +PG_HOST=product-service-postgres +PG_PORT=5432 \ No newline at end of file diff --git a/deploy/configs/product.env.example b/deploy/configs/product.env.example new file mode 100644 index 0000000..67daaa6 --- /dev/null +++ b/deploy/configs/product.env.example @@ -0,0 +1,10 @@ +MODE=dev + +PG_DB=postgres +PG_USER=postgres +PG_PASS=postgres +PG_HOST=product-service-postgres +PG_PORT=5432 + +KAFKA_BROKERS=kafka:19092 +OTEL_COLLECTOR_GRPC=otel-collector:4317 \ No newline at end of file diff --git a/deploy/configs/shipping-init.env.example b/deploy/configs/shipping-init.env.example new file mode 100644 index 0000000..bb0c3ea --- /dev/null +++ b/deploy/configs/shipping-init.env.example @@ -0,0 +1,9 @@ +INIT_SVC_NAME=shipping +INIT_MIGRATIONS=true +INIT_DEBEZIUM_HOST=http://debezium:8083 + +PG_DB=postgres +PG_USER=postgres +PG_PASS=postgres +PG_HOST=shipping-service-postgres +PG_PORT=5432 \ No newline at end of file diff --git a/deploy/configs/shipping.env.example b/deploy/configs/shipping.env.example new file mode 100644 index 0000000..492751f --- /dev/null +++ b/deploy/configs/shipping.env.example @@ -0,0 +1,10 @@ +MODE=dev + +PG_DB=postgres +PG_USER=postgres +PG_PASS=postgres +PG_HOST=shipping-service-postgres +PG_PORT=5432 + +KAFKA_BROKERS=kafka:19092 +OTEL_COLLECTOR_GRPC=otel-collector:4317 \ No newline at end of file diff --git a/deploy/configs/user-init.env.example b/deploy/configs/user-init.env.example new file mode 100644 index 0000000..46ddc6e --- /dev/null +++ b/deploy/configs/user-init.env.example @@ -0,0 +1,9 @@ +INIT_SVC_NAME=user +INIT_MIGRATIONS=true +INIT_DEBEZIUM_HOST=http://debezium:8083 + +PG_DB=postgres +PG_USER=postgres +PG_PASS=postgres +PG_HOST=user-service-postgres +PG_PORT=5432 \ No newline at end of file diff --git a/deploy/configs/user.env.example b/deploy/configs/user.env.example new file mode 100644 index 0000000..af92179 --- /dev/null +++ b/deploy/configs/user.env.example @@ -0,0 +1,12 @@ +MODE=dev + +PG_DB=postgres +PG_USER=postgres +PG_PASS=postgres +PG_HOST=user-service-postgres +PG_PORT=5432 + +KAFKA_BROKERS=kafka:19092 +OTEL_COLLECTOR_GRPC=otel-collector:4317 + +AUTH_SERVICE_GRPC=auth-service:9090 \ No newline at end of file diff --git a/deploy/configs/warehouse-init.env.example b/deploy/configs/warehouse-init.env.example new file mode 100644 index 0000000..fe97421 --- /dev/null +++ b/deploy/configs/warehouse-init.env.example @@ -0,0 +1,9 @@ +INIT_SVC_NAME=warehouse +INIT_MIGRATIONS=true +INIT_DEBEZIUM_HOST=http://debezium:8083 + +PG_DB=postgres +PG_USER=postgres +PG_PASS=postgres +PG_HOST=warehouse-service-postgres +PG_PORT=5432 \ No newline at end of file diff --git a/deploy/configs/warehouse.env.example b/deploy/configs/warehouse.env.example new file mode 100644 index 0000000..5ca27e7 --- /dev/null +++ b/deploy/configs/warehouse.env.example @@ -0,0 +1,10 @@ +MODE=dev + +PG_DB=postgres +PG_USER=postgres +PG_PASS=postgres +PG_HOST=warehouse-service-postgres +PG_PORT=5432 + +KAFKA_BROKERS=kafka:19092 +OTEL_COLLECTOR_GRPC=otel-collector:4317 \ No newline at end of file diff --git a/deploy/docker/compose.override.yaml b/deploy/docker/compose.override.yaml new file mode 100644 index 0000000..645efb2 --- /dev/null +++ b/deploy/docker/compose.override.yaml @@ -0,0 +1,63 @@ +services: + # Services + auth-service: + ports: + - 91:90 + - 9091:9090 + + order-service: + ports: + - 92:90 + - 9092:9090 + + payment-service: + ports: + - 93:90 + - 9093:9090 + + product-service: + ports: + - 94:90 + - 9094:9090 + + shipping-service: + ports: + - 95:90 + - 9095:9090 + + user-service: + ports: + - 96:90 + - 9096:9090 + + warehouse-service: + ports: + - 97:90 + - 9097:9090 + + # Development Utilities + dev-kafka-ui: + image: provectuslabs/kafka-ui:latest + restart: unless-stopped + environment: + KAFKA_CLUSTERS_0_NAME: "kafka" + KAFKA_CLUSTERS_0_BOOTSTRAPSERVERS: "kafka:19092" + DYNAMIC_CONFIG_ENABLED: "true" + ports: + - 8080:8080 + networks: + - stocklet-network + + dev-adminer: + image: adminer:latest + restart: unless-stopped + ports: + - 8081:8080 + networks: + - stocklet-auth-network + - stocklet-order-network + - stocklet-payment-network + - stocklet-product-network + - stocklet-shipping-network + - stocklet-user-network + - stocklet-warehouse-network \ No newline at end of file diff --git a/deploy/docker/compose.yaml b/deploy/docker/compose.yaml new file mode 100644 index 0000000..0c746f0 --- /dev/null +++ b/deploy/docker/compose.yaml @@ -0,0 +1,479 @@ +services: + # Infrastructure + edge-gateway: + image: stocklet/edge-gateway + build: + context: ../../build/edge-gateway + ports: + - 80:80 + depends_on: + - otel-collector + networks: + - stocklet-network + + otel-collector: + image: stocklet/otel-collector + build: + context: ../../build/otel-collector + networks: + - stocklet-network + + kafka: + image: bitnami/kafka:3.4 + restart: unless-stopped + environment: + - KAFKA_CFG_NODE_ID=0 + - KAFKA_CFG_PROCESS_ROLES=controller,broker + - KAFKA_CFG_LISTENERS=CONTROLLER://:19093,INTERNAL://:19092,EXTERNAL://:9092 + - KAFKA_CFG_ADVERTISED_LISTENERS=INTERNAL://kafka:19092,EXTERNAL://localhost:9092 + - KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP=CONTROLLER:PLAINTEXT,INTERNAL:PLAINTEXT,EXTERNAL:PLAINTEXT + - KAFKA_CFG_CONTROLLER_QUORUM_VOTERS=0@kafka:19093 + - KAFKA_CFG_INTER_BROKER_LISTENER_NAME=INTERNAL + - KAFKA_CFG_CONTROLLER_LISTENER_NAMES=CONTROLLER + - KAFKA_KRAFT_CLUSTER_ID=g9rbXaCaSGqB3CURPeEvTA + healthcheck: + test: ["CMD-SHELL", "kafka-topics.sh --bootstrap-server localhost:9092 --list"] + interval: 10s + timeout: 5s + retries: 5 + start_period: 30s + depends_on: + - otel-collector + volumes: + - stocklet-kafka-volume:/bitnami/kafka + networks: + - stocklet-network + + debezium: + image: debezium/connect:latest + restart: unless-stopped + environment: + - GROUP_ID=0 + - BOOTSTRAP_SERVERS=kafka:19092 + - CONFIG_STORAGE_TOPIC=debezium-config + - STATUS_STORAGE_TOPIC=debezium-status + - OFFSET_STORAGE_TOPIC=debezium-offset + healthcheck: + test: ["CMD-SHELL", "curl --silent --fail -X GET http://localhost:8083/connectors"] + interval: 10s + timeout: 5s + retries: 10 + start_period: 15s + depends_on: + kafka: + condition: service_healthy + order-service-postgres: + condition: service_healthy + networks: + - stocklet-network + - stocklet-order-network + - stocklet-payment-network + - stocklet-product-network + - stocklet-shipping-network + - stocklet-user-network + - stocklet-warehouse-network + + # Services + auth-service: + image: stocklet/auth-service + build: + context: ../../ + dockerfile: build/auth-service/Dockerfile + depends_on: + init-auth-service: + condition: service_completed_successfully + auth-service-postgres: + condition: service_healthy + kafka: + condition: service_healthy + env_file: + - ../configs/auth.env + networks: + - stocklet-network + - stocklet-auth-network + + order-service: + image: stocklet/order-service + build: + context: ../../ + dockerfile: build/order-service/Dockerfile + depends_on: + init-order-service: + condition: service_completed_successfully + order-service-postgres: + condition: service_healthy + kafka: + condition: service_healthy + env_file: + - ../configs/order.env + networks: + - stocklet-network + - stocklet-order-network + + payment-service: + image: stocklet/payment-service + build: + context: ../../ + dockerfile: build/payment-service/Dockerfile + depends_on: + init-payment-service: + condition: service_completed_successfully + payment-service-postgres: + condition: service_healthy + kafka: + condition: service_healthy + env_file: + - ../configs/payment.env + networks: + - stocklet-network + - stocklet-payment-network + + product-service: + image: stocklet/product-service + build: + context: ../../ + dockerfile: build/product-service/Dockerfile + depends_on: + init-product-service: + condition: service_completed_successfully + product-service-postgres: + condition: service_healthy + kafka: + condition: service_healthy + env_file: + - ../configs/product.env + networks: + - stocklet-network + - stocklet-product-network + + shipping-service: + image: stocklet/shipping-service + build: + context: ../../ + dockerfile: build/shipping-service/Dockerfile + depends_on: + init-shipping-service: + condition: service_completed_successfully + shipping-service-postgres: + condition: service_healthy + kafka: + condition: service_healthy + env_file: + - ../configs/shipping.env + networks: + - stocklet-network + - stocklet-shipping-network + + user-service: + image: stocklet/user-service + build: + context: ../../ + dockerfile: build/user-service/Dockerfile + depends_on: + init-user-service: + condition: service_completed_successfully + user-service-postgres: + condition: service_healthy + kafka: + condition: service_healthy + env_file: + - ../configs/user.env + networks: + - stocklet-network + - stocklet-user-network + + warehouse-service: + image: stocklet/warehouse-service + build: + context: ../../ + dockerfile: build/warehouse-service/Dockerfile + depends_on: + init-warehouse-service: + condition: service_completed_successfully + warehouse-service-postgres: + condition: service_healthy + kafka: + condition: service_healthy + env_file: + - ../configs/warehouse.env + networks: + - stocklet-network + - stocklet-warehouse-network + + # Service Databases + auth-service-postgres: + image: postgres:16-bookworm + restart: unless-stopped + environment: + POSTGRES_DB: "postgres" + POSTGRES_USER: "postgres" + POSTGRES_PASSWORD: "postgres" + healthcheck: + test: ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB"] + interval: 30s + timeout: 15s + retries: 3 + start_period: 30s + command: ["postgres", "-c", "wal_level=logical"] + volumes: + - stocklet-auth-postgres-volume:/var/lib/postgresql + networks: + - stocklet-auth-network + + order-service-postgres: + image: postgres:16-bookworm + restart: unless-stopped + environment: + POSTGRES_DB: "postgres" + POSTGRES_USER: "postgres" + POSTGRES_PASSWORD: "postgres" + healthcheck: + test: ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB"] + interval: 30s + timeout: 15s + retries: 3 + start_period: 30s + command: ["postgres", "-c", "wal_level=logical"] + volumes: + - stocklet-order-postgres-volume:/var/lib/postgresql + networks: + - stocklet-order-network + + payment-service-postgres: + image: postgres:16-bookworm + restart: unless-stopped + environment: + POSTGRES_DB: "postgres" + POSTGRES_USER: "postgres" + POSTGRES_PASSWORD: "postgres" + healthcheck: + test: ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB"] + interval: 30s + timeout: 15s + retries: 3 + start_period: 30s + command: ["postgres", "-c", "wal_level=logical"] + volumes: + - stocklet-payment-postgres-volume:/var/lib/postgresql + networks: + - stocklet-payment-network + + product-service-postgres: + image: postgres:16-bookworm + restart: unless-stopped + environment: + POSTGRES_DB: "postgres" + POSTGRES_USER: "postgres" + POSTGRES_PASSWORD: "postgres" + healthcheck: + test: ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB"] + interval: 30s + timeout: 15s + retries: 3 + start_period: 30s + command: ["postgres", "-c", "wal_level=logical"] + volumes: + - stocklet-product-postgres-volume:/var/lib/postgresql + networks: + - stocklet-product-network + + shipping-service-postgres: + image: postgres:16-bookworm + restart: unless-stopped + environment: + POSTGRES_DB: "postgres" + POSTGRES_USER: "postgres" + POSTGRES_PASSWORD: "postgres" + healthcheck: + test: ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB"] + interval: 30s + timeout: 15s + retries: 3 + start_period: 30s + command: ["postgres", "-c", "wal_level=logical"] + volumes: + - stocklet-shipping-postgres-volume:/var/lib/postgresql + networks: + - stocklet-shipping-network + + user-service-postgres: + image: postgres:16-bookworm + restart: unless-stopped + environment: + POSTGRES_DB: "postgres" + POSTGRES_USER: "postgres" + POSTGRES_PASSWORD: "postgres" + healthcheck: + test: ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB"] + interval: 30s + timeout: 15s + retries: 3 + start_period: 30s + command: ["postgres", "-c", "wal_level=logical"] + volumes: + - stocklet-user-postgres-volume:/var/lib/postgresql + networks: + - stocklet-user-network + + warehouse-service-postgres: + image: postgres:16-bookworm + restart: unless-stopped + environment: + POSTGRES_DB: "postgres" + POSTGRES_USER: "postgres" + POSTGRES_PASSWORD: "postgres" + healthcheck: + test: ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB"] + interval: 30s + timeout: 15s + retries: 3 + start_period: 30s + command: ["postgres", "-c", "wal_level=logical"] + volumes: + - stocklet-warehouse-postgres-volume:/var/lib/postgresql + networks: + - stocklet-warehouse-network + + # Service Init Containers + init-auth-service: + image: stocklet/service-init + build: + context: ../../ + dockerfile: build/service-init/Dockerfile + depends_on: + auth-service-postgres: + condition: service_healthy + env_file: + - ../configs/auth-init.env + volumes: + - ../../schema/sql/auth:/migrations + networks: + - stocklet-auth-network + + init-order-service: + image: stocklet/service-init + build: + context: ../../ + dockerfile: build/service-init/Dockerfile + depends_on: + debezium: + condition: service_healthy + order-service-postgres: + condition: service_healthy + env_file: + - ../configs/order-init.env + volumes: + - ../../schema/sql/order:/migrations + networks: + - stocklet-network + - stocklet-order-network + + init-payment-service: + image: stocklet/service-init + build: + context: ../../ + dockerfile: build/service-init/Dockerfile + depends_on: + debezium: + condition: service_healthy + payment-service-postgres: + condition: service_healthy + env_file: + - ../configs/payment-init.env + volumes: + - ../../schema/sql/payment:/migrations + networks: + - stocklet-network + - stocklet-payment-network + + init-product-service: + image: stocklet/service-init + build: + context: ../../ + dockerfile: build/service-init/Dockerfile + depends_on: + debezium: + condition: service_healthy + product-service-postgres: + condition: service_healthy + env_file: + - ../configs/product-init.env + volumes: + - ../../schema/sql/product:/migrations + networks: + - stocklet-network + - stocklet-product-network + + init-shipping-service: + image: stocklet/service-init + build: + context: ../../ + dockerfile: build/service-init/Dockerfile + depends_on: + debezium: + condition: service_healthy + shipping-service-postgres: + condition: service_healthy + env_file: + - ../configs/shipping-init.env + volumes: + - ../../schema/sql/shipping:/migrations + networks: + - stocklet-network + - stocklet-shipping-network + + init-user-service: + image: stocklet/service-init + build: + context: ../../ + dockerfile: build/service-init/Dockerfile + depends_on: + debezium: + condition: service_healthy + user-service-postgres: + condition: service_healthy + env_file: + - ../configs/user-init.env + volumes: + - ../../schema/sql/user:/migrations + networks: + - stocklet-network + - stocklet-user-network + + init-warehouse-service: + image: stocklet/service-init + build: + context: ../../ + dockerfile: build/service-init/Dockerfile + depends_on: + debezium: + condition: service_healthy + warehouse-service-postgres: + condition: service_healthy + env_file: + - ../configs/warehouse-init.env + volumes: + - ../../schema/sql/warehouse:/migrations + networks: + - stocklet-network + - stocklet-warehouse-network + +networks: + stocklet-network: + stocklet-auth-network: + stocklet-order-network: + stocklet-payment-network: + stocklet-product-network: + stocklet-shipping-network: + stocklet-user-network: + stocklet-warehouse-network: + +volumes: + stocklet-kafka-volume: + stocklet-auth-postgres-volume: + stocklet-order-postgres-volume: + stocklet-payment-postgres-volume: + stocklet-product-postgres-volume: + stocklet-shipping-postgres-volume: + stocklet-user-postgres-volume: + stocklet-warehouse-postgres-volume: \ No newline at end of file diff --git a/docs/EVENTS.md b/docs/EVENTS.md new file mode 100644 index 0000000..0bc9d76 --- /dev/null +++ b/docs/EVENTS.md @@ -0,0 +1,120 @@ +# Stocklet Docs: Events + +## Table of Contents + +* [Repository Overview](/README.md) +* [Documentation: Overview](/docs/README.md) +* [Documentation: Events](/docs/EVENTS.md) +* [Documentation: Feature Roadmap](/docs/ROADMAP.md) + +## Overview + +The events are schemed and serialised using [protocol buffers](https://protobuf.dev/). The events schemas can be found in [``/schema/protobufs/stocklet/events/``](/schema/protobufs/stocklet/events/) + +They are dispatched using the [transactional outbox pattern](https://microservices.io/patterns/data/transactional-outbox.html). Debezium is used as a relay to publish events from database outbox tables to the message broker (Kafka). The Debezium connectors are configured by the ``service-init`` containers, which are also responsible for performing database migrations for their respective services. + +## Services + +### Auth Service + +**Produces:** + +* n/a + +**Consumes:** + +* UserDeletedEvent + +### Order Service + +**Produces:** + +* OrderCreatedEvent +* OrderPendingEvent +* OrderRejectedEvent +* OrderApprovedEvent + +**Consumes:** + +* ProductPriceQuoteEvent +* StockReservationEvent +* ShipmentAllocationEvent +* PaymentProcessedEvent + +### Payment Service + +**Produces:** + +* BalanceCreatedEvent +* BalanceCreditedEvent +* BalanceDebitedEvent +* BalanceClosedEvent +* TransactionLoggedEvent +* TransactionReversedEvent *(currently unused)* +* PaymentProcessedEvent + +**Consumes:** + +* UserCreatedEvent +* UserDeletedEvent +* ShipmentAllocationEvent + +### Product Service + +**Produces:** + +* ProductCreatedEvent +* ProductPriceUpdatedEvent +* ProductDeletedEvent +* ProductPriceQuoteEvent + +**Consumes:** + +* OrderCreatedEvent + +### Shipping Service + +**Produces:** + +* ShipmentAllocationEvent +* ShipmentDispatchedEvent *(currently unused)* + +**Consumes:** + +* StockReservationEvent +* PaymentProcessedEvent + +### User Service + +**Produces:** + +* UserCreatedEvent +* UserEmailUpdatedEvent +* UserDeletedEvent + +**Consumes:** + +* n/a + +### Warehouse Service + +**Produces:** + +* StockCreatedEvent +* StockAddedEvent *(currently unused)* +* StockRemovedEvent +* StockReservationEvent + +**Consumes:** + +* OrderPendingEvent +* ShipmentAllocationEvent +* PaymentProcessedEvent + +## Miscellaneous + +### Place Order Saga + +The place order [saga](https://microservices.io/patterns/data/saga.html) is initiated when a new order is created. + +![Place Order Saga](/docs/imgs/placeordersaga.svg) diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 0000000..0623f75 --- /dev/null +++ b/docs/README.md @@ -0,0 +1,18 @@ +# Stocklet Docs + +## Table of Contents + +* [Repository Overview](/README.md) +* [Documentation: Overview](/docs/README.md) +* [Documentation: Events](/docs/EVENTS.md) +* [Documentation: Feature Roadmap](/docs/ROADMAP.md) + +## Formatting, styling, etc + +The code has been formatted using [`gofmt`](https://pkg.go.dev/cmd/gofmt). + +The protobuf schema files have been formatted using [`buf format`](https://buf.build/docs/reference/cli/buf/format). + +The markdown files have been linted and formatted using [markdownlint](https://github.com/DavidAnson/markdownlint). + +I used [PlantUML](https://plantuml.com/) as the tool to help make the diagrams. The PlantUML files are avaliable alongside the resulting images: [`/docs/imgs/overview.plantuml`](/docs/imgs/overview.plantuml) and [`/docs/imgs/placeordersaga.plantuml`](/docs/imgs/placeordersaga.plantuml) diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md new file mode 100644 index 0000000..eeab679 --- /dev/null +++ b/docs/ROADMAP.md @@ -0,0 +1,35 @@ +# Stocklet Docs: Feature Roadmap + +## Table of Contents + +* [Repository Overview](/README.md) +* [Documentation: Overview](/docs/README.md) +* [Documentation: Events](/docs/EVENTS.md) +* [Documentation: Feature Roadmap](/docs/ROADMAP.md) + +## Prologue + +This document should be considered a brainstorm of ideas. + +There is no guarantee that I will implement any listed features or functionality below. After all, I initially made this application as an experiment with EDA, and there are areas that could use improvement and expansion (the application is a prototype in current format). Some of the current implemented functionality is quite bare-bones, so if I come to revisit this project at a later date this document is where I'd first look. + +However, contributions are welcome; if you feel like implementing something (already below or not), or otherwise spot other areas that could use improvement, then please feel free to open an issue to discuss or a pull request with your implementation. + +## Feature Ideas + +* Front-end user interface + * Allow interfaces with the application through alternatives means +* Notification service + * Send notifications to users (e.g. through a mock email or a unread messages mechanism) upon reciept of events related to order status changes (i.e. OrderApprovedEvent) +* Product recommendation service + * Provide a list of recommended products catered to specific customers + +## Miscellaneous Ideas + +* Integration tests +* Ensured idempotency in event consumers (service-side) +* Clear-up of event processes +* Kubernetes deployment (prepare manifest files) +* Interchangable infrastructure + * Support for NATS as a message broker + * Support for MongoDB as a database diff --git a/docs/imgs/overview.plantuml b/docs/imgs/overview.plantuml new file mode 100644 index 0000000..00a9984 --- /dev/null +++ b/docs/imgs/overview.plantuml @@ -0,0 +1,125 @@ +' Copyright (C) 2024 Declan Teevan +' +' This program is free software: you can redistribute it and/or modify +' it under the terms of the GNU Affero General Public License as published by +' the Free Software Foundation, either version 3 of the License, or +' (at your option) any later version. +' +' This program is distributed in the hope that it will be useful, +' but WITHOUT ANY WARRANTY; without even the implied warranty of +' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +' GNU Affero General Public License for more details. +' +' You should have received a copy of the GNU Affero General Public License +' along with this program. If not, see . + +@startuml overview +!theme mars + +cloud "API Gateway (Envoy)" as APIGateway +queue "Message Broker (Kafka)" as MsgBroker +collections "Message Relay (Debezium)" as OutboxConnector + +database "Auth Database" as AuthDB +database "Order Database" as OrderDB +database "Payment Database" as PaymentDB +database "Product Database" as ProductDB +database "Shipping Database" as ShippingDB +database "User Database" as UserDB +database "Warehouse Database" as WarehouseDB + +rectangle "Auth Service" as AuthService { + agent "gRPC Gateway" as AuthGateway + agent "Event Consumer" as AuthConsumer + usecase "gRPC Service" as AuthGrpc + + AuthGrpc <-u- AuthGateway + AuthGrpc <-u- AuthConsumer + AuthGrpc --> AuthDB +} + +rectangle "Order Service" as OrderService { + agent "gRPC Gateway" as OrderGateway + agent "Event Consumer" as OrderConsumer + usecase "gRPC Service" as OrderGrpc + + OrderGrpc <-u- OrderGateway + OrderGrpc <-u- OrderConsumer + OrderGrpc --> OrderDB +} + +rectangle "Payment Service" as PaymentService { + agent "gRPC Gateway" as PaymentGateway + agent "Event Consumer" as PaymentConsumer + usecase "gRPC Service" as PaymentGrpc + + PaymentGrpc <-u- PaymentGateway + PaymentGrpc <-u- PaymentConsumer + PaymentGrpc --> PaymentDB +} + +rectangle "Product Service" as ProductService { + agent "gRPC Gateway" as ProductGateway + agent "Event Consumer" as ProductConsumer + usecase "gRPC Service" as ProductGrpc + + ProductGrpc <-u- ProductGateway + ProductGrpc <-u- ProductConsumer + ProductGrpc --> ProductDB +} + +rectangle "Shipping Service" as ShippingService { + agent "gRPC Gateway" as ShippingGateway + agent "Event Consumer" as ShippingConsumer + usecase "gRPC Service" as ShippingGrpc + + ShippingGrpc <-u- ShippingGateway + ShippingGrpc <-u- ShippingConsumer + ShippingGrpc --> ShippingDB +} + +rectangle "User Service" as UserService { + agent "gRPC Gateway" as UserGateway + usecase "gRPC Service" as UserGrpc + + UserGrpc <-u- UserGateway + UserGrpc --> UserDB +} + +rectangle "Warehouse Service" as WarehouseService { + agent "gRPC Gateway" as WarehouseGateway + agent "Event Consumer" as WarehouseConsumer + usecase "gRPC Service" as WarehouseGrpc + + WarehouseGrpc <-u- WarehouseGateway + WarehouseGrpc <-u- WarehouseConsumer + WarehouseGrpc --> WarehouseDB +} + +APIGateway ....> AuthGateway : "HTTP" +APIGateway ....> OrderGateway : "HTTP" +APIGateway ....> PaymentGateway : "HTTP" +APIGateway ....> ProductGateway : "HTTP" +APIGateway ....> ShippingGateway : "HTTP" +APIGateway ....> UserGateway : "HTTP" +APIGateway ....> WarehouseGateway : "HTTP" + +UserGrpc .l.> AuthGrpc : "gRPC " + +AuthDB ---[hidden]> OutboxConnector +OrderDB ---> OutboxConnector : "Outbox" +PaymentDB ---> OutboxConnector : "Outbox" +ProductDB ---> OutboxConnector : "Outbox" +ShippingDB ---> OutboxConnector : "Outbox" +UserDB ---> OutboxConnector : "Outbox" +WarehouseDB ---> OutboxConnector : "Outbox" + +OutboxConnector ..> MsgBroker : "Publish Events" + +MsgBroker ...> AuthConsumer +MsgBroker ...> OrderConsumer +MsgBroker ...> PaymentConsumer +MsgBroker ...> ProductConsumer +MsgBroker ...> ShippingConsumer +MsgBroker ...> WarehouseConsumer +@enduml \ No newline at end of file diff --git a/docs/imgs/overview.svg b/docs/imgs/overview.svg new file mode 100644 index 0000000..ae47e19 --- /dev/null +++ b/docs/imgs/overview.svg @@ -0,0 +1,235 @@ + + + +Auth Service + +Order Service + +Payment Service + +Product Service + +Shipping Service + +User Service + +Warehouse Service + +gRPC Gateway + +Event Consumer + +gRPC Service + +gRPC Gateway + +Event Consumer + +gRPC Service + +gRPC Gateway + +Event Consumer + +gRPC Service + +gRPC Gateway + +Event Consumer + +gRPC Service + +gRPC Gateway + +Event Consumer + +gRPC Service + +gRPC Gateway + +gRPC Service + +gRPC Gateway + +Event Consumer + +gRPC Service + +API Gateway (Envoy) + + +Message Broker (Kafka) + + +Message Relay (Debezium) + + +Auth Database + + +Order Database + + +Payment Database + + +Product Database + + +Shipping Database + + +User Database + + +Warehouse Database + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +HTTP + + +HTTP + + +HTTP + + +HTTP + + +HTTP + + +HTTP + + +HTTP + + +gRPC + + +Outbox + + +Outbox + + +Outbox + + +Outbox + + +Outbox + + +Outbox + + +Publish Events + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/imgs/placeordersaga.plantuml b/docs/imgs/placeordersaga.plantuml new file mode 100644 index 0000000..22ada43 --- /dev/null +++ b/docs/imgs/placeordersaga.plantuml @@ -0,0 +1,81 @@ +' Copyright (C) 2024 Declan Teevan +' +' This program is free software: you can redistribute it and/or modify +' it under the terms of the GNU Affero General Public License as published by +' the Free Software Foundation, either version 3 of the License, or +' (at your option) any later version. +' +' This program is distributed in the hope that it will be useful, +' but WITHOUT ANY WARRANTY; without even the implied warranty of +' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +' GNU Affero General Public License for more details. +' +' You should have received a copy of the GNU Affero General Public License +' along with this program. If not, see . + +@startuml placeordersaga +!theme mars + +|Order| +start +:OrderCreatedEvent; + +|Product| +:ProductPriceQuoteEvent; +if (type) is (UNAVALIABLE) then + |Order| + :OrderRejectedEvent; + kill +else (AVALIABLE) +endif + +|Order| +:OrderPendingEvent; + +|Warehouse| +:StockReservationEvent; +if (type) is (INSUFFICIENT_STOCK) then + |Order| + :OrderRejectedEvent; + kill +else (STOCK_RESERVED) +endif + +|Shipping| +:ShipmentAllocationEvent; +if (type) is (FAILED) then + |Warehouse| + :StockReservationEvent\ntype: STOCK_RETURNED; + + |Order| + :OrderRejectedEvent; + kill +else (ALLOCATED) +endif + +|Payment| +:PaymentProcessedEvent; +if (type) is (FAILED) then + |Shipping| + :ShipmentAllocationEvent\ntype: ALLOCATION_RELEASED; + + |Warehouse| + :StockReservationEvent\ntype: STOCK_RETURNED; + + |Order| + :OrderRejectedEvent; + kill +else (SUCCESS) +endif + +fork + |Warehouse| + :StockReservationEvent\ntype: STOCK_CONSUMED; + kill +fork again + |Order| + :OrderApprovedEvent; + stop +end merge + +@enduml \ No newline at end of file diff --git a/docs/imgs/placeordersaga.svg b/docs/imgs/placeordersaga.svg new file mode 100644 index 0000000..b09c9ad --- /dev/null +++ b/docs/imgs/placeordersaga.svg @@ -0,0 +1,142 @@ + + + + + + +OrderCreatedEvent + +OrderRejectedEvent + +OrderPendingEvent + +OrderRejectedEvent + +OrderRejectedEvent + +OrderRejectedEvent + +OrderApprovedEvent + + + + +ProductPriceQuoteEvent + +UNAVALIABLE +type +AVALIABLE + + +StockReservationEvent + +INSUFFICIENT_STOCK +type +STOCK_RESERVED + +StockReservationEvent +type: STOCK_RETURNED + +StockReservationEvent +type: STOCK_RETURNED + +StockReservationEvent +type: STOCK_CONSUMED + + +ShipmentAllocationEvent + +FAILED +type +ALLOCATED + +ShipmentAllocationEvent +type: ALLOCATION_RELEASED + + +PaymentProcessedEvent + +FAILED +type +SUCCESS + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Order +Product +Warehouse +Shipping +Payment + diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..ad21b9e --- /dev/null +++ b/go.mod @@ -0,0 +1,71 @@ +module github.com/hexolan/stocklet + +go 1.21.1 + +require ( + buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.31.0-20231106192134-1baebb0a1518.2 + github.com/bufbuild/protovalidate-go v0.4.1 + github.com/doug-martin/goqu/v9 v9.19.0 + github.com/golang-migrate/migrate/v4 v4.16.2 + github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.0 + github.com/jackc/pgx/v5 v5.3.1 + github.com/lestrrat-go/jwx/v2 v2.0.18 + github.com/rs/zerolog v1.31.0 + github.com/twmb/franz-go v1.15.0 + github.com/twmb/franz-go/pkg/kadm v1.9.2 + go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.46.1 + go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.46.1 + go.opentelemetry.io/otel v1.21.0 + go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.21.0 + go.opentelemetry.io/otel/sdk v1.21.0 + golang.org/x/crypto v0.16.0 + golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa + google.golang.org/genproto/googleapis/api v0.0.0-20231106174013-bbf56f31fb17 + google.golang.org/grpc v1.59.0 + google.golang.org/protobuf v1.31.1-0.20231027082548-f4a6c1f6e5c1 +) + +require ( + github.com/antlr4-go/antlr/v4 v4.13.0 // indirect + github.com/cenkalti/backoff/v4 v4.2.1 // indirect + github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect + github.com/distribution/reference v0.5.0 // indirect + github.com/docker/distribution v2.8.3+incompatible // indirect + github.com/docker/docker v24.0.7+incompatible // indirect + github.com/felixge/httpsnoop v1.0.4 // indirect + github.com/go-logr/logr v1.3.0 // indirect + github.com/go-logr/stdr v1.2.2 // indirect + github.com/goccy/go-json v0.10.2 // indirect + github.com/golang/protobuf v1.5.3 // indirect + github.com/google/cel-go v0.18.2 // indirect + github.com/hashicorp/errwrap v1.1.0 // indirect + github.com/hashicorp/go-multierror v1.1.1 // indirect + github.com/jackc/pgpassfile v1.0.0 // indirect + github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect + github.com/jackc/puddle/v2 v2.2.0 // indirect + github.com/klauspost/compress v1.17.2 // indirect + github.com/lestrrat-go/blackmagic v1.0.2 // indirect + github.com/lestrrat-go/httpcc v1.0.1 // indirect + github.com/lestrrat-go/httprc v1.0.4 // indirect + github.com/lestrrat-go/iter v1.0.2 // indirect + github.com/lestrrat-go/option v1.0.1 // indirect + github.com/lib/pq v1.10.2 // indirect + github.com/mattn/go-colorable v0.1.13 // indirect + github.com/mattn/go-isatty v0.0.19 // indirect + github.com/opencontainers/image-spec v1.1.0-rc5 // indirect + github.com/pierrec/lz4/v4 v4.1.18 // indirect + github.com/segmentio/asm v1.2.0 // indirect + github.com/stoewer/go-strcase v1.3.0 // indirect + github.com/twmb/franz-go/pkg/kmsg v1.6.1 // indirect + go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.21.0 // indirect + go.opentelemetry.io/otel/metric v1.21.0 // indirect + go.opentelemetry.io/otel/trace v1.21.0 // indirect + go.opentelemetry.io/proto/otlp v1.0.0 // indirect + go.uber.org/atomic v1.11.0 // indirect + golang.org/x/net v0.18.0 // indirect + golang.org/x/sync v0.5.0 // indirect + golang.org/x/sys v0.15.0 // indirect + golang.org/x/text v0.14.0 // indirect + google.golang.org/genproto v0.0.0-20231030173426-d783a09b4405 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20231106174013-bbf56f31fb17 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..6090873 --- /dev/null +++ b/go.sum @@ -0,0 +1,252 @@ +buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.31.0-20231106192134-1baebb0a1518.2 h1:iRWpWLm1nrsCHBVhibqPJQB3iIf3FRsAXioJVU8m6w0= +buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.31.0-20231106192134-1baebb0a1518.2/go.mod h1:xafc+XIsTxTy76GJQ1TKgvJWsSugFBqMaN27WhUblew= +cloud.google.com/go v0.110.9 h1:e7ITSqGFFk4rbz/JFIqZh3G4VEHguhAL4BQcFlWtU68= +cloud.google.com/go/compute v1.23.2 h1:nWEMDhgbBkBJjfpVySqU4jgWdc22PLR0o4vEexZHers= +cloud.google.com/go/compute v1.23.2/go.mod h1:JJ0atRC0J/oWYiiVBmsSsrRnh92DhZPG4hFDcR04Rns= +cloud.google.com/go/compute/metadata v0.2.3 h1:mg4jlk7mCAj6xXp9UJ4fjI9VUI5rubuGBW5aJ7UnBMY= +cloud.google.com/go/compute/metadata v0.2.3/go.mod h1:VAV5nSsACxMJvgaAuX6Pk2AawlZn8kiOGuCv6gTkwuA= +github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 h1:L/gRVlceqvL25UVaW/CKtUDjefjrs0SPonmDGUVOYP0= +github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E= +github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60= +github.com/DATA-DOG/go-sqlmock v1.5.0/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM= +github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow= +github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM= +github.com/antlr4-go/antlr/v4 v4.13.0 h1:lxCg3LAv+EUK6t1i0y1V6/SLeUi0eKEKdhQAlS8TVTI= +github.com/antlr4-go/antlr/v4 v4.13.0/go.mod h1:pfChB/xh/Unjila75QW7+VU4TSnWnnk9UTnmpPaOR2g= +github.com/bufbuild/protovalidate-go v0.4.1 h1:ye/8S72WbEklCeltPkSEeT8Eu1A7P/gmMsmapkwqTFk= +github.com/bufbuild/protovalidate-go v0.4.1/go.mod h1:+p5FXfOjSEgLz5WBDTOMPMdQPXqALEERbJZU7huDCtA= +github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM= +github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= +github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4 h1:/inchEIKaYC1Akx+H+gqO04wryn5h75LSazbRlnya1k= +github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= +github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/decred/dcrd/crypto/blake256 v1.0.1/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo= +github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 h1:8UrgZ3GkP4i/CLijOJx79Yu+etlyjdBU4sfcs2WYQMs= +github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0= +github.com/denisenkom/go-mssqldb v0.10.0/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU= +github.com/dhui/dktest v0.3.16 h1:i6gq2YQEtcrjKbeJpBkWjE8MmLZPYllcjOFbTZuPDnw= +github.com/dhui/dktest v0.3.16/go.mod h1:gYaA3LRmM8Z4vJl2MA0THIigJoZrwOansEOsp+kqxp0= +github.com/distribution/reference v0.5.0 h1:/FUIFXtfc/x2gpa5/VGfiGLuOIdYa1t65IKK2OFGvA0= +github.com/distribution/reference v0.5.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E= +github.com/docker/distribution v2.8.3+incompatible h1:AtKxIZ36LoNK51+Z6RpzLpddBirtxJnzDrHLEKxTAYk= +github.com/docker/distribution v2.8.3+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= +github.com/docker/docker v24.0.7+incompatible h1:Wo6l37AuwP3JaMnZa226lzVXGA3F9Ig1seQen0cKYlM= +github.com/docker/docker v24.0.7+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= +github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ= +github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec= +github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4= +github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= +github.com/doug-martin/goqu/v9 v9.19.0 h1:PD7t1X3tRcUiSdc5TEyOFKujZA5gs3VSA7wxSvBx7qo= +github.com/doug-martin/goqu/v9 v9.19.0/go.mod h1:nf0Wc2/hV3gYK9LiyqIrzBEVGlI8qW3GuDCEobC4wBQ= +github.com/envoyproxy/protoc-gen-validate v1.0.2 h1:QkIBuU5k+x7/QXPvPPnWXWlCdaBFApVqftFV6k087DA= +github.com/envoyproxy/protoc-gen-validate v1.0.2/go.mod h1:GpiZQP3dDbg4JouG/NNS7QWXpgx6x8QiMKdmN72jogE= +github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= +github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= +github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/logr v1.3.0 h1:2y3SDp0ZXuc6/cjLSZ+Q3ir+QB9T/iG5yYRXqsagWSY= +github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= +github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= +github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= +github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= +github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= +github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= +github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= +github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= +github.com/golang-migrate/migrate/v4 v4.16.2 h1:8coYbMKUyInrFk1lfGfRovTLAW7PhWp8qQDT2iKfuoA= +github.com/golang-migrate/migrate/v4 v4.16.2/go.mod h1:pfcJX4nPHaVdc5nmdCikFBWtm+UBpiZjRNNsyBbp0/o= +github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0= +github.com/golang/glog v1.1.2 h1:DVjP2PbBOzHyzA+dn3WhHIq4NdVu3Q+pvivFICf/7fo= +github.com/golang/glog v1.1.2/go.mod h1:zR+okUeTbrL6EL3xHUDxZuEtGv04p5shwip1+mL/rLQ= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= +github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/google/cel-go v0.18.2 h1:L0B6sNBSVmt0OyECi8v6VOS74KOc9W/tLiWKfZABvf4= +github.com/google/cel-go v0.18.2/go.mod h1:kWcIzTsPX0zmQ+H3TirHstLLf9ep5QTsZBN9u4dOYLg= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.0 h1:RtRsiaGvWxcwd8y3BiRZxsylPT8hLWZ5SPcfI+3IDNk= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.0/go.mod h1:TzP6duP4Py2pHLVPPQp42aoYI92+PCrVotyR5e8Vqlk= +github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= +github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I= +github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= +github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= +github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= +github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM= +github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg= +github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk= +github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= +github.com/jackc/pgx/v5 v5.3.1 h1:Fcr8QJ1ZeLi5zsPZqQeUZhNhxfkkKBOgJuYkJHoBOtU= +github.com/jackc/pgx/v5 v5.3.1/go.mod h1:t3JDKnCBlYIc0ewLF0Q7B8MXmoIaBOZj/ic7iHozM/8= +github.com/jackc/puddle/v2 v2.2.0 h1:RdcDk92EJBuBS55nQMMYFXTxwstHug4jkhT5pq8VxPk= +github.com/jackc/puddle/v2 v2.2.0/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4= +github.com/klauspost/compress v1.17.2 h1:RlWWUY/Dr4fL8qk9YG7DTZ7PDgME2V4csBXA8L/ixi4= +github.com/klauspost/compress v1.17.2/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= +github.com/lestrrat-go/blackmagic v1.0.2 h1:Cg2gVSc9h7sz9NOByczrbUvLopQmXrfFx//N+AkAr5k= +github.com/lestrrat-go/blackmagic v1.0.2/go.mod h1:UrEqBzIR2U6CnzVyUtfM6oZNMt/7O7Vohk2J0OGSAtU= +github.com/lestrrat-go/httpcc v1.0.1 h1:ydWCStUeJLkpYyjLDHihupbn2tYmZ7m22BGkcvZZrIE= +github.com/lestrrat-go/httpcc v1.0.1/go.mod h1:qiltp3Mt56+55GPVCbTdM9MlqhvzyuL6W/NMDA8vA5E= +github.com/lestrrat-go/httprc v1.0.4 h1:bAZymwoZQb+Oq8MEbyipag7iSq6YIga8Wj6GOiJGdI8= +github.com/lestrrat-go/httprc v1.0.4/go.mod h1:mwwz3JMTPBjHUkkDv/IGJ39aALInZLrhBp0X7KGUZlo= +github.com/lestrrat-go/iter v1.0.2 h1:gMXo1q4c2pHmC3dn8LzRhJfP1ceCbgSiT9lUydIzltI= +github.com/lestrrat-go/iter v1.0.2/go.mod h1:Momfcq3AnRlRjI5b5O8/G5/BvpzrhoFTZcn06fEOPt4= +github.com/lestrrat-go/jwx/v2 v2.0.18 h1:HHZkYS5wWDDyAiNBwztEtDoX07WDhGEdixm8G06R50o= +github.com/lestrrat-go/jwx/v2 v2.0.18/go.mod h1:fAJ+k5eTgKdDqanzCuK6DAt3W7n3cs2/FX7JhQdk83U= +github.com/lestrrat-go/option v1.0.0/go.mod h1:5ZHFbivi4xwXxhxY9XHDe2FHo6/Z7WWmtT7T5nBBp3I= +github.com/lestrrat-go/option v1.0.1 h1:oAzP2fvZGQKWkvHa1/SAcFolBEca1oN+mQ7eooNBEYU= +github.com/lestrrat-go/option v1.0.1/go.mod h1:5ZHFbivi4xwXxhxY9XHDe2FHo6/Z7WWmtT7T5nBBp3I= +github.com/lib/pq v1.10.1/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= +github.com/lib/pq v1.10.2 h1:AqzbZs4ZoCBp+GtejcpCpcxM3zlSMx29dXbUSeVtJb8= +github.com/lib/pq v1.10.2/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= +github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= +github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= +github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= +github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-sqlite3 v1.14.7/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU= +github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0= +github.com/moby/term v0.5.0/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y= +github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A= +github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc= +github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= +github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= +github.com/opencontainers/image-spec v1.1.0-rc5 h1:Ygwkfw9bpDvs+c9E34SdgGOj41dX/cbdlwvlWt0pnFI= +github.com/opencontainers/image-spec v1.1.0-rc5/go.mod h1:X4pATf0uXsnn3g5aiGIsVnJBR4mxhKzfwmvK/B2NTm8= +github.com/pierrec/lz4/v4 v4.1.18 h1:xaKrnTkyoqfh1YItXl56+6KJNVYWlEEPuAQW9xsplYQ= +github.com/pierrec/lz4/v4 v4.1.18/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= +github.com/rs/zerolog v1.31.0 h1:FcTR3NnLWW+NnTwwhFWiJSZr4ECLpqCm6QsEnyvbV4A= +github.com/rs/zerolog v1.31.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss= +github.com/segmentio/asm v1.2.0 h1:9BQrFxC+YOHJlTlHGkTrFWf59nbL3XnCoFLTwDCI7ys= +github.com/segmentio/asm v1.2.0/go.mod h1:BqMnlJP91P8d+4ibuonYZw9mfnzI9HfxselHZr5aAcs= +github.com/stoewer/go-strcase v1.3.0 h1:g0eASXYtp+yvN9fK8sH94oCIk0fau9uV1/ZdJ0AVEzs= +github.com/stoewer/go-strcase v1.3.0/go.mod h1:fAH5hQ5pehh+j3nZfvwdk2RgEgQjAoM8wodgtPmh1xo= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/twmb/franz-go v1.15.0 h1:bw5n1COKJzWpkCXG/kMtHrurcS9HSWV6e3If5CUdc+M= +github.com/twmb/franz-go v1.15.0/go.mod h1:nMAvTC2kHtK+ceaSHeHm4dlxC78389M/1DjpOswEgu4= +github.com/twmb/franz-go/pkg/kadm v1.9.2 h1:2Aj7DOaSFT5TyJ5BLEbAanXuby7CeWjpXW9ht8fy73c= +github.com/twmb/franz-go/pkg/kadm v1.9.2/go.mod h1:hUMoV4SRho+2ij/S9cL39JaLsr+XINjn0ZkCdBY2DXc= +github.com/twmb/franz-go/pkg/kmsg v1.6.1 h1:tm6hXPv5antMHLasTfKv9R+X03AjHSkSkXhQo2c5ALM= +github.com/twmb/franz-go/pkg/kmsg v1.6.1/go.mod h1:se9Mjdt0Nwzc9lnjJ0HyDtLyBnaBDAd7pCje47OhSyw= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.46.1 h1:SpGay3w+nEwMpfVnbqOLH5gY52/foP8RE8UzTZ1pdSE= +go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.46.1/go.mod h1:4UoMYEZOC0yN/sPGH76KPkkU7zgiEWYWL9vwmbnTJPE= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.46.1 h1:aFJWCqJMNjENlcleuuOkGAPH82y0yULBScfXcIEdS24= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.46.1/go.mod h1:sEGXWArGqc3tVa+ekntsN65DmVbVeW+7lTKTjZF3/Fo= +go.opentelemetry.io/otel v1.21.0 h1:hzLeKBZEL7Okw2mGzZ0cc4k/A7Fta0uoPgaJCr8fsFc= +go.opentelemetry.io/otel v1.21.0/go.mod h1:QZzNPQPm1zLX4gZK4cMi+71eaorMSGT3A4znnUvNNEo= +go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.21.0 h1:cl5P5/GIfFh4t6xyruOgJP5QiA1pw4fYYdv6nc6CBWw= +go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.21.0/go.mod h1:zgBdWWAu7oEEMC06MMKc5NLbA/1YDXV1sMpSqEeLQLg= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.21.0 h1:tIqheXEFWAZ7O8A7m+J0aPTmpJN3YQ7qetUAdkkkKpk= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.21.0/go.mod h1:nUeKExfxAQVbiVFn32YXpXZZHZ61Cc3s3Rn1pDBGAb0= +go.opentelemetry.io/otel/metric v1.21.0 h1:tlYWfeo+Bocx5kLEloTjbcDwBuELRrIFxwdQ36PlJu4= +go.opentelemetry.io/otel/metric v1.21.0/go.mod h1:o1p3CA8nNHW8j5yuQLdc1eeqEaPfzug24uvsyIEJRWM= +go.opentelemetry.io/otel/sdk v1.21.0 h1:FTt8qirL1EysG6sTQRZ5TokkU8d0ugCj8htOgThZXQ8= +go.opentelemetry.io/otel/sdk v1.21.0/go.mod h1:Nna6Yv7PWTdgJHVRD9hIYywQBRx7pbox6nwBnZIxl/E= +go.opentelemetry.io/otel/trace v1.21.0 h1:WD9i5gzvoUPuXIXH24ZNBudiarZDKuekPqi/E8fpfLc= +go.opentelemetry.io/otel/trace v1.21.0/go.mod h1:LGbsEB0f9LGjN+OZaQQ26sohbOmiMR+BaslueVtS/qQ= +go.opentelemetry.io/proto/otlp v1.0.0 h1:T0TX0tmXU8a3CbNXzEKGeU5mIVOdf0oykP+u2lIVU/I= +go.opentelemetry.io/proto/otlp v1.0.0/go.mod h1:Sy6pihPLfYHkr3NkUbEhGHFhINUSI/v80hjKIs5JXpM= +go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE= +go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0= +go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= +go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.16.0 h1:mMMrFzRSCF0GvB7Ne27XVtVAaXLrPmgPC7/v0tkwHaY= +golang.org/x/crypto v0.16.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= +golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa h1:FRnLl4eNAQl8hwxVVC17teOw8kdjVDVAiFMtgUdTSRQ= +golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa/go.mod h1:zk2irFbV9DP96SEBUUAy67IdHUaZuSnrz1n472HUCLE= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0= +golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= +golang.org/x/net v0.18.0 h1:mIYleuAkSbHh0tCv7RvjL3F6ZVbLjq4+R7zbOn3Kokg= +golang.org/x/net v0.18.0/go.mod h1:/czyP5RqHAH4odGYxBJ1qz0+CE5WZ+2j1YgoEo8F2jQ= +golang.org/x/oauth2 v0.12.0 h1:smVPGxink+n1ZI5pkQa8y6fZT0RW0MgCO5bFpepy4B4= +golang.org/x/oauth2 v0.12.0/go.mod h1:A74bZ3aGXgCY0qaIC9Ahg6Lglin4AMAco8cIv9baba4= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE= +golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= +golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= +golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= +golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= +golang.org/x/tools v0.15.0 h1:zdAyfUGbYmuVokhzVmghFl2ZJh5QhcfebBgmVPFYA+8= +golang.org/x/tools v0.15.0/go.mod h1:hpksKq4dtpQWS1uQ61JkdqWM3LscIS6Slf+VVkm+wQk= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c= +google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= +google.golang.org/genproto v0.0.0-20231030173426-d783a09b4405 h1:I6WNifs6pF9tNdSob2W24JtyxIYjzFB9qDlpUC76q+U= +google.golang.org/genproto v0.0.0-20231030173426-d783a09b4405/go.mod h1:3WDQMjmJk36UQhjQ89emUzb1mdaHcPeeAh4SCBKznB4= +google.golang.org/genproto/googleapis/api v0.0.0-20231106174013-bbf56f31fb17 h1:JpwMPBpFN3uKhdaekDpiNlImDdkUAyiJ6ez/uxGaUSo= +google.golang.org/genproto/googleapis/api v0.0.0-20231106174013-bbf56f31fb17/go.mod h1:0xJLfVdJqpAPl8tDg1ujOCGzx6LFLttXT5NhllGOXY4= +google.golang.org/genproto/googleapis/rpc v0.0.0-20231106174013-bbf56f31fb17 h1:Jyp0Hsi0bmHXG6k9eATXoYtjd6e2UzZ1SCn/wIupY14= +google.golang.org/genproto/googleapis/rpc v0.0.0-20231106174013-bbf56f31fb17/go.mod h1:oQ5rr10WTTMvP4A36n8JpR1OrO1BEiV4f78CneXZxkA= +google.golang.org/grpc v1.59.0 h1:Z5Iec2pjwb+LEOqzpB2MR12/eKFhDPhuqW91O+4bwUk= +google.golang.org/grpc v1.59.0/go.mod h1:aUPDwccQo6OTjy7Hct4AfBPD1GptF4fyUjIkQ9YtF98= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +google.golang.org/protobuf v1.31.1-0.20231027082548-f4a6c1f6e5c1 h1:fk72uXZyuZiTtW5tgd63jyVK6582lF61nRC/kGv6vCA= +google.golang.org/protobuf v1.31.1-0.20231027082548-f4a6c1f6e5c1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/internal/pkg/config/config.go b/internal/pkg/config/config.go new file mode 100644 index 0000000..a145418 --- /dev/null +++ b/internal/pkg/config/config.go @@ -0,0 +1,70 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package config + +import ( + "os" + + "github.com/hexolan/stocklet/internal/pkg/errors" +) + +// Load an option from an environment variable +func loadFromEnv(name string) *string { + value, exists := os.LookupEnv(name) + if !exists || value == "" { + return nil + } + + return &value +} + +// Require an option from an environment variable +func RequireFromEnv(name string) (string, error) { + value := loadFromEnv(name) + if value == nil { + return "", errors.NewServiceErrorf(errors.ErrCodeService, "failed to load required cfg option (%s)", name) + } + + return *value, nil +} + +// Shared configuration implemented by all services +type SharedConfig struct { + // Env Var: "MODE" (optional) + // 'dev' or 'development' -> true + // Defaults to false + DevMode bool + + Otel OtelConfig +} + +// Load the options in the shared config +func (cfg *SharedConfig) Load() error { + // Determine application mode + cfg.DevMode = false + if mode, err := RequireFromEnv("MODE"); err == nil && (mode == "dev" || mode == "development") { + cfg.DevMode = true + } + + // load the Open Telemetry config + cfg.Otel = OtelConfig{} + if err := cfg.Otel.Load(); err != nil { + return err + } + + // Config succesfully loaded + return nil +} diff --git a/internal/pkg/config/kafka.go b/internal/pkg/config/kafka.go new file mode 100644 index 0000000..c99a320 --- /dev/null +++ b/internal/pkg/config/kafka.go @@ -0,0 +1,40 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package config + +import ( + "strings" +) + +type KafkaConfig struct { + // Env Var: "KAFKA_BROKERS" + // Comma delimited from env var. + Brokers []string +} + +func (cfg *KafkaConfig) Load() error { + // load configurations from env + brokersOpt, err := RequireFromEnv("KAFKA_BROKERS") + if err != nil { + return err + } + + // Comma seperate the kafka brokers + cfg.Brokers = strings.Split(brokersOpt, ",") + + // Config options were succesfully loaded + return nil +} diff --git a/internal/pkg/config/otel.go b/internal/pkg/config/otel.go new file mode 100644 index 0000000..6fdaaca --- /dev/null +++ b/internal/pkg/config/otel.go @@ -0,0 +1,33 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package config + +type OtelConfig struct { + // Env Var: "OTEL_COLLECTOR_GRPC" + CollectorGrpc string +} + +func (cfg *OtelConfig) Load() error { + // Load configurations from env + if collectorGrpc, err := RequireFromEnv("OTEL_COLLECTOR_GRPC"); err != nil { + return err + } else { + cfg.CollectorGrpc = collectorGrpc + } + + // Succesfully loaded config properties + return nil +} diff --git a/internal/pkg/config/postgres.go b/internal/pkg/config/postgres.go new file mode 100644 index 0000000..7bedbb5 --- /dev/null +++ b/internal/pkg/config/postgres.go @@ -0,0 +1,85 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package config + +import ( + "fmt" +) + +type PostgresConfig struct { + // Env Var: "PG_USER" + Username string + + // Env Var: "PG_PASS" + Password string + + // Env Var: "PG_HOST" + Host string + + // Env Var: "PG_PORT" (optional) + // Defaults to "5432" + Port string + + // Env Var: "PG_DB" + Database string +} + +func (conf *PostgresConfig) GetDSN() string { + return fmt.Sprintf( + "postgresql://%s:%s@%s:%s/%s?sslmode=disable", + conf.Username, + conf.Password, + conf.Host, + conf.Port, + conf.Database, + ) +} + +func (cfg *PostgresConfig) Load() error { + // Load configurations from env + if opt, err := RequireFromEnv("PG_USER"); err != nil { + return err + } else { + cfg.Username = opt + } + + if opt, err := RequireFromEnv("PG_PASS"); err != nil { + return err + } else { + cfg.Password = opt + } + + if opt, err := RequireFromEnv("PG_HOST"); err != nil { + return err + } else { + cfg.Host = opt + } + + if opt, err := RequireFromEnv("PG_PORT"); err != nil { + cfg.Port = "5432" + } else { + cfg.Port = opt + } + + if opt, err := RequireFromEnv("PG_DB"); err != nil { + return err + } else { + cfg.Database = opt + } + + // Config properties succesfully loaded + return nil +} diff --git a/internal/pkg/errors/codes.go b/internal/pkg/errors/codes.go new file mode 100644 index 0000000..e020c61 --- /dev/null +++ b/internal/pkg/errors/codes.go @@ -0,0 +1,62 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package errors + +import ( + "google.golang.org/grpc/codes" +) + +type ErrorCode int32 + +const ( + ErrCodeUnknown ErrorCode = iota + + ErrCodeService + ErrCodeExtService + + ErrCodeNotFound + ErrCodeAlreadyExists + + ErrCodeForbidden + ErrCodeUnauthorised + + ErrCodeInvalidArgument +) + +// Maps the custom service error codes +// to their gRPC status code equivalents. +func (c ErrorCode) GRPCCode() codes.Code { + codeMap := map[ErrorCode]codes.Code{ + ErrCodeUnknown: codes.Unknown, + + ErrCodeService: codes.Internal, + ErrCodeExtService: codes.Unavailable, + + ErrCodeNotFound: codes.NotFound, + ErrCodeAlreadyExists: codes.AlreadyExists, + + ErrCodeForbidden: codes.PermissionDenied, + ErrCodeUnauthorised: codes.PermissionDenied, + + ErrCodeInvalidArgument: codes.InvalidArgument, + } + + grpcCode, mapped := codeMap[c] + if mapped { + return grpcCode + } + return codes.Unknown +} diff --git a/internal/pkg/errors/errors.go b/internal/pkg/errors/errors.go new file mode 100644 index 0000000..6afdbf0 --- /dev/null +++ b/internal/pkg/errors/errors.go @@ -0,0 +1,71 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package errors + +import ( + "fmt" + + "google.golang.org/grpc/status" +) + +type ServiceError struct { + code ErrorCode + msg string + wrapped error +} + +func NewServiceError(code ErrorCode, msg string) error { + return &ServiceError{ + code: code, + msg: msg, + } +} + +func NewServiceErrorf(code ErrorCode, msg string, args ...interface{}) error { + return NewServiceError(code, fmt.Sprintf(msg, args...)) +} + +func WrapServiceError(code ErrorCode, msg string, wrapped error) error { + return &ServiceError{ + code: code, + msg: msg, + wrapped: wrapped, + } +} + +func (e ServiceError) Error() string { + if e.wrapped != nil { + return fmt.Sprintf("%s: %s", e.msg, e.wrapped.Error()) + } + + return e.msg +} + +func (e ServiceError) Code() ErrorCode { + return e.code +} + +// Set the gRPC status to only expose the top error message. +// +// This is to prevent any full error contexts (from wrapped errors) being exposed to users by the gateway. +// e.g. "{"code":2,"message":"something went wrong scanning order: failed to connect to `host=postgres user=postgres database=postgres`: hostname resolving error (lookup postgres on 127.0.0.11:53: server misbehaving)","details":[]}" +func (e ServiceError) GRPCStatus() *status.Status { + return status.New(e.Code().GRPCCode(), e.msg) +} + +func (e ServiceError) Unwrap() error { + return e.wrapped +} diff --git a/internal/pkg/gwauth/gateway.go b/internal/pkg/gwauth/gateway.go new file mode 100644 index 0000000..7c9ecb8 --- /dev/null +++ b/internal/pkg/gwauth/gateway.go @@ -0,0 +1,96 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package gwauth + +import ( + "context" + "encoding/base64" + "encoding/json" + + "google.golang.org/grpc/metadata" + + "github.com/hexolan/stocklet/internal/pkg/errors" +) + +const JWTPayloadHeader string = "X-JWT-Payload" + +type JWTClaims struct { + Subject string `json:"sub"` + IssuedAt int64 `json:"iat"` + Expiry int64 `json:"exp"` +} + +func IsGatewayRequest(ctx context.Context) (bool, *metadata.MD) { + // Check the gRPC request has metadata + md, exists := metadata.FromIncomingContext(ctx) + if !exists { + return false, nil + } + + if len(md.Get("from-gateway")) != 0 { + return true, &md + } + + return false, &md +} + +func GetGatewayUser(md *metadata.MD) (*JWTClaims, error) { + // Check a token payload has been passed down + // Envoy validates JWT tokens and provides a "X-JWT-Payload" header (containing base64 JWT token claims) + authorization := md.Get("jwt-payload") + if len(authorization) != 1 { + return nil, errors.NewServiceError(errors.ErrCodeUnauthorised, "invalid jwt") + } + + // User is authenticated + // Attempt to decode the jwt-payload + bytes, err := base64.StdEncoding.DecodeString(authorization[0]) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeUnauthorised, "malformed jwt", err) + } + + var claims JWTClaims + err = json.Unmarshal(bytes, &claims) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeUnauthorised, "malformed jwt", err) + } + + return &claims, nil +} + +func getTokenPayload(md *metadata.MD) (*JWTClaims, error) { + // Envoy validates JWT tokens and provides a header containing + // valid auth token claims in base64 format. + authorization := md.Get("jwt-payload") + if len(authorization) != 1 { + return nil, errors.NewServiceError(errors.ErrCodeUnauthorised, "auth token not provided") + } + + // User is authenticated + // Attempt to decode the jwt-payload + bytes, err := base64.StdEncoding.DecodeString(authorization[0]) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeUnauthorised, "malformed jwt", err) + } + + var claims JWTClaims + err = json.Unmarshal(bytes, &claims) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeUnauthorised, "malformed jwt", err) + } + + return &claims, nil +} diff --git a/internal/pkg/messaging/kafka.go b/internal/pkg/messaging/kafka.go new file mode 100644 index 0000000..89a57f9 --- /dev/null +++ b/internal/pkg/messaging/kafka.go @@ -0,0 +1,48 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package messaging + +import ( + "context" + + "github.com/twmb/franz-go/pkg/kadm" + "github.com/twmb/franz-go/pkg/kgo" + + "github.com/hexolan/stocklet/internal/pkg/config" + "github.com/hexolan/stocklet/internal/pkg/errors" +) + +func NewKafkaConn(conf *config.KafkaConfig, opts ...kgo.Opt) (*kgo.Client, error) { + opts = append(opts, kgo.SeedBrokers(conf.Brokers...)) + cl, err := kgo.NewClient(opts...) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeExtService, "failed to connect to Kafka", err) + } + + return cl, nil +} + +func EnsureKafkaTopics(cl *kgo.Client, topics ...string) error { + ctx := context.Background() + kadmCl := kadm.NewClient(cl) + + _, err := kadmCl.CreateTopics(ctx, -1, -1, nil, topics...) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to create Kafka topics", err) + } + + return nil +} diff --git a/internal/pkg/messaging/messaging.go b/internal/pkg/messaging/messaging.go new file mode 100644 index 0000000..529e0dd --- /dev/null +++ b/internal/pkg/messaging/messaging.go @@ -0,0 +1,93 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package messaging + +import ( + "google.golang.org/protobuf/proto" + "google.golang.org/protobuf/reflect/protoreflect" +) + +type ConsumerController interface { + Start() + Stop() +} + +// Topic Definitions +const ( + // Order Topics + Order_State_Topic = "order.state" + Order_State_Created_Topic = Order_State_Topic + ".created" + Order_State_Pending_Topic = Order_State_Topic + ".pending" + Order_State_Rejected_Topic = Order_State_Topic + ".rejected" + Order_State_Approved_Topic = Order_State_Topic + ".approved" + + // Payment Topics + Payment_Balance_Topic = "payment.balance" + Payment_Balance_Created_Topic = Payment_Balance_Topic + ".created" + Payment_Balance_Credited_Topic = Payment_Balance_Topic + ".credited" + Payment_Balance_Debited_Topic = Payment_Balance_Topic + ".debited" + Payment_Balance_Closed_Topic = Payment_Balance_Topic + ".closed" + + Payment_Transaction_Topic = "payment.transaction" + Payment_Transaction_Created_Topic = Payment_Transaction_Topic + ".created" + Payment_Transaction_Reversed_Topic = Payment_Transaction_Topic + ".reversed" + + Payment_Processing_Topic = "payment.processing" + + // Product Topics + Product_State_Topic = "product.state" + Product_State_Created_Topic = Product_State_Topic + ".created" + Product_State_Deleted_Topic = Product_State_Topic + ".deleted" + + Product_Attribute_Topic = "product.attr" + Product_Attribute_Price_Topic = Product_Attribute_Topic + ".price" + + Product_PriceQuotation_Topic = "product.pricequotation" + + // Shipping Topics + Shipping_Shipment_Topic = "shipping.shipment" + Shipping_Shipment_Allocation_Topic = Shipping_Shipment_Topic + ".allocation" + Shipping_Shipment_Dispatched_Topic = Shipping_Shipment_Topic + ".dispatched" + + // User Topics + User_State_Topic = "user.state" + User_State_Created_Topic = User_State_Topic + ".created" + User_State_Deleted_Topic = User_State_Topic + ".deleted" + + User_Attribute_Topic = "user.attr" + User_Attribute_Email_Topic = User_Attribute_Topic + ".email" + + // Warehouse Topics + Warehouse_Stock_Topic = "warehouse.stock" + Warehouse_Stock_Created_Topic = Warehouse_Stock_Topic + ".created" + Warehouse_Stock_Added_Topic = Warehouse_Stock_Topic + ".added" + Warehouse_Stock_Removed_Topic = Warehouse_Stock_Topic + ".removed" + + Warehouse_Reservation_Topic = "warehouse.reservation" + Warehouse_Reservation_Failed_Topic = Warehouse_Reservation_Topic + ".failed" + Warehouse_Reservation_Reserved_Topic = Warehouse_Reservation_Topic + ".reserved" + Warehouse_Reservation_Returned_Topic = Warehouse_Reservation_Topic + ".returned" + Warehouse_Reservation_Consumed_Topic = Warehouse_Reservation_Topic + ".consumed" +) + +func MarshalEvent(event protoreflect.ProtoMessage, topic string) ([]byte, string, error) { + wireEvent, err := proto.Marshal(event) + if err != nil { + return []byte{}, "", err + } + + return wireEvent, topic, nil +} diff --git a/internal/pkg/metrics/logging.go b/internal/pkg/metrics/logging.go new file mode 100644 index 0000000..6f9b833 --- /dev/null +++ b/internal/pkg/metrics/logging.go @@ -0,0 +1,24 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package metrics + +import ( + "github.com/rs/zerolog" +) + +func ConfigureLogger() { + zerolog.TimeFieldFormat = zerolog.TimeFormatUnix +} diff --git a/internal/pkg/metrics/otel.go b/internal/pkg/metrics/otel.go new file mode 100644 index 0000000..7e51b94 --- /dev/null +++ b/internal/pkg/metrics/otel.go @@ -0,0 +1,82 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package metrics + +import ( + "context" + + "github.com/rs/zerolog/log" + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc" + "go.opentelemetry.io/otel/propagation" + sdkresource "go.opentelemetry.io/otel/sdk/resource" + sdktrace "go.opentelemetry.io/otel/sdk/trace" + semconv "go.opentelemetry.io/otel/semconv/v1.21.0" + + "github.com/hexolan/stocklet/internal/pkg/config" +) + +// Initiate the OpenTelemetry tracer provider +func InitTracerProvider(cfg *config.OtelConfig, svcName string) *sdktrace.TracerProvider { + // Create resource and trace exporter (to otel-collector) + resource := initTracerResource(svcName) + exporter := initTracerExporter(cfg.CollectorGrpc) + + // Create the trace provider + tp := sdktrace.NewTracerProvider( + sdktrace.WithBatcher(exporter), + + sdktrace.WithResource(resource), + ) + + otel.SetTracerProvider(tp) + otel.SetTextMapPropagator(propagation.TraceContext{}) + + return tp +} + +// Establishes a connection to otel-collector over gRPC +func initTracerExporter(collectorEndpoint string) sdktrace.SpanExporter { + ctx := context.Background() + + exporter, err := otlptracegrpc.New( + ctx, + otlptracegrpc.WithEndpoint(collectorEndpoint), + otlptracegrpc.WithInsecure(), + ) + if err != nil { + log.Panic().Err(err).Msg("otel: failed to start otlp gRPC exporter") + } + + return exporter +} + +// Prepare a tracer resource to use with the tracing provider +func initTracerResource(svcName string) *sdkresource.Resource { + ctx := context.Background() + + resource, err := sdkresource.New( + ctx, + sdkresource.WithAttributes( + semconv.ServiceName(svcName), + ), + ) + if err != nil { + log.Panic().Err(err).Msg("otel: failed to create tracer resource") + } + + return resource +} diff --git a/internal/pkg/protogen/auth/v1/service.pb.go b/internal/pkg/protogen/auth/v1/service.pb.go new file mode 100644 index 0000000..7cad732 --- /dev/null +++ b/internal/pkg/protogen/auth/v1/service.pb.go @@ -0,0 +1,579 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.31.0 +// protoc (unknown) +// source: stocklet/auth/v1/service.proto + +package auth_v1 + +import ( + _ "buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go/buf/validate" + v1 "github.com/hexolan/stocklet/internal/pkg/protogen/common/v1" + v11 "github.com/hexolan/stocklet/internal/pkg/protogen/events/v1" + _ "google.golang.org/genproto/googleapis/api/annotations" + _ "google.golang.org/genproto/googleapis/api/visibility" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + emptypb "google.golang.org/protobuf/types/known/emptypb" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type GetJwksRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *GetJwksRequest) Reset() { + *x = GetJwksRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_auth_v1_service_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetJwksRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetJwksRequest) ProtoMessage() {} + +func (x *GetJwksRequest) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_auth_v1_service_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetJwksRequest.ProtoReflect.Descriptor instead. +func (*GetJwksRequest) Descriptor() ([]byte, []int) { + return file_stocklet_auth_v1_service_proto_rawDescGZIP(), []int{0} +} + +type GetJwksResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Keys []*PublicEcJWK `protobuf:"bytes,1,rep,name=keys,proto3" json:"keys,omitempty"` +} + +func (x *GetJwksResponse) Reset() { + *x = GetJwksResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_auth_v1_service_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetJwksResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetJwksResponse) ProtoMessage() {} + +func (x *GetJwksResponse) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_auth_v1_service_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetJwksResponse.ProtoReflect.Descriptor instead. +func (*GetJwksResponse) Descriptor() ([]byte, []int) { + return file_stocklet_auth_v1_service_proto_rawDescGZIP(), []int{1} +} + +func (x *GetJwksResponse) GetKeys() []*PublicEcJWK { + if x != nil { + return x.Keys + } + return nil +} + +type LoginPasswordRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + UserId string `protobuf:"bytes,1,opt,name=user_id,json=userId,proto3" json:"user_id,omitempty"` + Password string `protobuf:"bytes,2,opt,name=password,proto3" json:"password,omitempty"` +} + +func (x *LoginPasswordRequest) Reset() { + *x = LoginPasswordRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_auth_v1_service_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *LoginPasswordRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*LoginPasswordRequest) ProtoMessage() {} + +func (x *LoginPasswordRequest) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_auth_v1_service_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use LoginPasswordRequest.ProtoReflect.Descriptor instead. +func (*LoginPasswordRequest) Descriptor() ([]byte, []int) { + return file_stocklet_auth_v1_service_proto_rawDescGZIP(), []int{2} +} + +func (x *LoginPasswordRequest) GetUserId() string { + if x != nil { + return x.UserId + } + return "" +} + +func (x *LoginPasswordRequest) GetPassword() string { + if x != nil { + return x.Password + } + return "" +} + +type LoginPasswordResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Detail string `protobuf:"bytes,1,opt,name=detail,proto3" json:"detail,omitempty"` + Data *AuthToken `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` +} + +func (x *LoginPasswordResponse) Reset() { + *x = LoginPasswordResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_auth_v1_service_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *LoginPasswordResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*LoginPasswordResponse) ProtoMessage() {} + +func (x *LoginPasswordResponse) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_auth_v1_service_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use LoginPasswordResponse.ProtoReflect.Descriptor instead. +func (*LoginPasswordResponse) Descriptor() ([]byte, []int) { + return file_stocklet_auth_v1_service_proto_rawDescGZIP(), []int{3} +} + +func (x *LoginPasswordResponse) GetDetail() string { + if x != nil { + return x.Detail + } + return "" +} + +func (x *LoginPasswordResponse) GetData() *AuthToken { + if x != nil { + return x.Data + } + return nil +} + +type SetPasswordRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + UserId string `protobuf:"bytes,1,opt,name=user_id,json=userId,proto3" json:"user_id,omitempty"` + Password string `protobuf:"bytes,2,opt,name=password,proto3" json:"password,omitempty"` +} + +func (x *SetPasswordRequest) Reset() { + *x = SetPasswordRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_auth_v1_service_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *SetPasswordRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SetPasswordRequest) ProtoMessage() {} + +func (x *SetPasswordRequest) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_auth_v1_service_proto_msgTypes[4] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use SetPasswordRequest.ProtoReflect.Descriptor instead. +func (*SetPasswordRequest) Descriptor() ([]byte, []int) { + return file_stocklet_auth_v1_service_proto_rawDescGZIP(), []int{4} +} + +func (x *SetPasswordRequest) GetUserId() string { + if x != nil { + return x.UserId + } + return "" +} + +func (x *SetPasswordRequest) GetPassword() string { + if x != nil { + return x.Password + } + return "" +} + +type SetPasswordResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Detail string `protobuf:"bytes,1,opt,name=detail,proto3" json:"detail,omitempty"` +} + +func (x *SetPasswordResponse) Reset() { + *x = SetPasswordResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_auth_v1_service_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *SetPasswordResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SetPasswordResponse) ProtoMessage() {} + +func (x *SetPasswordResponse) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_auth_v1_service_proto_msgTypes[5] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use SetPasswordResponse.ProtoReflect.Descriptor instead. +func (*SetPasswordResponse) Descriptor() ([]byte, []int) { + return file_stocklet_auth_v1_service_proto_rawDescGZIP(), []int{5} +} + +func (x *SetPasswordResponse) GetDetail() string { + if x != nil { + return x.Detail + } + return "" +} + +var File_stocklet_auth_v1_service_proto protoreflect.FileDescriptor + +var file_stocklet_auth_v1_service_proto_rawDesc = []byte{ + 0x0a, 0x1e, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2f, 0x61, 0x75, 0x74, 0x68, 0x2f, + 0x76, 0x31, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x12, 0x10, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x61, 0x75, 0x74, 0x68, 0x2e, + 0x76, 0x31, 0x1a, 0x1b, 0x62, 0x75, 0x66, 0x2f, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, + 0x2f, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, + 0x1c, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x61, 0x6e, 0x6e, 0x6f, + 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1f, 0x67, + 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x5f, + 0x62, 0x65, 0x68, 0x61, 0x76, 0x69, 0x6f, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1b, + 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x69, 0x73, 0x69, 0x62, + 0x69, 0x6c, 0x69, 0x74, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1b, 0x67, 0x6f, 0x6f, + 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x65, 0x6d, 0x70, + 0x74, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1c, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, + 0x65, 0x74, 0x2f, 0x61, 0x75, 0x74, 0x68, 0x2f, 0x76, 0x31, 0x2f, 0x74, 0x79, 0x70, 0x65, 0x73, + 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x21, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, + 0x2f, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2f, 0x76, 0x31, 0x2f, 0x72, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1d, 0x73, 0x74, 0x6f, 0x63, 0x6b, + 0x6c, 0x65, 0x74, 0x2f, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x2f, 0x76, 0x31, 0x2f, 0x75, 0x73, + 0x65, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x10, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x4a, + 0x77, 0x6b, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x44, 0x0a, 0x0f, 0x47, 0x65, + 0x74, 0x4a, 0x77, 0x6b, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x31, 0x0a, + 0x04, 0x6b, 0x65, 0x79, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1d, 0x2e, 0x73, 0x74, + 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x61, 0x75, 0x74, 0x68, 0x2e, 0x76, 0x31, 0x2e, 0x50, + 0x75, 0x62, 0x6c, 0x69, 0x63, 0x45, 0x63, 0x4a, 0x57, 0x4b, 0x52, 0x04, 0x6b, 0x65, 0x79, 0x73, + 0x22, 0x65, 0x0a, 0x14, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x50, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, + 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x23, 0x0a, 0x07, 0x75, 0x73, 0x65, 0x72, + 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, 0x0a, 0xe0, 0x41, 0x02, 0xba, 0x48, + 0x04, 0x72, 0x02, 0x10, 0x01, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x28, 0x0a, + 0x08, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x42, + 0x0c, 0xe0, 0x41, 0x02, 0xba, 0x48, 0x06, 0x72, 0x04, 0x10, 0x01, 0x18, 0x40, 0x52, 0x08, 0x70, + 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x22, 0x60, 0x0a, 0x15, 0x4c, 0x6f, 0x67, 0x69, 0x6e, + 0x50, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, + 0x12, 0x16, 0x0a, 0x06, 0x64, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x06, 0x64, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x12, 0x2f, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1b, 0x2e, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, + 0x74, 0x2e, 0x61, 0x75, 0x74, 0x68, 0x2e, 0x76, 0x31, 0x2e, 0x41, 0x75, 0x74, 0x68, 0x54, 0x6f, + 0x6b, 0x65, 0x6e, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x22, 0x63, 0x0a, 0x12, 0x53, 0x65, 0x74, + 0x50, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, + 0x23, 0x0a, 0x07, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, + 0x42, 0x0a, 0xe0, 0x41, 0x02, 0xba, 0x48, 0x04, 0x72, 0x02, 0x10, 0x01, 0x52, 0x06, 0x75, 0x73, + 0x65, 0x72, 0x49, 0x64, 0x12, 0x28, 0x0a, 0x08, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x42, 0x0c, 0xe0, 0x41, 0x02, 0xba, 0x48, 0x06, 0x72, 0x04, + 0x10, 0x01, 0x18, 0x40, 0x52, 0x08, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x22, 0x2d, + 0x0a, 0x13, 0x53, 0x65, 0x74, 0x50, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x64, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x64, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x32, 0xd0, 0x04, + 0x0a, 0x0b, 0x41, 0x75, 0x74, 0x68, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x78, 0x0a, + 0x0b, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x26, 0x2e, 0x73, + 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x76, + 0x31, 0x2e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x1a, 0x27, 0x2e, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, + 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, + 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x18, 0x82, + 0xd3, 0xe4, 0x93, 0x02, 0x12, 0x12, 0x10, 0x2f, 0x76, 0x31, 0x2f, 0x61, 0x75, 0x74, 0x68, 0x2f, + 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x65, 0x0a, 0x07, 0x47, 0x65, 0x74, 0x4a, 0x77, + 0x6b, 0x73, 0x12, 0x20, 0x2e, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x61, 0x75, + 0x74, 0x68, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x4a, 0x77, 0x6b, 0x73, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x1a, 0x21, 0x2e, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, + 0x61, 0x75, 0x74, 0x68, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x4a, 0x77, 0x6b, 0x73, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x15, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x0f, 0x12, + 0x0d, 0x2f, 0x76, 0x31, 0x2f, 0x61, 0x75, 0x74, 0x68, 0x2f, 0x6a, 0x77, 0x6b, 0x73, 0x12, 0x7b, + 0x0a, 0x0d, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x50, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x12, + 0x26, 0x2e, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x61, 0x75, 0x74, 0x68, 0x2e, + 0x76, 0x31, 0x2e, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x50, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x27, 0x2e, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, + 0x65, 0x74, 0x2e, 0x61, 0x75, 0x74, 0x68, 0x2e, 0x76, 0x31, 0x2e, 0x4c, 0x6f, 0x67, 0x69, 0x6e, + 0x50, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, + 0x22, 0x19, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x13, 0x3a, 0x01, 0x2a, 0x22, 0x0e, 0x2f, 0x76, 0x31, + 0x2f, 0x61, 0x75, 0x74, 0x68, 0x2f, 0x6c, 0x6f, 0x67, 0x69, 0x6e, 0x12, 0x78, 0x0a, 0x0b, 0x53, + 0x65, 0x74, 0x50, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x12, 0x24, 0x2e, 0x73, 0x74, 0x6f, + 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x61, 0x75, 0x74, 0x68, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x65, + 0x74, 0x50, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x1a, 0x25, 0x2e, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x61, 0x75, 0x74, 0x68, + 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x65, 0x74, 0x50, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x1c, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x16, 0x3a, + 0x01, 0x2a, 0x22, 0x11, 0x2f, 0x76, 0x31, 0x2f, 0x61, 0x75, 0x74, 0x68, 0x2f, 0x70, 0x61, 0x73, + 0x73, 0x77, 0x6f, 0x72, 0x64, 0x12, 0x69, 0x0a, 0x17, 0x50, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, + 0x55, 0x73, 0x65, 0x72, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x64, 0x45, 0x76, 0x65, 0x6e, 0x74, + 0x12, 0x24, 0x2e, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x65, 0x76, 0x65, 0x6e, + 0x74, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, + 0x64, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x10, + 0xfa, 0xd2, 0xe4, 0x93, 0x02, 0x0a, 0x12, 0x08, 0x49, 0x4e, 0x54, 0x45, 0x52, 0x4e, 0x41, 0x4c, + 0x42, 0x43, 0x5a, 0x41, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x68, + 0x65, 0x78, 0x6f, 0x6c, 0x61, 0x6e, 0x2f, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2f, + 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x67, 0x65, 0x6e, 0x2f, 0x61, 0x75, 0x74, 0x68, 0x2f, 0x76, 0x31, 0x3b, 0x61, 0x75, + 0x74, 0x68, 0x5f, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_stocklet_auth_v1_service_proto_rawDescOnce sync.Once + file_stocklet_auth_v1_service_proto_rawDescData = file_stocklet_auth_v1_service_proto_rawDesc +) + +func file_stocklet_auth_v1_service_proto_rawDescGZIP() []byte { + file_stocklet_auth_v1_service_proto_rawDescOnce.Do(func() { + file_stocklet_auth_v1_service_proto_rawDescData = protoimpl.X.CompressGZIP(file_stocklet_auth_v1_service_proto_rawDescData) + }) + return file_stocklet_auth_v1_service_proto_rawDescData +} + +var file_stocklet_auth_v1_service_proto_msgTypes = make([]protoimpl.MessageInfo, 6) +var file_stocklet_auth_v1_service_proto_goTypes = []interface{}{ + (*GetJwksRequest)(nil), // 0: stocklet.auth.v1.GetJwksRequest + (*GetJwksResponse)(nil), // 1: stocklet.auth.v1.GetJwksResponse + (*LoginPasswordRequest)(nil), // 2: stocklet.auth.v1.LoginPasswordRequest + (*LoginPasswordResponse)(nil), // 3: stocklet.auth.v1.LoginPasswordResponse + (*SetPasswordRequest)(nil), // 4: stocklet.auth.v1.SetPasswordRequest + (*SetPasswordResponse)(nil), // 5: stocklet.auth.v1.SetPasswordResponse + (*PublicEcJWK)(nil), // 6: stocklet.auth.v1.PublicEcJWK + (*AuthToken)(nil), // 7: stocklet.auth.v1.AuthToken + (*v1.ServiceInfoRequest)(nil), // 8: stocklet.common.v1.ServiceInfoRequest + (*v11.UserDeletedEvent)(nil), // 9: stocklet.events.v1.UserDeletedEvent + (*v1.ServiceInfoResponse)(nil), // 10: stocklet.common.v1.ServiceInfoResponse + (*emptypb.Empty)(nil), // 11: google.protobuf.Empty +} +var file_stocklet_auth_v1_service_proto_depIdxs = []int32{ + 6, // 0: stocklet.auth.v1.GetJwksResponse.keys:type_name -> stocklet.auth.v1.PublicEcJWK + 7, // 1: stocklet.auth.v1.LoginPasswordResponse.data:type_name -> stocklet.auth.v1.AuthToken + 8, // 2: stocklet.auth.v1.AuthService.ServiceInfo:input_type -> stocklet.common.v1.ServiceInfoRequest + 0, // 3: stocklet.auth.v1.AuthService.GetJwks:input_type -> stocklet.auth.v1.GetJwksRequest + 2, // 4: stocklet.auth.v1.AuthService.LoginPassword:input_type -> stocklet.auth.v1.LoginPasswordRequest + 4, // 5: stocklet.auth.v1.AuthService.SetPassword:input_type -> stocklet.auth.v1.SetPasswordRequest + 9, // 6: stocklet.auth.v1.AuthService.ProcessUserDeletedEvent:input_type -> stocklet.events.v1.UserDeletedEvent + 10, // 7: stocklet.auth.v1.AuthService.ServiceInfo:output_type -> stocklet.common.v1.ServiceInfoResponse + 1, // 8: stocklet.auth.v1.AuthService.GetJwks:output_type -> stocklet.auth.v1.GetJwksResponse + 3, // 9: stocklet.auth.v1.AuthService.LoginPassword:output_type -> stocklet.auth.v1.LoginPasswordResponse + 5, // 10: stocklet.auth.v1.AuthService.SetPassword:output_type -> stocklet.auth.v1.SetPasswordResponse + 11, // 11: stocklet.auth.v1.AuthService.ProcessUserDeletedEvent:output_type -> google.protobuf.Empty + 7, // [7:12] is the sub-list for method output_type + 2, // [2:7] is the sub-list for method input_type + 2, // [2:2] is the sub-list for extension type_name + 2, // [2:2] is the sub-list for extension extendee + 0, // [0:2] is the sub-list for field type_name +} + +func init() { file_stocklet_auth_v1_service_proto_init() } +func file_stocklet_auth_v1_service_proto_init() { + if File_stocklet_auth_v1_service_proto != nil { + return + } + file_stocklet_auth_v1_types_proto_init() + if !protoimpl.UnsafeEnabled { + file_stocklet_auth_v1_service_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetJwksRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_stocklet_auth_v1_service_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetJwksResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_stocklet_auth_v1_service_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*LoginPasswordRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_stocklet_auth_v1_service_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*LoginPasswordResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_stocklet_auth_v1_service_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*SetPasswordRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_stocklet_auth_v1_service_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*SetPasswordResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_stocklet_auth_v1_service_proto_rawDesc, + NumEnums: 0, + NumMessages: 6, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_stocklet_auth_v1_service_proto_goTypes, + DependencyIndexes: file_stocklet_auth_v1_service_proto_depIdxs, + MessageInfos: file_stocklet_auth_v1_service_proto_msgTypes, + }.Build() + File_stocklet_auth_v1_service_proto = out.File + file_stocklet_auth_v1_service_proto_rawDesc = nil + file_stocklet_auth_v1_service_proto_goTypes = nil + file_stocklet_auth_v1_service_proto_depIdxs = nil +} diff --git a/internal/pkg/protogen/auth/v1/service.pb.gw.go b/internal/pkg/protogen/auth/v1/service.pb.gw.go new file mode 100644 index 0000000..cc4ec53 --- /dev/null +++ b/internal/pkg/protogen/auth/v1/service.pb.gw.go @@ -0,0 +1,395 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: stocklet/auth/v1/service.proto + +/* +Package auth_v1 is a reverse proxy. + +It translates gRPC into RESTful JSON APIs. +*/ +package auth_v1 + +import ( + "context" + "io" + "net/http" + + "github.com/grpc-ecosystem/grpc-gateway/v2/runtime" + "github.com/grpc-ecosystem/grpc-gateway/v2/utilities" + "github.com/hexolan/stocklet/internal/pkg/protogen/common/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/status" + "google.golang.org/protobuf/proto" +) + +// Suppress "imported and not used" errors +var _ codes.Code +var _ io.Reader +var _ status.Status +var _ = runtime.String +var _ = utilities.NewDoubleArray +var _ = metadata.Join + +func request_AuthService_ServiceInfo_0(ctx context.Context, marshaler runtime.Marshaler, client AuthServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq common_v1.ServiceInfoRequest + var metadata runtime.ServerMetadata + + msg, err := client.ServiceInfo(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_AuthService_ServiceInfo_0(ctx context.Context, marshaler runtime.Marshaler, server AuthServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq common_v1.ServiceInfoRequest + var metadata runtime.ServerMetadata + + msg, err := server.ServiceInfo(ctx, &protoReq) + return msg, metadata, err + +} + +func request_AuthService_GetJwks_0(ctx context.Context, marshaler runtime.Marshaler, client AuthServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq GetJwksRequest + var metadata runtime.ServerMetadata + + msg, err := client.GetJwks(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_AuthService_GetJwks_0(ctx context.Context, marshaler runtime.Marshaler, server AuthServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq GetJwksRequest + var metadata runtime.ServerMetadata + + msg, err := server.GetJwks(ctx, &protoReq) + return msg, metadata, err + +} + +func request_AuthService_LoginPassword_0(ctx context.Context, marshaler runtime.Marshaler, client AuthServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq LoginPasswordRequest + var metadata runtime.ServerMetadata + + newReader, berr := utilities.IOReaderFactory(req.Body) + if berr != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) + } + if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.LoginPassword(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_AuthService_LoginPassword_0(ctx context.Context, marshaler runtime.Marshaler, server AuthServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq LoginPasswordRequest + var metadata runtime.ServerMetadata + + newReader, berr := utilities.IOReaderFactory(req.Body) + if berr != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) + } + if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.LoginPassword(ctx, &protoReq) + return msg, metadata, err + +} + +func request_AuthService_SetPassword_0(ctx context.Context, marshaler runtime.Marshaler, client AuthServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq SetPasswordRequest + var metadata runtime.ServerMetadata + + newReader, berr := utilities.IOReaderFactory(req.Body) + if berr != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) + } + if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.SetPassword(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_AuthService_SetPassword_0(ctx context.Context, marshaler runtime.Marshaler, server AuthServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq SetPasswordRequest + var metadata runtime.ServerMetadata + + newReader, berr := utilities.IOReaderFactory(req.Body) + if berr != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) + } + if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.SetPassword(ctx, &protoReq) + return msg, metadata, err + +} + +// RegisterAuthServiceHandlerServer registers the http handlers for service AuthService to "mux". +// UnaryRPC :call AuthServiceServer directly. +// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. +// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterAuthServiceHandlerFromEndpoint instead. +func RegisterAuthServiceHandlerServer(ctx context.Context, mux *runtime.ServeMux, server AuthServiceServer) error { + + mux.Handle("GET", pattern_AuthService_ServiceInfo_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/stocklet.auth.v1.AuthService/ServiceInfo", runtime.WithHTTPPathPattern("/v1/auth/service")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_AuthService_ServiceInfo_0(annotatedContext, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_AuthService_ServiceInfo_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_AuthService_GetJwks_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/stocklet.auth.v1.AuthService/GetJwks", runtime.WithHTTPPathPattern("/v1/auth/jwks")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_AuthService_GetJwks_0(annotatedContext, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_AuthService_GetJwks_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("POST", pattern_AuthService_LoginPassword_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/stocklet.auth.v1.AuthService/LoginPassword", runtime.WithHTTPPathPattern("/v1/auth/login")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_AuthService_LoginPassword_0(annotatedContext, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_AuthService_LoginPassword_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("POST", pattern_AuthService_SetPassword_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/stocklet.auth.v1.AuthService/SetPassword", runtime.WithHTTPPathPattern("/v1/auth/password")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_AuthService_SetPassword_0(annotatedContext, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_AuthService_SetPassword_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +// RegisterAuthServiceHandlerFromEndpoint is same as RegisterAuthServiceHandler but +// automatically dials to "endpoint" and closes the connection when "ctx" gets done. +func RegisterAuthServiceHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { + conn, err := grpc.DialContext(ctx, endpoint, opts...) + if err != nil { + return err + } + defer func() { + if err != nil { + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + return + } + go func() { + <-ctx.Done() + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + }() + }() + + return RegisterAuthServiceHandler(ctx, mux, conn) +} + +// RegisterAuthServiceHandler registers the http handlers for service AuthService to "mux". +// The handlers forward requests to the grpc endpoint over "conn". +func RegisterAuthServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { + return RegisterAuthServiceHandlerClient(ctx, mux, NewAuthServiceClient(conn)) +} + +// RegisterAuthServiceHandlerClient registers the http handlers for service AuthService +// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "AuthServiceClient". +// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "AuthServiceClient" +// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in +// "AuthServiceClient" to call the correct interceptors. +func RegisterAuthServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux, client AuthServiceClient) error { + + mux.Handle("GET", pattern_AuthService_ServiceInfo_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/stocklet.auth.v1.AuthService/ServiceInfo", runtime.WithHTTPPathPattern("/v1/auth/service")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_AuthService_ServiceInfo_0(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_AuthService_ServiceInfo_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_AuthService_GetJwks_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/stocklet.auth.v1.AuthService/GetJwks", runtime.WithHTTPPathPattern("/v1/auth/jwks")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_AuthService_GetJwks_0(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_AuthService_GetJwks_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("POST", pattern_AuthService_LoginPassword_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/stocklet.auth.v1.AuthService/LoginPassword", runtime.WithHTTPPathPattern("/v1/auth/login")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_AuthService_LoginPassword_0(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_AuthService_LoginPassword_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("POST", pattern_AuthService_SetPassword_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/stocklet.auth.v1.AuthService/SetPassword", runtime.WithHTTPPathPattern("/v1/auth/password")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_AuthService_SetPassword_0(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_AuthService_SetPassword_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +var ( + pattern_AuthService_ServiceInfo_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v1", "auth", "service"}, "")) + + pattern_AuthService_GetJwks_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v1", "auth", "jwks"}, "")) + + pattern_AuthService_LoginPassword_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v1", "auth", "login"}, "")) + + pattern_AuthService_SetPassword_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v1", "auth", "password"}, "")) +) + +var ( + forward_AuthService_ServiceInfo_0 = runtime.ForwardResponseMessage + + forward_AuthService_GetJwks_0 = runtime.ForwardResponseMessage + + forward_AuthService_LoginPassword_0 = runtime.ForwardResponseMessage + + forward_AuthService_SetPassword_0 = runtime.ForwardResponseMessage +) diff --git a/internal/pkg/protogen/auth/v1/service_grpc.pb.go b/internal/pkg/protogen/auth/v1/service_grpc.pb.go new file mode 100644 index 0000000..c284114 --- /dev/null +++ b/internal/pkg/protogen/auth/v1/service_grpc.pb.go @@ -0,0 +1,291 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.3.0 +// - protoc (unknown) +// source: stocklet/auth/v1/service.proto + +package auth_v1 + +import ( + context "context" + v1 "github.com/hexolan/stocklet/internal/pkg/protogen/common/v1" + v11 "github.com/hexolan/stocklet/internal/pkg/protogen/events/v1" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + emptypb "google.golang.org/protobuf/types/known/emptypb" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.32.0 or later. +const _ = grpc.SupportPackageIsVersion7 + +const ( + AuthService_ServiceInfo_FullMethodName = "/stocklet.auth.v1.AuthService/ServiceInfo" + AuthService_GetJwks_FullMethodName = "/stocklet.auth.v1.AuthService/GetJwks" + AuthService_LoginPassword_FullMethodName = "/stocklet.auth.v1.AuthService/LoginPassword" + AuthService_SetPassword_FullMethodName = "/stocklet.auth.v1.AuthService/SetPassword" + AuthService_ProcessUserDeletedEvent_FullMethodName = "/stocklet.auth.v1.AuthService/ProcessUserDeletedEvent" +) + +// AuthServiceClient is the client API for AuthService service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +type AuthServiceClient interface { + // View information about the service. + // + // buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + ServiceInfo(ctx context.Context, in *v1.ServiceInfoRequest, opts ...grpc.CallOption) (*v1.ServiceInfoResponse, error) + GetJwks(ctx context.Context, in *GetJwksRequest, opts ...grpc.CallOption) (*GetJwksResponse, error) + LoginPassword(ctx context.Context, in *LoginPasswordRequest, opts ...grpc.CallOption) (*LoginPasswordResponse, error) + SetPassword(ctx context.Context, in *SetPasswordRequest, opts ...grpc.CallOption) (*SetPasswordResponse, error) + // A consumer will call this method to process events. + // + // buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + // buf:lint:ignore RPC_REQUEST_STANDARD_NAME + // buf:lint:ignore RPC_RESPONSE_STANDARD_NAME + ProcessUserDeletedEvent(ctx context.Context, in *v11.UserDeletedEvent, opts ...grpc.CallOption) (*emptypb.Empty, error) +} + +type authServiceClient struct { + cc grpc.ClientConnInterface +} + +func NewAuthServiceClient(cc grpc.ClientConnInterface) AuthServiceClient { + return &authServiceClient{cc} +} + +func (c *authServiceClient) ServiceInfo(ctx context.Context, in *v1.ServiceInfoRequest, opts ...grpc.CallOption) (*v1.ServiceInfoResponse, error) { + out := new(v1.ServiceInfoResponse) + err := c.cc.Invoke(ctx, AuthService_ServiceInfo_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *authServiceClient) GetJwks(ctx context.Context, in *GetJwksRequest, opts ...grpc.CallOption) (*GetJwksResponse, error) { + out := new(GetJwksResponse) + err := c.cc.Invoke(ctx, AuthService_GetJwks_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *authServiceClient) LoginPassword(ctx context.Context, in *LoginPasswordRequest, opts ...grpc.CallOption) (*LoginPasswordResponse, error) { + out := new(LoginPasswordResponse) + err := c.cc.Invoke(ctx, AuthService_LoginPassword_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *authServiceClient) SetPassword(ctx context.Context, in *SetPasswordRequest, opts ...grpc.CallOption) (*SetPasswordResponse, error) { + out := new(SetPasswordResponse) + err := c.cc.Invoke(ctx, AuthService_SetPassword_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *authServiceClient) ProcessUserDeletedEvent(ctx context.Context, in *v11.UserDeletedEvent, opts ...grpc.CallOption) (*emptypb.Empty, error) { + out := new(emptypb.Empty) + err := c.cc.Invoke(ctx, AuthService_ProcessUserDeletedEvent_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// AuthServiceServer is the server API for AuthService service. +// All implementations must embed UnimplementedAuthServiceServer +// for forward compatibility +type AuthServiceServer interface { + // View information about the service. + // + // buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + ServiceInfo(context.Context, *v1.ServiceInfoRequest) (*v1.ServiceInfoResponse, error) + GetJwks(context.Context, *GetJwksRequest) (*GetJwksResponse, error) + LoginPassword(context.Context, *LoginPasswordRequest) (*LoginPasswordResponse, error) + SetPassword(context.Context, *SetPasswordRequest) (*SetPasswordResponse, error) + // A consumer will call this method to process events. + // + // buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + // buf:lint:ignore RPC_REQUEST_STANDARD_NAME + // buf:lint:ignore RPC_RESPONSE_STANDARD_NAME + ProcessUserDeletedEvent(context.Context, *v11.UserDeletedEvent) (*emptypb.Empty, error) + mustEmbedUnimplementedAuthServiceServer() +} + +// UnimplementedAuthServiceServer must be embedded to have forward compatible implementations. +type UnimplementedAuthServiceServer struct { +} + +func (UnimplementedAuthServiceServer) ServiceInfo(context.Context, *v1.ServiceInfoRequest) (*v1.ServiceInfoResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method ServiceInfo not implemented") +} +func (UnimplementedAuthServiceServer) GetJwks(context.Context, *GetJwksRequest) (*GetJwksResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetJwks not implemented") +} +func (UnimplementedAuthServiceServer) LoginPassword(context.Context, *LoginPasswordRequest) (*LoginPasswordResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method LoginPassword not implemented") +} +func (UnimplementedAuthServiceServer) SetPassword(context.Context, *SetPasswordRequest) (*SetPasswordResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method SetPassword not implemented") +} +func (UnimplementedAuthServiceServer) ProcessUserDeletedEvent(context.Context, *v11.UserDeletedEvent) (*emptypb.Empty, error) { + return nil, status.Errorf(codes.Unimplemented, "method ProcessUserDeletedEvent not implemented") +} +func (UnimplementedAuthServiceServer) mustEmbedUnimplementedAuthServiceServer() {} + +// UnsafeAuthServiceServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to AuthServiceServer will +// result in compilation errors. +type UnsafeAuthServiceServer interface { + mustEmbedUnimplementedAuthServiceServer() +} + +func RegisterAuthServiceServer(s grpc.ServiceRegistrar, srv AuthServiceServer) { + s.RegisterService(&AuthService_ServiceDesc, srv) +} + +func _AuthService_ServiceInfo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(v1.ServiceInfoRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(AuthServiceServer).ServiceInfo(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: AuthService_ServiceInfo_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(AuthServiceServer).ServiceInfo(ctx, req.(*v1.ServiceInfoRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _AuthService_GetJwks_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetJwksRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(AuthServiceServer).GetJwks(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: AuthService_GetJwks_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(AuthServiceServer).GetJwks(ctx, req.(*GetJwksRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _AuthService_LoginPassword_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(LoginPasswordRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(AuthServiceServer).LoginPassword(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: AuthService_LoginPassword_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(AuthServiceServer).LoginPassword(ctx, req.(*LoginPasswordRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _AuthService_SetPassword_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(SetPasswordRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(AuthServiceServer).SetPassword(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: AuthService_SetPassword_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(AuthServiceServer).SetPassword(ctx, req.(*SetPasswordRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _AuthService_ProcessUserDeletedEvent_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(v11.UserDeletedEvent) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(AuthServiceServer).ProcessUserDeletedEvent(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: AuthService_ProcessUserDeletedEvent_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(AuthServiceServer).ProcessUserDeletedEvent(ctx, req.(*v11.UserDeletedEvent)) + } + return interceptor(ctx, in, info, handler) +} + +// AuthService_ServiceDesc is the grpc.ServiceDesc for AuthService service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var AuthService_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "stocklet.auth.v1.AuthService", + HandlerType: (*AuthServiceServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "ServiceInfo", + Handler: _AuthService_ServiceInfo_Handler, + }, + { + MethodName: "GetJwks", + Handler: _AuthService_GetJwks_Handler, + }, + { + MethodName: "LoginPassword", + Handler: _AuthService_LoginPassword_Handler, + }, + { + MethodName: "SetPassword", + Handler: _AuthService_SetPassword_Handler, + }, + { + MethodName: "ProcessUserDeletedEvent", + Handler: _AuthService_ProcessUserDeletedEvent_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "stocklet/auth/v1/service.proto", +} diff --git a/internal/pkg/protogen/auth/v1/types.pb.go b/internal/pkg/protogen/auth/v1/types.pb.go new file mode 100644 index 0000000..a540dd6 --- /dev/null +++ b/internal/pkg/protogen/auth/v1/types.pb.go @@ -0,0 +1,289 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.31.0 +// protoc (unknown) +// source: stocklet/auth/v1/types.proto + +package auth_v1 + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type PublicEcJWK struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Kty string `protobuf:"bytes,1,opt,name=kty,proto3" json:"kty,omitempty"` + Use string `protobuf:"bytes,2,opt,name=use,proto3" json:"use,omitempty"` + Alg string `protobuf:"bytes,3,opt,name=alg,proto3" json:"alg,omitempty"` + Crv string `protobuf:"bytes,4,opt,name=crv,proto3" json:"crv,omitempty"` + X string `protobuf:"bytes,5,opt,name=x,proto3" json:"x,omitempty"` + Y string `protobuf:"bytes,6,opt,name=y,proto3" json:"y,omitempty"` +} + +func (x *PublicEcJWK) Reset() { + *x = PublicEcJWK{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_auth_v1_types_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *PublicEcJWK) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*PublicEcJWK) ProtoMessage() {} + +func (x *PublicEcJWK) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_auth_v1_types_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use PublicEcJWK.ProtoReflect.Descriptor instead. +func (*PublicEcJWK) Descriptor() ([]byte, []int) { + return file_stocklet_auth_v1_types_proto_rawDescGZIP(), []int{0} +} + +func (x *PublicEcJWK) GetKty() string { + if x != nil { + return x.Kty + } + return "" +} + +func (x *PublicEcJWK) GetUse() string { + if x != nil { + return x.Use + } + return "" +} + +func (x *PublicEcJWK) GetAlg() string { + if x != nil { + return x.Alg + } + return "" +} + +func (x *PublicEcJWK) GetCrv() string { + if x != nil { + return x.Crv + } + return "" +} + +func (x *PublicEcJWK) GetX() string { + if x != nil { + return x.X + } + return "" +} + +func (x *PublicEcJWK) GetY() string { + if x != nil { + return x.Y + } + return "" +} + +type AuthToken struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + TokenType string `protobuf:"bytes,1,opt,name=token_type,json=tokenType,proto3" json:"token_type,omitempty"` + AccessToken string `protobuf:"bytes,2,opt,name=access_token,json=accessToken,proto3" json:"access_token,omitempty"` + ExpiresIn int64 `protobuf:"varint,3,opt,name=expires_in,json=expiresIn,proto3" json:"expires_in,omitempty"` +} + +func (x *AuthToken) Reset() { + *x = AuthToken{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_auth_v1_types_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *AuthToken) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AuthToken) ProtoMessage() {} + +func (x *AuthToken) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_auth_v1_types_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use AuthToken.ProtoReflect.Descriptor instead. +func (*AuthToken) Descriptor() ([]byte, []int) { + return file_stocklet_auth_v1_types_proto_rawDescGZIP(), []int{1} +} + +func (x *AuthToken) GetTokenType() string { + if x != nil { + return x.TokenType + } + return "" +} + +func (x *AuthToken) GetAccessToken() string { + if x != nil { + return x.AccessToken + } + return "" +} + +func (x *AuthToken) GetExpiresIn() int64 { + if x != nil { + return x.ExpiresIn + } + return 0 +} + +var File_stocklet_auth_v1_types_proto protoreflect.FileDescriptor + +var file_stocklet_auth_v1_types_proto_rawDesc = []byte{ + 0x0a, 0x1c, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2f, 0x61, 0x75, 0x74, 0x68, 0x2f, + 0x76, 0x31, 0x2f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x10, + 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x61, 0x75, 0x74, 0x68, 0x2e, 0x76, 0x31, + 0x22, 0x71, 0x0a, 0x0b, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x45, 0x63, 0x4a, 0x57, 0x4b, 0x12, + 0x10, 0x0a, 0x03, 0x6b, 0x74, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x74, + 0x79, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x73, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, + 0x75, 0x73, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x61, 0x6c, 0x67, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x03, 0x61, 0x6c, 0x67, 0x12, 0x10, 0x0a, 0x03, 0x63, 0x72, 0x76, 0x18, 0x04, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x03, 0x63, 0x72, 0x76, 0x12, 0x0c, 0x0a, 0x01, 0x78, 0x18, 0x05, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x01, 0x78, 0x12, 0x0c, 0x0a, 0x01, 0x79, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x01, 0x79, 0x22, 0x6c, 0x0a, 0x09, 0x41, 0x75, 0x74, 0x68, 0x54, 0x6f, 0x6b, 0x65, 0x6e, + 0x12, 0x1d, 0x0a, 0x0a, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x54, 0x79, 0x70, 0x65, 0x12, + 0x21, 0x0a, 0x0c, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0x54, 0x6f, 0x6b, + 0x65, 0x6e, 0x12, 0x1d, 0x0a, 0x0a, 0x65, 0x78, 0x70, 0x69, 0x72, 0x65, 0x73, 0x5f, 0x69, 0x6e, + 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x65, 0x78, 0x70, 0x69, 0x72, 0x65, 0x73, 0x49, + 0x6e, 0x42, 0x43, 0x5a, 0x41, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, + 0x68, 0x65, 0x78, 0x6f, 0x6c, 0x61, 0x6e, 0x2f, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, + 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x67, 0x65, 0x6e, 0x2f, 0x61, 0x75, 0x74, 0x68, 0x2f, 0x76, 0x31, 0x3b, 0x61, + 0x75, 0x74, 0x68, 0x5f, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_stocklet_auth_v1_types_proto_rawDescOnce sync.Once + file_stocklet_auth_v1_types_proto_rawDescData = file_stocklet_auth_v1_types_proto_rawDesc +) + +func file_stocklet_auth_v1_types_proto_rawDescGZIP() []byte { + file_stocklet_auth_v1_types_proto_rawDescOnce.Do(func() { + file_stocklet_auth_v1_types_proto_rawDescData = protoimpl.X.CompressGZIP(file_stocklet_auth_v1_types_proto_rawDescData) + }) + return file_stocklet_auth_v1_types_proto_rawDescData +} + +var file_stocklet_auth_v1_types_proto_msgTypes = make([]protoimpl.MessageInfo, 2) +var file_stocklet_auth_v1_types_proto_goTypes = []interface{}{ + (*PublicEcJWK)(nil), // 0: stocklet.auth.v1.PublicEcJWK + (*AuthToken)(nil), // 1: stocklet.auth.v1.AuthToken +} +var file_stocklet_auth_v1_types_proto_depIdxs = []int32{ + 0, // [0:0] is the sub-list for method output_type + 0, // [0:0] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_stocklet_auth_v1_types_proto_init() } +func file_stocklet_auth_v1_types_proto_init() { + if File_stocklet_auth_v1_types_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_stocklet_auth_v1_types_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*PublicEcJWK); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_stocklet_auth_v1_types_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*AuthToken); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_stocklet_auth_v1_types_proto_rawDesc, + NumEnums: 0, + NumMessages: 2, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_stocklet_auth_v1_types_proto_goTypes, + DependencyIndexes: file_stocklet_auth_v1_types_proto_depIdxs, + MessageInfos: file_stocklet_auth_v1_types_proto_msgTypes, + }.Build() + File_stocklet_auth_v1_types_proto = out.File + file_stocklet_auth_v1_types_proto_rawDesc = nil + file_stocklet_auth_v1_types_proto_goTypes = nil + file_stocklet_auth_v1_types_proto_depIdxs = nil +} diff --git a/internal/pkg/protogen/common/v1/requests.pb.go b/internal/pkg/protogen/common/v1/requests.pb.go new file mode 100644 index 0000000..32ed4f0 --- /dev/null +++ b/internal/pkg/protogen/common/v1/requests.pb.go @@ -0,0 +1,235 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.31.0 +// protoc (unknown) +// source: stocklet/common/v1/requests.proto + +package common_v1 + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type ServiceInfoRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *ServiceInfoRequest) Reset() { + *x = ServiceInfoRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_common_v1_requests_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ServiceInfoRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ServiceInfoRequest) ProtoMessage() {} + +func (x *ServiceInfoRequest) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_common_v1_requests_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ServiceInfoRequest.ProtoReflect.Descriptor instead. +func (*ServiceInfoRequest) Descriptor() ([]byte, []int) { + return file_stocklet_common_v1_requests_proto_rawDescGZIP(), []int{0} +} + +type ServiceInfoResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + Source string `protobuf:"bytes,2,opt,name=source,proto3" json:"source,omitempty"` + SourceLicense string `protobuf:"bytes,3,opt,name=source_license,json=sourceLicense,proto3" json:"source_license,omitempty"` +} + +func (x *ServiceInfoResponse) Reset() { + *x = ServiceInfoResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_common_v1_requests_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ServiceInfoResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ServiceInfoResponse) ProtoMessage() {} + +func (x *ServiceInfoResponse) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_common_v1_requests_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ServiceInfoResponse.ProtoReflect.Descriptor instead. +func (*ServiceInfoResponse) Descriptor() ([]byte, []int) { + return file_stocklet_common_v1_requests_proto_rawDescGZIP(), []int{1} +} + +func (x *ServiceInfoResponse) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +func (x *ServiceInfoResponse) GetSource() string { + if x != nil { + return x.Source + } + return "" +} + +func (x *ServiceInfoResponse) GetSourceLicense() string { + if x != nil { + return x.SourceLicense + } + return "" +} + +var File_stocklet_common_v1_requests_proto protoreflect.FileDescriptor + +var file_stocklet_common_v1_requests_proto_rawDesc = []byte{ + 0x0a, 0x21, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2f, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, + 0x6e, 0x2f, 0x76, 0x31, 0x2f, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x73, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x12, 0x12, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x63, 0x6f, + 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x76, 0x31, 0x22, 0x14, 0x0a, 0x12, 0x53, 0x65, 0x72, 0x76, 0x69, + 0x63, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x68, 0x0a, + 0x13, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x6f, 0x75, 0x72, + 0x63, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, + 0x12, 0x25, 0x0a, 0x0e, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x5f, 0x6c, 0x69, 0x63, 0x65, 0x6e, + 0x73, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, + 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x42, 0x47, 0x5a, 0x45, 0x67, 0x69, 0x74, 0x68, 0x75, + 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x68, 0x65, 0x78, 0x6f, 0x6c, 0x61, 0x6e, 0x2f, 0x73, 0x74, + 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, + 0x70, 0x6b, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x67, 0x65, 0x6e, 0x2f, 0x63, 0x6f, 0x6d, + 0x6d, 0x6f, 0x6e, 0x2f, 0x76, 0x31, 0x3b, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x5f, 0x76, 0x31, + 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_stocklet_common_v1_requests_proto_rawDescOnce sync.Once + file_stocklet_common_v1_requests_proto_rawDescData = file_stocklet_common_v1_requests_proto_rawDesc +) + +func file_stocklet_common_v1_requests_proto_rawDescGZIP() []byte { + file_stocklet_common_v1_requests_proto_rawDescOnce.Do(func() { + file_stocklet_common_v1_requests_proto_rawDescData = protoimpl.X.CompressGZIP(file_stocklet_common_v1_requests_proto_rawDescData) + }) + return file_stocklet_common_v1_requests_proto_rawDescData +} + +var file_stocklet_common_v1_requests_proto_msgTypes = make([]protoimpl.MessageInfo, 2) +var file_stocklet_common_v1_requests_proto_goTypes = []interface{}{ + (*ServiceInfoRequest)(nil), // 0: stocklet.common.v1.ServiceInfoRequest + (*ServiceInfoResponse)(nil), // 1: stocklet.common.v1.ServiceInfoResponse +} +var file_stocklet_common_v1_requests_proto_depIdxs = []int32{ + 0, // [0:0] is the sub-list for method output_type + 0, // [0:0] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_stocklet_common_v1_requests_proto_init() } +func file_stocklet_common_v1_requests_proto_init() { + if File_stocklet_common_v1_requests_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_stocklet_common_v1_requests_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ServiceInfoRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_stocklet_common_v1_requests_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ServiceInfoResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_stocklet_common_v1_requests_proto_rawDesc, + NumEnums: 0, + NumMessages: 2, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_stocklet_common_v1_requests_proto_goTypes, + DependencyIndexes: file_stocklet_common_v1_requests_proto_depIdxs, + MessageInfos: file_stocklet_common_v1_requests_proto_msgTypes, + }.Build() + File_stocklet_common_v1_requests_proto = out.File + file_stocklet_common_v1_requests_proto_rawDesc = nil + file_stocklet_common_v1_requests_proto_goTypes = nil + file_stocklet_common_v1_requests_proto_depIdxs = nil +} diff --git a/internal/pkg/protogen/events/v1/order.pb.go b/internal/pkg/protogen/events/v1/order.pb.go new file mode 100644 index 0000000..5395c7c --- /dev/null +++ b/internal/pkg/protogen/events/v1/order.pb.go @@ -0,0 +1,521 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.31.0 +// protoc (unknown) +// source: stocklet/events/v1/order.proto + +package events_v1 + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +// Order Status = processing +type OrderCreatedEvent struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Revision int32 `protobuf:"varint,1,opt,name=revision,proto3" json:"revision,omitempty"` + OrderId string `protobuf:"bytes,2,opt,name=order_id,json=orderId,proto3" json:"order_id,omitempty"` + CustomerId string `protobuf:"bytes,3,opt,name=customer_id,json=customerId,proto3" json:"customer_id,omitempty"` + ItemQuantities map[string]int32 `protobuf:"bytes,4,rep,name=item_quantities,json=itemQuantities,proto3" json:"item_quantities,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` +} + +func (x *OrderCreatedEvent) Reset() { + *x = OrderCreatedEvent{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_events_v1_order_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *OrderCreatedEvent) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*OrderCreatedEvent) ProtoMessage() {} + +func (x *OrderCreatedEvent) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_events_v1_order_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use OrderCreatedEvent.ProtoReflect.Descriptor instead. +func (*OrderCreatedEvent) Descriptor() ([]byte, []int) { + return file_stocklet_events_v1_order_proto_rawDescGZIP(), []int{0} +} + +func (x *OrderCreatedEvent) GetRevision() int32 { + if x != nil { + return x.Revision + } + return 0 +} + +func (x *OrderCreatedEvent) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +func (x *OrderCreatedEvent) GetCustomerId() string { + if x != nil { + return x.CustomerId + } + return "" +} + +func (x *OrderCreatedEvent) GetItemQuantities() map[string]int32 { + if x != nil { + return x.ItemQuantities + } + return nil +} + +// Order Status = pending +type OrderPendingEvent struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Revision int32 `protobuf:"varint,1,opt,name=revision,proto3" json:"revision,omitempty"` + OrderId string `protobuf:"bytes,2,opt,name=order_id,json=orderId,proto3" json:"order_id,omitempty"` + CustomerId string `protobuf:"bytes,3,opt,name=customer_id,json=customerId,proto3" json:"customer_id,omitempty"` + ItemQuantities map[string]int32 `protobuf:"bytes,4,rep,name=item_quantities,json=itemQuantities,proto3" json:"item_quantities,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` + ItemsPrice float32 `protobuf:"fixed32,5,opt,name=items_price,json=itemsPrice,proto3" json:"items_price,omitempty"` + TotalPrice float32 `protobuf:"fixed32,6,opt,name=total_price,json=totalPrice,proto3" json:"total_price,omitempty"` +} + +func (x *OrderPendingEvent) Reset() { + *x = OrderPendingEvent{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_events_v1_order_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *OrderPendingEvent) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*OrderPendingEvent) ProtoMessage() {} + +func (x *OrderPendingEvent) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_events_v1_order_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use OrderPendingEvent.ProtoReflect.Descriptor instead. +func (*OrderPendingEvent) Descriptor() ([]byte, []int) { + return file_stocklet_events_v1_order_proto_rawDescGZIP(), []int{1} +} + +func (x *OrderPendingEvent) GetRevision() int32 { + if x != nil { + return x.Revision + } + return 0 +} + +func (x *OrderPendingEvent) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +func (x *OrderPendingEvent) GetCustomerId() string { + if x != nil { + return x.CustomerId + } + return "" +} + +func (x *OrderPendingEvent) GetItemQuantities() map[string]int32 { + if x != nil { + return x.ItemQuantities + } + return nil +} + +func (x *OrderPendingEvent) GetItemsPrice() float32 { + if x != nil { + return x.ItemsPrice + } + return 0 +} + +func (x *OrderPendingEvent) GetTotalPrice() float32 { + if x != nil { + return x.TotalPrice + } + return 0 +} + +// Order Status = rejected +type OrderRejectedEvent struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Revision int32 `protobuf:"varint,1,opt,name=revision,proto3" json:"revision,omitempty"` + OrderId string `protobuf:"bytes,2,opt,name=order_id,json=orderId,proto3" json:"order_id,omitempty"` + TransactionId *string `protobuf:"bytes,3,opt,name=transaction_id,json=transactionId,proto3,oneof" json:"transaction_id,omitempty"` + ShippingId *string `protobuf:"bytes,4,opt,name=shipping_id,json=shippingId,proto3,oneof" json:"shipping_id,omitempty"` +} + +func (x *OrderRejectedEvent) Reset() { + *x = OrderRejectedEvent{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_events_v1_order_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *OrderRejectedEvent) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*OrderRejectedEvent) ProtoMessage() {} + +func (x *OrderRejectedEvent) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_events_v1_order_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use OrderRejectedEvent.ProtoReflect.Descriptor instead. +func (*OrderRejectedEvent) Descriptor() ([]byte, []int) { + return file_stocklet_events_v1_order_proto_rawDescGZIP(), []int{2} +} + +func (x *OrderRejectedEvent) GetRevision() int32 { + if x != nil { + return x.Revision + } + return 0 +} + +func (x *OrderRejectedEvent) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +func (x *OrderRejectedEvent) GetTransactionId() string { + if x != nil && x.TransactionId != nil { + return *x.TransactionId + } + return "" +} + +func (x *OrderRejectedEvent) GetShippingId() string { + if x != nil && x.ShippingId != nil { + return *x.ShippingId + } + return "" +} + +// Order Status = approved +type OrderApprovedEvent struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Revision int32 `protobuf:"varint,1,opt,name=revision,proto3" json:"revision,omitempty"` + OrderId string `protobuf:"bytes,2,opt,name=order_id,json=orderId,proto3" json:"order_id,omitempty"` + TransactionId string `protobuf:"bytes,3,opt,name=transaction_id,json=transactionId,proto3" json:"transaction_id,omitempty"` + ShippingId string `protobuf:"bytes,4,opt,name=shipping_id,json=shippingId,proto3" json:"shipping_id,omitempty"` +} + +func (x *OrderApprovedEvent) Reset() { + *x = OrderApprovedEvent{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_events_v1_order_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *OrderApprovedEvent) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*OrderApprovedEvent) ProtoMessage() {} + +func (x *OrderApprovedEvent) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_events_v1_order_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use OrderApprovedEvent.ProtoReflect.Descriptor instead. +func (*OrderApprovedEvent) Descriptor() ([]byte, []int) { + return file_stocklet_events_v1_order_proto_rawDescGZIP(), []int{3} +} + +func (x *OrderApprovedEvent) GetRevision() int32 { + if x != nil { + return x.Revision + } + return 0 +} + +func (x *OrderApprovedEvent) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +func (x *OrderApprovedEvent) GetTransactionId() string { + if x != nil { + return x.TransactionId + } + return "" +} + +func (x *OrderApprovedEvent) GetShippingId() string { + if x != nil { + return x.ShippingId + } + return "" +} + +var File_stocklet_events_v1_order_proto protoreflect.FileDescriptor + +var file_stocklet_events_v1_order_proto_rawDesc = []byte{ + 0x0a, 0x1e, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2f, 0x65, 0x76, 0x65, 0x6e, 0x74, + 0x73, 0x2f, 0x76, 0x31, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x12, 0x12, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x65, 0x76, 0x65, 0x6e, 0x74, + 0x73, 0x2e, 0x76, 0x31, 0x22, 0x92, 0x02, 0x0a, 0x11, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x43, 0x72, + 0x65, 0x61, 0x74, 0x65, 0x64, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x72, 0x65, + 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x72, 0x65, + 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x19, 0x0a, 0x08, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, + 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, + 0x64, 0x12, 0x1f, 0x0a, 0x0b, 0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x65, 0x72, 0x5f, 0x69, 0x64, + 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x65, 0x72, + 0x49, 0x64, 0x12, 0x62, 0x0a, 0x0f, 0x69, 0x74, 0x65, 0x6d, 0x5f, 0x71, 0x75, 0x61, 0x6e, 0x74, + 0x69, 0x74, 0x69, 0x65, 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x39, 0x2e, 0x73, 0x74, + 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x2e, 0x76, 0x31, + 0x2e, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x45, 0x76, 0x65, + 0x6e, 0x74, 0x2e, 0x49, 0x74, 0x65, 0x6d, 0x51, 0x75, 0x61, 0x6e, 0x74, 0x69, 0x74, 0x69, 0x65, + 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x0e, 0x69, 0x74, 0x65, 0x6d, 0x51, 0x75, 0x61, 0x6e, + 0x74, 0x69, 0x74, 0x69, 0x65, 0x73, 0x1a, 0x41, 0x0a, 0x13, 0x49, 0x74, 0x65, 0x6d, 0x51, 0x75, + 0x61, 0x6e, 0x74, 0x69, 0x74, 0x69, 0x65, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, + 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, + 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, + 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0xd4, 0x02, 0x0a, 0x11, 0x4f, 0x72, + 0x64, 0x65, 0x72, 0x50, 0x65, 0x6e, 0x64, 0x69, 0x6e, 0x67, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, + 0x1a, 0x0a, 0x08, 0x72, 0x65, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x05, 0x52, 0x08, 0x72, 0x65, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x19, 0x0a, 0x08, 0x6f, + 0x72, 0x64, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, + 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x12, 0x1f, 0x0a, 0x0b, 0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d, + 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x63, 0x75, 0x73, + 0x74, 0x6f, 0x6d, 0x65, 0x72, 0x49, 0x64, 0x12, 0x62, 0x0a, 0x0f, 0x69, 0x74, 0x65, 0x6d, 0x5f, + 0x71, 0x75, 0x61, 0x6e, 0x74, 0x69, 0x74, 0x69, 0x65, 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x0b, + 0x32, 0x39, 0x2e, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x65, 0x76, 0x65, 0x6e, + 0x74, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x50, 0x65, 0x6e, 0x64, 0x69, + 0x6e, 0x67, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x2e, 0x49, 0x74, 0x65, 0x6d, 0x51, 0x75, 0x61, 0x6e, + 0x74, 0x69, 0x74, 0x69, 0x65, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x0e, 0x69, 0x74, 0x65, + 0x6d, 0x51, 0x75, 0x61, 0x6e, 0x74, 0x69, 0x74, 0x69, 0x65, 0x73, 0x12, 0x1f, 0x0a, 0x0b, 0x69, + 0x74, 0x65, 0x6d, 0x73, 0x5f, 0x70, 0x72, 0x69, 0x63, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x02, + 0x52, 0x0a, 0x69, 0x74, 0x65, 0x6d, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x1f, 0x0a, 0x0b, + 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x5f, 0x70, 0x72, 0x69, 0x63, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, + 0x02, 0x52, 0x0a, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x50, 0x72, 0x69, 0x63, 0x65, 0x1a, 0x41, 0x0a, + 0x13, 0x49, 0x74, 0x65, 0x6d, 0x51, 0x75, 0x61, 0x6e, 0x74, 0x69, 0x74, 0x69, 0x65, 0x73, 0x45, + 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, + 0x22, 0xc0, 0x01, 0x0a, 0x12, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x6a, 0x65, 0x63, 0x74, + 0x65, 0x64, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x72, 0x65, 0x76, 0x69, 0x73, + 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x72, 0x65, 0x76, 0x69, 0x73, + 0x69, 0x6f, 0x6e, 0x12, 0x19, 0x0a, 0x08, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x12, 0x2a, + 0x0a, 0x0e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x69, 0x64, + 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x48, 0x00, 0x52, 0x0d, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x61, + 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x88, 0x01, 0x01, 0x12, 0x24, 0x0a, 0x0b, 0x73, 0x68, + 0x69, 0x70, 0x70, 0x69, 0x6e, 0x67, 0x5f, 0x69, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x48, + 0x01, 0x52, 0x0a, 0x73, 0x68, 0x69, 0x70, 0x70, 0x69, 0x6e, 0x67, 0x49, 0x64, 0x88, 0x01, 0x01, + 0x42, 0x11, 0x0a, 0x0f, 0x5f, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, + 0x5f, 0x69, 0x64, 0x42, 0x0e, 0x0a, 0x0c, 0x5f, 0x73, 0x68, 0x69, 0x70, 0x70, 0x69, 0x6e, 0x67, + 0x5f, 0x69, 0x64, 0x22, 0x93, 0x01, 0x0a, 0x12, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x41, 0x70, 0x70, + 0x72, 0x6f, 0x76, 0x65, 0x64, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x72, 0x65, + 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x72, 0x65, + 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x19, 0x0a, 0x08, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, + 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, + 0x64, 0x12, 0x25, 0x0a, 0x0e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, + 0x5f, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x74, 0x72, 0x61, 0x6e, 0x73, + 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x12, 0x1f, 0x0a, 0x0b, 0x73, 0x68, 0x69, 0x70, + 0x70, 0x69, 0x6e, 0x67, 0x5f, 0x69, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x73, + 0x68, 0x69, 0x70, 0x70, 0x69, 0x6e, 0x67, 0x49, 0x64, 0x42, 0x47, 0x5a, 0x45, 0x67, 0x69, 0x74, + 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x68, 0x65, 0x78, 0x6f, 0x6c, 0x61, 0x6e, 0x2f, + 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, + 0x6c, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x67, 0x65, 0x6e, 0x2f, 0x65, + 0x76, 0x65, 0x6e, 0x74, 0x73, 0x2f, 0x76, 0x31, 0x3b, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x5f, + 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_stocklet_events_v1_order_proto_rawDescOnce sync.Once + file_stocklet_events_v1_order_proto_rawDescData = file_stocklet_events_v1_order_proto_rawDesc +) + +func file_stocklet_events_v1_order_proto_rawDescGZIP() []byte { + file_stocklet_events_v1_order_proto_rawDescOnce.Do(func() { + file_stocklet_events_v1_order_proto_rawDescData = protoimpl.X.CompressGZIP(file_stocklet_events_v1_order_proto_rawDescData) + }) + return file_stocklet_events_v1_order_proto_rawDescData +} + +var file_stocklet_events_v1_order_proto_msgTypes = make([]protoimpl.MessageInfo, 6) +var file_stocklet_events_v1_order_proto_goTypes = []interface{}{ + (*OrderCreatedEvent)(nil), // 0: stocklet.events.v1.OrderCreatedEvent + (*OrderPendingEvent)(nil), // 1: stocklet.events.v1.OrderPendingEvent + (*OrderRejectedEvent)(nil), // 2: stocklet.events.v1.OrderRejectedEvent + (*OrderApprovedEvent)(nil), // 3: stocklet.events.v1.OrderApprovedEvent + nil, // 4: stocklet.events.v1.OrderCreatedEvent.ItemQuantitiesEntry + nil, // 5: stocklet.events.v1.OrderPendingEvent.ItemQuantitiesEntry +} +var file_stocklet_events_v1_order_proto_depIdxs = []int32{ + 4, // 0: stocklet.events.v1.OrderCreatedEvent.item_quantities:type_name -> stocklet.events.v1.OrderCreatedEvent.ItemQuantitiesEntry + 5, // 1: stocklet.events.v1.OrderPendingEvent.item_quantities:type_name -> stocklet.events.v1.OrderPendingEvent.ItemQuantitiesEntry + 2, // [2:2] is the sub-list for method output_type + 2, // [2:2] is the sub-list for method input_type + 2, // [2:2] is the sub-list for extension type_name + 2, // [2:2] is the sub-list for extension extendee + 0, // [0:2] is the sub-list for field type_name +} + +func init() { file_stocklet_events_v1_order_proto_init() } +func file_stocklet_events_v1_order_proto_init() { + if File_stocklet_events_v1_order_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_stocklet_events_v1_order_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*OrderCreatedEvent); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_stocklet_events_v1_order_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*OrderPendingEvent); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_stocklet_events_v1_order_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*OrderRejectedEvent); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_stocklet_events_v1_order_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*OrderApprovedEvent); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + file_stocklet_events_v1_order_proto_msgTypes[2].OneofWrappers = []interface{}{} + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_stocklet_events_v1_order_proto_rawDesc, + NumEnums: 0, + NumMessages: 6, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_stocklet_events_v1_order_proto_goTypes, + DependencyIndexes: file_stocklet_events_v1_order_proto_depIdxs, + MessageInfos: file_stocklet_events_v1_order_proto_msgTypes, + }.Build() + File_stocklet_events_v1_order_proto = out.File + file_stocklet_events_v1_order_proto_rawDesc = nil + file_stocklet_events_v1_order_proto_goTypes = nil + file_stocklet_events_v1_order_proto_depIdxs = nil +} diff --git a/internal/pkg/protogen/events/v1/payment.pb.go b/internal/pkg/protogen/events/v1/payment.pb.go new file mode 100644 index 0000000..eb688ef --- /dev/null +++ b/internal/pkg/protogen/events/v1/payment.pb.go @@ -0,0 +1,833 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.31.0 +// protoc (unknown) +// source: stocklet/events/v1/payment.proto + +package events_v1 + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type PaymentProcessedEvent_Type int32 + +const ( + PaymentProcessedEvent_TYPE_UNSPECIFIED PaymentProcessedEvent_Type = 0 + PaymentProcessedEvent_TYPE_FAILED PaymentProcessedEvent_Type = 1 + PaymentProcessedEvent_TYPE_SUCCESS PaymentProcessedEvent_Type = 2 +) + +// Enum value maps for PaymentProcessedEvent_Type. +var ( + PaymentProcessedEvent_Type_name = map[int32]string{ + 0: "TYPE_UNSPECIFIED", + 1: "TYPE_FAILED", + 2: "TYPE_SUCCESS", + } + PaymentProcessedEvent_Type_value = map[string]int32{ + "TYPE_UNSPECIFIED": 0, + "TYPE_FAILED": 1, + "TYPE_SUCCESS": 2, + } +) + +func (x PaymentProcessedEvent_Type) Enum() *PaymentProcessedEvent_Type { + p := new(PaymentProcessedEvent_Type) + *p = x + return p +} + +func (x PaymentProcessedEvent_Type) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (PaymentProcessedEvent_Type) Descriptor() protoreflect.EnumDescriptor { + return file_stocklet_events_v1_payment_proto_enumTypes[0].Descriptor() +} + +func (PaymentProcessedEvent_Type) Type() protoreflect.EnumType { + return &file_stocklet_events_v1_payment_proto_enumTypes[0] +} + +func (x PaymentProcessedEvent_Type) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use PaymentProcessedEvent_Type.Descriptor instead. +func (PaymentProcessedEvent_Type) EnumDescriptor() ([]byte, []int) { + return file_stocklet_events_v1_payment_proto_rawDescGZIP(), []int{6, 0} +} + +type BalanceCreatedEvent struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Revision int32 `protobuf:"varint,1,opt,name=revision,proto3" json:"revision,omitempty"` + CustomerId string `protobuf:"bytes,2,opt,name=customer_id,json=customerId,proto3" json:"customer_id,omitempty"` + Balance float32 `protobuf:"fixed32,3,opt,name=balance,proto3" json:"balance,omitempty"` +} + +func (x *BalanceCreatedEvent) Reset() { + *x = BalanceCreatedEvent{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_events_v1_payment_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BalanceCreatedEvent) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BalanceCreatedEvent) ProtoMessage() {} + +func (x *BalanceCreatedEvent) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_events_v1_payment_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use BalanceCreatedEvent.ProtoReflect.Descriptor instead. +func (*BalanceCreatedEvent) Descriptor() ([]byte, []int) { + return file_stocklet_events_v1_payment_proto_rawDescGZIP(), []int{0} +} + +func (x *BalanceCreatedEvent) GetRevision() int32 { + if x != nil { + return x.Revision + } + return 0 +} + +func (x *BalanceCreatedEvent) GetCustomerId() string { + if x != nil { + return x.CustomerId + } + return "" +} + +func (x *BalanceCreatedEvent) GetBalance() float32 { + if x != nil { + return x.Balance + } + return 0 +} + +type BalanceCreditedEvent struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Revision int32 `protobuf:"varint,1,opt,name=revision,proto3" json:"revision,omitempty"` + CustomerId string `protobuf:"bytes,2,opt,name=customer_id,json=customerId,proto3" json:"customer_id,omitempty"` + Amount float32 `protobuf:"fixed32,3,opt,name=amount,proto3" json:"amount,omitempty"` + NewBalance float32 `protobuf:"fixed32,4,opt,name=new_balance,json=newBalance,proto3" json:"new_balance,omitempty"` +} + +func (x *BalanceCreditedEvent) Reset() { + *x = BalanceCreditedEvent{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_events_v1_payment_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BalanceCreditedEvent) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BalanceCreditedEvent) ProtoMessage() {} + +func (x *BalanceCreditedEvent) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_events_v1_payment_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use BalanceCreditedEvent.ProtoReflect.Descriptor instead. +func (*BalanceCreditedEvent) Descriptor() ([]byte, []int) { + return file_stocklet_events_v1_payment_proto_rawDescGZIP(), []int{1} +} + +func (x *BalanceCreditedEvent) GetRevision() int32 { + if x != nil { + return x.Revision + } + return 0 +} + +func (x *BalanceCreditedEvent) GetCustomerId() string { + if x != nil { + return x.CustomerId + } + return "" +} + +func (x *BalanceCreditedEvent) GetAmount() float32 { + if x != nil { + return x.Amount + } + return 0 +} + +func (x *BalanceCreditedEvent) GetNewBalance() float32 { + if x != nil { + return x.NewBalance + } + return 0 +} + +type BalanceDebitedEvent struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Revision int32 `protobuf:"varint,1,opt,name=revision,proto3" json:"revision,omitempty"` + CustomerId string `protobuf:"bytes,2,opt,name=customer_id,json=customerId,proto3" json:"customer_id,omitempty"` + Amount float32 `protobuf:"fixed32,3,opt,name=amount,proto3" json:"amount,omitempty"` + NewBalance float32 `protobuf:"fixed32,4,opt,name=new_balance,json=newBalance,proto3" json:"new_balance,omitempty"` +} + +func (x *BalanceDebitedEvent) Reset() { + *x = BalanceDebitedEvent{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_events_v1_payment_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BalanceDebitedEvent) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BalanceDebitedEvent) ProtoMessage() {} + +func (x *BalanceDebitedEvent) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_events_v1_payment_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use BalanceDebitedEvent.ProtoReflect.Descriptor instead. +func (*BalanceDebitedEvent) Descriptor() ([]byte, []int) { + return file_stocklet_events_v1_payment_proto_rawDescGZIP(), []int{2} +} + +func (x *BalanceDebitedEvent) GetRevision() int32 { + if x != nil { + return x.Revision + } + return 0 +} + +func (x *BalanceDebitedEvent) GetCustomerId() string { + if x != nil { + return x.CustomerId + } + return "" +} + +func (x *BalanceDebitedEvent) GetAmount() float32 { + if x != nil { + return x.Amount + } + return 0 +} + +func (x *BalanceDebitedEvent) GetNewBalance() float32 { + if x != nil { + return x.NewBalance + } + return 0 +} + +type BalanceClosedEvent struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Revision int32 `protobuf:"varint,1,opt,name=revision,proto3" json:"revision,omitempty"` + CustomerId string `protobuf:"bytes,2,opt,name=customer_id,json=customerId,proto3" json:"customer_id,omitempty"` + Balance float32 `protobuf:"fixed32,3,opt,name=balance,proto3" json:"balance,omitempty"` +} + +func (x *BalanceClosedEvent) Reset() { + *x = BalanceClosedEvent{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_events_v1_payment_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BalanceClosedEvent) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BalanceClosedEvent) ProtoMessage() {} + +func (x *BalanceClosedEvent) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_events_v1_payment_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use BalanceClosedEvent.ProtoReflect.Descriptor instead. +func (*BalanceClosedEvent) Descriptor() ([]byte, []int) { + return file_stocklet_events_v1_payment_proto_rawDescGZIP(), []int{3} +} + +func (x *BalanceClosedEvent) GetRevision() int32 { + if x != nil { + return x.Revision + } + return 0 +} + +func (x *BalanceClosedEvent) GetCustomerId() string { + if x != nil { + return x.CustomerId + } + return "" +} + +func (x *BalanceClosedEvent) GetBalance() float32 { + if x != nil { + return x.Balance + } + return 0 +} + +type TransactionLoggedEvent struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Revision int32 `protobuf:"varint,1,opt,name=revision,proto3" json:"revision,omitempty"` + TransactionId string `protobuf:"bytes,2,opt,name=transaction_id,json=transactionId,proto3" json:"transaction_id,omitempty"` + Amount float32 `protobuf:"fixed32,3,opt,name=amount,proto3" json:"amount,omitempty"` + OrderId string `protobuf:"bytes,4,opt,name=order_id,json=orderId,proto3" json:"order_id,omitempty"` + CustomerId string `protobuf:"bytes,5,opt,name=customer_id,json=customerId,proto3" json:"customer_id,omitempty"` +} + +func (x *TransactionLoggedEvent) Reset() { + *x = TransactionLoggedEvent{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_events_v1_payment_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *TransactionLoggedEvent) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*TransactionLoggedEvent) ProtoMessage() {} + +func (x *TransactionLoggedEvent) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_events_v1_payment_proto_msgTypes[4] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use TransactionLoggedEvent.ProtoReflect.Descriptor instead. +func (*TransactionLoggedEvent) Descriptor() ([]byte, []int) { + return file_stocklet_events_v1_payment_proto_rawDescGZIP(), []int{4} +} + +func (x *TransactionLoggedEvent) GetRevision() int32 { + if x != nil { + return x.Revision + } + return 0 +} + +func (x *TransactionLoggedEvent) GetTransactionId() string { + if x != nil { + return x.TransactionId + } + return "" +} + +func (x *TransactionLoggedEvent) GetAmount() float32 { + if x != nil { + return x.Amount + } + return 0 +} + +func (x *TransactionLoggedEvent) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +func (x *TransactionLoggedEvent) GetCustomerId() string { + if x != nil { + return x.CustomerId + } + return "" +} + +type TransactionReversedEvent struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Revision int32 `protobuf:"varint,1,opt,name=revision,proto3" json:"revision,omitempty"` + TransactionId string `protobuf:"bytes,2,opt,name=transaction_id,json=transactionId,proto3" json:"transaction_id,omitempty"` + Amount float32 `protobuf:"fixed32,3,opt,name=amount,proto3" json:"amount,omitempty"` + OrderId string `protobuf:"bytes,4,opt,name=order_id,json=orderId,proto3" json:"order_id,omitempty"` + CustomerId string `protobuf:"bytes,5,opt,name=customer_id,json=customerId,proto3" json:"customer_id,omitempty"` +} + +func (x *TransactionReversedEvent) Reset() { + *x = TransactionReversedEvent{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_events_v1_payment_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *TransactionReversedEvent) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*TransactionReversedEvent) ProtoMessage() {} + +func (x *TransactionReversedEvent) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_events_v1_payment_proto_msgTypes[5] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use TransactionReversedEvent.ProtoReflect.Descriptor instead. +func (*TransactionReversedEvent) Descriptor() ([]byte, []int) { + return file_stocklet_events_v1_payment_proto_rawDescGZIP(), []int{5} +} + +func (x *TransactionReversedEvent) GetRevision() int32 { + if x != nil { + return x.Revision + } + return 0 +} + +func (x *TransactionReversedEvent) GetTransactionId() string { + if x != nil { + return x.TransactionId + } + return "" +} + +func (x *TransactionReversedEvent) GetAmount() float32 { + if x != nil { + return x.Amount + } + return 0 +} + +func (x *TransactionReversedEvent) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +func (x *TransactionReversedEvent) GetCustomerId() string { + if x != nil { + return x.CustomerId + } + return "" +} + +type PaymentProcessedEvent struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Revision int32 `protobuf:"varint,1,opt,name=revision,proto3" json:"revision,omitempty"` + Type PaymentProcessedEvent_Type `protobuf:"varint,2,opt,name=type,proto3,enum=stocklet.events.v1.PaymentProcessedEvent_Type" json:"type,omitempty"` + OrderId string `protobuf:"bytes,3,opt,name=order_id,json=orderId,proto3" json:"order_id,omitempty"` + CustomerId string `protobuf:"bytes,4,opt,name=customer_id,json=customerId,proto3" json:"customer_id,omitempty"` + Amount float32 `protobuf:"fixed32,5,opt,name=amount,proto3" json:"amount,omitempty"` + TransactionId *string `protobuf:"bytes,6,opt,name=transaction_id,json=transactionId,proto3,oneof" json:"transaction_id,omitempty"` +} + +func (x *PaymentProcessedEvent) Reset() { + *x = PaymentProcessedEvent{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_events_v1_payment_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *PaymentProcessedEvent) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*PaymentProcessedEvent) ProtoMessage() {} + +func (x *PaymentProcessedEvent) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_events_v1_payment_proto_msgTypes[6] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use PaymentProcessedEvent.ProtoReflect.Descriptor instead. +func (*PaymentProcessedEvent) Descriptor() ([]byte, []int) { + return file_stocklet_events_v1_payment_proto_rawDescGZIP(), []int{6} +} + +func (x *PaymentProcessedEvent) GetRevision() int32 { + if x != nil { + return x.Revision + } + return 0 +} + +func (x *PaymentProcessedEvent) GetType() PaymentProcessedEvent_Type { + if x != nil { + return x.Type + } + return PaymentProcessedEvent_TYPE_UNSPECIFIED +} + +func (x *PaymentProcessedEvent) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +func (x *PaymentProcessedEvent) GetCustomerId() string { + if x != nil { + return x.CustomerId + } + return "" +} + +func (x *PaymentProcessedEvent) GetAmount() float32 { + if x != nil { + return x.Amount + } + return 0 +} + +func (x *PaymentProcessedEvent) GetTransactionId() string { + if x != nil && x.TransactionId != nil { + return *x.TransactionId + } + return "" +} + +var File_stocklet_events_v1_payment_proto protoreflect.FileDescriptor + +var file_stocklet_events_v1_payment_proto_rawDesc = []byte{ + 0x0a, 0x20, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2f, 0x65, 0x76, 0x65, 0x6e, 0x74, + 0x73, 0x2f, 0x76, 0x31, 0x2f, 0x70, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x12, 0x12, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x65, 0x76, 0x65, + 0x6e, 0x74, 0x73, 0x2e, 0x76, 0x31, 0x22, 0x6c, 0x0a, 0x13, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, + 0x65, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x1a, 0x0a, + 0x08, 0x72, 0x65, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, + 0x08, 0x72, 0x65, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x1f, 0x0a, 0x0b, 0x63, 0x75, 0x73, + 0x74, 0x6f, 0x6d, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, + 0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x65, 0x72, 0x49, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x62, 0x61, + 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x02, 0x52, 0x07, 0x62, 0x61, 0x6c, + 0x61, 0x6e, 0x63, 0x65, 0x22, 0x8c, 0x01, 0x0a, 0x14, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, + 0x43, 0x72, 0x65, 0x64, 0x69, 0x74, 0x65, 0x64, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x1a, 0x0a, + 0x08, 0x72, 0x65, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, + 0x08, 0x72, 0x65, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x1f, 0x0a, 0x0b, 0x63, 0x75, 0x73, + 0x74, 0x6f, 0x6d, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, + 0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x65, 0x72, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x61, 0x6d, + 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x02, 0x52, 0x06, 0x61, 0x6d, 0x6f, 0x75, + 0x6e, 0x74, 0x12, 0x1f, 0x0a, 0x0b, 0x6e, 0x65, 0x77, 0x5f, 0x62, 0x61, 0x6c, 0x61, 0x6e, 0x63, + 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x02, 0x52, 0x0a, 0x6e, 0x65, 0x77, 0x42, 0x61, 0x6c, 0x61, + 0x6e, 0x63, 0x65, 0x22, 0x8b, 0x01, 0x0a, 0x13, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x44, + 0x65, 0x62, 0x69, 0x74, 0x65, 0x64, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x72, + 0x65, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x72, + 0x65, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x1f, 0x0a, 0x0b, 0x63, 0x75, 0x73, 0x74, 0x6f, + 0x6d, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x63, 0x75, + 0x73, 0x74, 0x6f, 0x6d, 0x65, 0x72, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x61, 0x6d, 0x6f, 0x75, + 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x02, 0x52, 0x06, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, + 0x12, 0x1f, 0x0a, 0x0b, 0x6e, 0x65, 0x77, 0x5f, 0x62, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x18, + 0x04, 0x20, 0x01, 0x28, 0x02, 0x52, 0x0a, 0x6e, 0x65, 0x77, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, + 0x65, 0x22, 0x6b, 0x0a, 0x12, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x43, 0x6c, 0x6f, 0x73, + 0x65, 0x64, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x72, 0x65, 0x76, 0x69, 0x73, + 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x72, 0x65, 0x76, 0x69, 0x73, + 0x69, 0x6f, 0x6e, 0x12, 0x1f, 0x0a, 0x0b, 0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x65, 0x72, 0x5f, + 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d, + 0x65, 0x72, 0x49, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x62, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x18, + 0x03, 0x20, 0x01, 0x28, 0x02, 0x52, 0x07, 0x62, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x22, 0xaf, + 0x01, 0x0a, 0x16, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x4c, 0x6f, + 0x67, 0x67, 0x65, 0x64, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x72, 0x65, 0x76, + 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x72, 0x65, 0x76, + 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x25, 0x0a, 0x0e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, + 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x74, + 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, + 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x02, 0x52, 0x06, 0x61, 0x6d, + 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x19, 0x0a, 0x08, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x69, 0x64, + 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x12, + 0x1f, 0x0a, 0x0b, 0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x05, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x65, 0x72, 0x49, 0x64, + 0x22, 0xb1, 0x01, 0x0a, 0x18, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, + 0x52, 0x65, 0x76, 0x65, 0x72, 0x73, 0x65, 0x64, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x1a, 0x0a, + 0x08, 0x72, 0x65, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, + 0x08, 0x72, 0x65, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x25, 0x0a, 0x0e, 0x74, 0x72, 0x61, + 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x0d, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x64, + 0x12, 0x16, 0x0a, 0x06, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x02, + 0x52, 0x06, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x19, 0x0a, 0x08, 0x6f, 0x72, 0x64, 0x65, + 0x72, 0x5f, 0x69, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, + 0x72, 0x49, 0x64, 0x12, 0x1f, 0x0a, 0x0b, 0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x65, 0x72, 0x5f, + 0x69, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d, + 0x65, 0x72, 0x49, 0x64, 0x22, 0xcb, 0x02, 0x0a, 0x15, 0x50, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, + 0x50, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, 0x65, 0x64, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x1a, + 0x0a, 0x08, 0x72, 0x65, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, + 0x52, 0x08, 0x72, 0x65, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x42, 0x0a, 0x04, 0x74, 0x79, + 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x2e, 0x2e, 0x73, 0x74, 0x6f, 0x63, 0x6b, + 0x6c, 0x65, 0x74, 0x2e, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x61, + 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x50, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, 0x65, 0x64, 0x45, 0x76, + 0x65, 0x6e, 0x74, 0x2e, 0x54, 0x79, 0x70, 0x65, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x19, + 0x0a, 0x08, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x12, 0x1f, 0x0a, 0x0b, 0x63, 0x75, 0x73, + 0x74, 0x6f, 0x6d, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, + 0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x65, 0x72, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x61, 0x6d, + 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, 0x02, 0x52, 0x06, 0x61, 0x6d, 0x6f, 0x75, + 0x6e, 0x74, 0x12, 0x2a, 0x0a, 0x0e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, + 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x48, 0x00, 0x52, 0x0d, 0x74, 0x72, + 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x88, 0x01, 0x01, 0x22, 0x3f, + 0x0a, 0x04, 0x54, 0x79, 0x70, 0x65, 0x12, 0x14, 0x0a, 0x10, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x55, + 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x0f, 0x0a, 0x0b, + 0x54, 0x59, 0x50, 0x45, 0x5f, 0x46, 0x41, 0x49, 0x4c, 0x45, 0x44, 0x10, 0x01, 0x12, 0x10, 0x0a, + 0x0c, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x53, 0x55, 0x43, 0x43, 0x45, 0x53, 0x53, 0x10, 0x02, 0x42, + 0x11, 0x0a, 0x0f, 0x5f, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x5f, + 0x69, 0x64, 0x42, 0x47, 0x5a, 0x45, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, + 0x2f, 0x68, 0x65, 0x78, 0x6f, 0x6c, 0x61, 0x6e, 0x2f, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, + 0x74, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x67, 0x65, 0x6e, 0x2f, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x2f, 0x76, + 0x31, 0x3b, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x5f, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x33, +} + +var ( + file_stocklet_events_v1_payment_proto_rawDescOnce sync.Once + file_stocklet_events_v1_payment_proto_rawDescData = file_stocklet_events_v1_payment_proto_rawDesc +) + +func file_stocklet_events_v1_payment_proto_rawDescGZIP() []byte { + file_stocklet_events_v1_payment_proto_rawDescOnce.Do(func() { + file_stocklet_events_v1_payment_proto_rawDescData = protoimpl.X.CompressGZIP(file_stocklet_events_v1_payment_proto_rawDescData) + }) + return file_stocklet_events_v1_payment_proto_rawDescData +} + +var file_stocklet_events_v1_payment_proto_enumTypes = make([]protoimpl.EnumInfo, 1) +var file_stocklet_events_v1_payment_proto_msgTypes = make([]protoimpl.MessageInfo, 7) +var file_stocklet_events_v1_payment_proto_goTypes = []interface{}{ + (PaymentProcessedEvent_Type)(0), // 0: stocklet.events.v1.PaymentProcessedEvent.Type + (*BalanceCreatedEvent)(nil), // 1: stocklet.events.v1.BalanceCreatedEvent + (*BalanceCreditedEvent)(nil), // 2: stocklet.events.v1.BalanceCreditedEvent + (*BalanceDebitedEvent)(nil), // 3: stocklet.events.v1.BalanceDebitedEvent + (*BalanceClosedEvent)(nil), // 4: stocklet.events.v1.BalanceClosedEvent + (*TransactionLoggedEvent)(nil), // 5: stocklet.events.v1.TransactionLoggedEvent + (*TransactionReversedEvent)(nil), // 6: stocklet.events.v1.TransactionReversedEvent + (*PaymentProcessedEvent)(nil), // 7: stocklet.events.v1.PaymentProcessedEvent +} +var file_stocklet_events_v1_payment_proto_depIdxs = []int32{ + 0, // 0: stocklet.events.v1.PaymentProcessedEvent.type:type_name -> stocklet.events.v1.PaymentProcessedEvent.Type + 1, // [1:1] is the sub-list for method output_type + 1, // [1:1] is the sub-list for method input_type + 1, // [1:1] is the sub-list for extension type_name + 1, // [1:1] is the sub-list for extension extendee + 0, // [0:1] is the sub-list for field type_name +} + +func init() { file_stocklet_events_v1_payment_proto_init() } +func file_stocklet_events_v1_payment_proto_init() { + if File_stocklet_events_v1_payment_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_stocklet_events_v1_payment_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*BalanceCreatedEvent); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_stocklet_events_v1_payment_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*BalanceCreditedEvent); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_stocklet_events_v1_payment_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*BalanceDebitedEvent); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_stocklet_events_v1_payment_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*BalanceClosedEvent); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_stocklet_events_v1_payment_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*TransactionLoggedEvent); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_stocklet_events_v1_payment_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*TransactionReversedEvent); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_stocklet_events_v1_payment_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*PaymentProcessedEvent); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + file_stocklet_events_v1_payment_proto_msgTypes[6].OneofWrappers = []interface{}{} + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_stocklet_events_v1_payment_proto_rawDesc, + NumEnums: 1, + NumMessages: 7, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_stocklet_events_v1_payment_proto_goTypes, + DependencyIndexes: file_stocklet_events_v1_payment_proto_depIdxs, + EnumInfos: file_stocklet_events_v1_payment_proto_enumTypes, + MessageInfos: file_stocklet_events_v1_payment_proto_msgTypes, + }.Build() + File_stocklet_events_v1_payment_proto = out.File + file_stocklet_events_v1_payment_proto_rawDesc = nil + file_stocklet_events_v1_payment_proto_goTypes = nil + file_stocklet_events_v1_payment_proto_depIdxs = nil +} diff --git a/internal/pkg/protogen/events/v1/product.pb.go b/internal/pkg/protogen/events/v1/product.pb.go new file mode 100644 index 0000000..cd23ad6 --- /dev/null +++ b/internal/pkg/protogen/events/v1/product.pb.go @@ -0,0 +1,555 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.31.0 +// protoc (unknown) +// source: stocklet/events/v1/product.proto + +package events_v1 + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type ProductPriceQuoteEvent_Type int32 + +const ( + ProductPriceQuoteEvent_TYPE_UNSPECIFIED ProductPriceQuoteEvent_Type = 0 + ProductPriceQuoteEvent_TYPE_UNAVALIABLE ProductPriceQuoteEvent_Type = 1 + ProductPriceQuoteEvent_TYPE_AVALIABLE ProductPriceQuoteEvent_Type = 2 +) + +// Enum value maps for ProductPriceQuoteEvent_Type. +var ( + ProductPriceQuoteEvent_Type_name = map[int32]string{ + 0: "TYPE_UNSPECIFIED", + 1: "TYPE_UNAVALIABLE", + 2: "TYPE_AVALIABLE", + } + ProductPriceQuoteEvent_Type_value = map[string]int32{ + "TYPE_UNSPECIFIED": 0, + "TYPE_UNAVALIABLE": 1, + "TYPE_AVALIABLE": 2, + } +) + +func (x ProductPriceQuoteEvent_Type) Enum() *ProductPriceQuoteEvent_Type { + p := new(ProductPriceQuoteEvent_Type) + *p = x + return p +} + +func (x ProductPriceQuoteEvent_Type) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (ProductPriceQuoteEvent_Type) Descriptor() protoreflect.EnumDescriptor { + return file_stocklet_events_v1_product_proto_enumTypes[0].Descriptor() +} + +func (ProductPriceQuoteEvent_Type) Type() protoreflect.EnumType { + return &file_stocklet_events_v1_product_proto_enumTypes[0] +} + +func (x ProductPriceQuoteEvent_Type) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use ProductPriceQuoteEvent_Type.Descriptor instead. +func (ProductPriceQuoteEvent_Type) EnumDescriptor() ([]byte, []int) { + return file_stocklet_events_v1_product_proto_rawDescGZIP(), []int{3, 0} +} + +type ProductCreatedEvent struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Revision int32 `protobuf:"varint,1,opt,name=revision,proto3" json:"revision,omitempty"` + ProductId string `protobuf:"bytes,2,opt,name=product_id,json=productId,proto3" json:"product_id,omitempty"` + Name string `protobuf:"bytes,3,opt,name=name,proto3" json:"name,omitempty"` + Description string `protobuf:"bytes,4,opt,name=description,proto3" json:"description,omitempty"` + Price float32 `protobuf:"fixed32,5,opt,name=price,proto3" json:"price,omitempty"` +} + +func (x *ProductCreatedEvent) Reset() { + *x = ProductCreatedEvent{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_events_v1_product_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ProductCreatedEvent) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ProductCreatedEvent) ProtoMessage() {} + +func (x *ProductCreatedEvent) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_events_v1_product_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ProductCreatedEvent.ProtoReflect.Descriptor instead. +func (*ProductCreatedEvent) Descriptor() ([]byte, []int) { + return file_stocklet_events_v1_product_proto_rawDescGZIP(), []int{0} +} + +func (x *ProductCreatedEvent) GetRevision() int32 { + if x != nil { + return x.Revision + } + return 0 +} + +func (x *ProductCreatedEvent) GetProductId() string { + if x != nil { + return x.ProductId + } + return "" +} + +func (x *ProductCreatedEvent) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +func (x *ProductCreatedEvent) GetDescription() string { + if x != nil { + return x.Description + } + return "" +} + +func (x *ProductCreatedEvent) GetPrice() float32 { + if x != nil { + return x.Price + } + return 0 +} + +type ProductPriceUpdatedEvent struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Revision int32 `protobuf:"varint,1,opt,name=revision,proto3" json:"revision,omitempty"` + ProductId string `protobuf:"bytes,2,opt,name=product_id,json=productId,proto3" json:"product_id,omitempty"` + Price float32 `protobuf:"fixed32,3,opt,name=price,proto3" json:"price,omitempty"` +} + +func (x *ProductPriceUpdatedEvent) Reset() { + *x = ProductPriceUpdatedEvent{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_events_v1_product_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ProductPriceUpdatedEvent) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ProductPriceUpdatedEvent) ProtoMessage() {} + +func (x *ProductPriceUpdatedEvent) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_events_v1_product_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ProductPriceUpdatedEvent.ProtoReflect.Descriptor instead. +func (*ProductPriceUpdatedEvent) Descriptor() ([]byte, []int) { + return file_stocklet_events_v1_product_proto_rawDescGZIP(), []int{1} +} + +func (x *ProductPriceUpdatedEvent) GetRevision() int32 { + if x != nil { + return x.Revision + } + return 0 +} + +func (x *ProductPriceUpdatedEvent) GetProductId() string { + if x != nil { + return x.ProductId + } + return "" +} + +func (x *ProductPriceUpdatedEvent) GetPrice() float32 { + if x != nil { + return x.Price + } + return 0 +} + +type ProductDeletedEvent struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Revision int32 `protobuf:"varint,1,opt,name=revision,proto3" json:"revision,omitempty"` + ProductId string `protobuf:"bytes,2,opt,name=product_id,json=productId,proto3" json:"product_id,omitempty"` +} + +func (x *ProductDeletedEvent) Reset() { + *x = ProductDeletedEvent{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_events_v1_product_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ProductDeletedEvent) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ProductDeletedEvent) ProtoMessage() {} + +func (x *ProductDeletedEvent) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_events_v1_product_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ProductDeletedEvent.ProtoReflect.Descriptor instead. +func (*ProductDeletedEvent) Descriptor() ([]byte, []int) { + return file_stocklet_events_v1_product_proto_rawDescGZIP(), []int{2} +} + +func (x *ProductDeletedEvent) GetRevision() int32 { + if x != nil { + return x.Revision + } + return 0 +} + +func (x *ProductDeletedEvent) GetProductId() string { + if x != nil { + return x.ProductId + } + return "" +} + +type ProductPriceQuoteEvent struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Revision int32 `protobuf:"varint,1,opt,name=revision,proto3" json:"revision,omitempty"` + Type ProductPriceQuoteEvent_Type `protobuf:"varint,2,opt,name=type,proto3,enum=stocklet.events.v1.ProductPriceQuoteEvent_Type" json:"type,omitempty"` + OrderId string `protobuf:"bytes,3,opt,name=order_id,json=orderId,proto3" json:"order_id,omitempty"` + // Product ID: Quantity + ProductQuantities map[string]int32 `protobuf:"bytes,4,rep,name=product_quantities,json=productQuantities,proto3" json:"product_quantities,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` + // Product ID: Unit Price + ProductPrices map[string]float32 `protobuf:"bytes,5,rep,name=product_prices,json=productPrices,proto3" json:"product_prices,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"fixed32,2,opt,name=value,proto3"` + TotalPrice float32 `protobuf:"fixed32,6,opt,name=total_price,json=totalPrice,proto3" json:"total_price,omitempty"` +} + +func (x *ProductPriceQuoteEvent) Reset() { + *x = ProductPriceQuoteEvent{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_events_v1_product_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ProductPriceQuoteEvent) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ProductPriceQuoteEvent) ProtoMessage() {} + +func (x *ProductPriceQuoteEvent) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_events_v1_product_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ProductPriceQuoteEvent.ProtoReflect.Descriptor instead. +func (*ProductPriceQuoteEvent) Descriptor() ([]byte, []int) { + return file_stocklet_events_v1_product_proto_rawDescGZIP(), []int{3} +} + +func (x *ProductPriceQuoteEvent) GetRevision() int32 { + if x != nil { + return x.Revision + } + return 0 +} + +func (x *ProductPriceQuoteEvent) GetType() ProductPriceQuoteEvent_Type { + if x != nil { + return x.Type + } + return ProductPriceQuoteEvent_TYPE_UNSPECIFIED +} + +func (x *ProductPriceQuoteEvent) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +func (x *ProductPriceQuoteEvent) GetProductQuantities() map[string]int32 { + if x != nil { + return x.ProductQuantities + } + return nil +} + +func (x *ProductPriceQuoteEvent) GetProductPrices() map[string]float32 { + if x != nil { + return x.ProductPrices + } + return nil +} + +func (x *ProductPriceQuoteEvent) GetTotalPrice() float32 { + if x != nil { + return x.TotalPrice + } + return 0 +} + +var File_stocklet_events_v1_product_proto protoreflect.FileDescriptor + +var file_stocklet_events_v1_product_proto_rawDesc = []byte{ + 0x0a, 0x20, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2f, 0x65, 0x76, 0x65, 0x6e, 0x74, + 0x73, 0x2f, 0x76, 0x31, 0x2f, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x12, 0x12, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x65, 0x76, 0x65, + 0x6e, 0x74, 0x73, 0x2e, 0x76, 0x31, 0x22, 0x9c, 0x01, 0x0a, 0x13, 0x50, 0x72, 0x6f, 0x64, 0x75, + 0x63, 0x74, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x1a, + 0x0a, 0x08, 0x72, 0x65, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, + 0x52, 0x08, 0x72, 0x65, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x1d, 0x0a, 0x0a, 0x70, 0x72, + 0x6f, 0x64, 0x75, 0x63, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, + 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x49, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, + 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x20, 0x0a, + 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x04, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x12, + 0x14, 0x0a, 0x05, 0x70, 0x72, 0x69, 0x63, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x02, 0x52, 0x05, + 0x70, 0x72, 0x69, 0x63, 0x65, 0x22, 0x6b, 0x0a, 0x18, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, + 0x50, 0x72, 0x69, 0x63, 0x65, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x45, 0x76, 0x65, 0x6e, + 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x72, 0x65, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x05, 0x52, 0x08, 0x72, 0x65, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x1d, 0x0a, + 0x0a, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x09, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x49, 0x64, 0x12, 0x14, 0x0a, 0x05, + 0x70, 0x72, 0x69, 0x63, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x02, 0x52, 0x05, 0x70, 0x72, 0x69, + 0x63, 0x65, 0x22, 0x50, 0x0a, 0x13, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x44, 0x65, 0x6c, + 0x65, 0x74, 0x65, 0x64, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x72, 0x65, 0x76, + 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x72, 0x65, 0x76, + 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x1d, 0x0a, 0x0a, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, + 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x70, 0x72, 0x6f, 0x64, 0x75, + 0x63, 0x74, 0x49, 0x64, 0x22, 0xdd, 0x04, 0x0a, 0x16, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, + 0x50, 0x72, 0x69, 0x63, 0x65, 0x51, 0x75, 0x6f, 0x74, 0x65, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, + 0x1a, 0x0a, 0x08, 0x72, 0x65, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x05, 0x52, 0x08, 0x72, 0x65, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x43, 0x0a, 0x04, 0x74, + 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x2f, 0x2e, 0x73, 0x74, 0x6f, 0x63, + 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x50, + 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x51, 0x75, 0x6f, 0x74, 0x65, + 0x45, 0x76, 0x65, 0x6e, 0x74, 0x2e, 0x54, 0x79, 0x70, 0x65, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, + 0x12, 0x19, 0x0a, 0x08, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x12, 0x70, 0x0a, 0x12, 0x70, + 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x5f, 0x71, 0x75, 0x61, 0x6e, 0x74, 0x69, 0x74, 0x69, 0x65, + 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x41, 0x2e, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, + 0x65, 0x74, 0x2e, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x72, 0x6f, + 0x64, 0x75, 0x63, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x51, 0x75, 0x6f, 0x74, 0x65, 0x45, 0x76, + 0x65, 0x6e, 0x74, 0x2e, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x51, 0x75, 0x61, 0x6e, 0x74, + 0x69, 0x74, 0x69, 0x65, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x11, 0x70, 0x72, 0x6f, 0x64, + 0x75, 0x63, 0x74, 0x51, 0x75, 0x61, 0x6e, 0x74, 0x69, 0x74, 0x69, 0x65, 0x73, 0x12, 0x64, 0x0a, + 0x0e, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x5f, 0x70, 0x72, 0x69, 0x63, 0x65, 0x73, 0x18, + 0x05, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x3d, 0x2e, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, + 0x2e, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x72, 0x6f, 0x64, 0x75, + 0x63, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x51, 0x75, 0x6f, 0x74, 0x65, 0x45, 0x76, 0x65, 0x6e, + 0x74, 0x2e, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x73, 0x45, + 0x6e, 0x74, 0x72, 0x79, 0x52, 0x0d, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x50, 0x72, 0x69, + 0x63, 0x65, 0x73, 0x12, 0x1f, 0x0a, 0x0b, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x5f, 0x70, 0x72, 0x69, + 0x63, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x02, 0x52, 0x0a, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x50, + 0x72, 0x69, 0x63, 0x65, 0x1a, 0x44, 0x0a, 0x16, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x51, + 0x75, 0x61, 0x6e, 0x74, 0x69, 0x74, 0x69, 0x65, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, + 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, + 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, + 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x40, 0x0a, 0x12, 0x50, 0x72, + 0x6f, 0x64, 0x75, 0x63, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, + 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, + 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x02, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x46, 0x0a, 0x04, + 0x54, 0x79, 0x70, 0x65, 0x12, 0x14, 0x0a, 0x10, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x55, 0x4e, 0x53, + 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x14, 0x0a, 0x10, 0x54, 0x59, + 0x50, 0x45, 0x5f, 0x55, 0x4e, 0x41, 0x56, 0x41, 0x4c, 0x49, 0x41, 0x42, 0x4c, 0x45, 0x10, 0x01, + 0x12, 0x12, 0x0a, 0x0e, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x41, 0x56, 0x41, 0x4c, 0x49, 0x41, 0x42, + 0x4c, 0x45, 0x10, 0x02, 0x42, 0x47, 0x5a, 0x45, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, + 0x6f, 0x6d, 0x2f, 0x68, 0x65, 0x78, 0x6f, 0x6c, 0x61, 0x6e, 0x2f, 0x73, 0x74, 0x6f, 0x63, 0x6b, + 0x6c, 0x65, 0x74, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x70, 0x6b, 0x67, + 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x67, 0x65, 0x6e, 0x2f, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, + 0x2f, 0x76, 0x31, 0x3b, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x5f, 0x76, 0x31, 0x62, 0x06, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_stocklet_events_v1_product_proto_rawDescOnce sync.Once + file_stocklet_events_v1_product_proto_rawDescData = file_stocklet_events_v1_product_proto_rawDesc +) + +func file_stocklet_events_v1_product_proto_rawDescGZIP() []byte { + file_stocklet_events_v1_product_proto_rawDescOnce.Do(func() { + file_stocklet_events_v1_product_proto_rawDescData = protoimpl.X.CompressGZIP(file_stocklet_events_v1_product_proto_rawDescData) + }) + return file_stocklet_events_v1_product_proto_rawDescData +} + +var file_stocklet_events_v1_product_proto_enumTypes = make([]protoimpl.EnumInfo, 1) +var file_stocklet_events_v1_product_proto_msgTypes = make([]protoimpl.MessageInfo, 6) +var file_stocklet_events_v1_product_proto_goTypes = []interface{}{ + (ProductPriceQuoteEvent_Type)(0), // 0: stocklet.events.v1.ProductPriceQuoteEvent.Type + (*ProductCreatedEvent)(nil), // 1: stocklet.events.v1.ProductCreatedEvent + (*ProductPriceUpdatedEvent)(nil), // 2: stocklet.events.v1.ProductPriceUpdatedEvent + (*ProductDeletedEvent)(nil), // 3: stocklet.events.v1.ProductDeletedEvent + (*ProductPriceQuoteEvent)(nil), // 4: stocklet.events.v1.ProductPriceQuoteEvent + nil, // 5: stocklet.events.v1.ProductPriceQuoteEvent.ProductQuantitiesEntry + nil, // 6: stocklet.events.v1.ProductPriceQuoteEvent.ProductPricesEntry +} +var file_stocklet_events_v1_product_proto_depIdxs = []int32{ + 0, // 0: stocklet.events.v1.ProductPriceQuoteEvent.type:type_name -> stocklet.events.v1.ProductPriceQuoteEvent.Type + 5, // 1: stocklet.events.v1.ProductPriceQuoteEvent.product_quantities:type_name -> stocklet.events.v1.ProductPriceQuoteEvent.ProductQuantitiesEntry + 6, // 2: stocklet.events.v1.ProductPriceQuoteEvent.product_prices:type_name -> stocklet.events.v1.ProductPriceQuoteEvent.ProductPricesEntry + 3, // [3:3] is the sub-list for method output_type + 3, // [3:3] is the sub-list for method input_type + 3, // [3:3] is the sub-list for extension type_name + 3, // [3:3] is the sub-list for extension extendee + 0, // [0:3] is the sub-list for field type_name +} + +func init() { file_stocklet_events_v1_product_proto_init() } +func file_stocklet_events_v1_product_proto_init() { + if File_stocklet_events_v1_product_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_stocklet_events_v1_product_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ProductCreatedEvent); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_stocklet_events_v1_product_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ProductPriceUpdatedEvent); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_stocklet_events_v1_product_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ProductDeletedEvent); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_stocklet_events_v1_product_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ProductPriceQuoteEvent); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_stocklet_events_v1_product_proto_rawDesc, + NumEnums: 1, + NumMessages: 6, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_stocklet_events_v1_product_proto_goTypes, + DependencyIndexes: file_stocklet_events_v1_product_proto_depIdxs, + EnumInfos: file_stocklet_events_v1_product_proto_enumTypes, + MessageInfos: file_stocklet_events_v1_product_proto_msgTypes, + }.Build() + File_stocklet_events_v1_product_proto = out.File + file_stocklet_events_v1_product_proto_rawDesc = nil + file_stocklet_events_v1_product_proto_goTypes = nil + file_stocklet_events_v1_product_proto_depIdxs = nil +} diff --git a/internal/pkg/protogen/events/v1/shipping.pb.go b/internal/pkg/protogen/events/v1/shipping.pb.go new file mode 100644 index 0000000..0921606 --- /dev/null +++ b/internal/pkg/protogen/events/v1/shipping.pb.go @@ -0,0 +1,482 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.31.0 +// protoc (unknown) +// source: stocklet/events/v1/shipping.proto + +package events_v1 + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type ShipmentAllocationEvent_Type int32 + +const ( + ShipmentAllocationEvent_TYPE_UNSPECIFIED ShipmentAllocationEvent_Type = 0 + ShipmentAllocationEvent_TYPE_FAILED ShipmentAllocationEvent_Type = 1 + ShipmentAllocationEvent_TYPE_ALLOCATED ShipmentAllocationEvent_Type = 2 + ShipmentAllocationEvent_TYPE_ALLOCATION_RELEASED ShipmentAllocationEvent_Type = 3 +) + +// Enum value maps for ShipmentAllocationEvent_Type. +var ( + ShipmentAllocationEvent_Type_name = map[int32]string{ + 0: "TYPE_UNSPECIFIED", + 1: "TYPE_FAILED", + 2: "TYPE_ALLOCATED", + 3: "TYPE_ALLOCATION_RELEASED", + } + ShipmentAllocationEvent_Type_value = map[string]int32{ + "TYPE_UNSPECIFIED": 0, + "TYPE_FAILED": 1, + "TYPE_ALLOCATED": 2, + "TYPE_ALLOCATION_RELEASED": 3, + } +) + +func (x ShipmentAllocationEvent_Type) Enum() *ShipmentAllocationEvent_Type { + p := new(ShipmentAllocationEvent_Type) + *p = x + return p +} + +func (x ShipmentAllocationEvent_Type) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (ShipmentAllocationEvent_Type) Descriptor() protoreflect.EnumDescriptor { + return file_stocklet_events_v1_shipping_proto_enumTypes[0].Descriptor() +} + +func (ShipmentAllocationEvent_Type) Type() protoreflect.EnumType { + return &file_stocklet_events_v1_shipping_proto_enumTypes[0] +} + +func (x ShipmentAllocationEvent_Type) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use ShipmentAllocationEvent_Type.Descriptor instead. +func (ShipmentAllocationEvent_Type) EnumDescriptor() ([]byte, []int) { + return file_stocklet_events_v1_shipping_proto_rawDescGZIP(), []int{0, 0} +} + +type ShipmentAllocationEvent struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Revision int32 `protobuf:"varint,1,opt,name=revision,proto3" json:"revision,omitempty"` + Type ShipmentAllocationEvent_Type `protobuf:"varint,2,opt,name=type,proto3,enum=stocklet.events.v1.ShipmentAllocationEvent_Type" json:"type,omitempty"` + OrderId string `protobuf:"bytes,3,opt,name=order_id,json=orderId,proto3" json:"order_id,omitempty"` + OrderMetadata *ShipmentAllocationEvent_OrderMetadata `protobuf:"bytes,4,opt,name=order_metadata,json=orderMetadata,proto3" json:"order_metadata,omitempty"` + ShipmentId string `protobuf:"bytes,5,opt,name=shipment_id,json=shipmentId,proto3" json:"shipment_id,omitempty"` // provided with type enum value 2+ + ProductQuantities map[string]int32 `protobuf:"bytes,6,rep,name=product_quantities,json=productQuantities,proto3" json:"product_quantities,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` +} + +func (x *ShipmentAllocationEvent) Reset() { + *x = ShipmentAllocationEvent{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_events_v1_shipping_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ShipmentAllocationEvent) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ShipmentAllocationEvent) ProtoMessage() {} + +func (x *ShipmentAllocationEvent) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_events_v1_shipping_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ShipmentAllocationEvent.ProtoReflect.Descriptor instead. +func (*ShipmentAllocationEvent) Descriptor() ([]byte, []int) { + return file_stocklet_events_v1_shipping_proto_rawDescGZIP(), []int{0} +} + +func (x *ShipmentAllocationEvent) GetRevision() int32 { + if x != nil { + return x.Revision + } + return 0 +} + +func (x *ShipmentAllocationEvent) GetType() ShipmentAllocationEvent_Type { + if x != nil { + return x.Type + } + return ShipmentAllocationEvent_TYPE_UNSPECIFIED +} + +func (x *ShipmentAllocationEvent) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +func (x *ShipmentAllocationEvent) GetOrderMetadata() *ShipmentAllocationEvent_OrderMetadata { + if x != nil { + return x.OrderMetadata + } + return nil +} + +func (x *ShipmentAllocationEvent) GetShipmentId() string { + if x != nil { + return x.ShipmentId + } + return "" +} + +func (x *ShipmentAllocationEvent) GetProductQuantities() map[string]int32 { + if x != nil { + return x.ProductQuantities + } + return nil +} + +type ShipmentDispatchedEvent struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Revision int32 `protobuf:"varint,1,opt,name=revision,proto3" json:"revision,omitempty"` + ShipmentId string `protobuf:"bytes,2,opt,name=shipment_id,json=shipmentId,proto3" json:"shipment_id,omitempty"` + OrderId string `protobuf:"bytes,3,opt,name=order_id,json=orderId,proto3" json:"order_id,omitempty"` + ProductQuantities map[string]int32 `protobuf:"bytes,4,rep,name=product_quantities,json=productQuantities,proto3" json:"product_quantities,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` +} + +func (x *ShipmentDispatchedEvent) Reset() { + *x = ShipmentDispatchedEvent{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_events_v1_shipping_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ShipmentDispatchedEvent) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ShipmentDispatchedEvent) ProtoMessage() {} + +func (x *ShipmentDispatchedEvent) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_events_v1_shipping_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ShipmentDispatchedEvent.ProtoReflect.Descriptor instead. +func (*ShipmentDispatchedEvent) Descriptor() ([]byte, []int) { + return file_stocklet_events_v1_shipping_proto_rawDescGZIP(), []int{1} +} + +func (x *ShipmentDispatchedEvent) GetRevision() int32 { + if x != nil { + return x.Revision + } + return 0 +} + +func (x *ShipmentDispatchedEvent) GetShipmentId() string { + if x != nil { + return x.ShipmentId + } + return "" +} + +func (x *ShipmentDispatchedEvent) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +func (x *ShipmentDispatchedEvent) GetProductQuantities() map[string]int32 { + if x != nil { + return x.ProductQuantities + } + return nil +} + +type ShipmentAllocationEvent_OrderMetadata struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + CustomerId string `protobuf:"bytes,1,opt,name=customer_id,json=customerId,proto3" json:"customer_id,omitempty"` + ItemsPrice float32 `protobuf:"fixed32,2,opt,name=items_price,json=itemsPrice,proto3" json:"items_price,omitempty"` + TotalPrice float32 `protobuf:"fixed32,3,opt,name=total_price,json=totalPrice,proto3" json:"total_price,omitempty"` +} + +func (x *ShipmentAllocationEvent_OrderMetadata) Reset() { + *x = ShipmentAllocationEvent_OrderMetadata{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_events_v1_shipping_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ShipmentAllocationEvent_OrderMetadata) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ShipmentAllocationEvent_OrderMetadata) ProtoMessage() {} + +func (x *ShipmentAllocationEvent_OrderMetadata) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_events_v1_shipping_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ShipmentAllocationEvent_OrderMetadata.ProtoReflect.Descriptor instead. +func (*ShipmentAllocationEvent_OrderMetadata) Descriptor() ([]byte, []int) { + return file_stocklet_events_v1_shipping_proto_rawDescGZIP(), []int{0, 0} +} + +func (x *ShipmentAllocationEvent_OrderMetadata) GetCustomerId() string { + if x != nil { + return x.CustomerId + } + return "" +} + +func (x *ShipmentAllocationEvent_OrderMetadata) GetItemsPrice() float32 { + if x != nil { + return x.ItemsPrice + } + return 0 +} + +func (x *ShipmentAllocationEvent_OrderMetadata) GetTotalPrice() float32 { + if x != nil { + return x.TotalPrice + } + return 0 +} + +var File_stocklet_events_v1_shipping_proto protoreflect.FileDescriptor + +var file_stocklet_events_v1_shipping_proto_rawDesc = []byte{ + 0x0a, 0x21, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2f, 0x65, 0x76, 0x65, 0x6e, 0x74, + 0x73, 0x2f, 0x76, 0x31, 0x2f, 0x73, 0x68, 0x69, 0x70, 0x70, 0x69, 0x6e, 0x67, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x12, 0x12, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x65, 0x76, + 0x65, 0x6e, 0x74, 0x73, 0x2e, 0x76, 0x31, 0x22, 0xa7, 0x05, 0x0a, 0x17, 0x53, 0x68, 0x69, 0x70, + 0x6d, 0x65, 0x6e, 0x74, 0x41, 0x6c, 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x45, 0x76, + 0x65, 0x6e, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x72, 0x65, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x72, 0x65, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x12, + 0x44, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x30, 0x2e, + 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x2e, + 0x76, 0x31, 0x2e, 0x53, 0x68, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x41, 0x6c, 0x6c, 0x6f, 0x63, + 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x2e, 0x54, 0x79, 0x70, 0x65, 0x52, + 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x19, 0x0a, 0x08, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x69, + 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, + 0x12, 0x60, 0x0a, 0x0e, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, + 0x74, 0x61, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x39, 0x2e, 0x73, 0x74, 0x6f, 0x63, 0x6b, + 0x6c, 0x65, 0x74, 0x2e, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x68, + 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x41, 0x6c, 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, + 0x45, 0x76, 0x65, 0x6e, 0x74, 0x2e, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x4d, 0x65, 0x74, 0x61, 0x64, + 0x61, 0x74, 0x61, 0x52, 0x0d, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, + 0x74, 0x61, 0x12, 0x1f, 0x0a, 0x0b, 0x73, 0x68, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x5f, 0x69, + 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x73, 0x68, 0x69, 0x70, 0x6d, 0x65, 0x6e, + 0x74, 0x49, 0x64, 0x12, 0x71, 0x0a, 0x12, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x5f, 0x71, + 0x75, 0x61, 0x6e, 0x74, 0x69, 0x74, 0x69, 0x65, 0x73, 0x18, 0x06, 0x20, 0x03, 0x28, 0x0b, 0x32, + 0x42, 0x2e, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x65, 0x76, 0x65, 0x6e, 0x74, + 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x68, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x41, 0x6c, 0x6c, + 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x2e, 0x50, 0x72, 0x6f, + 0x64, 0x75, 0x63, 0x74, 0x51, 0x75, 0x61, 0x6e, 0x74, 0x69, 0x74, 0x69, 0x65, 0x73, 0x45, 0x6e, + 0x74, 0x72, 0x79, 0x52, 0x11, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x51, 0x75, 0x61, 0x6e, + 0x74, 0x69, 0x74, 0x69, 0x65, 0x73, 0x1a, 0x72, 0x0a, 0x0d, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x4d, + 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x12, 0x1f, 0x0a, 0x0b, 0x63, 0x75, 0x73, 0x74, 0x6f, + 0x6d, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x63, 0x75, + 0x73, 0x74, 0x6f, 0x6d, 0x65, 0x72, 0x49, 0x64, 0x12, 0x1f, 0x0a, 0x0b, 0x69, 0x74, 0x65, 0x6d, + 0x73, 0x5f, 0x70, 0x72, 0x69, 0x63, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x02, 0x52, 0x0a, 0x69, + 0x74, 0x65, 0x6d, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x1f, 0x0a, 0x0b, 0x74, 0x6f, 0x74, + 0x61, 0x6c, 0x5f, 0x70, 0x72, 0x69, 0x63, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x02, 0x52, 0x0a, + 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x50, 0x72, 0x69, 0x63, 0x65, 0x1a, 0x44, 0x0a, 0x16, 0x50, 0x72, + 0x6f, 0x64, 0x75, 0x63, 0x74, 0x51, 0x75, 0x61, 0x6e, 0x74, 0x69, 0x74, 0x69, 0x65, 0x73, 0x45, + 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, + 0x22, 0x5f, 0x0a, 0x04, 0x54, 0x79, 0x70, 0x65, 0x12, 0x14, 0x0a, 0x10, 0x54, 0x59, 0x50, 0x45, + 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x0f, + 0x0a, 0x0b, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x46, 0x41, 0x49, 0x4c, 0x45, 0x44, 0x10, 0x01, 0x12, + 0x12, 0x0a, 0x0e, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x41, 0x4c, 0x4c, 0x4f, 0x43, 0x41, 0x54, 0x45, + 0x44, 0x10, 0x02, 0x12, 0x1c, 0x0a, 0x18, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x41, 0x4c, 0x4c, 0x4f, + 0x43, 0x41, 0x54, 0x49, 0x4f, 0x4e, 0x5f, 0x52, 0x45, 0x4c, 0x45, 0x41, 0x53, 0x45, 0x44, 0x10, + 0x03, 0x22, 0xaa, 0x02, 0x0a, 0x17, 0x53, 0x68, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x44, 0x69, + 0x73, 0x70, 0x61, 0x74, 0x63, 0x68, 0x65, 0x64, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x1a, 0x0a, + 0x08, 0x72, 0x65, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, + 0x08, 0x72, 0x65, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x1f, 0x0a, 0x0b, 0x73, 0x68, 0x69, + 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, + 0x73, 0x68, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x12, 0x19, 0x0a, 0x08, 0x6f, 0x72, + 0x64, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x72, + 0x64, 0x65, 0x72, 0x49, 0x64, 0x12, 0x71, 0x0a, 0x12, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, + 0x5f, 0x71, 0x75, 0x61, 0x6e, 0x74, 0x69, 0x74, 0x69, 0x65, 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, + 0x0b, 0x32, 0x42, 0x2e, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x65, 0x76, 0x65, + 0x6e, 0x74, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x68, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x44, + 0x69, 0x73, 0x70, 0x61, 0x74, 0x63, 0x68, 0x65, 0x64, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x2e, 0x50, + 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x51, 0x75, 0x61, 0x6e, 0x74, 0x69, 0x74, 0x69, 0x65, 0x73, + 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x11, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x51, 0x75, + 0x61, 0x6e, 0x74, 0x69, 0x74, 0x69, 0x65, 0x73, 0x1a, 0x44, 0x0a, 0x16, 0x50, 0x72, 0x6f, 0x64, + 0x75, 0x63, 0x74, 0x51, 0x75, 0x61, 0x6e, 0x74, 0x69, 0x74, 0x69, 0x65, 0x73, 0x45, 0x6e, 0x74, + 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x05, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x42, 0x47, + 0x5a, 0x45, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x68, 0x65, 0x78, + 0x6f, 0x6c, 0x61, 0x6e, 0x2f, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2f, 0x69, 0x6e, + 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x67, 0x65, 0x6e, 0x2f, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x2f, 0x76, 0x31, 0x3b, 0x65, 0x76, + 0x65, 0x6e, 0x74, 0x73, 0x5f, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_stocklet_events_v1_shipping_proto_rawDescOnce sync.Once + file_stocklet_events_v1_shipping_proto_rawDescData = file_stocklet_events_v1_shipping_proto_rawDesc +) + +func file_stocklet_events_v1_shipping_proto_rawDescGZIP() []byte { + file_stocklet_events_v1_shipping_proto_rawDescOnce.Do(func() { + file_stocklet_events_v1_shipping_proto_rawDescData = protoimpl.X.CompressGZIP(file_stocklet_events_v1_shipping_proto_rawDescData) + }) + return file_stocklet_events_v1_shipping_proto_rawDescData +} + +var file_stocklet_events_v1_shipping_proto_enumTypes = make([]protoimpl.EnumInfo, 1) +var file_stocklet_events_v1_shipping_proto_msgTypes = make([]protoimpl.MessageInfo, 5) +var file_stocklet_events_v1_shipping_proto_goTypes = []interface{}{ + (ShipmentAllocationEvent_Type)(0), // 0: stocklet.events.v1.ShipmentAllocationEvent.Type + (*ShipmentAllocationEvent)(nil), // 1: stocklet.events.v1.ShipmentAllocationEvent + (*ShipmentDispatchedEvent)(nil), // 2: stocklet.events.v1.ShipmentDispatchedEvent + (*ShipmentAllocationEvent_OrderMetadata)(nil), // 3: stocklet.events.v1.ShipmentAllocationEvent.OrderMetadata + nil, // 4: stocklet.events.v1.ShipmentAllocationEvent.ProductQuantitiesEntry + nil, // 5: stocklet.events.v1.ShipmentDispatchedEvent.ProductQuantitiesEntry +} +var file_stocklet_events_v1_shipping_proto_depIdxs = []int32{ + 0, // 0: stocklet.events.v1.ShipmentAllocationEvent.type:type_name -> stocklet.events.v1.ShipmentAllocationEvent.Type + 3, // 1: stocklet.events.v1.ShipmentAllocationEvent.order_metadata:type_name -> stocklet.events.v1.ShipmentAllocationEvent.OrderMetadata + 4, // 2: stocklet.events.v1.ShipmentAllocationEvent.product_quantities:type_name -> stocklet.events.v1.ShipmentAllocationEvent.ProductQuantitiesEntry + 5, // 3: stocklet.events.v1.ShipmentDispatchedEvent.product_quantities:type_name -> stocklet.events.v1.ShipmentDispatchedEvent.ProductQuantitiesEntry + 4, // [4:4] is the sub-list for method output_type + 4, // [4:4] is the sub-list for method input_type + 4, // [4:4] is the sub-list for extension type_name + 4, // [4:4] is the sub-list for extension extendee + 0, // [0:4] is the sub-list for field type_name +} + +func init() { file_stocklet_events_v1_shipping_proto_init() } +func file_stocklet_events_v1_shipping_proto_init() { + if File_stocklet_events_v1_shipping_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_stocklet_events_v1_shipping_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ShipmentAllocationEvent); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_stocklet_events_v1_shipping_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ShipmentDispatchedEvent); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_stocklet_events_v1_shipping_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ShipmentAllocationEvent_OrderMetadata); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_stocklet_events_v1_shipping_proto_rawDesc, + NumEnums: 1, + NumMessages: 5, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_stocklet_events_v1_shipping_proto_goTypes, + DependencyIndexes: file_stocklet_events_v1_shipping_proto_depIdxs, + EnumInfos: file_stocklet_events_v1_shipping_proto_enumTypes, + MessageInfos: file_stocklet_events_v1_shipping_proto_msgTypes, + }.Build() + File_stocklet_events_v1_shipping_proto = out.File + file_stocklet_events_v1_shipping_proto_rawDesc = nil + file_stocklet_events_v1_shipping_proto_goTypes = nil + file_stocklet_events_v1_shipping_proto_depIdxs = nil +} diff --git a/internal/pkg/protogen/events/v1/user.pb.go b/internal/pkg/protogen/events/v1/user.pb.go new file mode 100644 index 0000000..f201304 --- /dev/null +++ b/internal/pkg/protogen/events/v1/user.pb.go @@ -0,0 +1,366 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.31.0 +// protoc (unknown) +// source: stocklet/events/v1/user.proto + +package events_v1 + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type UserCreatedEvent struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Revision int32 `protobuf:"varint,1,opt,name=revision,proto3" json:"revision,omitempty"` + UserId string `protobuf:"bytes,2,opt,name=user_id,json=userId,proto3" json:"user_id,omitempty"` + Email string `protobuf:"bytes,3,opt,name=email,proto3" json:"email,omitempty"` + FirstName string `protobuf:"bytes,4,opt,name=first_name,json=firstName,proto3" json:"first_name,omitempty"` + LastName string `protobuf:"bytes,5,opt,name=last_name,json=lastName,proto3" json:"last_name,omitempty"` +} + +func (x *UserCreatedEvent) Reset() { + *x = UserCreatedEvent{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_events_v1_user_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *UserCreatedEvent) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UserCreatedEvent) ProtoMessage() {} + +func (x *UserCreatedEvent) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_events_v1_user_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use UserCreatedEvent.ProtoReflect.Descriptor instead. +func (*UserCreatedEvent) Descriptor() ([]byte, []int) { + return file_stocklet_events_v1_user_proto_rawDescGZIP(), []int{0} +} + +func (x *UserCreatedEvent) GetRevision() int32 { + if x != nil { + return x.Revision + } + return 0 +} + +func (x *UserCreatedEvent) GetUserId() string { + if x != nil { + return x.UserId + } + return "" +} + +func (x *UserCreatedEvent) GetEmail() string { + if x != nil { + return x.Email + } + return "" +} + +func (x *UserCreatedEvent) GetFirstName() string { + if x != nil { + return x.FirstName + } + return "" +} + +func (x *UserCreatedEvent) GetLastName() string { + if x != nil { + return x.LastName + } + return "" +} + +type UserEmailUpdatedEvent struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Revision int32 `protobuf:"varint,1,opt,name=revision,proto3" json:"revision,omitempty"` + UserId string `protobuf:"bytes,2,opt,name=user_id,json=userId,proto3" json:"user_id,omitempty"` + Email string `protobuf:"bytes,3,opt,name=email,proto3" json:"email,omitempty"` +} + +func (x *UserEmailUpdatedEvent) Reset() { + *x = UserEmailUpdatedEvent{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_events_v1_user_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *UserEmailUpdatedEvent) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UserEmailUpdatedEvent) ProtoMessage() {} + +func (x *UserEmailUpdatedEvent) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_events_v1_user_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use UserEmailUpdatedEvent.ProtoReflect.Descriptor instead. +func (*UserEmailUpdatedEvent) Descriptor() ([]byte, []int) { + return file_stocklet_events_v1_user_proto_rawDescGZIP(), []int{1} +} + +func (x *UserEmailUpdatedEvent) GetRevision() int32 { + if x != nil { + return x.Revision + } + return 0 +} + +func (x *UserEmailUpdatedEvent) GetUserId() string { + if x != nil { + return x.UserId + } + return "" +} + +func (x *UserEmailUpdatedEvent) GetEmail() string { + if x != nil { + return x.Email + } + return "" +} + +type UserDeletedEvent struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Revision int32 `protobuf:"varint,1,opt,name=revision,proto3" json:"revision,omitempty"` + UserId string `protobuf:"bytes,2,opt,name=user_id,json=userId,proto3" json:"user_id,omitempty"` + Email string `protobuf:"bytes,3,opt,name=email,proto3" json:"email,omitempty"` +} + +func (x *UserDeletedEvent) Reset() { + *x = UserDeletedEvent{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_events_v1_user_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *UserDeletedEvent) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UserDeletedEvent) ProtoMessage() {} + +func (x *UserDeletedEvent) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_events_v1_user_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use UserDeletedEvent.ProtoReflect.Descriptor instead. +func (*UserDeletedEvent) Descriptor() ([]byte, []int) { + return file_stocklet_events_v1_user_proto_rawDescGZIP(), []int{2} +} + +func (x *UserDeletedEvent) GetRevision() int32 { + if x != nil { + return x.Revision + } + return 0 +} + +func (x *UserDeletedEvent) GetUserId() string { + if x != nil { + return x.UserId + } + return "" +} + +func (x *UserDeletedEvent) GetEmail() string { + if x != nil { + return x.Email + } + return "" +} + +var File_stocklet_events_v1_user_proto protoreflect.FileDescriptor + +var file_stocklet_events_v1_user_proto_rawDesc = []byte{ + 0x0a, 0x1d, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2f, 0x65, 0x76, 0x65, 0x6e, 0x74, + 0x73, 0x2f, 0x76, 0x31, 0x2f, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, + 0x12, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, + 0x2e, 0x76, 0x31, 0x22, 0x99, 0x01, 0x0a, 0x10, 0x55, 0x73, 0x65, 0x72, 0x43, 0x72, 0x65, 0x61, + 0x74, 0x65, 0x64, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x72, 0x65, 0x76, 0x69, + 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x72, 0x65, 0x76, 0x69, + 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x17, 0x0a, 0x07, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x14, 0x0a, + 0x05, 0x65, 0x6d, 0x61, 0x69, 0x6c, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x65, 0x6d, + 0x61, 0x69, 0x6c, 0x12, 0x1d, 0x0a, 0x0a, 0x66, 0x69, 0x72, 0x73, 0x74, 0x5f, 0x6e, 0x61, 0x6d, + 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x66, 0x69, 0x72, 0x73, 0x74, 0x4e, 0x61, + 0x6d, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x6c, 0x61, 0x73, 0x74, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, + 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x6c, 0x61, 0x73, 0x74, 0x4e, 0x61, 0x6d, 0x65, 0x22, + 0x62, 0x0a, 0x15, 0x55, 0x73, 0x65, 0x72, 0x45, 0x6d, 0x61, 0x69, 0x6c, 0x55, 0x70, 0x64, 0x61, + 0x74, 0x65, 0x64, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x72, 0x65, 0x76, 0x69, + 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x72, 0x65, 0x76, 0x69, + 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x17, 0x0a, 0x07, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x14, 0x0a, + 0x05, 0x65, 0x6d, 0x61, 0x69, 0x6c, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x65, 0x6d, + 0x61, 0x69, 0x6c, 0x22, 0x5d, 0x0a, 0x10, 0x55, 0x73, 0x65, 0x72, 0x44, 0x65, 0x6c, 0x65, 0x74, + 0x65, 0x64, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x72, 0x65, 0x76, 0x69, 0x73, + 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x72, 0x65, 0x76, 0x69, 0x73, + 0x69, 0x6f, 0x6e, 0x12, 0x17, 0x0a, 0x07, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x14, 0x0a, 0x05, + 0x65, 0x6d, 0x61, 0x69, 0x6c, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x65, 0x6d, 0x61, + 0x69, 0x6c, 0x42, 0x47, 0x5a, 0x45, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, + 0x2f, 0x68, 0x65, 0x78, 0x6f, 0x6c, 0x61, 0x6e, 0x2f, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, + 0x74, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x67, 0x65, 0x6e, 0x2f, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x2f, 0x76, + 0x31, 0x3b, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x5f, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x33, +} + +var ( + file_stocklet_events_v1_user_proto_rawDescOnce sync.Once + file_stocklet_events_v1_user_proto_rawDescData = file_stocklet_events_v1_user_proto_rawDesc +) + +func file_stocklet_events_v1_user_proto_rawDescGZIP() []byte { + file_stocklet_events_v1_user_proto_rawDescOnce.Do(func() { + file_stocklet_events_v1_user_proto_rawDescData = protoimpl.X.CompressGZIP(file_stocklet_events_v1_user_proto_rawDescData) + }) + return file_stocklet_events_v1_user_proto_rawDescData +} + +var file_stocklet_events_v1_user_proto_msgTypes = make([]protoimpl.MessageInfo, 3) +var file_stocklet_events_v1_user_proto_goTypes = []interface{}{ + (*UserCreatedEvent)(nil), // 0: stocklet.events.v1.UserCreatedEvent + (*UserEmailUpdatedEvent)(nil), // 1: stocklet.events.v1.UserEmailUpdatedEvent + (*UserDeletedEvent)(nil), // 2: stocklet.events.v1.UserDeletedEvent +} +var file_stocklet_events_v1_user_proto_depIdxs = []int32{ + 0, // [0:0] is the sub-list for method output_type + 0, // [0:0] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_stocklet_events_v1_user_proto_init() } +func file_stocklet_events_v1_user_proto_init() { + if File_stocklet_events_v1_user_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_stocklet_events_v1_user_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*UserCreatedEvent); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_stocklet_events_v1_user_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*UserEmailUpdatedEvent); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_stocklet_events_v1_user_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*UserDeletedEvent); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_stocklet_events_v1_user_proto_rawDesc, + NumEnums: 0, + NumMessages: 3, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_stocklet_events_v1_user_proto_goTypes, + DependencyIndexes: file_stocklet_events_v1_user_proto_depIdxs, + MessageInfos: file_stocklet_events_v1_user_proto_msgTypes, + }.Build() + File_stocklet_events_v1_user_proto = out.File + file_stocklet_events_v1_user_proto_rawDesc = nil + file_stocklet_events_v1_user_proto_goTypes = nil + file_stocklet_events_v1_user_proto_depIdxs = nil +} diff --git a/internal/pkg/protogen/events/v1/warehouse.pb.go b/internal/pkg/protogen/events/v1/warehouse.pb.go new file mode 100644 index 0000000..fc2c898 --- /dev/null +++ b/internal/pkg/protogen/events/v1/warehouse.pb.go @@ -0,0 +1,671 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.31.0 +// protoc (unknown) +// source: stocklet/events/v1/warehouse.proto + +package events_v1 + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type StockReservationEvent_Type int32 + +const ( + StockReservationEvent_TYPE_UNSPECIFIED StockReservationEvent_Type = 0 + StockReservationEvent_TYPE_INSUFFICIENT_STOCK StockReservationEvent_Type = 1 + StockReservationEvent_TYPE_STOCK_RESERVED StockReservationEvent_Type = 2 + StockReservationEvent_TYPE_STOCK_RETURNED StockReservationEvent_Type = 3 + StockReservationEvent_TYPE_STOCK_CONSUMED StockReservationEvent_Type = 4 +) + +// Enum value maps for StockReservationEvent_Type. +var ( + StockReservationEvent_Type_name = map[int32]string{ + 0: "TYPE_UNSPECIFIED", + 1: "TYPE_INSUFFICIENT_STOCK", + 2: "TYPE_STOCK_RESERVED", + 3: "TYPE_STOCK_RETURNED", + 4: "TYPE_STOCK_CONSUMED", + } + StockReservationEvent_Type_value = map[string]int32{ + "TYPE_UNSPECIFIED": 0, + "TYPE_INSUFFICIENT_STOCK": 1, + "TYPE_STOCK_RESERVED": 2, + "TYPE_STOCK_RETURNED": 3, + "TYPE_STOCK_CONSUMED": 4, + } +) + +func (x StockReservationEvent_Type) Enum() *StockReservationEvent_Type { + p := new(StockReservationEvent_Type) + *p = x + return p +} + +func (x StockReservationEvent_Type) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (StockReservationEvent_Type) Descriptor() protoreflect.EnumDescriptor { + return file_stocklet_events_v1_warehouse_proto_enumTypes[0].Descriptor() +} + +func (StockReservationEvent_Type) Type() protoreflect.EnumType { + return &file_stocklet_events_v1_warehouse_proto_enumTypes[0] +} + +func (x StockReservationEvent_Type) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use StockReservationEvent_Type.Descriptor instead. +func (StockReservationEvent_Type) EnumDescriptor() ([]byte, []int) { + return file_stocklet_events_v1_warehouse_proto_rawDescGZIP(), []int{3, 0} +} + +type StockCreatedEvent struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Revision int32 `protobuf:"varint,1,opt,name=revision,proto3" json:"revision,omitempty"` + ProductId string `protobuf:"bytes,2,opt,name=product_id,json=productId,proto3" json:"product_id,omitempty"` + Quantity int32 `protobuf:"varint,3,opt,name=quantity,proto3" json:"quantity,omitempty"` +} + +func (x *StockCreatedEvent) Reset() { + *x = StockCreatedEvent{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_events_v1_warehouse_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *StockCreatedEvent) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*StockCreatedEvent) ProtoMessage() {} + +func (x *StockCreatedEvent) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_events_v1_warehouse_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use StockCreatedEvent.ProtoReflect.Descriptor instead. +func (*StockCreatedEvent) Descriptor() ([]byte, []int) { + return file_stocklet_events_v1_warehouse_proto_rawDescGZIP(), []int{0} +} + +func (x *StockCreatedEvent) GetRevision() int32 { + if x != nil { + return x.Revision + } + return 0 +} + +func (x *StockCreatedEvent) GetProductId() string { + if x != nil { + return x.ProductId + } + return "" +} + +func (x *StockCreatedEvent) GetQuantity() int32 { + if x != nil { + return x.Quantity + } + return 0 +} + +type StockAddedEvent struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Revision int32 `protobuf:"varint,1,opt,name=revision,proto3" json:"revision,omitempty"` + ProductId string `protobuf:"bytes,2,opt,name=product_id,json=productId,proto3" json:"product_id,omitempty"` + Amount int32 `protobuf:"varint,3,opt,name=amount,proto3" json:"amount,omitempty"` + // If the stock is returned as a result of a stock reservation outcome, + // then the reservation id will be included for reference. + ReservationId *string `protobuf:"bytes,4,opt,name=reservation_id,json=reservationId,proto3,oneof" json:"reservation_id,omitempty"` +} + +func (x *StockAddedEvent) Reset() { + *x = StockAddedEvent{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_events_v1_warehouse_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *StockAddedEvent) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*StockAddedEvent) ProtoMessage() {} + +func (x *StockAddedEvent) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_events_v1_warehouse_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use StockAddedEvent.ProtoReflect.Descriptor instead. +func (*StockAddedEvent) Descriptor() ([]byte, []int) { + return file_stocklet_events_v1_warehouse_proto_rawDescGZIP(), []int{1} +} + +func (x *StockAddedEvent) GetRevision() int32 { + if x != nil { + return x.Revision + } + return 0 +} + +func (x *StockAddedEvent) GetProductId() string { + if x != nil { + return x.ProductId + } + return "" +} + +func (x *StockAddedEvent) GetAmount() int32 { + if x != nil { + return x.Amount + } + return 0 +} + +func (x *StockAddedEvent) GetReservationId() string { + if x != nil && x.ReservationId != nil { + return *x.ReservationId + } + return "" +} + +type StockRemovedEvent struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Revision int32 `protobuf:"varint,1,opt,name=revision,proto3" json:"revision,omitempty"` + ProductId string `protobuf:"bytes,2,opt,name=product_id,json=productId,proto3" json:"product_id,omitempty"` + Amount int32 `protobuf:"varint,3,opt,name=amount,proto3" json:"amount,omitempty"` + // If the stock is removed as a result of a stock reservation being closed, + // then the reservation id will be included for reference. + ReservationId *string `protobuf:"bytes,4,opt,name=reservation_id,json=reservationId,proto3,oneof" json:"reservation_id,omitempty"` +} + +func (x *StockRemovedEvent) Reset() { + *x = StockRemovedEvent{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_events_v1_warehouse_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *StockRemovedEvent) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*StockRemovedEvent) ProtoMessage() {} + +func (x *StockRemovedEvent) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_events_v1_warehouse_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use StockRemovedEvent.ProtoReflect.Descriptor instead. +func (*StockRemovedEvent) Descriptor() ([]byte, []int) { + return file_stocklet_events_v1_warehouse_proto_rawDescGZIP(), []int{2} +} + +func (x *StockRemovedEvent) GetRevision() int32 { + if x != nil { + return x.Revision + } + return 0 +} + +func (x *StockRemovedEvent) GetProductId() string { + if x != nil { + return x.ProductId + } + return "" +} + +func (x *StockRemovedEvent) GetAmount() int32 { + if x != nil { + return x.Amount + } + return 0 +} + +func (x *StockRemovedEvent) GetReservationId() string { + if x != nil && x.ReservationId != nil { + return *x.ReservationId + } + return "" +} + +type StockReservationEvent struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Revision int32 `protobuf:"varint,1,opt,name=revision,proto3" json:"revision,omitempty"` + Type StockReservationEvent_Type `protobuf:"varint,2,opt,name=type,proto3,enum=stocklet.events.v1.StockReservationEvent_Type" json:"type,omitempty"` + OrderId string `protobuf:"bytes,3,opt,name=order_id,json=orderId,proto3" json:"order_id,omitempty"` + OrderMetadata *StockReservationEvent_OrderMetadata `protobuf:"bytes,4,opt,name=order_metadata,json=orderMetadata,proto3" json:"order_metadata,omitempty"` + ReservationId string `protobuf:"bytes,5,opt,name=reservation_id,json=reservationId,proto3" json:"reservation_id,omitempty"` // provided with type enum value 2+ + ReservationStock map[string]int32 `protobuf:"bytes,6,rep,name=reservation_stock,json=reservationStock,proto3" json:"reservation_stock,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` // Product ID: Quantity (provided with type enum value 2+) + InsufficientStock []string `protobuf:"bytes,7,rep,name=insufficient_stock,json=insufficientStock,proto3" json:"insufficient_stock,omitempty"` // Product IDs (only provided with TYPE_INSUFFICIENT_STOCK) +} + +func (x *StockReservationEvent) Reset() { + *x = StockReservationEvent{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_events_v1_warehouse_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *StockReservationEvent) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*StockReservationEvent) ProtoMessage() {} + +func (x *StockReservationEvent) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_events_v1_warehouse_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use StockReservationEvent.ProtoReflect.Descriptor instead. +func (*StockReservationEvent) Descriptor() ([]byte, []int) { + return file_stocklet_events_v1_warehouse_proto_rawDescGZIP(), []int{3} +} + +func (x *StockReservationEvent) GetRevision() int32 { + if x != nil { + return x.Revision + } + return 0 +} + +func (x *StockReservationEvent) GetType() StockReservationEvent_Type { + if x != nil { + return x.Type + } + return StockReservationEvent_TYPE_UNSPECIFIED +} + +func (x *StockReservationEvent) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +func (x *StockReservationEvent) GetOrderMetadata() *StockReservationEvent_OrderMetadata { + if x != nil { + return x.OrderMetadata + } + return nil +} + +func (x *StockReservationEvent) GetReservationId() string { + if x != nil { + return x.ReservationId + } + return "" +} + +func (x *StockReservationEvent) GetReservationStock() map[string]int32 { + if x != nil { + return x.ReservationStock + } + return nil +} + +func (x *StockReservationEvent) GetInsufficientStock() []string { + if x != nil { + return x.InsufficientStock + } + return nil +} + +type StockReservationEvent_OrderMetadata struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + CustomerId string `protobuf:"bytes,1,opt,name=customer_id,json=customerId,proto3" json:"customer_id,omitempty"` + ItemsPrice float32 `protobuf:"fixed32,2,opt,name=items_price,json=itemsPrice,proto3" json:"items_price,omitempty"` + TotalPrice float32 `protobuf:"fixed32,3,opt,name=total_price,json=totalPrice,proto3" json:"total_price,omitempty"` +} + +func (x *StockReservationEvent_OrderMetadata) Reset() { + *x = StockReservationEvent_OrderMetadata{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_events_v1_warehouse_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *StockReservationEvent_OrderMetadata) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*StockReservationEvent_OrderMetadata) ProtoMessage() {} + +func (x *StockReservationEvent_OrderMetadata) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_events_v1_warehouse_proto_msgTypes[4] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use StockReservationEvent_OrderMetadata.ProtoReflect.Descriptor instead. +func (*StockReservationEvent_OrderMetadata) Descriptor() ([]byte, []int) { + return file_stocklet_events_v1_warehouse_proto_rawDescGZIP(), []int{3, 0} +} + +func (x *StockReservationEvent_OrderMetadata) GetCustomerId() string { + if x != nil { + return x.CustomerId + } + return "" +} + +func (x *StockReservationEvent_OrderMetadata) GetItemsPrice() float32 { + if x != nil { + return x.ItemsPrice + } + return 0 +} + +func (x *StockReservationEvent_OrderMetadata) GetTotalPrice() float32 { + if x != nil { + return x.TotalPrice + } + return 0 +} + +var File_stocklet_events_v1_warehouse_proto protoreflect.FileDescriptor + +var file_stocklet_events_v1_warehouse_proto_rawDesc = []byte{ + 0x0a, 0x22, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2f, 0x65, 0x76, 0x65, 0x6e, 0x74, + 0x73, 0x2f, 0x76, 0x31, 0x2f, 0x77, 0x61, 0x72, 0x65, 0x68, 0x6f, 0x75, 0x73, 0x65, 0x2e, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x12, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x65, + 0x76, 0x65, 0x6e, 0x74, 0x73, 0x2e, 0x76, 0x31, 0x22, 0x6a, 0x0a, 0x11, 0x53, 0x74, 0x6f, 0x63, + 0x6b, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x1a, 0x0a, + 0x08, 0x72, 0x65, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, + 0x08, 0x72, 0x65, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x1d, 0x0a, 0x0a, 0x70, 0x72, 0x6f, + 0x64, 0x75, 0x63, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x70, + 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x71, 0x75, 0x61, 0x6e, + 0x74, 0x69, 0x74, 0x79, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x71, 0x75, 0x61, 0x6e, + 0x74, 0x69, 0x74, 0x79, 0x22, 0xa3, 0x01, 0x0a, 0x0f, 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x41, 0x64, + 0x64, 0x65, 0x64, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x72, 0x65, 0x76, 0x69, + 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x72, 0x65, 0x76, 0x69, + 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x1d, 0x0a, 0x0a, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x5f, + 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, + 0x74, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x03, 0x20, + 0x01, 0x28, 0x05, 0x52, 0x06, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x2a, 0x0a, 0x0e, 0x72, + 0x65, 0x73, 0x65, 0x72, 0x76, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x04, 0x20, + 0x01, 0x28, 0x09, 0x48, 0x00, 0x52, 0x0d, 0x72, 0x65, 0x73, 0x65, 0x72, 0x76, 0x61, 0x74, 0x69, + 0x6f, 0x6e, 0x49, 0x64, 0x88, 0x01, 0x01, 0x42, 0x11, 0x0a, 0x0f, 0x5f, 0x72, 0x65, 0x73, 0x65, + 0x72, 0x76, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x69, 0x64, 0x22, 0xa5, 0x01, 0x0a, 0x11, 0x53, + 0x74, 0x6f, 0x63, 0x6b, 0x52, 0x65, 0x6d, 0x6f, 0x76, 0x65, 0x64, 0x45, 0x76, 0x65, 0x6e, 0x74, + 0x12, 0x1a, 0x0a, 0x08, 0x72, 0x65, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x05, 0x52, 0x08, 0x72, 0x65, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x1d, 0x0a, 0x0a, + 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x09, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x61, + 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x61, 0x6d, 0x6f, + 0x75, 0x6e, 0x74, 0x12, 0x2a, 0x0a, 0x0e, 0x72, 0x65, 0x73, 0x65, 0x72, 0x76, 0x61, 0x74, 0x69, + 0x6f, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x48, 0x00, 0x52, 0x0d, 0x72, + 0x65, 0x73, 0x65, 0x72, 0x76, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x88, 0x01, 0x01, 0x42, + 0x11, 0x0a, 0x0f, 0x5f, 0x72, 0x65, 0x73, 0x65, 0x72, 0x76, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, + 0x69, 0x64, 0x22, 0xf6, 0x05, 0x0a, 0x15, 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x52, 0x65, 0x73, 0x65, + 0x72, 0x76, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x1a, 0x0a, 0x08, + 0x72, 0x65, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, + 0x72, 0x65, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x42, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x2e, 0x2e, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, + 0x74, 0x2e, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x74, 0x6f, 0x63, + 0x6b, 0x52, 0x65, 0x73, 0x65, 0x72, 0x76, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x45, 0x76, 0x65, 0x6e, + 0x74, 0x2e, 0x54, 0x79, 0x70, 0x65, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x19, 0x0a, 0x08, + 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, + 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x12, 0x5e, 0x0a, 0x0e, 0x6f, 0x72, 0x64, 0x65, 0x72, + 0x5f, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, + 0x37, 0x2e, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x65, 0x76, 0x65, 0x6e, 0x74, + 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x52, 0x65, 0x73, 0x65, 0x72, 0x76, + 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x2e, 0x4f, 0x72, 0x64, 0x65, 0x72, + 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x52, 0x0d, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4d, + 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x12, 0x25, 0x0a, 0x0e, 0x72, 0x65, 0x73, 0x65, 0x72, + 0x76, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x0d, 0x72, 0x65, 0x73, 0x65, 0x72, 0x76, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x12, 0x6c, + 0x0a, 0x11, 0x72, 0x65, 0x73, 0x65, 0x72, 0x76, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x73, 0x74, + 0x6f, 0x63, 0x6b, 0x18, 0x06, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x3f, 0x2e, 0x73, 0x74, 0x6f, 0x63, + 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x53, + 0x74, 0x6f, 0x63, 0x6b, 0x52, 0x65, 0x73, 0x65, 0x72, 0x76, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x45, + 0x76, 0x65, 0x6e, 0x74, 0x2e, 0x52, 0x65, 0x73, 0x65, 0x72, 0x76, 0x61, 0x74, 0x69, 0x6f, 0x6e, + 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x10, 0x72, 0x65, 0x73, 0x65, + 0x72, 0x76, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x12, 0x2d, 0x0a, 0x12, + 0x69, 0x6e, 0x73, 0x75, 0x66, 0x66, 0x69, 0x63, 0x69, 0x65, 0x6e, 0x74, 0x5f, 0x73, 0x74, 0x6f, + 0x63, 0x6b, 0x18, 0x07, 0x20, 0x03, 0x28, 0x09, 0x52, 0x11, 0x69, 0x6e, 0x73, 0x75, 0x66, 0x66, + 0x69, 0x63, 0x69, 0x65, 0x6e, 0x74, 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x1a, 0x72, 0x0a, 0x0d, 0x4f, + 0x72, 0x64, 0x65, 0x72, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x12, 0x1f, 0x0a, 0x0b, + 0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x0a, 0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x65, 0x72, 0x49, 0x64, 0x12, 0x1f, 0x0a, + 0x0b, 0x69, 0x74, 0x65, 0x6d, 0x73, 0x5f, 0x70, 0x72, 0x69, 0x63, 0x65, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x02, 0x52, 0x0a, 0x69, 0x74, 0x65, 0x6d, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x1f, + 0x0a, 0x0b, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x5f, 0x70, 0x72, 0x69, 0x63, 0x65, 0x18, 0x03, 0x20, + 0x01, 0x28, 0x02, 0x52, 0x0a, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x50, 0x72, 0x69, 0x63, 0x65, 0x1a, + 0x43, 0x0a, 0x15, 0x52, 0x65, 0x73, 0x65, 0x72, 0x76, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x53, 0x74, + 0x6f, 0x63, 0x6b, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, + 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, + 0x3a, 0x02, 0x38, 0x01, 0x22, 0x84, 0x01, 0x0a, 0x04, 0x54, 0x79, 0x70, 0x65, 0x12, 0x14, 0x0a, + 0x10, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, + 0x44, 0x10, 0x00, 0x12, 0x1b, 0x0a, 0x17, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x49, 0x4e, 0x53, 0x55, + 0x46, 0x46, 0x49, 0x43, 0x49, 0x45, 0x4e, 0x54, 0x5f, 0x53, 0x54, 0x4f, 0x43, 0x4b, 0x10, 0x01, + 0x12, 0x17, 0x0a, 0x13, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x53, 0x54, 0x4f, 0x43, 0x4b, 0x5f, 0x52, + 0x45, 0x53, 0x45, 0x52, 0x56, 0x45, 0x44, 0x10, 0x02, 0x12, 0x17, 0x0a, 0x13, 0x54, 0x59, 0x50, + 0x45, 0x5f, 0x53, 0x54, 0x4f, 0x43, 0x4b, 0x5f, 0x52, 0x45, 0x54, 0x55, 0x52, 0x4e, 0x45, 0x44, + 0x10, 0x03, 0x12, 0x17, 0x0a, 0x13, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x53, 0x54, 0x4f, 0x43, 0x4b, + 0x5f, 0x43, 0x4f, 0x4e, 0x53, 0x55, 0x4d, 0x45, 0x44, 0x10, 0x04, 0x42, 0x47, 0x5a, 0x45, 0x67, + 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x68, 0x65, 0x78, 0x6f, 0x6c, 0x61, + 0x6e, 0x2f, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, + 0x6e, 0x61, 0x6c, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x67, 0x65, 0x6e, + 0x2f, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x2f, 0x76, 0x31, 0x3b, 0x65, 0x76, 0x65, 0x6e, 0x74, + 0x73, 0x5f, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_stocklet_events_v1_warehouse_proto_rawDescOnce sync.Once + file_stocklet_events_v1_warehouse_proto_rawDescData = file_stocklet_events_v1_warehouse_proto_rawDesc +) + +func file_stocklet_events_v1_warehouse_proto_rawDescGZIP() []byte { + file_stocklet_events_v1_warehouse_proto_rawDescOnce.Do(func() { + file_stocklet_events_v1_warehouse_proto_rawDescData = protoimpl.X.CompressGZIP(file_stocklet_events_v1_warehouse_proto_rawDescData) + }) + return file_stocklet_events_v1_warehouse_proto_rawDescData +} + +var file_stocklet_events_v1_warehouse_proto_enumTypes = make([]protoimpl.EnumInfo, 1) +var file_stocklet_events_v1_warehouse_proto_msgTypes = make([]protoimpl.MessageInfo, 6) +var file_stocklet_events_v1_warehouse_proto_goTypes = []interface{}{ + (StockReservationEvent_Type)(0), // 0: stocklet.events.v1.StockReservationEvent.Type + (*StockCreatedEvent)(nil), // 1: stocklet.events.v1.StockCreatedEvent + (*StockAddedEvent)(nil), // 2: stocklet.events.v1.StockAddedEvent + (*StockRemovedEvent)(nil), // 3: stocklet.events.v1.StockRemovedEvent + (*StockReservationEvent)(nil), // 4: stocklet.events.v1.StockReservationEvent + (*StockReservationEvent_OrderMetadata)(nil), // 5: stocklet.events.v1.StockReservationEvent.OrderMetadata + nil, // 6: stocklet.events.v1.StockReservationEvent.ReservationStockEntry +} +var file_stocklet_events_v1_warehouse_proto_depIdxs = []int32{ + 0, // 0: stocklet.events.v1.StockReservationEvent.type:type_name -> stocklet.events.v1.StockReservationEvent.Type + 5, // 1: stocklet.events.v1.StockReservationEvent.order_metadata:type_name -> stocklet.events.v1.StockReservationEvent.OrderMetadata + 6, // 2: stocklet.events.v1.StockReservationEvent.reservation_stock:type_name -> stocklet.events.v1.StockReservationEvent.ReservationStockEntry + 3, // [3:3] is the sub-list for method output_type + 3, // [3:3] is the sub-list for method input_type + 3, // [3:3] is the sub-list for extension type_name + 3, // [3:3] is the sub-list for extension extendee + 0, // [0:3] is the sub-list for field type_name +} + +func init() { file_stocklet_events_v1_warehouse_proto_init() } +func file_stocklet_events_v1_warehouse_proto_init() { + if File_stocklet_events_v1_warehouse_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_stocklet_events_v1_warehouse_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*StockCreatedEvent); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_stocklet_events_v1_warehouse_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*StockAddedEvent); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_stocklet_events_v1_warehouse_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*StockRemovedEvent); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_stocklet_events_v1_warehouse_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*StockReservationEvent); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_stocklet_events_v1_warehouse_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*StockReservationEvent_OrderMetadata); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + file_stocklet_events_v1_warehouse_proto_msgTypes[1].OneofWrappers = []interface{}{} + file_stocklet_events_v1_warehouse_proto_msgTypes[2].OneofWrappers = []interface{}{} + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_stocklet_events_v1_warehouse_proto_rawDesc, + NumEnums: 1, + NumMessages: 6, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_stocklet_events_v1_warehouse_proto_goTypes, + DependencyIndexes: file_stocklet_events_v1_warehouse_proto_depIdxs, + EnumInfos: file_stocklet_events_v1_warehouse_proto_enumTypes, + MessageInfos: file_stocklet_events_v1_warehouse_proto_msgTypes, + }.Build() + File_stocklet_events_v1_warehouse_proto = out.File + file_stocklet_events_v1_warehouse_proto_rawDesc = nil + file_stocklet_events_v1_warehouse_proto_goTypes = nil + file_stocklet_events_v1_warehouse_proto_depIdxs = nil +} diff --git a/internal/pkg/protogen/order/v1/service.pb.go b/internal/pkg/protogen/order/v1/service.pb.go new file mode 100644 index 0000000..ed98153 --- /dev/null +++ b/internal/pkg/protogen/order/v1/service.pb.go @@ -0,0 +1,753 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.31.0 +// protoc (unknown) +// source: stocklet/order/v1/service.proto + +package order_v1 + +import ( + _ "buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go/buf/validate" + v1 "github.com/hexolan/stocklet/internal/pkg/protogen/common/v1" + v11 "github.com/hexolan/stocklet/internal/pkg/protogen/events/v1" + _ "google.golang.org/genproto/googleapis/api/annotations" + _ "google.golang.org/genproto/googleapis/api/visibility" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + emptypb "google.golang.org/protobuf/types/known/emptypb" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type ViewOrderRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=order_id,json=orderId,proto3" json:"order_id,omitempty"` +} + +func (x *ViewOrderRequest) Reset() { + *x = ViewOrderRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_order_v1_service_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ViewOrderRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ViewOrderRequest) ProtoMessage() {} + +func (x *ViewOrderRequest) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_order_v1_service_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ViewOrderRequest.ProtoReflect.Descriptor instead. +func (*ViewOrderRequest) Descriptor() ([]byte, []int) { + return file_stocklet_order_v1_service_proto_rawDescGZIP(), []int{0} +} + +func (x *ViewOrderRequest) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +type ViewOrderResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Order *Order `protobuf:"bytes,1,opt,name=order,proto3" json:"order,omitempty"` +} + +func (x *ViewOrderResponse) Reset() { + *x = ViewOrderResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_order_v1_service_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ViewOrderResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ViewOrderResponse) ProtoMessage() {} + +func (x *ViewOrderResponse) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_order_v1_service_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ViewOrderResponse.ProtoReflect.Descriptor instead. +func (*ViewOrderResponse) Descriptor() ([]byte, []int) { + return file_stocklet_order_v1_service_proto_rawDescGZIP(), []int{1} +} + +func (x *ViewOrderResponse) GetOrder() *Order { + if x != nil { + return x.Order + } + return nil +} + +type ViewOrdersRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + CustomerId string `protobuf:"bytes,1,opt,name=customer_id,json=customerId,proto3" json:"customer_id,omitempty"` +} + +func (x *ViewOrdersRequest) Reset() { + *x = ViewOrdersRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_order_v1_service_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ViewOrdersRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ViewOrdersRequest) ProtoMessage() {} + +func (x *ViewOrdersRequest) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_order_v1_service_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ViewOrdersRequest.ProtoReflect.Descriptor instead. +func (*ViewOrdersRequest) Descriptor() ([]byte, []int) { + return file_stocklet_order_v1_service_proto_rawDescGZIP(), []int{2} +} + +func (x *ViewOrdersRequest) GetCustomerId() string { + if x != nil { + return x.CustomerId + } + return "" +} + +type ViewOrdersResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Orders []*Order `protobuf:"bytes,1,rep,name=orders,proto3" json:"orders,omitempty"` +} + +func (x *ViewOrdersResponse) Reset() { + *x = ViewOrdersResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_order_v1_service_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ViewOrdersResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ViewOrdersResponse) ProtoMessage() {} + +func (x *ViewOrdersResponse) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_order_v1_service_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ViewOrdersResponse.ProtoReflect.Descriptor instead. +func (*ViewOrdersResponse) Descriptor() ([]byte, []int) { + return file_stocklet_order_v1_service_proto_rawDescGZIP(), []int{3} +} + +func (x *ViewOrdersResponse) GetOrders() []*Order { + if x != nil { + return x.Orders + } + return nil +} + +type GetOrderItemsRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` +} + +func (x *GetOrderItemsRequest) Reset() { + *x = GetOrderItemsRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_order_v1_service_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetOrderItemsRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetOrderItemsRequest) ProtoMessage() {} + +func (x *GetOrderItemsRequest) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_order_v1_service_proto_msgTypes[4] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetOrderItemsRequest.ProtoReflect.Descriptor instead. +func (*GetOrderItemsRequest) Descriptor() ([]byte, []int) { + return file_stocklet_order_v1_service_proto_rawDescGZIP(), []int{4} +} + +func (x *GetOrderItemsRequest) GetId() string { + if x != nil { + return x.Id + } + return "" +} + +type GetOrderItemsResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Items map[string]int32 `protobuf:"bytes,1,rep,name=items,proto3" json:"items,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` +} + +func (x *GetOrderItemsResponse) Reset() { + *x = GetOrderItemsResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_order_v1_service_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetOrderItemsResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetOrderItemsResponse) ProtoMessage() {} + +func (x *GetOrderItemsResponse) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_order_v1_service_proto_msgTypes[5] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetOrderItemsResponse.ProtoReflect.Descriptor instead. +func (*GetOrderItemsResponse) Descriptor() ([]byte, []int) { + return file_stocklet_order_v1_service_proto_rawDescGZIP(), []int{5} +} + +func (x *GetOrderItemsResponse) GetItems() map[string]int32 { + if x != nil { + return x.Items + } + return nil +} + +type PlaceOrderRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Cart map[string]int32 `protobuf:"bytes,1,rep,name=cart,proto3" json:"cart,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` + CustomerId string `protobuf:"bytes,2,opt,name=customer_id,json=customerId,proto3" json:"customer_id,omitempty"` +} + +func (x *PlaceOrderRequest) Reset() { + *x = PlaceOrderRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_order_v1_service_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *PlaceOrderRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*PlaceOrderRequest) ProtoMessage() {} + +func (x *PlaceOrderRequest) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_order_v1_service_proto_msgTypes[6] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use PlaceOrderRequest.ProtoReflect.Descriptor instead. +func (*PlaceOrderRequest) Descriptor() ([]byte, []int) { + return file_stocklet_order_v1_service_proto_rawDescGZIP(), []int{6} +} + +func (x *PlaceOrderRequest) GetCart() map[string]int32 { + if x != nil { + return x.Cart + } + return nil +} + +func (x *PlaceOrderRequest) GetCustomerId() string { + if x != nil { + return x.CustomerId + } + return "" +} + +type PlaceOrderResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Order *Order `protobuf:"bytes,1,opt,name=order,proto3" json:"order,omitempty"` +} + +func (x *PlaceOrderResponse) Reset() { + *x = PlaceOrderResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_order_v1_service_proto_msgTypes[7] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *PlaceOrderResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*PlaceOrderResponse) ProtoMessage() {} + +func (x *PlaceOrderResponse) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_order_v1_service_proto_msgTypes[7] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use PlaceOrderResponse.ProtoReflect.Descriptor instead. +func (*PlaceOrderResponse) Descriptor() ([]byte, []int) { + return file_stocklet_order_v1_service_proto_rawDescGZIP(), []int{7} +} + +func (x *PlaceOrderResponse) GetOrder() *Order { + if x != nil { + return x.Order + } + return nil +} + +var File_stocklet_order_v1_service_proto protoreflect.FileDescriptor + +var file_stocklet_order_v1_service_proto_rawDesc = []byte{ + 0x0a, 0x1f, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, + 0x2f, 0x76, 0x31, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x12, 0x11, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x6f, 0x72, 0x64, 0x65, + 0x72, 0x2e, 0x76, 0x31, 0x1a, 0x1b, 0x62, 0x75, 0x66, 0x2f, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, + 0x74, 0x65, 0x2f, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x1a, 0x1c, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x61, 0x6e, + 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, + 0x1b, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x69, 0x73, 0x69, + 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1b, 0x67, 0x6f, + 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x65, 0x6d, + 0x70, 0x74, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x21, 0x73, 0x74, 0x6f, 0x63, 0x6b, + 0x6c, 0x65, 0x74, 0x2f, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2f, 0x76, 0x31, 0x2f, 0x72, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x20, 0x73, 0x74, + 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2f, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x2f, 0x76, 0x31, + 0x2f, 0x70, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x20, + 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2f, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x2f, + 0x76, 0x31, 0x2f, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x1a, 0x21, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2f, 0x65, 0x76, 0x65, 0x6e, 0x74, + 0x73, 0x2f, 0x76, 0x31, 0x2f, 0x73, 0x68, 0x69, 0x70, 0x70, 0x69, 0x6e, 0x67, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x1a, 0x22, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2f, 0x65, 0x76, + 0x65, 0x6e, 0x74, 0x73, 0x2f, 0x76, 0x31, 0x2f, 0x77, 0x61, 0x72, 0x65, 0x68, 0x6f, 0x75, 0x73, + 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1d, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, + 0x74, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x2f, 0x76, 0x31, 0x2f, 0x74, 0x79, 0x70, 0x65, 0x73, + 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x36, 0x0a, 0x10, 0x56, 0x69, 0x65, 0x77, 0x4f, 0x72, + 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x22, 0x0a, 0x08, 0x6f, 0x72, + 0x64, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, 0x07, 0xba, 0x48, + 0x04, 0x72, 0x02, 0x10, 0x01, 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x22, 0x43, + 0x0a, 0x11, 0x56, 0x69, 0x65, 0x77, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x6f, + 0x6e, 0x73, 0x65, 0x12, 0x2e, 0x0a, 0x05, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x0b, 0x32, 0x18, 0x2e, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x6f, 0x72, + 0x64, 0x65, 0x72, 0x2e, 0x76, 0x31, 0x2e, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x05, 0x6f, 0x72, + 0x64, 0x65, 0x72, 0x22, 0x3d, 0x0a, 0x11, 0x56, 0x69, 0x65, 0x77, 0x4f, 0x72, 0x64, 0x65, 0x72, + 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x28, 0x0a, 0x0b, 0x63, 0x75, 0x73, 0x74, + 0x6f, 0x6d, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, 0x07, 0xba, + 0x48, 0x04, 0x72, 0x02, 0x10, 0x01, 0x52, 0x0a, 0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x65, 0x72, + 0x49, 0x64, 0x22, 0x46, 0x0a, 0x12, 0x56, 0x69, 0x65, 0x77, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x73, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x30, 0x0a, 0x06, 0x6f, 0x72, 0x64, 0x65, + 0x72, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x18, 0x2e, 0x73, 0x74, 0x6f, 0x63, 0x6b, + 0x6c, 0x65, 0x74, 0x2e, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x2e, 0x76, 0x31, 0x2e, 0x4f, 0x72, 0x64, + 0x65, 0x72, 0x52, 0x06, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x73, 0x22, 0x2f, 0x0a, 0x14, 0x47, 0x65, + 0x74, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x74, 0x65, 0x6d, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x12, 0x17, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, 0x07, + 0xba, 0x48, 0x04, 0x72, 0x02, 0x10, 0x01, 0x52, 0x02, 0x69, 0x64, 0x22, 0xaa, 0x01, 0x0a, 0x15, + 0x47, 0x65, 0x74, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x74, 0x65, 0x6d, 0x73, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x57, 0x0a, 0x05, 0x69, 0x74, 0x65, 0x6d, 0x73, 0x18, 0x01, + 0x20, 0x03, 0x28, 0x0b, 0x32, 0x33, 0x2e, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, + 0x6f, 0x72, 0x64, 0x65, 0x72, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x4f, 0x72, 0x64, 0x65, + 0x72, 0x49, 0x74, 0x65, 0x6d, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x2e, 0x49, + 0x74, 0x65, 0x6d, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x42, 0x0c, 0xba, 0x48, 0x09, 0x9a, 0x01, + 0x06, 0x2a, 0x04, 0x1a, 0x02, 0x20, 0x00, 0x52, 0x05, 0x69, 0x74, 0x65, 0x6d, 0x73, 0x1a, 0x38, + 0x0a, 0x0a, 0x49, 0x74, 0x65, 0x6d, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, + 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, + 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x76, + 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0xbf, 0x01, 0x0a, 0x11, 0x50, 0x6c, 0x61, + 0x63, 0x65, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x50, + 0x0a, 0x04, 0x63, 0x61, 0x72, 0x74, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x2e, 0x2e, 0x73, + 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x2e, 0x76, 0x31, + 0x2e, 0x50, 0x6c, 0x61, 0x63, 0x65, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x2e, 0x43, 0x61, 0x72, 0x74, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x42, 0x0c, 0xba, 0x48, + 0x09, 0x9a, 0x01, 0x06, 0x2a, 0x04, 0x1a, 0x02, 0x20, 0x00, 0x52, 0x04, 0x63, 0x61, 0x72, 0x74, + 0x12, 0x1f, 0x0a, 0x0b, 0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x65, 0x72, 0x49, + 0x64, 0x1a, 0x37, 0x0a, 0x09, 0x43, 0x61, 0x72, 0x74, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, + 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, + 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, + 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x44, 0x0a, 0x12, 0x50, 0x6c, + 0x61, 0x63, 0x65, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, + 0x12, 0x2e, 0x0a, 0x05, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, + 0x18, 0x2e, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x6f, 0x72, 0x64, 0x65, 0x72, + 0x2e, 0x76, 0x31, 0x2e, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x05, 0x6f, 0x72, 0x64, 0x65, 0x72, + 0x32, 0xcd, 0x07, 0x0a, 0x0c, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, + 0x65, 0x12, 0x79, 0x0a, 0x0b, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x49, 0x6e, 0x66, 0x6f, + 0x12, 0x26, 0x2e, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, + 0x6f, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x49, 0x6e, 0x66, + 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x27, 0x2e, 0x73, 0x74, 0x6f, 0x63, 0x6b, + 0x6c, 0x65, 0x74, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x65, + 0x72, 0x76, 0x69, 0x63, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x22, 0x19, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x13, 0x12, 0x11, 0x2f, 0x76, 0x31, 0x2f, 0x6f, + 0x72, 0x64, 0x65, 0x72, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x7b, 0x0a, 0x09, + 0x56, 0x69, 0x65, 0x77, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x12, 0x23, 0x2e, 0x73, 0x74, 0x6f, 0x63, + 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x2e, 0x76, 0x31, 0x2e, 0x56, 0x69, + 0x65, 0x77, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x24, + 0x2e, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x2e, + 0x76, 0x31, 0x2e, 0x56, 0x69, 0x65, 0x77, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x23, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x1d, 0x12, 0x1b, 0x2f, 0x76, + 0x31, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x73, 0x2f, 0x7b, + 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x7d, 0x12, 0x71, 0x0a, 0x0a, 0x56, 0x69, 0x65, + 0x77, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x73, 0x12, 0x24, 0x2e, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, + 0x65, 0x74, 0x2e, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x2e, 0x76, 0x31, 0x2e, 0x56, 0x69, 0x65, 0x77, + 0x4f, 0x72, 0x64, 0x65, 0x72, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x25, 0x2e, + 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x2e, 0x76, + 0x31, 0x2e, 0x56, 0x69, 0x65, 0x77, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x73, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x16, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x10, 0x12, 0x0e, 0x2f, 0x76, + 0x31, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x2f, 0x6c, 0x69, 0x73, 0x74, 0x12, 0x78, 0x0a, 0x0a, + 0x50, 0x6c, 0x61, 0x63, 0x65, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x12, 0x24, 0x2e, 0x73, 0x74, 0x6f, + 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x2e, 0x76, 0x31, 0x2e, 0x50, + 0x6c, 0x61, 0x63, 0x65, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x1a, 0x25, 0x2e, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x6f, 0x72, 0x64, 0x65, + 0x72, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x6c, 0x61, 0x63, 0x65, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x1d, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x17, 0x3a, + 0x04, 0x63, 0x61, 0x72, 0x74, 0x22, 0x0f, 0x2f, 0x76, 0x31, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, + 0x2f, 0x70, 0x6c, 0x61, 0x63, 0x65, 0x12, 0x75, 0x0a, 0x1d, 0x50, 0x72, 0x6f, 0x63, 0x65, 0x73, + 0x73, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x51, 0x75, 0x6f, + 0x74, 0x65, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x2a, 0x2e, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, + 0x65, 0x74, 0x2e, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x72, 0x6f, + 0x64, 0x75, 0x63, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x51, 0x75, 0x6f, 0x74, 0x65, 0x45, 0x76, + 0x65, 0x6e, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x10, 0xfa, 0xd2, 0xe4, + 0x93, 0x02, 0x0a, 0x12, 0x08, 0x49, 0x4e, 0x54, 0x45, 0x52, 0x4e, 0x41, 0x4c, 0x12, 0x73, 0x0a, + 0x1c, 0x50, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x52, 0x65, 0x73, + 0x65, 0x72, 0x76, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x29, 0x2e, + 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x2e, + 0x76, 0x31, 0x2e, 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x52, 0x65, 0x73, 0x65, 0x72, 0x76, 0x61, 0x74, + 0x69, 0x6f, 0x6e, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, + 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, + 0x22, 0x10, 0xfa, 0xd2, 0xe4, 0x93, 0x02, 0x0a, 0x12, 0x08, 0x49, 0x4e, 0x54, 0x45, 0x52, 0x4e, + 0x41, 0x4c, 0x12, 0x77, 0x0a, 0x1e, 0x50, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, 0x53, 0x68, 0x69, + 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x41, 0x6c, 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x45, + 0x76, 0x65, 0x6e, 0x74, 0x12, 0x2b, 0x2e, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, + 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x68, 0x69, 0x70, 0x6d, 0x65, + 0x6e, 0x74, 0x41, 0x6c, 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x45, 0x76, 0x65, 0x6e, + 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x10, 0xfa, 0xd2, 0xe4, 0x93, 0x02, + 0x0a, 0x12, 0x08, 0x49, 0x4e, 0x54, 0x45, 0x52, 0x4e, 0x41, 0x4c, 0x12, 0x73, 0x0a, 0x1c, 0x50, + 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, 0x50, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x50, 0x72, 0x6f, + 0x63, 0x65, 0x73, 0x73, 0x65, 0x64, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x29, 0x2e, 0x73, 0x74, + 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x2e, 0x76, 0x31, + 0x2e, 0x50, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x50, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, 0x65, + 0x64, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x10, + 0xfa, 0xd2, 0xe4, 0x93, 0x02, 0x0a, 0x12, 0x08, 0x49, 0x4e, 0x54, 0x45, 0x52, 0x4e, 0x41, 0x4c, + 0x42, 0x45, 0x5a, 0x43, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x68, + 0x65, 0x78, 0x6f, 0x6c, 0x61, 0x6e, 0x2f, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2f, + 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x67, 0x65, 0x6e, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x2f, 0x76, 0x31, 0x3b, 0x6f, + 0x72, 0x64, 0x65, 0x72, 0x5f, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_stocklet_order_v1_service_proto_rawDescOnce sync.Once + file_stocklet_order_v1_service_proto_rawDescData = file_stocklet_order_v1_service_proto_rawDesc +) + +func file_stocklet_order_v1_service_proto_rawDescGZIP() []byte { + file_stocklet_order_v1_service_proto_rawDescOnce.Do(func() { + file_stocklet_order_v1_service_proto_rawDescData = protoimpl.X.CompressGZIP(file_stocklet_order_v1_service_proto_rawDescData) + }) + return file_stocklet_order_v1_service_proto_rawDescData +} + +var file_stocklet_order_v1_service_proto_msgTypes = make([]protoimpl.MessageInfo, 10) +var file_stocklet_order_v1_service_proto_goTypes = []interface{}{ + (*ViewOrderRequest)(nil), // 0: stocklet.order.v1.ViewOrderRequest + (*ViewOrderResponse)(nil), // 1: stocklet.order.v1.ViewOrderResponse + (*ViewOrdersRequest)(nil), // 2: stocklet.order.v1.ViewOrdersRequest + (*ViewOrdersResponse)(nil), // 3: stocklet.order.v1.ViewOrdersResponse + (*GetOrderItemsRequest)(nil), // 4: stocklet.order.v1.GetOrderItemsRequest + (*GetOrderItemsResponse)(nil), // 5: stocklet.order.v1.GetOrderItemsResponse + (*PlaceOrderRequest)(nil), // 6: stocklet.order.v1.PlaceOrderRequest + (*PlaceOrderResponse)(nil), // 7: stocklet.order.v1.PlaceOrderResponse + nil, // 8: stocklet.order.v1.GetOrderItemsResponse.ItemsEntry + nil, // 9: stocklet.order.v1.PlaceOrderRequest.CartEntry + (*Order)(nil), // 10: stocklet.order.v1.Order + (*v1.ServiceInfoRequest)(nil), // 11: stocklet.common.v1.ServiceInfoRequest + (*v11.ProductPriceQuoteEvent)(nil), // 12: stocklet.events.v1.ProductPriceQuoteEvent + (*v11.StockReservationEvent)(nil), // 13: stocklet.events.v1.StockReservationEvent + (*v11.ShipmentAllocationEvent)(nil), // 14: stocklet.events.v1.ShipmentAllocationEvent + (*v11.PaymentProcessedEvent)(nil), // 15: stocklet.events.v1.PaymentProcessedEvent + (*v1.ServiceInfoResponse)(nil), // 16: stocklet.common.v1.ServiceInfoResponse + (*emptypb.Empty)(nil), // 17: google.protobuf.Empty +} +var file_stocklet_order_v1_service_proto_depIdxs = []int32{ + 10, // 0: stocklet.order.v1.ViewOrderResponse.order:type_name -> stocklet.order.v1.Order + 10, // 1: stocklet.order.v1.ViewOrdersResponse.orders:type_name -> stocklet.order.v1.Order + 8, // 2: stocklet.order.v1.GetOrderItemsResponse.items:type_name -> stocklet.order.v1.GetOrderItemsResponse.ItemsEntry + 9, // 3: stocklet.order.v1.PlaceOrderRequest.cart:type_name -> stocklet.order.v1.PlaceOrderRequest.CartEntry + 10, // 4: stocklet.order.v1.PlaceOrderResponse.order:type_name -> stocklet.order.v1.Order + 11, // 5: stocklet.order.v1.OrderService.ServiceInfo:input_type -> stocklet.common.v1.ServiceInfoRequest + 0, // 6: stocklet.order.v1.OrderService.ViewOrder:input_type -> stocklet.order.v1.ViewOrderRequest + 2, // 7: stocklet.order.v1.OrderService.ViewOrders:input_type -> stocklet.order.v1.ViewOrdersRequest + 6, // 8: stocklet.order.v1.OrderService.PlaceOrder:input_type -> stocklet.order.v1.PlaceOrderRequest + 12, // 9: stocklet.order.v1.OrderService.ProcessProductPriceQuoteEvent:input_type -> stocklet.events.v1.ProductPriceQuoteEvent + 13, // 10: stocklet.order.v1.OrderService.ProcessStockReservationEvent:input_type -> stocklet.events.v1.StockReservationEvent + 14, // 11: stocklet.order.v1.OrderService.ProcessShipmentAllocationEvent:input_type -> stocklet.events.v1.ShipmentAllocationEvent + 15, // 12: stocklet.order.v1.OrderService.ProcessPaymentProcessedEvent:input_type -> stocklet.events.v1.PaymentProcessedEvent + 16, // 13: stocklet.order.v1.OrderService.ServiceInfo:output_type -> stocklet.common.v1.ServiceInfoResponse + 1, // 14: stocklet.order.v1.OrderService.ViewOrder:output_type -> stocklet.order.v1.ViewOrderResponse + 3, // 15: stocklet.order.v1.OrderService.ViewOrders:output_type -> stocklet.order.v1.ViewOrdersResponse + 7, // 16: stocklet.order.v1.OrderService.PlaceOrder:output_type -> stocklet.order.v1.PlaceOrderResponse + 17, // 17: stocklet.order.v1.OrderService.ProcessProductPriceQuoteEvent:output_type -> google.protobuf.Empty + 17, // 18: stocklet.order.v1.OrderService.ProcessStockReservationEvent:output_type -> google.protobuf.Empty + 17, // 19: stocklet.order.v1.OrderService.ProcessShipmentAllocationEvent:output_type -> google.protobuf.Empty + 17, // 20: stocklet.order.v1.OrderService.ProcessPaymentProcessedEvent:output_type -> google.protobuf.Empty + 13, // [13:21] is the sub-list for method output_type + 5, // [5:13] is the sub-list for method input_type + 5, // [5:5] is the sub-list for extension type_name + 5, // [5:5] is the sub-list for extension extendee + 0, // [0:5] is the sub-list for field type_name +} + +func init() { file_stocklet_order_v1_service_proto_init() } +func file_stocklet_order_v1_service_proto_init() { + if File_stocklet_order_v1_service_proto != nil { + return + } + file_stocklet_order_v1_types_proto_init() + if !protoimpl.UnsafeEnabled { + file_stocklet_order_v1_service_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ViewOrderRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_stocklet_order_v1_service_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ViewOrderResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_stocklet_order_v1_service_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ViewOrdersRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_stocklet_order_v1_service_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ViewOrdersResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_stocklet_order_v1_service_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetOrderItemsRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_stocklet_order_v1_service_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetOrderItemsResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_stocklet_order_v1_service_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*PlaceOrderRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_stocklet_order_v1_service_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*PlaceOrderResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_stocklet_order_v1_service_proto_rawDesc, + NumEnums: 0, + NumMessages: 10, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_stocklet_order_v1_service_proto_goTypes, + DependencyIndexes: file_stocklet_order_v1_service_proto_depIdxs, + MessageInfos: file_stocklet_order_v1_service_proto_msgTypes, + }.Build() + File_stocklet_order_v1_service_proto = out.File + file_stocklet_order_v1_service_proto_rawDesc = nil + file_stocklet_order_v1_service_proto_goTypes = nil + file_stocklet_order_v1_service_proto_depIdxs = nil +} diff --git a/internal/pkg/protogen/order/v1/service.pb.gw.go b/internal/pkg/protogen/order/v1/service.pb.gw.go new file mode 100644 index 0000000..f971975 --- /dev/null +++ b/internal/pkg/protogen/order/v1/service.pb.gw.go @@ -0,0 +1,449 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: stocklet/order/v1/service.proto + +/* +Package order_v1 is a reverse proxy. + +It translates gRPC into RESTful JSON APIs. +*/ +package order_v1 + +import ( + "context" + "io" + "net/http" + + "github.com/grpc-ecosystem/grpc-gateway/v2/runtime" + "github.com/grpc-ecosystem/grpc-gateway/v2/utilities" + "github.com/hexolan/stocklet/internal/pkg/protogen/common/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/status" + "google.golang.org/protobuf/proto" +) + +// Suppress "imported and not used" errors +var _ codes.Code +var _ io.Reader +var _ status.Status +var _ = runtime.String +var _ = utilities.NewDoubleArray +var _ = metadata.Join + +func request_OrderService_ServiceInfo_0(ctx context.Context, marshaler runtime.Marshaler, client OrderServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq common_v1.ServiceInfoRequest + var metadata runtime.ServerMetadata + + msg, err := client.ServiceInfo(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_OrderService_ServiceInfo_0(ctx context.Context, marshaler runtime.Marshaler, server OrderServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq common_v1.ServiceInfoRequest + var metadata runtime.ServerMetadata + + msg, err := server.ServiceInfo(ctx, &protoReq) + return msg, metadata, err + +} + +func request_OrderService_ViewOrder_0(ctx context.Context, marshaler runtime.Marshaler, client OrderServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq ViewOrderRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["order_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "order_id") + } + + protoReq.OrderId, err = runtime.String(val) + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "order_id", err) + } + + msg, err := client.ViewOrder(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_OrderService_ViewOrder_0(ctx context.Context, marshaler runtime.Marshaler, server OrderServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq ViewOrderRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["order_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "order_id") + } + + protoReq.OrderId, err = runtime.String(val) + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "order_id", err) + } + + msg, err := server.ViewOrder(ctx, &protoReq) + return msg, metadata, err + +} + +var ( + filter_OrderService_ViewOrders_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} +) + +func request_OrderService_ViewOrders_0(ctx context.Context, marshaler runtime.Marshaler, client OrderServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq ViewOrdersRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_OrderService_ViewOrders_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.ViewOrders(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_OrderService_ViewOrders_0(ctx context.Context, marshaler runtime.Marshaler, server OrderServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq ViewOrdersRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_OrderService_ViewOrders_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.ViewOrders(ctx, &protoReq) + return msg, metadata, err + +} + +var ( + filter_OrderService_PlaceOrder_0 = &utilities.DoubleArray{Encoding: map[string]int{"cart": 0}, Base: []int{1, 2, 0, 0}, Check: []int{0, 1, 2, 2}} +) + +func request_OrderService_PlaceOrder_0(ctx context.Context, marshaler runtime.Marshaler, client OrderServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq PlaceOrderRequest + var metadata runtime.ServerMetadata + + newReader, berr := utilities.IOReaderFactory(req.Body) + if berr != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) + } + if err := marshaler.NewDecoder(newReader()).Decode(&protoReq.Cart); err != nil && err != io.EOF { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_OrderService_PlaceOrder_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.PlaceOrder(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_OrderService_PlaceOrder_0(ctx context.Context, marshaler runtime.Marshaler, server OrderServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq PlaceOrderRequest + var metadata runtime.ServerMetadata + + newReader, berr := utilities.IOReaderFactory(req.Body) + if berr != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) + } + if err := marshaler.NewDecoder(newReader()).Decode(&protoReq.Cart); err != nil && err != io.EOF { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_OrderService_PlaceOrder_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.PlaceOrder(ctx, &protoReq) + return msg, metadata, err + +} + +// RegisterOrderServiceHandlerServer registers the http handlers for service OrderService to "mux". +// UnaryRPC :call OrderServiceServer directly. +// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. +// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterOrderServiceHandlerFromEndpoint instead. +func RegisterOrderServiceHandlerServer(ctx context.Context, mux *runtime.ServeMux, server OrderServiceServer) error { + + mux.Handle("GET", pattern_OrderService_ServiceInfo_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/stocklet.order.v1.OrderService/ServiceInfo", runtime.WithHTTPPathPattern("/v1/order/service")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_OrderService_ServiceInfo_0(annotatedContext, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_OrderService_ServiceInfo_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_OrderService_ViewOrder_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/stocklet.order.v1.OrderService/ViewOrder", runtime.WithHTTPPathPattern("/v1/order/orders/{order_id}")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_OrderService_ViewOrder_0(annotatedContext, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_OrderService_ViewOrder_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_OrderService_ViewOrders_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/stocklet.order.v1.OrderService/ViewOrders", runtime.WithHTTPPathPattern("/v1/order/list")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_OrderService_ViewOrders_0(annotatedContext, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_OrderService_ViewOrders_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("POST", pattern_OrderService_PlaceOrder_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/stocklet.order.v1.OrderService/PlaceOrder", runtime.WithHTTPPathPattern("/v1/order/place")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_OrderService_PlaceOrder_0(annotatedContext, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_OrderService_PlaceOrder_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +// RegisterOrderServiceHandlerFromEndpoint is same as RegisterOrderServiceHandler but +// automatically dials to "endpoint" and closes the connection when "ctx" gets done. +func RegisterOrderServiceHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { + conn, err := grpc.DialContext(ctx, endpoint, opts...) + if err != nil { + return err + } + defer func() { + if err != nil { + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + return + } + go func() { + <-ctx.Done() + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + }() + }() + + return RegisterOrderServiceHandler(ctx, mux, conn) +} + +// RegisterOrderServiceHandler registers the http handlers for service OrderService to "mux". +// The handlers forward requests to the grpc endpoint over "conn". +func RegisterOrderServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { + return RegisterOrderServiceHandlerClient(ctx, mux, NewOrderServiceClient(conn)) +} + +// RegisterOrderServiceHandlerClient registers the http handlers for service OrderService +// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "OrderServiceClient". +// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "OrderServiceClient" +// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in +// "OrderServiceClient" to call the correct interceptors. +func RegisterOrderServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux, client OrderServiceClient) error { + + mux.Handle("GET", pattern_OrderService_ServiceInfo_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/stocklet.order.v1.OrderService/ServiceInfo", runtime.WithHTTPPathPattern("/v1/order/service")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_OrderService_ServiceInfo_0(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_OrderService_ServiceInfo_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_OrderService_ViewOrder_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/stocklet.order.v1.OrderService/ViewOrder", runtime.WithHTTPPathPattern("/v1/order/orders/{order_id}")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_OrderService_ViewOrder_0(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_OrderService_ViewOrder_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_OrderService_ViewOrders_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/stocklet.order.v1.OrderService/ViewOrders", runtime.WithHTTPPathPattern("/v1/order/list")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_OrderService_ViewOrders_0(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_OrderService_ViewOrders_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("POST", pattern_OrderService_PlaceOrder_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/stocklet.order.v1.OrderService/PlaceOrder", runtime.WithHTTPPathPattern("/v1/order/place")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_OrderService_PlaceOrder_0(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_OrderService_PlaceOrder_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +var ( + pattern_OrderService_ServiceInfo_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v1", "order", "service"}, "")) + + pattern_OrderService_ViewOrder_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"v1", "order", "orders", "order_id"}, "")) + + pattern_OrderService_ViewOrders_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v1", "order", "list"}, "")) + + pattern_OrderService_PlaceOrder_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v1", "order", "place"}, "")) +) + +var ( + forward_OrderService_ServiceInfo_0 = runtime.ForwardResponseMessage + + forward_OrderService_ViewOrder_0 = runtime.ForwardResponseMessage + + forward_OrderService_ViewOrders_0 = runtime.ForwardResponseMessage + + forward_OrderService_PlaceOrder_0 = runtime.ForwardResponseMessage +) diff --git a/internal/pkg/protogen/order/v1/service_grpc.pb.go b/internal/pkg/protogen/order/v1/service_grpc.pb.go new file mode 100644 index 0000000..b7c6b8d --- /dev/null +++ b/internal/pkg/protogen/order/v1/service_grpc.pb.go @@ -0,0 +1,436 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.3.0 +// - protoc (unknown) +// source: stocklet/order/v1/service.proto + +package order_v1 + +import ( + context "context" + v1 "github.com/hexolan/stocklet/internal/pkg/protogen/common/v1" + v11 "github.com/hexolan/stocklet/internal/pkg/protogen/events/v1" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + emptypb "google.golang.org/protobuf/types/known/emptypb" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.32.0 or later. +const _ = grpc.SupportPackageIsVersion7 + +const ( + OrderService_ServiceInfo_FullMethodName = "/stocklet.order.v1.OrderService/ServiceInfo" + OrderService_ViewOrder_FullMethodName = "/stocklet.order.v1.OrderService/ViewOrder" + OrderService_ViewOrders_FullMethodName = "/stocklet.order.v1.OrderService/ViewOrders" + OrderService_PlaceOrder_FullMethodName = "/stocklet.order.v1.OrderService/PlaceOrder" + OrderService_ProcessProductPriceQuoteEvent_FullMethodName = "/stocklet.order.v1.OrderService/ProcessProductPriceQuoteEvent" + OrderService_ProcessStockReservationEvent_FullMethodName = "/stocklet.order.v1.OrderService/ProcessStockReservationEvent" + OrderService_ProcessShipmentAllocationEvent_FullMethodName = "/stocklet.order.v1.OrderService/ProcessShipmentAllocationEvent" + OrderService_ProcessPaymentProcessedEvent_FullMethodName = "/stocklet.order.v1.OrderService/ProcessPaymentProcessedEvent" +) + +// OrderServiceClient is the client API for OrderService service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +type OrderServiceClient interface { + // View information about the service. + // + // buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + ServiceInfo(ctx context.Context, in *v1.ServiceInfoRequest, opts ...grpc.CallOption) (*v1.ServiceInfoResponse, error) + ViewOrder(ctx context.Context, in *ViewOrderRequest, opts ...grpc.CallOption) (*ViewOrderResponse, error) + // Get a list of a customer's orders. + // If accessed through the gateway - shows the current user's orders. + ViewOrders(ctx context.Context, in *ViewOrdersRequest, opts ...grpc.CallOption) (*ViewOrdersResponse, error) + PlaceOrder(ctx context.Context, in *PlaceOrderRequest, opts ...grpc.CallOption) (*PlaceOrderResponse, error) + // A consumer will call this method to process events. + // + // buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + // buf:lint:ignore RPC_REQUEST_STANDARD_NAME + // buf:lint:ignore RPC_RESPONSE_STANDARD_NAME + ProcessProductPriceQuoteEvent(ctx context.Context, in *v11.ProductPriceQuoteEvent, opts ...grpc.CallOption) (*emptypb.Empty, error) + // A consumer will call this method to process events. + // + // buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + // buf:lint:ignore RPC_REQUEST_STANDARD_NAME + // buf:lint:ignore RPC_RESPONSE_STANDARD_NAME + ProcessStockReservationEvent(ctx context.Context, in *v11.StockReservationEvent, opts ...grpc.CallOption) (*emptypb.Empty, error) + // A consumer will call this method to process events. + // + // buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + // buf:lint:ignore RPC_REQUEST_STANDARD_NAME + // buf:lint:ignore RPC_RESPONSE_STANDARD_NAME + ProcessShipmentAllocationEvent(ctx context.Context, in *v11.ShipmentAllocationEvent, opts ...grpc.CallOption) (*emptypb.Empty, error) + // A consumer will call this method to process events. + // + // buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + // buf:lint:ignore RPC_REQUEST_STANDARD_NAME + // buf:lint:ignore RPC_RESPONSE_STANDARD_NAME + ProcessPaymentProcessedEvent(ctx context.Context, in *v11.PaymentProcessedEvent, opts ...grpc.CallOption) (*emptypb.Empty, error) +} + +type orderServiceClient struct { + cc grpc.ClientConnInterface +} + +func NewOrderServiceClient(cc grpc.ClientConnInterface) OrderServiceClient { + return &orderServiceClient{cc} +} + +func (c *orderServiceClient) ServiceInfo(ctx context.Context, in *v1.ServiceInfoRequest, opts ...grpc.CallOption) (*v1.ServiceInfoResponse, error) { + out := new(v1.ServiceInfoResponse) + err := c.cc.Invoke(ctx, OrderService_ServiceInfo_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *orderServiceClient) ViewOrder(ctx context.Context, in *ViewOrderRequest, opts ...grpc.CallOption) (*ViewOrderResponse, error) { + out := new(ViewOrderResponse) + err := c.cc.Invoke(ctx, OrderService_ViewOrder_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *orderServiceClient) ViewOrders(ctx context.Context, in *ViewOrdersRequest, opts ...grpc.CallOption) (*ViewOrdersResponse, error) { + out := new(ViewOrdersResponse) + err := c.cc.Invoke(ctx, OrderService_ViewOrders_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *orderServiceClient) PlaceOrder(ctx context.Context, in *PlaceOrderRequest, opts ...grpc.CallOption) (*PlaceOrderResponse, error) { + out := new(PlaceOrderResponse) + err := c.cc.Invoke(ctx, OrderService_PlaceOrder_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *orderServiceClient) ProcessProductPriceQuoteEvent(ctx context.Context, in *v11.ProductPriceQuoteEvent, opts ...grpc.CallOption) (*emptypb.Empty, error) { + out := new(emptypb.Empty) + err := c.cc.Invoke(ctx, OrderService_ProcessProductPriceQuoteEvent_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *orderServiceClient) ProcessStockReservationEvent(ctx context.Context, in *v11.StockReservationEvent, opts ...grpc.CallOption) (*emptypb.Empty, error) { + out := new(emptypb.Empty) + err := c.cc.Invoke(ctx, OrderService_ProcessStockReservationEvent_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *orderServiceClient) ProcessShipmentAllocationEvent(ctx context.Context, in *v11.ShipmentAllocationEvent, opts ...grpc.CallOption) (*emptypb.Empty, error) { + out := new(emptypb.Empty) + err := c.cc.Invoke(ctx, OrderService_ProcessShipmentAllocationEvent_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *orderServiceClient) ProcessPaymentProcessedEvent(ctx context.Context, in *v11.PaymentProcessedEvent, opts ...grpc.CallOption) (*emptypb.Empty, error) { + out := new(emptypb.Empty) + err := c.cc.Invoke(ctx, OrderService_ProcessPaymentProcessedEvent_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// OrderServiceServer is the server API for OrderService service. +// All implementations must embed UnimplementedOrderServiceServer +// for forward compatibility +type OrderServiceServer interface { + // View information about the service. + // + // buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + ServiceInfo(context.Context, *v1.ServiceInfoRequest) (*v1.ServiceInfoResponse, error) + ViewOrder(context.Context, *ViewOrderRequest) (*ViewOrderResponse, error) + // Get a list of a customer's orders. + // If accessed through the gateway - shows the current user's orders. + ViewOrders(context.Context, *ViewOrdersRequest) (*ViewOrdersResponse, error) + PlaceOrder(context.Context, *PlaceOrderRequest) (*PlaceOrderResponse, error) + // A consumer will call this method to process events. + // + // buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + // buf:lint:ignore RPC_REQUEST_STANDARD_NAME + // buf:lint:ignore RPC_RESPONSE_STANDARD_NAME + ProcessProductPriceQuoteEvent(context.Context, *v11.ProductPriceQuoteEvent) (*emptypb.Empty, error) + // A consumer will call this method to process events. + // + // buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + // buf:lint:ignore RPC_REQUEST_STANDARD_NAME + // buf:lint:ignore RPC_RESPONSE_STANDARD_NAME + ProcessStockReservationEvent(context.Context, *v11.StockReservationEvent) (*emptypb.Empty, error) + // A consumer will call this method to process events. + // + // buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + // buf:lint:ignore RPC_REQUEST_STANDARD_NAME + // buf:lint:ignore RPC_RESPONSE_STANDARD_NAME + ProcessShipmentAllocationEvent(context.Context, *v11.ShipmentAllocationEvent) (*emptypb.Empty, error) + // A consumer will call this method to process events. + // + // buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + // buf:lint:ignore RPC_REQUEST_STANDARD_NAME + // buf:lint:ignore RPC_RESPONSE_STANDARD_NAME + ProcessPaymentProcessedEvent(context.Context, *v11.PaymentProcessedEvent) (*emptypb.Empty, error) + mustEmbedUnimplementedOrderServiceServer() +} + +// UnimplementedOrderServiceServer must be embedded to have forward compatible implementations. +type UnimplementedOrderServiceServer struct { +} + +func (UnimplementedOrderServiceServer) ServiceInfo(context.Context, *v1.ServiceInfoRequest) (*v1.ServiceInfoResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method ServiceInfo not implemented") +} +func (UnimplementedOrderServiceServer) ViewOrder(context.Context, *ViewOrderRequest) (*ViewOrderResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method ViewOrder not implemented") +} +func (UnimplementedOrderServiceServer) ViewOrders(context.Context, *ViewOrdersRequest) (*ViewOrdersResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method ViewOrders not implemented") +} +func (UnimplementedOrderServiceServer) PlaceOrder(context.Context, *PlaceOrderRequest) (*PlaceOrderResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method PlaceOrder not implemented") +} +func (UnimplementedOrderServiceServer) ProcessProductPriceQuoteEvent(context.Context, *v11.ProductPriceQuoteEvent) (*emptypb.Empty, error) { + return nil, status.Errorf(codes.Unimplemented, "method ProcessProductPriceQuoteEvent not implemented") +} +func (UnimplementedOrderServiceServer) ProcessStockReservationEvent(context.Context, *v11.StockReservationEvent) (*emptypb.Empty, error) { + return nil, status.Errorf(codes.Unimplemented, "method ProcessStockReservationEvent not implemented") +} +func (UnimplementedOrderServiceServer) ProcessShipmentAllocationEvent(context.Context, *v11.ShipmentAllocationEvent) (*emptypb.Empty, error) { + return nil, status.Errorf(codes.Unimplemented, "method ProcessShipmentAllocationEvent not implemented") +} +func (UnimplementedOrderServiceServer) ProcessPaymentProcessedEvent(context.Context, *v11.PaymentProcessedEvent) (*emptypb.Empty, error) { + return nil, status.Errorf(codes.Unimplemented, "method ProcessPaymentProcessedEvent not implemented") +} +func (UnimplementedOrderServiceServer) mustEmbedUnimplementedOrderServiceServer() {} + +// UnsafeOrderServiceServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to OrderServiceServer will +// result in compilation errors. +type UnsafeOrderServiceServer interface { + mustEmbedUnimplementedOrderServiceServer() +} + +func RegisterOrderServiceServer(s grpc.ServiceRegistrar, srv OrderServiceServer) { + s.RegisterService(&OrderService_ServiceDesc, srv) +} + +func _OrderService_ServiceInfo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(v1.ServiceInfoRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(OrderServiceServer).ServiceInfo(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: OrderService_ServiceInfo_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(OrderServiceServer).ServiceInfo(ctx, req.(*v1.ServiceInfoRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _OrderService_ViewOrder_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ViewOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(OrderServiceServer).ViewOrder(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: OrderService_ViewOrder_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(OrderServiceServer).ViewOrder(ctx, req.(*ViewOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _OrderService_ViewOrders_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ViewOrdersRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(OrderServiceServer).ViewOrders(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: OrderService_ViewOrders_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(OrderServiceServer).ViewOrders(ctx, req.(*ViewOrdersRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _OrderService_PlaceOrder_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(PlaceOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(OrderServiceServer).PlaceOrder(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: OrderService_PlaceOrder_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(OrderServiceServer).PlaceOrder(ctx, req.(*PlaceOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _OrderService_ProcessProductPriceQuoteEvent_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(v11.ProductPriceQuoteEvent) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(OrderServiceServer).ProcessProductPriceQuoteEvent(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: OrderService_ProcessProductPriceQuoteEvent_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(OrderServiceServer).ProcessProductPriceQuoteEvent(ctx, req.(*v11.ProductPriceQuoteEvent)) + } + return interceptor(ctx, in, info, handler) +} + +func _OrderService_ProcessStockReservationEvent_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(v11.StockReservationEvent) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(OrderServiceServer).ProcessStockReservationEvent(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: OrderService_ProcessStockReservationEvent_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(OrderServiceServer).ProcessStockReservationEvent(ctx, req.(*v11.StockReservationEvent)) + } + return interceptor(ctx, in, info, handler) +} + +func _OrderService_ProcessShipmentAllocationEvent_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(v11.ShipmentAllocationEvent) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(OrderServiceServer).ProcessShipmentAllocationEvent(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: OrderService_ProcessShipmentAllocationEvent_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(OrderServiceServer).ProcessShipmentAllocationEvent(ctx, req.(*v11.ShipmentAllocationEvent)) + } + return interceptor(ctx, in, info, handler) +} + +func _OrderService_ProcessPaymentProcessedEvent_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(v11.PaymentProcessedEvent) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(OrderServiceServer).ProcessPaymentProcessedEvent(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: OrderService_ProcessPaymentProcessedEvent_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(OrderServiceServer).ProcessPaymentProcessedEvent(ctx, req.(*v11.PaymentProcessedEvent)) + } + return interceptor(ctx, in, info, handler) +} + +// OrderService_ServiceDesc is the grpc.ServiceDesc for OrderService service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var OrderService_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "stocklet.order.v1.OrderService", + HandlerType: (*OrderServiceServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "ServiceInfo", + Handler: _OrderService_ServiceInfo_Handler, + }, + { + MethodName: "ViewOrder", + Handler: _OrderService_ViewOrder_Handler, + }, + { + MethodName: "ViewOrders", + Handler: _OrderService_ViewOrders_Handler, + }, + { + MethodName: "PlaceOrder", + Handler: _OrderService_PlaceOrder_Handler, + }, + { + MethodName: "ProcessProductPriceQuoteEvent", + Handler: _OrderService_ProcessProductPriceQuoteEvent_Handler, + }, + { + MethodName: "ProcessStockReservationEvent", + Handler: _OrderService_ProcessStockReservationEvent_Handler, + }, + { + MethodName: "ProcessShipmentAllocationEvent", + Handler: _OrderService_ProcessShipmentAllocationEvent_Handler, + }, + { + MethodName: "ProcessPaymentProcessedEvent", + Handler: _OrderService_ProcessPaymentProcessedEvent_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "stocklet/order/v1/service.proto", +} diff --git a/internal/pkg/protogen/order/v1/types.pb.go b/internal/pkg/protogen/order/v1/types.pb.go new file mode 100644 index 0000000..ba1b67f --- /dev/null +++ b/internal/pkg/protogen/order/v1/types.pb.go @@ -0,0 +1,327 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.31.0 +// protoc (unknown) +// source: stocklet/order/v1/types.proto + +package order_v1 + +import ( + _ "buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go/buf/validate" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type OrderStatus int32 + +const ( + OrderStatus_ORDER_STATUS_UNSPECIFIED OrderStatus = 0 + OrderStatus_ORDER_STATUS_PROCESSING OrderStatus = 1 // awaiting price quotes for products + OrderStatus_ORDER_STATUS_PENDING OrderStatus = 2 // awaiting stock allocation, shipping allotment and payment + OrderStatus_ORDER_STATUS_REJECTED OrderStatus = 3 + OrderStatus_ORDER_STATUS_APPROVED OrderStatus = 4 + OrderStatus_ORDER_STATUS_COMPLETED OrderStatus = 5 +) + +// Enum value maps for OrderStatus. +var ( + OrderStatus_name = map[int32]string{ + 0: "ORDER_STATUS_UNSPECIFIED", + 1: "ORDER_STATUS_PROCESSING", + 2: "ORDER_STATUS_PENDING", + 3: "ORDER_STATUS_REJECTED", + 4: "ORDER_STATUS_APPROVED", + 5: "ORDER_STATUS_COMPLETED", + } + OrderStatus_value = map[string]int32{ + "ORDER_STATUS_UNSPECIFIED": 0, + "ORDER_STATUS_PROCESSING": 1, + "ORDER_STATUS_PENDING": 2, + "ORDER_STATUS_REJECTED": 3, + "ORDER_STATUS_APPROVED": 4, + "ORDER_STATUS_COMPLETED": 5, + } +) + +func (x OrderStatus) Enum() *OrderStatus { + p := new(OrderStatus) + *p = x + return p +} + +func (x OrderStatus) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (OrderStatus) Descriptor() protoreflect.EnumDescriptor { + return file_stocklet_order_v1_types_proto_enumTypes[0].Descriptor() +} + +func (OrderStatus) Type() protoreflect.EnumType { + return &file_stocklet_order_v1_types_proto_enumTypes[0] +} + +func (x OrderStatus) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use OrderStatus.Descriptor instead. +func (OrderStatus) EnumDescriptor() ([]byte, []int) { + return file_stocklet_order_v1_types_proto_rawDescGZIP(), []int{0} +} + +type Order struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + Status OrderStatus `protobuf:"varint,2,opt,name=status,proto3,enum=stocklet.order.v1.OrderStatus" json:"status,omitempty"` + // 'items' consists of a mapping of Product ID to Quantity. + Items map[string]int32 `protobuf:"bytes,3,rep,name=items,proto3" json:"items,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` + CustomerId string `protobuf:"bytes,4,opt,name=customer_id,json=customerId,proto3" json:"customer_id,omitempty"` + TransactionId *string `protobuf:"bytes,5,opt,name=transaction_id,json=transactionId,proto3,oneof" json:"transaction_id,omitempty"` + ShippingId *string `protobuf:"bytes,6,opt,name=shipping_id,json=shippingId,proto3,oneof" json:"shipping_id,omitempty"` + CreatedAt int64 `protobuf:"varint,7,opt,name=created_at,json=createdAt,proto3" json:"created_at,omitempty"` + UpdatedAt *int64 `protobuf:"varint,8,opt,name=updated_at,json=updatedAt,proto3,oneof" json:"updated_at,omitempty"` +} + +func (x *Order) Reset() { + *x = Order{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_order_v1_types_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Order) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Order) ProtoMessage() {} + +func (x *Order) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_order_v1_types_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Order.ProtoReflect.Descriptor instead. +func (*Order) Descriptor() ([]byte, []int) { + return file_stocklet_order_v1_types_proto_rawDescGZIP(), []int{0} +} + +func (x *Order) GetId() string { + if x != nil { + return x.Id + } + return "" +} + +func (x *Order) GetStatus() OrderStatus { + if x != nil { + return x.Status + } + return OrderStatus_ORDER_STATUS_UNSPECIFIED +} + +func (x *Order) GetItems() map[string]int32 { + if x != nil { + return x.Items + } + return nil +} + +func (x *Order) GetCustomerId() string { + if x != nil { + return x.CustomerId + } + return "" +} + +func (x *Order) GetTransactionId() string { + if x != nil && x.TransactionId != nil { + return *x.TransactionId + } + return "" +} + +func (x *Order) GetShippingId() string { + if x != nil && x.ShippingId != nil { + return *x.ShippingId + } + return "" +} + +func (x *Order) GetCreatedAt() int64 { + if x != nil { + return x.CreatedAt + } + return 0 +} + +func (x *Order) GetUpdatedAt() int64 { + if x != nil && x.UpdatedAt != nil { + return *x.UpdatedAt + } + return 0 +} + +var File_stocklet_order_v1_types_proto protoreflect.FileDescriptor + +var file_stocklet_order_v1_types_proto_rawDesc = []byte{ + 0x0a, 0x1d, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, + 0x2f, 0x76, 0x31, 0x2f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, + 0x11, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x2e, + 0x76, 0x31, 0x1a, 0x1b, 0x62, 0x75, 0x66, 0x2f, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, + 0x2f, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, + 0xeb, 0x03, 0x0a, 0x05, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x12, 0x17, 0x0a, 0x02, 0x69, 0x64, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, 0x07, 0xba, 0x48, 0x04, 0x72, 0x02, 0x10, 0x01, 0x52, 0x02, + 0x69, 0x64, 0x12, 0x43, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x0e, 0x32, 0x1e, 0x2e, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x6f, 0x72, + 0x64, 0x65, 0x72, 0x2e, 0x76, 0x31, 0x2e, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x53, 0x74, 0x61, 0x74, + 0x75, 0x73, 0x42, 0x0b, 0xba, 0x48, 0x08, 0x82, 0x01, 0x05, 0x10, 0x01, 0x22, 0x01, 0x00, 0x52, + 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x47, 0x0a, 0x05, 0x69, 0x74, 0x65, 0x6d, 0x73, + 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x23, 0x2e, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, + 0x74, 0x2e, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x2e, 0x76, 0x31, 0x2e, 0x4f, 0x72, 0x64, 0x65, 0x72, + 0x2e, 0x49, 0x74, 0x65, 0x6d, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x42, 0x0c, 0xba, 0x48, 0x09, + 0x9a, 0x01, 0x06, 0x2a, 0x04, 0x1a, 0x02, 0x20, 0x00, 0x52, 0x05, 0x69, 0x74, 0x65, 0x6d, 0x73, + 0x12, 0x28, 0x0a, 0x0b, 0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, + 0x04, 0x20, 0x01, 0x28, 0x09, 0x42, 0x07, 0xba, 0x48, 0x04, 0x72, 0x02, 0x10, 0x01, 0x52, 0x0a, + 0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x65, 0x72, 0x49, 0x64, 0x12, 0x33, 0x0a, 0x0e, 0x74, 0x72, + 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x05, 0x20, 0x01, + 0x28, 0x09, 0x42, 0x07, 0xba, 0x48, 0x04, 0x72, 0x02, 0x10, 0x01, 0x48, 0x00, 0x52, 0x0d, 0x74, + 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x88, 0x01, 0x01, 0x12, + 0x2d, 0x0a, 0x0b, 0x73, 0x68, 0x69, 0x70, 0x70, 0x69, 0x6e, 0x67, 0x5f, 0x69, 0x64, 0x18, 0x06, + 0x20, 0x01, 0x28, 0x09, 0x42, 0x07, 0xba, 0x48, 0x04, 0x72, 0x02, 0x10, 0x01, 0x48, 0x01, 0x52, + 0x0a, 0x73, 0x68, 0x69, 0x70, 0x70, 0x69, 0x6e, 0x67, 0x49, 0x64, 0x88, 0x01, 0x01, 0x12, 0x1d, + 0x0a, 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x61, 0x74, 0x18, 0x07, 0x20, 0x01, + 0x28, 0x03, 0x52, 0x09, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x41, 0x74, 0x12, 0x22, 0x0a, + 0x0a, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x61, 0x74, 0x18, 0x08, 0x20, 0x01, 0x28, + 0x03, 0x48, 0x02, 0x52, 0x09, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x41, 0x74, 0x88, 0x01, + 0x01, 0x1a, 0x38, 0x0a, 0x0a, 0x49, 0x74, 0x65, 0x6d, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, + 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, + 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, + 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x42, 0x11, 0x0a, 0x0f, 0x5f, + 0x74, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x69, 0x64, 0x42, 0x0e, + 0x0a, 0x0c, 0x5f, 0x73, 0x68, 0x69, 0x70, 0x70, 0x69, 0x6e, 0x67, 0x5f, 0x69, 0x64, 0x42, 0x0d, + 0x0a, 0x0b, 0x5f, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x61, 0x74, 0x2a, 0xb4, 0x01, + 0x0a, 0x0b, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x1c, 0x0a, + 0x18, 0x4f, 0x52, 0x44, 0x45, 0x52, 0x5f, 0x53, 0x54, 0x41, 0x54, 0x55, 0x53, 0x5f, 0x55, 0x4e, + 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x1b, 0x0a, 0x17, 0x4f, + 0x52, 0x44, 0x45, 0x52, 0x5f, 0x53, 0x54, 0x41, 0x54, 0x55, 0x53, 0x5f, 0x50, 0x52, 0x4f, 0x43, + 0x45, 0x53, 0x53, 0x49, 0x4e, 0x47, 0x10, 0x01, 0x12, 0x18, 0x0a, 0x14, 0x4f, 0x52, 0x44, 0x45, + 0x52, 0x5f, 0x53, 0x54, 0x41, 0x54, 0x55, 0x53, 0x5f, 0x50, 0x45, 0x4e, 0x44, 0x49, 0x4e, 0x47, + 0x10, 0x02, 0x12, 0x19, 0x0a, 0x15, 0x4f, 0x52, 0x44, 0x45, 0x52, 0x5f, 0x53, 0x54, 0x41, 0x54, + 0x55, 0x53, 0x5f, 0x52, 0x45, 0x4a, 0x45, 0x43, 0x54, 0x45, 0x44, 0x10, 0x03, 0x12, 0x19, 0x0a, + 0x15, 0x4f, 0x52, 0x44, 0x45, 0x52, 0x5f, 0x53, 0x54, 0x41, 0x54, 0x55, 0x53, 0x5f, 0x41, 0x50, + 0x50, 0x52, 0x4f, 0x56, 0x45, 0x44, 0x10, 0x04, 0x12, 0x1a, 0x0a, 0x16, 0x4f, 0x52, 0x44, 0x45, + 0x52, 0x5f, 0x53, 0x54, 0x41, 0x54, 0x55, 0x53, 0x5f, 0x43, 0x4f, 0x4d, 0x50, 0x4c, 0x45, 0x54, + 0x45, 0x44, 0x10, 0x05, 0x42, 0x45, 0x5a, 0x43, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, + 0x6f, 0x6d, 0x2f, 0x68, 0x65, 0x78, 0x6f, 0x6c, 0x61, 0x6e, 0x2f, 0x73, 0x74, 0x6f, 0x63, 0x6b, + 0x6c, 0x65, 0x74, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x70, 0x6b, 0x67, + 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x67, 0x65, 0x6e, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x2f, + 0x76, 0x31, 0x3b, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x33, +} + +var ( + file_stocklet_order_v1_types_proto_rawDescOnce sync.Once + file_stocklet_order_v1_types_proto_rawDescData = file_stocklet_order_v1_types_proto_rawDesc +) + +func file_stocklet_order_v1_types_proto_rawDescGZIP() []byte { + file_stocklet_order_v1_types_proto_rawDescOnce.Do(func() { + file_stocklet_order_v1_types_proto_rawDescData = protoimpl.X.CompressGZIP(file_stocklet_order_v1_types_proto_rawDescData) + }) + return file_stocklet_order_v1_types_proto_rawDescData +} + +var file_stocklet_order_v1_types_proto_enumTypes = make([]protoimpl.EnumInfo, 1) +var file_stocklet_order_v1_types_proto_msgTypes = make([]protoimpl.MessageInfo, 2) +var file_stocklet_order_v1_types_proto_goTypes = []interface{}{ + (OrderStatus)(0), // 0: stocklet.order.v1.OrderStatus + (*Order)(nil), // 1: stocklet.order.v1.Order + nil, // 2: stocklet.order.v1.Order.ItemsEntry +} +var file_stocklet_order_v1_types_proto_depIdxs = []int32{ + 0, // 0: stocklet.order.v1.Order.status:type_name -> stocklet.order.v1.OrderStatus + 2, // 1: stocklet.order.v1.Order.items:type_name -> stocklet.order.v1.Order.ItemsEntry + 2, // [2:2] is the sub-list for method output_type + 2, // [2:2] is the sub-list for method input_type + 2, // [2:2] is the sub-list for extension type_name + 2, // [2:2] is the sub-list for extension extendee + 0, // [0:2] is the sub-list for field type_name +} + +func init() { file_stocklet_order_v1_types_proto_init() } +func file_stocklet_order_v1_types_proto_init() { + if File_stocklet_order_v1_types_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_stocklet_order_v1_types_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Order); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + file_stocklet_order_v1_types_proto_msgTypes[0].OneofWrappers = []interface{}{} + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_stocklet_order_v1_types_proto_rawDesc, + NumEnums: 1, + NumMessages: 2, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_stocklet_order_v1_types_proto_goTypes, + DependencyIndexes: file_stocklet_order_v1_types_proto_depIdxs, + EnumInfos: file_stocklet_order_v1_types_proto_enumTypes, + MessageInfos: file_stocklet_order_v1_types_proto_msgTypes, + }.Build() + File_stocklet_order_v1_types_proto = out.File + file_stocklet_order_v1_types_proto_rawDesc = nil + file_stocklet_order_v1_types_proto_goTypes = nil + file_stocklet_order_v1_types_proto_depIdxs = nil +} diff --git a/internal/pkg/protogen/payment/v1/service.pb.go b/internal/pkg/protogen/payment/v1/service.pb.go new file mode 100644 index 0000000..6c2e705 --- /dev/null +++ b/internal/pkg/protogen/payment/v1/service.pb.go @@ -0,0 +1,454 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.31.0 +// protoc (unknown) +// source: stocklet/payment/v1/service.proto + +package payment_v1 + +import ( + _ "buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go/buf/validate" + v1 "github.com/hexolan/stocklet/internal/pkg/protogen/common/v1" + v11 "github.com/hexolan/stocklet/internal/pkg/protogen/events/v1" + _ "google.golang.org/genproto/googleapis/api/annotations" + _ "google.golang.org/genproto/googleapis/api/visibility" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + emptypb "google.golang.org/protobuf/types/known/emptypb" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type ViewTransactionRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + TransactionId string `protobuf:"bytes,1,opt,name=transaction_id,json=transactionId,proto3" json:"transaction_id,omitempty"` +} + +func (x *ViewTransactionRequest) Reset() { + *x = ViewTransactionRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_payment_v1_service_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ViewTransactionRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ViewTransactionRequest) ProtoMessage() {} + +func (x *ViewTransactionRequest) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_payment_v1_service_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ViewTransactionRequest.ProtoReflect.Descriptor instead. +func (*ViewTransactionRequest) Descriptor() ([]byte, []int) { + return file_stocklet_payment_v1_service_proto_rawDescGZIP(), []int{0} +} + +func (x *ViewTransactionRequest) GetTransactionId() string { + if x != nil { + return x.TransactionId + } + return "" +} + +type ViewTransactionResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Transaction *Transaction `protobuf:"bytes,1,opt,name=transaction,proto3" json:"transaction,omitempty"` +} + +func (x *ViewTransactionResponse) Reset() { + *x = ViewTransactionResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_payment_v1_service_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ViewTransactionResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ViewTransactionResponse) ProtoMessage() {} + +func (x *ViewTransactionResponse) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_payment_v1_service_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ViewTransactionResponse.ProtoReflect.Descriptor instead. +func (*ViewTransactionResponse) Descriptor() ([]byte, []int) { + return file_stocklet_payment_v1_service_proto_rawDescGZIP(), []int{1} +} + +func (x *ViewTransactionResponse) GetTransaction() *Transaction { + if x != nil { + return x.Transaction + } + return nil +} + +type ViewBalanceRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + CustomerId string `protobuf:"bytes,1,opt,name=customer_id,json=customerId,proto3" json:"customer_id,omitempty"` +} + +func (x *ViewBalanceRequest) Reset() { + *x = ViewBalanceRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_payment_v1_service_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ViewBalanceRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ViewBalanceRequest) ProtoMessage() {} + +func (x *ViewBalanceRequest) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_payment_v1_service_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ViewBalanceRequest.ProtoReflect.Descriptor instead. +func (*ViewBalanceRequest) Descriptor() ([]byte, []int) { + return file_stocklet_payment_v1_service_proto_rawDescGZIP(), []int{2} +} + +func (x *ViewBalanceRequest) GetCustomerId() string { + if x != nil { + return x.CustomerId + } + return "" +} + +type ViewBalanceResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Balance *CustomerBalance `protobuf:"bytes,1,opt,name=balance,proto3" json:"balance,omitempty"` +} + +func (x *ViewBalanceResponse) Reset() { + *x = ViewBalanceResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_payment_v1_service_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ViewBalanceResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ViewBalanceResponse) ProtoMessage() {} + +func (x *ViewBalanceResponse) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_payment_v1_service_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ViewBalanceResponse.ProtoReflect.Descriptor instead. +func (*ViewBalanceResponse) Descriptor() ([]byte, []int) { + return file_stocklet_payment_v1_service_proto_rawDescGZIP(), []int{3} +} + +func (x *ViewBalanceResponse) GetBalance() *CustomerBalance { + if x != nil { + return x.Balance + } + return nil +} + +var File_stocklet_payment_v1_service_proto protoreflect.FileDescriptor + +var file_stocklet_payment_v1_service_proto_rawDesc = []byte{ + 0x0a, 0x21, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2f, 0x70, 0x61, 0x79, 0x6d, 0x65, + 0x6e, 0x74, 0x2f, 0x76, 0x31, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x12, 0x13, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x70, 0x61, + 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x2e, 0x76, 0x31, 0x1a, 0x1b, 0x62, 0x75, 0x66, 0x2f, 0x76, 0x61, + 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x2f, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1c, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x61, 0x70, + 0x69, 0x2f, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x1a, 0x1b, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, + 0x76, 0x69, 0x73, 0x69, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x1a, 0x1b, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, + 0x66, 0x2f, 0x65, 0x6d, 0x70, 0x74, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x21, 0x73, + 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2f, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2f, 0x76, + 0x31, 0x2f, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x1a, 0x21, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2f, 0x65, 0x76, 0x65, 0x6e, 0x74, + 0x73, 0x2f, 0x76, 0x31, 0x2f, 0x73, 0x68, 0x69, 0x70, 0x70, 0x69, 0x6e, 0x67, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x1a, 0x1d, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2f, 0x65, 0x76, + 0x65, 0x6e, 0x74, 0x73, 0x2f, 0x76, 0x31, 0x2f, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x1a, 0x1f, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2f, 0x70, 0x61, 0x79, + 0x6d, 0x65, 0x6e, 0x74, 0x2f, 0x76, 0x31, 0x2f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x22, 0x48, 0x0a, 0x16, 0x56, 0x69, 0x65, 0x77, 0x54, 0x72, 0x61, 0x6e, 0x73, + 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x2e, 0x0a, + 0x0e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x69, 0x64, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, 0x07, 0xba, 0x48, 0x04, 0x72, 0x02, 0x10, 0x01, 0x52, 0x0d, + 0x74, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x22, 0x5d, 0x0a, + 0x17, 0x56, 0x69, 0x65, 0x77, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x42, 0x0a, 0x0b, 0x74, 0x72, 0x61, 0x6e, + 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x20, 0x2e, + 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x70, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, + 0x2e, 0x76, 0x31, 0x2e, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x52, + 0x0b, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x3e, 0x0a, 0x12, + 0x56, 0x69, 0x65, 0x77, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x12, 0x28, 0x0a, 0x0b, 0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x65, 0x72, 0x5f, 0x69, + 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, 0x07, 0xba, 0x48, 0x04, 0x72, 0x02, 0x10, 0x01, + 0x52, 0x0a, 0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x65, 0x72, 0x49, 0x64, 0x22, 0x55, 0x0a, 0x13, + 0x56, 0x69, 0x65, 0x77, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, + 0x6e, 0x73, 0x65, 0x12, 0x3e, 0x0a, 0x07, 0x62, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x0b, 0x32, 0x24, 0x2e, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, + 0x70, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x75, 0x73, 0x74, 0x6f, + 0x6d, 0x65, 0x72, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x52, 0x07, 0x62, 0x61, 0x6c, 0x61, + 0x6e, 0x63, 0x65, 0x32, 0x8b, 0x06, 0x0a, 0x0e, 0x50, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x53, + 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x7b, 0x0a, 0x0b, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, + 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x26, 0x2e, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, + 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x65, 0x72, 0x76, 0x69, + 0x63, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x27, 0x2e, + 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, + 0x76, 0x31, 0x2e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x1b, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x15, 0x12, 0x13, + 0x2f, 0x76, 0x31, 0x2f, 0x70, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x2f, 0x73, 0x65, 0x72, 0x76, + 0x69, 0x63, 0x65, 0x12, 0x9e, 0x01, 0x0a, 0x0f, 0x56, 0x69, 0x65, 0x77, 0x54, 0x72, 0x61, 0x6e, + 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x2b, 0x2e, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, + 0x65, 0x74, 0x2e, 0x70, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x2e, 0x76, 0x31, 0x2e, 0x56, 0x69, + 0x65, 0x77, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2c, 0x2e, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, + 0x70, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x2e, 0x76, 0x31, 0x2e, 0x56, 0x69, 0x65, 0x77, 0x54, + 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x73, 0x65, 0x22, 0x30, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x2a, 0x12, 0x28, 0x2f, 0x76, 0x31, 0x2f, + 0x70, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x2f, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, + 0x69, 0x6f, 0x6e, 0x2f, 0x7b, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, + 0x5f, 0x69, 0x64, 0x7d, 0x12, 0x8b, 0x01, 0x0a, 0x0b, 0x56, 0x69, 0x65, 0x77, 0x42, 0x61, 0x6c, + 0x61, 0x6e, 0x63, 0x65, 0x12, 0x27, 0x2e, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, + 0x70, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x2e, 0x76, 0x31, 0x2e, 0x56, 0x69, 0x65, 0x77, 0x42, + 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x28, 0x2e, + 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x70, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, + 0x2e, 0x76, 0x31, 0x2e, 0x56, 0x69, 0x65, 0x77, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x29, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x23, 0x12, + 0x21, 0x2f, 0x76, 0x31, 0x2f, 0x70, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x2f, 0x62, 0x61, 0x6c, + 0x61, 0x6e, 0x63, 0x65, 0x2f, 0x7b, 0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x65, 0x72, 0x5f, 0x69, + 0x64, 0x7d, 0x12, 0x69, 0x0a, 0x17, 0x50, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, 0x55, 0x73, 0x65, + 0x72, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x24, 0x2e, + 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x2e, + 0x76, 0x31, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x45, 0x76, + 0x65, 0x6e, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x10, 0xfa, 0xd2, 0xe4, + 0x93, 0x02, 0x0a, 0x12, 0x08, 0x49, 0x4e, 0x54, 0x45, 0x52, 0x4e, 0x41, 0x4c, 0x12, 0x69, 0x0a, + 0x17, 0x50, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, 0x55, 0x73, 0x65, 0x72, 0x44, 0x65, 0x6c, 0x65, + 0x74, 0x65, 0x64, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x24, 0x2e, 0x73, 0x74, 0x6f, 0x63, 0x6b, + 0x6c, 0x65, 0x74, 0x2e, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x55, 0x73, + 0x65, 0x72, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x64, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x1a, 0x16, + 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, + 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x10, 0xfa, 0xd2, 0xe4, 0x93, 0x02, 0x0a, 0x12, 0x08, + 0x49, 0x4e, 0x54, 0x45, 0x52, 0x4e, 0x41, 0x4c, 0x12, 0x77, 0x0a, 0x1e, 0x50, 0x72, 0x6f, 0x63, + 0x65, 0x73, 0x73, 0x53, 0x68, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x41, 0x6c, 0x6c, 0x6f, 0x63, + 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x2b, 0x2e, 0x73, 0x74, 0x6f, + 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x2e, 0x76, 0x31, 0x2e, + 0x53, 0x68, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x41, 0x6c, 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x69, + 0x6f, 0x6e, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, + 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, + 0x10, 0xfa, 0xd2, 0xe4, 0x93, 0x02, 0x0a, 0x12, 0x08, 0x49, 0x4e, 0x54, 0x45, 0x52, 0x4e, 0x41, + 0x4c, 0x42, 0x49, 0x5a, 0x47, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, + 0x68, 0x65, 0x78, 0x6f, 0x6c, 0x61, 0x6e, 0x2f, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, + 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x67, 0x65, 0x6e, 0x2f, 0x70, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x2f, 0x76, + 0x31, 0x3b, 0x70, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x5f, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_stocklet_payment_v1_service_proto_rawDescOnce sync.Once + file_stocklet_payment_v1_service_proto_rawDescData = file_stocklet_payment_v1_service_proto_rawDesc +) + +func file_stocklet_payment_v1_service_proto_rawDescGZIP() []byte { + file_stocklet_payment_v1_service_proto_rawDescOnce.Do(func() { + file_stocklet_payment_v1_service_proto_rawDescData = protoimpl.X.CompressGZIP(file_stocklet_payment_v1_service_proto_rawDescData) + }) + return file_stocklet_payment_v1_service_proto_rawDescData +} + +var file_stocklet_payment_v1_service_proto_msgTypes = make([]protoimpl.MessageInfo, 4) +var file_stocklet_payment_v1_service_proto_goTypes = []interface{}{ + (*ViewTransactionRequest)(nil), // 0: stocklet.payment.v1.ViewTransactionRequest + (*ViewTransactionResponse)(nil), // 1: stocklet.payment.v1.ViewTransactionResponse + (*ViewBalanceRequest)(nil), // 2: stocklet.payment.v1.ViewBalanceRequest + (*ViewBalanceResponse)(nil), // 3: stocklet.payment.v1.ViewBalanceResponse + (*Transaction)(nil), // 4: stocklet.payment.v1.Transaction + (*CustomerBalance)(nil), // 5: stocklet.payment.v1.CustomerBalance + (*v1.ServiceInfoRequest)(nil), // 6: stocklet.common.v1.ServiceInfoRequest + (*v11.UserCreatedEvent)(nil), // 7: stocklet.events.v1.UserCreatedEvent + (*v11.UserDeletedEvent)(nil), // 8: stocklet.events.v1.UserDeletedEvent + (*v11.ShipmentAllocationEvent)(nil), // 9: stocklet.events.v1.ShipmentAllocationEvent + (*v1.ServiceInfoResponse)(nil), // 10: stocklet.common.v1.ServiceInfoResponse + (*emptypb.Empty)(nil), // 11: google.protobuf.Empty +} +var file_stocklet_payment_v1_service_proto_depIdxs = []int32{ + 4, // 0: stocklet.payment.v1.ViewTransactionResponse.transaction:type_name -> stocklet.payment.v1.Transaction + 5, // 1: stocklet.payment.v1.ViewBalanceResponse.balance:type_name -> stocklet.payment.v1.CustomerBalance + 6, // 2: stocklet.payment.v1.PaymentService.ServiceInfo:input_type -> stocklet.common.v1.ServiceInfoRequest + 0, // 3: stocklet.payment.v1.PaymentService.ViewTransaction:input_type -> stocklet.payment.v1.ViewTransactionRequest + 2, // 4: stocklet.payment.v1.PaymentService.ViewBalance:input_type -> stocklet.payment.v1.ViewBalanceRequest + 7, // 5: stocklet.payment.v1.PaymentService.ProcessUserCreatedEvent:input_type -> stocklet.events.v1.UserCreatedEvent + 8, // 6: stocklet.payment.v1.PaymentService.ProcessUserDeletedEvent:input_type -> stocklet.events.v1.UserDeletedEvent + 9, // 7: stocklet.payment.v1.PaymentService.ProcessShipmentAllocationEvent:input_type -> stocklet.events.v1.ShipmentAllocationEvent + 10, // 8: stocklet.payment.v1.PaymentService.ServiceInfo:output_type -> stocklet.common.v1.ServiceInfoResponse + 1, // 9: stocklet.payment.v1.PaymentService.ViewTransaction:output_type -> stocklet.payment.v1.ViewTransactionResponse + 3, // 10: stocklet.payment.v1.PaymentService.ViewBalance:output_type -> stocklet.payment.v1.ViewBalanceResponse + 11, // 11: stocklet.payment.v1.PaymentService.ProcessUserCreatedEvent:output_type -> google.protobuf.Empty + 11, // 12: stocklet.payment.v1.PaymentService.ProcessUserDeletedEvent:output_type -> google.protobuf.Empty + 11, // 13: stocklet.payment.v1.PaymentService.ProcessShipmentAllocationEvent:output_type -> google.protobuf.Empty + 8, // [8:14] is the sub-list for method output_type + 2, // [2:8] is the sub-list for method input_type + 2, // [2:2] is the sub-list for extension type_name + 2, // [2:2] is the sub-list for extension extendee + 0, // [0:2] is the sub-list for field type_name +} + +func init() { file_stocklet_payment_v1_service_proto_init() } +func file_stocklet_payment_v1_service_proto_init() { + if File_stocklet_payment_v1_service_proto != nil { + return + } + file_stocklet_payment_v1_types_proto_init() + if !protoimpl.UnsafeEnabled { + file_stocklet_payment_v1_service_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ViewTransactionRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_stocklet_payment_v1_service_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ViewTransactionResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_stocklet_payment_v1_service_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ViewBalanceRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_stocklet_payment_v1_service_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ViewBalanceResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_stocklet_payment_v1_service_proto_rawDesc, + NumEnums: 0, + NumMessages: 4, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_stocklet_payment_v1_service_proto_goTypes, + DependencyIndexes: file_stocklet_payment_v1_service_proto_depIdxs, + MessageInfos: file_stocklet_payment_v1_service_proto_msgTypes, + }.Build() + File_stocklet_payment_v1_service_proto = out.File + file_stocklet_payment_v1_service_proto_rawDesc = nil + file_stocklet_payment_v1_service_proto_goTypes = nil + file_stocklet_payment_v1_service_proto_depIdxs = nil +} diff --git a/internal/pkg/protogen/payment/v1/service.pb.gw.go b/internal/pkg/protogen/payment/v1/service.pb.gw.go new file mode 100644 index 0000000..5516c59 --- /dev/null +++ b/internal/pkg/protogen/payment/v1/service.pb.gw.go @@ -0,0 +1,362 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: stocklet/payment/v1/service.proto + +/* +Package payment_v1 is a reverse proxy. + +It translates gRPC into RESTful JSON APIs. +*/ +package payment_v1 + +import ( + "context" + "io" + "net/http" + + "github.com/grpc-ecosystem/grpc-gateway/v2/runtime" + "github.com/grpc-ecosystem/grpc-gateway/v2/utilities" + "github.com/hexolan/stocklet/internal/pkg/protogen/common/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/status" + "google.golang.org/protobuf/proto" +) + +// Suppress "imported and not used" errors +var _ codes.Code +var _ io.Reader +var _ status.Status +var _ = runtime.String +var _ = utilities.NewDoubleArray +var _ = metadata.Join + +func request_PaymentService_ServiceInfo_0(ctx context.Context, marshaler runtime.Marshaler, client PaymentServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq common_v1.ServiceInfoRequest + var metadata runtime.ServerMetadata + + msg, err := client.ServiceInfo(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_PaymentService_ServiceInfo_0(ctx context.Context, marshaler runtime.Marshaler, server PaymentServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq common_v1.ServiceInfoRequest + var metadata runtime.ServerMetadata + + msg, err := server.ServiceInfo(ctx, &protoReq) + return msg, metadata, err + +} + +func request_PaymentService_ViewTransaction_0(ctx context.Context, marshaler runtime.Marshaler, client PaymentServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq ViewTransactionRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["transaction_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "transaction_id") + } + + protoReq.TransactionId, err = runtime.String(val) + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "transaction_id", err) + } + + msg, err := client.ViewTransaction(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_PaymentService_ViewTransaction_0(ctx context.Context, marshaler runtime.Marshaler, server PaymentServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq ViewTransactionRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["transaction_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "transaction_id") + } + + protoReq.TransactionId, err = runtime.String(val) + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "transaction_id", err) + } + + msg, err := server.ViewTransaction(ctx, &protoReq) + return msg, metadata, err + +} + +func request_PaymentService_ViewBalance_0(ctx context.Context, marshaler runtime.Marshaler, client PaymentServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq ViewBalanceRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["customer_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "customer_id") + } + + protoReq.CustomerId, err = runtime.String(val) + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "customer_id", err) + } + + msg, err := client.ViewBalance(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_PaymentService_ViewBalance_0(ctx context.Context, marshaler runtime.Marshaler, server PaymentServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq ViewBalanceRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["customer_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "customer_id") + } + + protoReq.CustomerId, err = runtime.String(val) + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "customer_id", err) + } + + msg, err := server.ViewBalance(ctx, &protoReq) + return msg, metadata, err + +} + +// RegisterPaymentServiceHandlerServer registers the http handlers for service PaymentService to "mux". +// UnaryRPC :call PaymentServiceServer directly. +// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. +// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterPaymentServiceHandlerFromEndpoint instead. +func RegisterPaymentServiceHandlerServer(ctx context.Context, mux *runtime.ServeMux, server PaymentServiceServer) error { + + mux.Handle("GET", pattern_PaymentService_ServiceInfo_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/stocklet.payment.v1.PaymentService/ServiceInfo", runtime.WithHTTPPathPattern("/v1/payment/service")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_PaymentService_ServiceInfo_0(annotatedContext, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_PaymentService_ServiceInfo_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_PaymentService_ViewTransaction_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/stocklet.payment.v1.PaymentService/ViewTransaction", runtime.WithHTTPPathPattern("/v1/payment/transaction/{transaction_id}")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_PaymentService_ViewTransaction_0(annotatedContext, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_PaymentService_ViewTransaction_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_PaymentService_ViewBalance_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/stocklet.payment.v1.PaymentService/ViewBalance", runtime.WithHTTPPathPattern("/v1/payment/balance/{customer_id}")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_PaymentService_ViewBalance_0(annotatedContext, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_PaymentService_ViewBalance_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +// RegisterPaymentServiceHandlerFromEndpoint is same as RegisterPaymentServiceHandler but +// automatically dials to "endpoint" and closes the connection when "ctx" gets done. +func RegisterPaymentServiceHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { + conn, err := grpc.DialContext(ctx, endpoint, opts...) + if err != nil { + return err + } + defer func() { + if err != nil { + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + return + } + go func() { + <-ctx.Done() + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + }() + }() + + return RegisterPaymentServiceHandler(ctx, mux, conn) +} + +// RegisterPaymentServiceHandler registers the http handlers for service PaymentService to "mux". +// The handlers forward requests to the grpc endpoint over "conn". +func RegisterPaymentServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { + return RegisterPaymentServiceHandlerClient(ctx, mux, NewPaymentServiceClient(conn)) +} + +// RegisterPaymentServiceHandlerClient registers the http handlers for service PaymentService +// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "PaymentServiceClient". +// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "PaymentServiceClient" +// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in +// "PaymentServiceClient" to call the correct interceptors. +func RegisterPaymentServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux, client PaymentServiceClient) error { + + mux.Handle("GET", pattern_PaymentService_ServiceInfo_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/stocklet.payment.v1.PaymentService/ServiceInfo", runtime.WithHTTPPathPattern("/v1/payment/service")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_PaymentService_ServiceInfo_0(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_PaymentService_ServiceInfo_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_PaymentService_ViewTransaction_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/stocklet.payment.v1.PaymentService/ViewTransaction", runtime.WithHTTPPathPattern("/v1/payment/transaction/{transaction_id}")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_PaymentService_ViewTransaction_0(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_PaymentService_ViewTransaction_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_PaymentService_ViewBalance_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/stocklet.payment.v1.PaymentService/ViewBalance", runtime.WithHTTPPathPattern("/v1/payment/balance/{customer_id}")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_PaymentService_ViewBalance_0(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_PaymentService_ViewBalance_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +var ( + pattern_PaymentService_ServiceInfo_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v1", "payment", "service"}, "")) + + pattern_PaymentService_ViewTransaction_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"v1", "payment", "transaction", "transaction_id"}, "")) + + pattern_PaymentService_ViewBalance_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"v1", "payment", "balance", "customer_id"}, "")) +) + +var ( + forward_PaymentService_ServiceInfo_0 = runtime.ForwardResponseMessage + + forward_PaymentService_ViewTransaction_0 = runtime.ForwardResponseMessage + + forward_PaymentService_ViewBalance_0 = runtime.ForwardResponseMessage +) diff --git a/internal/pkg/protogen/payment/v1/service_grpc.pb.go b/internal/pkg/protogen/payment/v1/service_grpc.pb.go new file mode 100644 index 0000000..5a2c531 --- /dev/null +++ b/internal/pkg/protogen/payment/v1/service_grpc.pb.go @@ -0,0 +1,348 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.3.0 +// - protoc (unknown) +// source: stocklet/payment/v1/service.proto + +package payment_v1 + +import ( + context "context" + v1 "github.com/hexolan/stocklet/internal/pkg/protogen/common/v1" + v11 "github.com/hexolan/stocklet/internal/pkg/protogen/events/v1" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + emptypb "google.golang.org/protobuf/types/known/emptypb" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.32.0 or later. +const _ = grpc.SupportPackageIsVersion7 + +const ( + PaymentService_ServiceInfo_FullMethodName = "/stocklet.payment.v1.PaymentService/ServiceInfo" + PaymentService_ViewTransaction_FullMethodName = "/stocklet.payment.v1.PaymentService/ViewTransaction" + PaymentService_ViewBalance_FullMethodName = "/stocklet.payment.v1.PaymentService/ViewBalance" + PaymentService_ProcessUserCreatedEvent_FullMethodName = "/stocklet.payment.v1.PaymentService/ProcessUserCreatedEvent" + PaymentService_ProcessUserDeletedEvent_FullMethodName = "/stocklet.payment.v1.PaymentService/ProcessUserDeletedEvent" + PaymentService_ProcessShipmentAllocationEvent_FullMethodName = "/stocklet.payment.v1.PaymentService/ProcessShipmentAllocationEvent" +) + +// PaymentServiceClient is the client API for PaymentService service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +type PaymentServiceClient interface { + // View information about the service. + // + // buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + ServiceInfo(ctx context.Context, in *v1.ServiceInfoRequest, opts ...grpc.CallOption) (*v1.ServiceInfoResponse, error) + ViewTransaction(ctx context.Context, in *ViewTransactionRequest, opts ...grpc.CallOption) (*ViewTransactionResponse, error) + ViewBalance(ctx context.Context, in *ViewBalanceRequest, opts ...grpc.CallOption) (*ViewBalanceResponse, error) + // A consumer will call this method to process events. + // + // buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + // buf:lint:ignore RPC_REQUEST_STANDARD_NAME + // buf:lint:ignore RPC_RESPONSE_STANDARD_NAME + ProcessUserCreatedEvent(ctx context.Context, in *v11.UserCreatedEvent, opts ...grpc.CallOption) (*emptypb.Empty, error) + // A consumer will call this method to process events. + // + // buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + // buf:lint:ignore RPC_REQUEST_STANDARD_NAME + // buf:lint:ignore RPC_RESPONSE_STANDARD_NAME + ProcessUserDeletedEvent(ctx context.Context, in *v11.UserDeletedEvent, opts ...grpc.CallOption) (*emptypb.Empty, error) + // A consumer will call this method to process events. + // + // buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + // buf:lint:ignore RPC_REQUEST_STANDARD_NAME + // buf:lint:ignore RPC_RESPONSE_STANDARD_NAME + ProcessShipmentAllocationEvent(ctx context.Context, in *v11.ShipmentAllocationEvent, opts ...grpc.CallOption) (*emptypb.Empty, error) +} + +type paymentServiceClient struct { + cc grpc.ClientConnInterface +} + +func NewPaymentServiceClient(cc grpc.ClientConnInterface) PaymentServiceClient { + return &paymentServiceClient{cc} +} + +func (c *paymentServiceClient) ServiceInfo(ctx context.Context, in *v1.ServiceInfoRequest, opts ...grpc.CallOption) (*v1.ServiceInfoResponse, error) { + out := new(v1.ServiceInfoResponse) + err := c.cc.Invoke(ctx, PaymentService_ServiceInfo_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *paymentServiceClient) ViewTransaction(ctx context.Context, in *ViewTransactionRequest, opts ...grpc.CallOption) (*ViewTransactionResponse, error) { + out := new(ViewTransactionResponse) + err := c.cc.Invoke(ctx, PaymentService_ViewTransaction_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *paymentServiceClient) ViewBalance(ctx context.Context, in *ViewBalanceRequest, opts ...grpc.CallOption) (*ViewBalanceResponse, error) { + out := new(ViewBalanceResponse) + err := c.cc.Invoke(ctx, PaymentService_ViewBalance_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *paymentServiceClient) ProcessUserCreatedEvent(ctx context.Context, in *v11.UserCreatedEvent, opts ...grpc.CallOption) (*emptypb.Empty, error) { + out := new(emptypb.Empty) + err := c.cc.Invoke(ctx, PaymentService_ProcessUserCreatedEvent_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *paymentServiceClient) ProcessUserDeletedEvent(ctx context.Context, in *v11.UserDeletedEvent, opts ...grpc.CallOption) (*emptypb.Empty, error) { + out := new(emptypb.Empty) + err := c.cc.Invoke(ctx, PaymentService_ProcessUserDeletedEvent_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *paymentServiceClient) ProcessShipmentAllocationEvent(ctx context.Context, in *v11.ShipmentAllocationEvent, opts ...grpc.CallOption) (*emptypb.Empty, error) { + out := new(emptypb.Empty) + err := c.cc.Invoke(ctx, PaymentService_ProcessShipmentAllocationEvent_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// PaymentServiceServer is the server API for PaymentService service. +// All implementations must embed UnimplementedPaymentServiceServer +// for forward compatibility +type PaymentServiceServer interface { + // View information about the service. + // + // buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + ServiceInfo(context.Context, *v1.ServiceInfoRequest) (*v1.ServiceInfoResponse, error) + ViewTransaction(context.Context, *ViewTransactionRequest) (*ViewTransactionResponse, error) + ViewBalance(context.Context, *ViewBalanceRequest) (*ViewBalanceResponse, error) + // A consumer will call this method to process events. + // + // buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + // buf:lint:ignore RPC_REQUEST_STANDARD_NAME + // buf:lint:ignore RPC_RESPONSE_STANDARD_NAME + ProcessUserCreatedEvent(context.Context, *v11.UserCreatedEvent) (*emptypb.Empty, error) + // A consumer will call this method to process events. + // + // buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + // buf:lint:ignore RPC_REQUEST_STANDARD_NAME + // buf:lint:ignore RPC_RESPONSE_STANDARD_NAME + ProcessUserDeletedEvent(context.Context, *v11.UserDeletedEvent) (*emptypb.Empty, error) + // A consumer will call this method to process events. + // + // buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + // buf:lint:ignore RPC_REQUEST_STANDARD_NAME + // buf:lint:ignore RPC_RESPONSE_STANDARD_NAME + ProcessShipmentAllocationEvent(context.Context, *v11.ShipmentAllocationEvent) (*emptypb.Empty, error) + mustEmbedUnimplementedPaymentServiceServer() +} + +// UnimplementedPaymentServiceServer must be embedded to have forward compatible implementations. +type UnimplementedPaymentServiceServer struct { +} + +func (UnimplementedPaymentServiceServer) ServiceInfo(context.Context, *v1.ServiceInfoRequest) (*v1.ServiceInfoResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method ServiceInfo not implemented") +} +func (UnimplementedPaymentServiceServer) ViewTransaction(context.Context, *ViewTransactionRequest) (*ViewTransactionResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method ViewTransaction not implemented") +} +func (UnimplementedPaymentServiceServer) ViewBalance(context.Context, *ViewBalanceRequest) (*ViewBalanceResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method ViewBalance not implemented") +} +func (UnimplementedPaymentServiceServer) ProcessUserCreatedEvent(context.Context, *v11.UserCreatedEvent) (*emptypb.Empty, error) { + return nil, status.Errorf(codes.Unimplemented, "method ProcessUserCreatedEvent not implemented") +} +func (UnimplementedPaymentServiceServer) ProcessUserDeletedEvent(context.Context, *v11.UserDeletedEvent) (*emptypb.Empty, error) { + return nil, status.Errorf(codes.Unimplemented, "method ProcessUserDeletedEvent not implemented") +} +func (UnimplementedPaymentServiceServer) ProcessShipmentAllocationEvent(context.Context, *v11.ShipmentAllocationEvent) (*emptypb.Empty, error) { + return nil, status.Errorf(codes.Unimplemented, "method ProcessShipmentAllocationEvent not implemented") +} +func (UnimplementedPaymentServiceServer) mustEmbedUnimplementedPaymentServiceServer() {} + +// UnsafePaymentServiceServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to PaymentServiceServer will +// result in compilation errors. +type UnsafePaymentServiceServer interface { + mustEmbedUnimplementedPaymentServiceServer() +} + +func RegisterPaymentServiceServer(s grpc.ServiceRegistrar, srv PaymentServiceServer) { + s.RegisterService(&PaymentService_ServiceDesc, srv) +} + +func _PaymentService_ServiceInfo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(v1.ServiceInfoRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(PaymentServiceServer).ServiceInfo(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: PaymentService_ServiceInfo_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(PaymentServiceServer).ServiceInfo(ctx, req.(*v1.ServiceInfoRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _PaymentService_ViewTransaction_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ViewTransactionRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(PaymentServiceServer).ViewTransaction(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: PaymentService_ViewTransaction_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(PaymentServiceServer).ViewTransaction(ctx, req.(*ViewTransactionRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _PaymentService_ViewBalance_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ViewBalanceRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(PaymentServiceServer).ViewBalance(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: PaymentService_ViewBalance_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(PaymentServiceServer).ViewBalance(ctx, req.(*ViewBalanceRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _PaymentService_ProcessUserCreatedEvent_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(v11.UserCreatedEvent) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(PaymentServiceServer).ProcessUserCreatedEvent(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: PaymentService_ProcessUserCreatedEvent_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(PaymentServiceServer).ProcessUserCreatedEvent(ctx, req.(*v11.UserCreatedEvent)) + } + return interceptor(ctx, in, info, handler) +} + +func _PaymentService_ProcessUserDeletedEvent_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(v11.UserDeletedEvent) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(PaymentServiceServer).ProcessUserDeletedEvent(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: PaymentService_ProcessUserDeletedEvent_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(PaymentServiceServer).ProcessUserDeletedEvent(ctx, req.(*v11.UserDeletedEvent)) + } + return interceptor(ctx, in, info, handler) +} + +func _PaymentService_ProcessShipmentAllocationEvent_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(v11.ShipmentAllocationEvent) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(PaymentServiceServer).ProcessShipmentAllocationEvent(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: PaymentService_ProcessShipmentAllocationEvent_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(PaymentServiceServer).ProcessShipmentAllocationEvent(ctx, req.(*v11.ShipmentAllocationEvent)) + } + return interceptor(ctx, in, info, handler) +} + +// PaymentService_ServiceDesc is the grpc.ServiceDesc for PaymentService service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var PaymentService_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "stocklet.payment.v1.PaymentService", + HandlerType: (*PaymentServiceServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "ServiceInfo", + Handler: _PaymentService_ServiceInfo_Handler, + }, + { + MethodName: "ViewTransaction", + Handler: _PaymentService_ViewTransaction_Handler, + }, + { + MethodName: "ViewBalance", + Handler: _PaymentService_ViewBalance_Handler, + }, + { + MethodName: "ProcessUserCreatedEvent", + Handler: _PaymentService_ProcessUserCreatedEvent_Handler, + }, + { + MethodName: "ProcessUserDeletedEvent", + Handler: _PaymentService_ProcessUserDeletedEvent_Handler, + }, + { + MethodName: "ProcessShipmentAllocationEvent", + Handler: _PaymentService_ProcessShipmentAllocationEvent_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "stocklet/payment/v1/service.proto", +} diff --git a/internal/pkg/protogen/payment/v1/types.pb.go b/internal/pkg/protogen/payment/v1/types.pb.go new file mode 100644 index 0000000..ad04d94 --- /dev/null +++ b/internal/pkg/protogen/payment/v1/types.pb.go @@ -0,0 +1,294 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.31.0 +// protoc (unknown) +// source: stocklet/payment/v1/types.proto + +package payment_v1 + +import ( + _ "buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go/buf/validate" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type Transaction struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + Amount float32 `protobuf:"fixed32,2,opt,name=amount,proto3" json:"amount,omitempty"` + OrderId string `protobuf:"bytes,3,opt,name=order_id,json=orderId,proto3" json:"order_id,omitempty"` + CustomerId string `protobuf:"bytes,4,opt,name=customer_id,json=customerId,proto3" json:"customer_id,omitempty"` + // Optional - If set, then the transaction has been refunded. + ReversedAt *int64 `protobuf:"varint,5,opt,name=reversed_at,json=reversedAt,proto3,oneof" json:"reversed_at,omitempty"` + ProcessedAt int64 `protobuf:"varint,6,opt,name=processed_at,json=processedAt,proto3" json:"processed_at,omitempty"` +} + +func (x *Transaction) Reset() { + *x = Transaction{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_payment_v1_types_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Transaction) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Transaction) ProtoMessage() {} + +func (x *Transaction) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_payment_v1_types_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Transaction.ProtoReflect.Descriptor instead. +func (*Transaction) Descriptor() ([]byte, []int) { + return file_stocklet_payment_v1_types_proto_rawDescGZIP(), []int{0} +} + +func (x *Transaction) GetId() string { + if x != nil { + return x.Id + } + return "" +} + +func (x *Transaction) GetAmount() float32 { + if x != nil { + return x.Amount + } + return 0 +} + +func (x *Transaction) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +func (x *Transaction) GetCustomerId() string { + if x != nil { + return x.CustomerId + } + return "" +} + +func (x *Transaction) GetReversedAt() int64 { + if x != nil && x.ReversedAt != nil { + return *x.ReversedAt + } + return 0 +} + +func (x *Transaction) GetProcessedAt() int64 { + if x != nil { + return x.ProcessedAt + } + return 0 +} + +type CustomerBalance struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + CustomerId string `protobuf:"bytes,1,opt,name=customer_id,json=customerId,proto3" json:"customer_id,omitempty"` + Balance float32 `protobuf:"fixed32,2,opt,name=balance,proto3" json:"balance,omitempty"` +} + +func (x *CustomerBalance) Reset() { + *x = CustomerBalance{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_payment_v1_types_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *CustomerBalance) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CustomerBalance) ProtoMessage() {} + +func (x *CustomerBalance) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_payment_v1_types_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use CustomerBalance.ProtoReflect.Descriptor instead. +func (*CustomerBalance) Descriptor() ([]byte, []int) { + return file_stocklet_payment_v1_types_proto_rawDescGZIP(), []int{1} +} + +func (x *CustomerBalance) GetCustomerId() string { + if x != nil { + return x.CustomerId + } + return "" +} + +func (x *CustomerBalance) GetBalance() float32 { + if x != nil { + return x.Balance + } + return 0 +} + +var File_stocklet_payment_v1_types_proto protoreflect.FileDescriptor + +var file_stocklet_payment_v1_types_proto_rawDesc = []byte{ + 0x0a, 0x1f, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2f, 0x70, 0x61, 0x79, 0x6d, 0x65, + 0x6e, 0x74, 0x2f, 0x76, 0x31, 0x2f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x12, 0x13, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x70, 0x61, 0x79, 0x6d, + 0x65, 0x6e, 0x74, 0x2e, 0x76, 0x31, 0x1a, 0x1b, 0x62, 0x75, 0x66, 0x2f, 0x76, 0x61, 0x6c, 0x69, + 0x64, 0x61, 0x74, 0x65, 0x2f, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x22, 0xf1, 0x01, 0x0a, 0x0b, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, + 0x69, 0x6f, 0x6e, 0x12, 0x17, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, + 0x07, 0xba, 0x48, 0x04, 0x72, 0x02, 0x10, 0x01, 0x52, 0x02, 0x69, 0x64, 0x12, 0x22, 0x0a, 0x06, + 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x02, 0x42, 0x0a, 0xba, 0x48, + 0x07, 0x0a, 0x05, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x52, 0x06, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, + 0x12, 0x22, 0x0a, 0x08, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, + 0x28, 0x09, 0x42, 0x07, 0xba, 0x48, 0x04, 0x72, 0x02, 0x10, 0x01, 0x52, 0x07, 0x6f, 0x72, 0x64, + 0x65, 0x72, 0x49, 0x64, 0x12, 0x28, 0x0a, 0x0b, 0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x65, 0x72, + 0x5f, 0x69, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x42, 0x07, 0xba, 0x48, 0x04, 0x72, 0x02, + 0x10, 0x01, 0x52, 0x0a, 0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x65, 0x72, 0x49, 0x64, 0x12, 0x24, + 0x0a, 0x0b, 0x72, 0x65, 0x76, 0x65, 0x72, 0x73, 0x65, 0x64, 0x5f, 0x61, 0x74, 0x18, 0x05, 0x20, + 0x01, 0x28, 0x03, 0x48, 0x00, 0x52, 0x0a, 0x72, 0x65, 0x76, 0x65, 0x72, 0x73, 0x65, 0x64, 0x41, + 0x74, 0x88, 0x01, 0x01, 0x12, 0x21, 0x0a, 0x0c, 0x70, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, 0x65, + 0x64, 0x5f, 0x61, 0x74, 0x18, 0x06, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0b, 0x70, 0x72, 0x6f, 0x63, + 0x65, 0x73, 0x73, 0x65, 0x64, 0x41, 0x74, 0x42, 0x0e, 0x0a, 0x0c, 0x5f, 0x72, 0x65, 0x76, 0x65, + 0x72, 0x73, 0x65, 0x64, 0x5f, 0x61, 0x74, 0x22, 0x61, 0x0a, 0x0f, 0x43, 0x75, 0x73, 0x74, 0x6f, + 0x6d, 0x65, 0x72, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x12, 0x28, 0x0a, 0x0b, 0x63, 0x75, + 0x73, 0x74, 0x6f, 0x6d, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, + 0x07, 0xba, 0x48, 0x04, 0x72, 0x02, 0x10, 0x01, 0x52, 0x0a, 0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d, + 0x65, 0x72, 0x49, 0x64, 0x12, 0x24, 0x0a, 0x07, 0x62, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x02, 0x42, 0x0a, 0xba, 0x48, 0x07, 0x0a, 0x05, 0x2d, 0x00, 0x00, 0x00, + 0x00, 0x52, 0x07, 0x62, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x42, 0x49, 0x5a, 0x47, 0x67, 0x69, + 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x68, 0x65, 0x78, 0x6f, 0x6c, 0x61, 0x6e, + 0x2f, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, + 0x61, 0x6c, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x67, 0x65, 0x6e, 0x2f, + 0x70, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x2f, 0x76, 0x31, 0x3b, 0x70, 0x61, 0x79, 0x6d, 0x65, + 0x6e, 0x74, 0x5f, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_stocklet_payment_v1_types_proto_rawDescOnce sync.Once + file_stocklet_payment_v1_types_proto_rawDescData = file_stocklet_payment_v1_types_proto_rawDesc +) + +func file_stocklet_payment_v1_types_proto_rawDescGZIP() []byte { + file_stocklet_payment_v1_types_proto_rawDescOnce.Do(func() { + file_stocklet_payment_v1_types_proto_rawDescData = protoimpl.X.CompressGZIP(file_stocklet_payment_v1_types_proto_rawDescData) + }) + return file_stocklet_payment_v1_types_proto_rawDescData +} + +var file_stocklet_payment_v1_types_proto_msgTypes = make([]protoimpl.MessageInfo, 2) +var file_stocklet_payment_v1_types_proto_goTypes = []interface{}{ + (*Transaction)(nil), // 0: stocklet.payment.v1.Transaction + (*CustomerBalance)(nil), // 1: stocklet.payment.v1.CustomerBalance +} +var file_stocklet_payment_v1_types_proto_depIdxs = []int32{ + 0, // [0:0] is the sub-list for method output_type + 0, // [0:0] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_stocklet_payment_v1_types_proto_init() } +func file_stocklet_payment_v1_types_proto_init() { + if File_stocklet_payment_v1_types_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_stocklet_payment_v1_types_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Transaction); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_stocklet_payment_v1_types_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*CustomerBalance); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + file_stocklet_payment_v1_types_proto_msgTypes[0].OneofWrappers = []interface{}{} + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_stocklet_payment_v1_types_proto_rawDesc, + NumEnums: 0, + NumMessages: 2, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_stocklet_payment_v1_types_proto_goTypes, + DependencyIndexes: file_stocklet_payment_v1_types_proto_depIdxs, + MessageInfos: file_stocklet_payment_v1_types_proto_msgTypes, + }.Build() + File_stocklet_payment_v1_types_proto = out.File + file_stocklet_payment_v1_types_proto_rawDesc = nil + file_stocklet_payment_v1_types_proto_goTypes = nil + file_stocklet_payment_v1_types_proto_depIdxs = nil +} diff --git a/internal/pkg/protogen/product/v1/service.pb.go b/internal/pkg/protogen/product/v1/service.pb.go new file mode 100644 index 0000000..bc05889 --- /dev/null +++ b/internal/pkg/protogen/product/v1/service.pb.go @@ -0,0 +1,413 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.31.0 +// protoc (unknown) +// source: stocklet/product/v1/service.proto + +package product_v1 + +import ( + _ "buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go/buf/validate" + v1 "github.com/hexolan/stocklet/internal/pkg/protogen/common/v1" + v11 "github.com/hexolan/stocklet/internal/pkg/protogen/events/v1" + _ "google.golang.org/genproto/googleapis/api/annotations" + _ "google.golang.org/genproto/googleapis/api/visibility" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + emptypb "google.golang.org/protobuf/types/known/emptypb" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type ViewProductRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` +} + +func (x *ViewProductRequest) Reset() { + *x = ViewProductRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_product_v1_service_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ViewProductRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ViewProductRequest) ProtoMessage() {} + +func (x *ViewProductRequest) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_product_v1_service_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ViewProductRequest.ProtoReflect.Descriptor instead. +func (*ViewProductRequest) Descriptor() ([]byte, []int) { + return file_stocklet_product_v1_service_proto_rawDescGZIP(), []int{0} +} + +func (x *ViewProductRequest) GetId() string { + if x != nil { + return x.Id + } + return "" +} + +type ViewProductResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Product *Product `protobuf:"bytes,1,opt,name=product,proto3" json:"product,omitempty"` +} + +func (x *ViewProductResponse) Reset() { + *x = ViewProductResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_product_v1_service_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ViewProductResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ViewProductResponse) ProtoMessage() {} + +func (x *ViewProductResponse) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_product_v1_service_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ViewProductResponse.ProtoReflect.Descriptor instead. +func (*ViewProductResponse) Descriptor() ([]byte, []int) { + return file_stocklet_product_v1_service_proto_rawDescGZIP(), []int{1} +} + +func (x *ViewProductResponse) GetProduct() *Product { + if x != nil { + return x.Product + } + return nil +} + +type ViewProductsRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *ViewProductsRequest) Reset() { + *x = ViewProductsRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_product_v1_service_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ViewProductsRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ViewProductsRequest) ProtoMessage() {} + +func (x *ViewProductsRequest) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_product_v1_service_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ViewProductsRequest.ProtoReflect.Descriptor instead. +func (*ViewProductsRequest) Descriptor() ([]byte, []int) { + return file_stocklet_product_v1_service_proto_rawDescGZIP(), []int{2} +} + +type ViewProductsResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Products []*Product `protobuf:"bytes,1,rep,name=products,proto3" json:"products,omitempty"` +} + +func (x *ViewProductsResponse) Reset() { + *x = ViewProductsResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_product_v1_service_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ViewProductsResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ViewProductsResponse) ProtoMessage() {} + +func (x *ViewProductsResponse) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_product_v1_service_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ViewProductsResponse.ProtoReflect.Descriptor instead. +func (*ViewProductsResponse) Descriptor() ([]byte, []int) { + return file_stocklet_product_v1_service_proto_rawDescGZIP(), []int{3} +} + +func (x *ViewProductsResponse) GetProducts() []*Product { + if x != nil { + return x.Products + } + return nil +} + +var File_stocklet_product_v1_service_proto protoreflect.FileDescriptor + +var file_stocklet_product_v1_service_proto_rawDesc = []byte{ + 0x0a, 0x21, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2f, 0x70, 0x72, 0x6f, 0x64, 0x75, + 0x63, 0x74, 0x2f, 0x76, 0x31, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x12, 0x13, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x70, 0x72, + 0x6f, 0x64, 0x75, 0x63, 0x74, 0x2e, 0x76, 0x31, 0x1a, 0x1b, 0x62, 0x75, 0x66, 0x2f, 0x76, 0x61, + 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x2f, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1c, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x61, 0x70, + 0x69, 0x2f, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x1a, 0x1b, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, + 0x76, 0x69, 0x73, 0x69, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x1a, 0x1b, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, + 0x66, 0x2f, 0x65, 0x6d, 0x70, 0x74, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x21, 0x73, + 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2f, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2f, 0x76, + 0x31, 0x2f, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x1a, 0x1e, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2f, 0x65, 0x76, 0x65, 0x6e, 0x74, + 0x73, 0x2f, 0x76, 0x31, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x1a, 0x1f, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2f, 0x70, 0x72, 0x6f, 0x64, 0x75, + 0x63, 0x74, 0x2f, 0x76, 0x31, 0x2f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x22, 0x2d, 0x0a, 0x12, 0x56, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x17, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x09, 0x42, 0x07, 0xba, 0x48, 0x04, 0x72, 0x02, 0x10, 0x01, 0x52, 0x02, 0x69, 0x64, + 0x22, 0x4d, 0x0a, 0x13, 0x56, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x36, 0x0a, 0x07, 0x70, 0x72, 0x6f, 0x64, 0x75, + 0x63, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1c, 0x2e, 0x73, 0x74, 0x6f, 0x63, 0x6b, + 0x6c, 0x65, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x2e, 0x76, 0x31, 0x2e, 0x50, + 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x52, 0x07, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x22, + 0x15, 0x0a, 0x13, 0x56, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x73, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x50, 0x0a, 0x14, 0x56, 0x69, 0x65, 0x77, 0x50, 0x72, + 0x6f, 0x64, 0x75, 0x63, 0x74, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x38, + 0x0a, 0x08, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, + 0x32, 0x1c, 0x2e, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x64, + 0x75, 0x63, 0x74, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x52, 0x08, + 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x73, 0x32, 0xf5, 0x03, 0x0a, 0x0e, 0x50, 0x72, 0x6f, + 0x64, 0x75, 0x63, 0x74, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x7b, 0x0a, 0x0b, 0x53, + 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x26, 0x2e, 0x73, 0x74, 0x6f, + 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x76, 0x31, 0x2e, + 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x1a, 0x27, 0x2e, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x63, 0x6f, + 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x49, + 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x1b, 0x82, 0xd3, 0xe4, + 0x93, 0x02, 0x15, 0x12, 0x13, 0x2f, 0x76, 0x31, 0x2f, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, + 0x2f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x7a, 0x0a, 0x0b, 0x56, 0x69, 0x65, 0x77, + 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x12, 0x27, 0x2e, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, + 0x65, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x2e, 0x76, 0x31, 0x2e, 0x56, 0x69, + 0x65, 0x77, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x1a, 0x28, 0x2e, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x64, + 0x75, 0x63, 0x74, 0x2e, 0x76, 0x31, 0x2e, 0x56, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x64, 0x75, + 0x63, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x18, 0x82, 0xd3, 0xe4, 0x93, + 0x02, 0x12, 0x12, 0x10, 0x2f, 0x76, 0x31, 0x2f, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x2f, + 0x7b, 0x69, 0x64, 0x7d, 0x12, 0x7d, 0x0a, 0x0c, 0x56, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x64, + 0x75, 0x63, 0x74, 0x73, 0x12, 0x28, 0x2e, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, + 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x2e, 0x76, 0x31, 0x2e, 0x56, 0x69, 0x65, 0x77, 0x50, + 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x29, + 0x2e, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, + 0x74, 0x2e, 0x76, 0x31, 0x2e, 0x56, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, + 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x18, 0x82, 0xd3, 0xe4, 0x93, 0x02, + 0x12, 0x12, 0x10, 0x2f, 0x76, 0x31, 0x2f, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x2f, 0x6c, + 0x69, 0x73, 0x74, 0x12, 0x6b, 0x0a, 0x18, 0x50, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, 0x4f, 0x72, + 0x64, 0x65, 0x72, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, + 0x25, 0x2e, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x65, 0x76, 0x65, 0x6e, 0x74, + 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, + 0x64, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x10, + 0xfa, 0xd2, 0xe4, 0x93, 0x02, 0x0a, 0x12, 0x08, 0x49, 0x4e, 0x54, 0x45, 0x52, 0x4e, 0x41, 0x4c, + 0x42, 0x49, 0x5a, 0x47, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x68, + 0x65, 0x78, 0x6f, 0x6c, 0x61, 0x6e, 0x2f, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2f, + 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x67, 0x65, 0x6e, 0x2f, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x2f, 0x76, 0x31, + 0x3b, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x5f, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x33, +} + +var ( + file_stocklet_product_v1_service_proto_rawDescOnce sync.Once + file_stocklet_product_v1_service_proto_rawDescData = file_stocklet_product_v1_service_proto_rawDesc +) + +func file_stocklet_product_v1_service_proto_rawDescGZIP() []byte { + file_stocklet_product_v1_service_proto_rawDescOnce.Do(func() { + file_stocklet_product_v1_service_proto_rawDescData = protoimpl.X.CompressGZIP(file_stocklet_product_v1_service_proto_rawDescData) + }) + return file_stocklet_product_v1_service_proto_rawDescData +} + +var file_stocklet_product_v1_service_proto_msgTypes = make([]protoimpl.MessageInfo, 4) +var file_stocklet_product_v1_service_proto_goTypes = []interface{}{ + (*ViewProductRequest)(nil), // 0: stocklet.product.v1.ViewProductRequest + (*ViewProductResponse)(nil), // 1: stocklet.product.v1.ViewProductResponse + (*ViewProductsRequest)(nil), // 2: stocklet.product.v1.ViewProductsRequest + (*ViewProductsResponse)(nil), // 3: stocklet.product.v1.ViewProductsResponse + (*Product)(nil), // 4: stocklet.product.v1.Product + (*v1.ServiceInfoRequest)(nil), // 5: stocklet.common.v1.ServiceInfoRequest + (*v11.OrderCreatedEvent)(nil), // 6: stocklet.events.v1.OrderCreatedEvent + (*v1.ServiceInfoResponse)(nil), // 7: stocklet.common.v1.ServiceInfoResponse + (*emptypb.Empty)(nil), // 8: google.protobuf.Empty +} +var file_stocklet_product_v1_service_proto_depIdxs = []int32{ + 4, // 0: stocklet.product.v1.ViewProductResponse.product:type_name -> stocklet.product.v1.Product + 4, // 1: stocklet.product.v1.ViewProductsResponse.products:type_name -> stocklet.product.v1.Product + 5, // 2: stocklet.product.v1.ProductService.ServiceInfo:input_type -> stocklet.common.v1.ServiceInfoRequest + 0, // 3: stocklet.product.v1.ProductService.ViewProduct:input_type -> stocklet.product.v1.ViewProductRequest + 2, // 4: stocklet.product.v1.ProductService.ViewProducts:input_type -> stocklet.product.v1.ViewProductsRequest + 6, // 5: stocklet.product.v1.ProductService.ProcessOrderCreatedEvent:input_type -> stocklet.events.v1.OrderCreatedEvent + 7, // 6: stocklet.product.v1.ProductService.ServiceInfo:output_type -> stocklet.common.v1.ServiceInfoResponse + 1, // 7: stocklet.product.v1.ProductService.ViewProduct:output_type -> stocklet.product.v1.ViewProductResponse + 3, // 8: stocklet.product.v1.ProductService.ViewProducts:output_type -> stocklet.product.v1.ViewProductsResponse + 8, // 9: stocklet.product.v1.ProductService.ProcessOrderCreatedEvent:output_type -> google.protobuf.Empty + 6, // [6:10] is the sub-list for method output_type + 2, // [2:6] is the sub-list for method input_type + 2, // [2:2] is the sub-list for extension type_name + 2, // [2:2] is the sub-list for extension extendee + 0, // [0:2] is the sub-list for field type_name +} + +func init() { file_stocklet_product_v1_service_proto_init() } +func file_stocklet_product_v1_service_proto_init() { + if File_stocklet_product_v1_service_proto != nil { + return + } + file_stocklet_product_v1_types_proto_init() + if !protoimpl.UnsafeEnabled { + file_stocklet_product_v1_service_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ViewProductRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_stocklet_product_v1_service_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ViewProductResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_stocklet_product_v1_service_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ViewProductsRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_stocklet_product_v1_service_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ViewProductsResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_stocklet_product_v1_service_proto_rawDesc, + NumEnums: 0, + NumMessages: 4, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_stocklet_product_v1_service_proto_goTypes, + DependencyIndexes: file_stocklet_product_v1_service_proto_depIdxs, + MessageInfos: file_stocklet_product_v1_service_proto_msgTypes, + }.Build() + File_stocklet_product_v1_service_proto = out.File + file_stocklet_product_v1_service_proto_rawDesc = nil + file_stocklet_product_v1_service_proto_goTypes = nil + file_stocklet_product_v1_service_proto_depIdxs = nil +} diff --git a/internal/pkg/protogen/product/v1/service.pb.gw.go b/internal/pkg/protogen/product/v1/service.pb.gw.go new file mode 100644 index 0000000..5d54a5b --- /dev/null +++ b/internal/pkg/protogen/product/v1/service.pb.gw.go @@ -0,0 +1,328 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: stocklet/product/v1/service.proto + +/* +Package product_v1 is a reverse proxy. + +It translates gRPC into RESTful JSON APIs. +*/ +package product_v1 + +import ( + "context" + "io" + "net/http" + + "github.com/grpc-ecosystem/grpc-gateway/v2/runtime" + "github.com/grpc-ecosystem/grpc-gateway/v2/utilities" + "github.com/hexolan/stocklet/internal/pkg/protogen/common/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/status" + "google.golang.org/protobuf/proto" +) + +// Suppress "imported and not used" errors +var _ codes.Code +var _ io.Reader +var _ status.Status +var _ = runtime.String +var _ = utilities.NewDoubleArray +var _ = metadata.Join + +func request_ProductService_ServiceInfo_0(ctx context.Context, marshaler runtime.Marshaler, client ProductServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq common_v1.ServiceInfoRequest + var metadata runtime.ServerMetadata + + msg, err := client.ServiceInfo(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_ProductService_ServiceInfo_0(ctx context.Context, marshaler runtime.Marshaler, server ProductServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq common_v1.ServiceInfoRequest + var metadata runtime.ServerMetadata + + msg, err := server.ServiceInfo(ctx, &protoReq) + return msg, metadata, err + +} + +func request_ProductService_ViewProduct_0(ctx context.Context, marshaler runtime.Marshaler, client ProductServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq ViewProductRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id") + } + + protoReq.Id, err = runtime.String(val) + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err) + } + + msg, err := client.ViewProduct(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_ProductService_ViewProduct_0(ctx context.Context, marshaler runtime.Marshaler, server ProductServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq ViewProductRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id") + } + + protoReq.Id, err = runtime.String(val) + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err) + } + + msg, err := server.ViewProduct(ctx, &protoReq) + return msg, metadata, err + +} + +func request_ProductService_ViewProducts_0(ctx context.Context, marshaler runtime.Marshaler, client ProductServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq ViewProductsRequest + var metadata runtime.ServerMetadata + + msg, err := client.ViewProducts(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_ProductService_ViewProducts_0(ctx context.Context, marshaler runtime.Marshaler, server ProductServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq ViewProductsRequest + var metadata runtime.ServerMetadata + + msg, err := server.ViewProducts(ctx, &protoReq) + return msg, metadata, err + +} + +// RegisterProductServiceHandlerServer registers the http handlers for service ProductService to "mux". +// UnaryRPC :call ProductServiceServer directly. +// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. +// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterProductServiceHandlerFromEndpoint instead. +func RegisterProductServiceHandlerServer(ctx context.Context, mux *runtime.ServeMux, server ProductServiceServer) error { + + mux.Handle("GET", pattern_ProductService_ServiceInfo_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/stocklet.product.v1.ProductService/ServiceInfo", runtime.WithHTTPPathPattern("/v1/product/service")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_ProductService_ServiceInfo_0(annotatedContext, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_ProductService_ServiceInfo_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_ProductService_ViewProduct_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/stocklet.product.v1.ProductService/ViewProduct", runtime.WithHTTPPathPattern("/v1/product/{id}")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_ProductService_ViewProduct_0(annotatedContext, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_ProductService_ViewProduct_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_ProductService_ViewProducts_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/stocklet.product.v1.ProductService/ViewProducts", runtime.WithHTTPPathPattern("/v1/product/list")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_ProductService_ViewProducts_0(annotatedContext, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_ProductService_ViewProducts_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +// RegisterProductServiceHandlerFromEndpoint is same as RegisterProductServiceHandler but +// automatically dials to "endpoint" and closes the connection when "ctx" gets done. +func RegisterProductServiceHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { + conn, err := grpc.DialContext(ctx, endpoint, opts...) + if err != nil { + return err + } + defer func() { + if err != nil { + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + return + } + go func() { + <-ctx.Done() + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + }() + }() + + return RegisterProductServiceHandler(ctx, mux, conn) +} + +// RegisterProductServiceHandler registers the http handlers for service ProductService to "mux". +// The handlers forward requests to the grpc endpoint over "conn". +func RegisterProductServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { + return RegisterProductServiceHandlerClient(ctx, mux, NewProductServiceClient(conn)) +} + +// RegisterProductServiceHandlerClient registers the http handlers for service ProductService +// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "ProductServiceClient". +// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "ProductServiceClient" +// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in +// "ProductServiceClient" to call the correct interceptors. +func RegisterProductServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux, client ProductServiceClient) error { + + mux.Handle("GET", pattern_ProductService_ServiceInfo_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/stocklet.product.v1.ProductService/ServiceInfo", runtime.WithHTTPPathPattern("/v1/product/service")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_ProductService_ServiceInfo_0(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_ProductService_ServiceInfo_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_ProductService_ViewProduct_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/stocklet.product.v1.ProductService/ViewProduct", runtime.WithHTTPPathPattern("/v1/product/{id}")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_ProductService_ViewProduct_0(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_ProductService_ViewProduct_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_ProductService_ViewProducts_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/stocklet.product.v1.ProductService/ViewProducts", runtime.WithHTTPPathPattern("/v1/product/list")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_ProductService_ViewProducts_0(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_ProductService_ViewProducts_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +var ( + pattern_ProductService_ServiceInfo_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v1", "product", "service"}, "")) + + pattern_ProductService_ViewProduct_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2}, []string{"v1", "product", "id"}, "")) + + pattern_ProductService_ViewProducts_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v1", "product", "list"}, "")) +) + +var ( + forward_ProductService_ServiceInfo_0 = runtime.ForwardResponseMessage + + forward_ProductService_ViewProduct_0 = runtime.ForwardResponseMessage + + forward_ProductService_ViewProducts_0 = runtime.ForwardResponseMessage +) diff --git a/internal/pkg/protogen/product/v1/service_grpc.pb.go b/internal/pkg/protogen/product/v1/service_grpc.pb.go new file mode 100644 index 0000000..0fa14b3 --- /dev/null +++ b/internal/pkg/protogen/product/v1/service_grpc.pb.go @@ -0,0 +1,254 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.3.0 +// - protoc (unknown) +// source: stocklet/product/v1/service.proto + +package product_v1 + +import ( + context "context" + v1 "github.com/hexolan/stocklet/internal/pkg/protogen/common/v1" + v11 "github.com/hexolan/stocklet/internal/pkg/protogen/events/v1" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + emptypb "google.golang.org/protobuf/types/known/emptypb" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.32.0 or later. +const _ = grpc.SupportPackageIsVersion7 + +const ( + ProductService_ServiceInfo_FullMethodName = "/stocklet.product.v1.ProductService/ServiceInfo" + ProductService_ViewProduct_FullMethodName = "/stocklet.product.v1.ProductService/ViewProduct" + ProductService_ViewProducts_FullMethodName = "/stocklet.product.v1.ProductService/ViewProducts" + ProductService_ProcessOrderCreatedEvent_FullMethodName = "/stocklet.product.v1.ProductService/ProcessOrderCreatedEvent" +) + +// ProductServiceClient is the client API for ProductService service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +type ProductServiceClient interface { + // View information about the service. + // + // buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + ServiceInfo(ctx context.Context, in *v1.ServiceInfoRequest, opts ...grpc.CallOption) (*v1.ServiceInfoResponse, error) + ViewProduct(ctx context.Context, in *ViewProductRequest, opts ...grpc.CallOption) (*ViewProductResponse, error) + ViewProducts(ctx context.Context, in *ViewProductsRequest, opts ...grpc.CallOption) (*ViewProductsResponse, error) + // A consumer will call this method to process events. + // + // buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + // buf:lint:ignore RPC_REQUEST_STANDARD_NAME + // buf:lint:ignore RPC_RESPONSE_STANDARD_NAME + ProcessOrderCreatedEvent(ctx context.Context, in *v11.OrderCreatedEvent, opts ...grpc.CallOption) (*emptypb.Empty, error) +} + +type productServiceClient struct { + cc grpc.ClientConnInterface +} + +func NewProductServiceClient(cc grpc.ClientConnInterface) ProductServiceClient { + return &productServiceClient{cc} +} + +func (c *productServiceClient) ServiceInfo(ctx context.Context, in *v1.ServiceInfoRequest, opts ...grpc.CallOption) (*v1.ServiceInfoResponse, error) { + out := new(v1.ServiceInfoResponse) + err := c.cc.Invoke(ctx, ProductService_ServiceInfo_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *productServiceClient) ViewProduct(ctx context.Context, in *ViewProductRequest, opts ...grpc.CallOption) (*ViewProductResponse, error) { + out := new(ViewProductResponse) + err := c.cc.Invoke(ctx, ProductService_ViewProduct_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *productServiceClient) ViewProducts(ctx context.Context, in *ViewProductsRequest, opts ...grpc.CallOption) (*ViewProductsResponse, error) { + out := new(ViewProductsResponse) + err := c.cc.Invoke(ctx, ProductService_ViewProducts_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *productServiceClient) ProcessOrderCreatedEvent(ctx context.Context, in *v11.OrderCreatedEvent, opts ...grpc.CallOption) (*emptypb.Empty, error) { + out := new(emptypb.Empty) + err := c.cc.Invoke(ctx, ProductService_ProcessOrderCreatedEvent_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// ProductServiceServer is the server API for ProductService service. +// All implementations must embed UnimplementedProductServiceServer +// for forward compatibility +type ProductServiceServer interface { + // View information about the service. + // + // buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + ServiceInfo(context.Context, *v1.ServiceInfoRequest) (*v1.ServiceInfoResponse, error) + ViewProduct(context.Context, *ViewProductRequest) (*ViewProductResponse, error) + ViewProducts(context.Context, *ViewProductsRequest) (*ViewProductsResponse, error) + // A consumer will call this method to process events. + // + // buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + // buf:lint:ignore RPC_REQUEST_STANDARD_NAME + // buf:lint:ignore RPC_RESPONSE_STANDARD_NAME + ProcessOrderCreatedEvent(context.Context, *v11.OrderCreatedEvent) (*emptypb.Empty, error) + mustEmbedUnimplementedProductServiceServer() +} + +// UnimplementedProductServiceServer must be embedded to have forward compatible implementations. +type UnimplementedProductServiceServer struct { +} + +func (UnimplementedProductServiceServer) ServiceInfo(context.Context, *v1.ServiceInfoRequest) (*v1.ServiceInfoResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method ServiceInfo not implemented") +} +func (UnimplementedProductServiceServer) ViewProduct(context.Context, *ViewProductRequest) (*ViewProductResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method ViewProduct not implemented") +} +func (UnimplementedProductServiceServer) ViewProducts(context.Context, *ViewProductsRequest) (*ViewProductsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method ViewProducts not implemented") +} +func (UnimplementedProductServiceServer) ProcessOrderCreatedEvent(context.Context, *v11.OrderCreatedEvent) (*emptypb.Empty, error) { + return nil, status.Errorf(codes.Unimplemented, "method ProcessOrderCreatedEvent not implemented") +} +func (UnimplementedProductServiceServer) mustEmbedUnimplementedProductServiceServer() {} + +// UnsafeProductServiceServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to ProductServiceServer will +// result in compilation errors. +type UnsafeProductServiceServer interface { + mustEmbedUnimplementedProductServiceServer() +} + +func RegisterProductServiceServer(s grpc.ServiceRegistrar, srv ProductServiceServer) { + s.RegisterService(&ProductService_ServiceDesc, srv) +} + +func _ProductService_ServiceInfo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(v1.ServiceInfoRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ProductServiceServer).ServiceInfo(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ProductService_ServiceInfo_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ProductServiceServer).ServiceInfo(ctx, req.(*v1.ServiceInfoRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _ProductService_ViewProduct_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ViewProductRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ProductServiceServer).ViewProduct(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ProductService_ViewProduct_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ProductServiceServer).ViewProduct(ctx, req.(*ViewProductRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _ProductService_ViewProducts_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ViewProductsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ProductServiceServer).ViewProducts(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ProductService_ViewProducts_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ProductServiceServer).ViewProducts(ctx, req.(*ViewProductsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _ProductService_ProcessOrderCreatedEvent_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(v11.OrderCreatedEvent) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ProductServiceServer).ProcessOrderCreatedEvent(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ProductService_ProcessOrderCreatedEvent_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ProductServiceServer).ProcessOrderCreatedEvent(ctx, req.(*v11.OrderCreatedEvent)) + } + return interceptor(ctx, in, info, handler) +} + +// ProductService_ServiceDesc is the grpc.ServiceDesc for ProductService service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var ProductService_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "stocklet.product.v1.ProductService", + HandlerType: (*ProductServiceServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "ServiceInfo", + Handler: _ProductService_ServiceInfo_Handler, + }, + { + MethodName: "ViewProduct", + Handler: _ProductService_ViewProduct_Handler, + }, + { + MethodName: "ViewProducts", + Handler: _ProductService_ViewProducts_Handler, + }, + { + MethodName: "ProcessOrderCreatedEvent", + Handler: _ProductService_ProcessOrderCreatedEvent_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "stocklet/product/v1/service.proto", +} diff --git a/internal/pkg/protogen/product/v1/types.pb.go b/internal/pkg/protogen/product/v1/types.pb.go new file mode 100644 index 0000000..bf75bb2 --- /dev/null +++ b/internal/pkg/protogen/product/v1/types.pb.go @@ -0,0 +1,218 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.31.0 +// protoc (unknown) +// source: stocklet/product/v1/types.proto + +package product_v1 + +import ( + _ "buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go/buf/validate" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type Product struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` + Description string `protobuf:"bytes,3,opt,name=description,proto3" json:"description,omitempty"` + Price float32 `protobuf:"fixed32,4,opt,name=price,proto3" json:"price,omitempty"` + CreatedAt int64 `protobuf:"varint,5,opt,name=created_at,json=createdAt,proto3" json:"created_at,omitempty"` + UpdatedAt *int64 `protobuf:"varint,6,opt,name=updated_at,json=updatedAt,proto3,oneof" json:"updated_at,omitempty"` +} + +func (x *Product) Reset() { + *x = Product{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_product_v1_types_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Product) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Product) ProtoMessage() {} + +func (x *Product) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_product_v1_types_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Product.ProtoReflect.Descriptor instead. +func (*Product) Descriptor() ([]byte, []int) { + return file_stocklet_product_v1_types_proto_rawDescGZIP(), []int{0} +} + +func (x *Product) GetId() string { + if x != nil { + return x.Id + } + return "" +} + +func (x *Product) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +func (x *Product) GetDescription() string { + if x != nil { + return x.Description + } + return "" +} + +func (x *Product) GetPrice() float32 { + if x != nil { + return x.Price + } + return 0 +} + +func (x *Product) GetCreatedAt() int64 { + if x != nil { + return x.CreatedAt + } + return 0 +} + +func (x *Product) GetUpdatedAt() int64 { + if x != nil && x.UpdatedAt != nil { + return *x.UpdatedAt + } + return 0 +} + +var File_stocklet_product_v1_types_proto protoreflect.FileDescriptor + +var file_stocklet_product_v1_types_proto_rawDesc = []byte{ + 0x0a, 0x1f, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2f, 0x70, 0x72, 0x6f, 0x64, 0x75, + 0x63, 0x74, 0x2f, 0x76, 0x31, 0x2f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x12, 0x13, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x64, + 0x75, 0x63, 0x74, 0x2e, 0x76, 0x31, 0x1a, 0x1b, 0x62, 0x75, 0x66, 0x2f, 0x76, 0x61, 0x6c, 0x69, + 0x64, 0x61, 0x74, 0x65, 0x2f, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x22, 0xde, 0x01, 0x0a, 0x07, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x12, + 0x17, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, 0x07, 0xba, 0x48, 0x04, + 0x72, 0x02, 0x10, 0x01, 0x52, 0x02, 0x69, 0x64, 0x12, 0x1b, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x42, 0x07, 0xba, 0x48, 0x04, 0x72, 0x02, 0x10, 0x01, 0x52, + 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x29, 0x0a, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, + 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x42, 0x07, 0xba, 0x48, 0x04, 0x72, + 0x02, 0x10, 0x01, 0x52, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, + 0x12, 0x20, 0x0a, 0x05, 0x70, 0x72, 0x69, 0x63, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x02, 0x42, + 0x0a, 0xba, 0x48, 0x07, 0x0a, 0x05, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x52, 0x05, 0x70, 0x72, 0x69, + 0x63, 0x65, 0x12, 0x1d, 0x0a, 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x61, 0x74, + 0x18, 0x05, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x41, + 0x74, 0x12, 0x22, 0x0a, 0x0a, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x61, 0x74, 0x18, + 0x06, 0x20, 0x01, 0x28, 0x03, 0x48, 0x00, 0x52, 0x09, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, + 0x41, 0x74, 0x88, 0x01, 0x01, 0x42, 0x0d, 0x0a, 0x0b, 0x5f, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, + 0x64, 0x5f, 0x61, 0x74, 0x42, 0x49, 0x5a, 0x47, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, + 0x6f, 0x6d, 0x2f, 0x68, 0x65, 0x78, 0x6f, 0x6c, 0x61, 0x6e, 0x2f, 0x73, 0x74, 0x6f, 0x63, 0x6b, + 0x6c, 0x65, 0x74, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x70, 0x6b, 0x67, + 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x67, 0x65, 0x6e, 0x2f, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, + 0x74, 0x2f, 0x76, 0x31, 0x3b, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x5f, 0x76, 0x31, 0x62, + 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_stocklet_product_v1_types_proto_rawDescOnce sync.Once + file_stocklet_product_v1_types_proto_rawDescData = file_stocklet_product_v1_types_proto_rawDesc +) + +func file_stocklet_product_v1_types_proto_rawDescGZIP() []byte { + file_stocklet_product_v1_types_proto_rawDescOnce.Do(func() { + file_stocklet_product_v1_types_proto_rawDescData = protoimpl.X.CompressGZIP(file_stocklet_product_v1_types_proto_rawDescData) + }) + return file_stocklet_product_v1_types_proto_rawDescData +} + +var file_stocklet_product_v1_types_proto_msgTypes = make([]protoimpl.MessageInfo, 1) +var file_stocklet_product_v1_types_proto_goTypes = []interface{}{ + (*Product)(nil), // 0: stocklet.product.v1.Product +} +var file_stocklet_product_v1_types_proto_depIdxs = []int32{ + 0, // [0:0] is the sub-list for method output_type + 0, // [0:0] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_stocklet_product_v1_types_proto_init() } +func file_stocklet_product_v1_types_proto_init() { + if File_stocklet_product_v1_types_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_stocklet_product_v1_types_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Product); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + file_stocklet_product_v1_types_proto_msgTypes[0].OneofWrappers = []interface{}{} + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_stocklet_product_v1_types_proto_rawDesc, + NumEnums: 0, + NumMessages: 1, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_stocklet_product_v1_types_proto_goTypes, + DependencyIndexes: file_stocklet_product_v1_types_proto_depIdxs, + MessageInfos: file_stocklet_product_v1_types_proto_msgTypes, + }.Build() + File_stocklet_product_v1_types_proto = out.File + file_stocklet_product_v1_types_proto_rawDesc = nil + file_stocklet_product_v1_types_proto_goTypes = nil + file_stocklet_product_v1_types_proto_depIdxs = nil +} diff --git a/internal/pkg/protogen/shipping/v1/service.pb.go b/internal/pkg/protogen/shipping/v1/service.pb.go new file mode 100644 index 0000000..27c9c57 --- /dev/null +++ b/internal/pkg/protogen/shipping/v1/service.pb.go @@ -0,0 +1,447 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.31.0 +// protoc (unknown) +// source: stocklet/shipping/v1/service.proto + +package shipping_v1 + +import ( + _ "buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go/buf/validate" + v1 "github.com/hexolan/stocklet/internal/pkg/protogen/common/v1" + v11 "github.com/hexolan/stocklet/internal/pkg/protogen/events/v1" + _ "google.golang.org/genproto/googleapis/api/annotations" + _ "google.golang.org/genproto/googleapis/api/visibility" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + emptypb "google.golang.org/protobuf/types/known/emptypb" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type ViewShipmentRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + ShipmentId string `protobuf:"bytes,1,opt,name=shipment_id,json=shipmentId,proto3" json:"shipment_id,omitempty"` +} + +func (x *ViewShipmentRequest) Reset() { + *x = ViewShipmentRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_shipping_v1_service_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ViewShipmentRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ViewShipmentRequest) ProtoMessage() {} + +func (x *ViewShipmentRequest) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_shipping_v1_service_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ViewShipmentRequest.ProtoReflect.Descriptor instead. +func (*ViewShipmentRequest) Descriptor() ([]byte, []int) { + return file_stocklet_shipping_v1_service_proto_rawDescGZIP(), []int{0} +} + +func (x *ViewShipmentRequest) GetShipmentId() string { + if x != nil { + return x.ShipmentId + } + return "" +} + +type ViewShipmentResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Shipment *Shipment `protobuf:"bytes,1,opt,name=shipment,proto3" json:"shipment,omitempty"` +} + +func (x *ViewShipmentResponse) Reset() { + *x = ViewShipmentResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_shipping_v1_service_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ViewShipmentResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ViewShipmentResponse) ProtoMessage() {} + +func (x *ViewShipmentResponse) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_shipping_v1_service_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ViewShipmentResponse.ProtoReflect.Descriptor instead. +func (*ViewShipmentResponse) Descriptor() ([]byte, []int) { + return file_stocklet_shipping_v1_service_proto_rawDescGZIP(), []int{1} +} + +func (x *ViewShipmentResponse) GetShipment() *Shipment { + if x != nil { + return x.Shipment + } + return nil +} + +type ViewShipmentManifestRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + ShipmentId string `protobuf:"bytes,1,opt,name=shipment_id,json=shipmentId,proto3" json:"shipment_id,omitempty"` +} + +func (x *ViewShipmentManifestRequest) Reset() { + *x = ViewShipmentManifestRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_shipping_v1_service_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ViewShipmentManifestRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ViewShipmentManifestRequest) ProtoMessage() {} + +func (x *ViewShipmentManifestRequest) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_shipping_v1_service_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ViewShipmentManifestRequest.ProtoReflect.Descriptor instead. +func (*ViewShipmentManifestRequest) Descriptor() ([]byte, []int) { + return file_stocklet_shipping_v1_service_proto_rawDescGZIP(), []int{2} +} + +func (x *ViewShipmentManifestRequest) GetShipmentId() string { + if x != nil { + return x.ShipmentId + } + return "" +} + +type ViewShipmentManifestResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Manifest []*ShipmentItem `protobuf:"bytes,1,rep,name=manifest,proto3" json:"manifest,omitempty"` +} + +func (x *ViewShipmentManifestResponse) Reset() { + *x = ViewShipmentManifestResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_shipping_v1_service_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ViewShipmentManifestResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ViewShipmentManifestResponse) ProtoMessage() {} + +func (x *ViewShipmentManifestResponse) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_shipping_v1_service_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ViewShipmentManifestResponse.ProtoReflect.Descriptor instead. +func (*ViewShipmentManifestResponse) Descriptor() ([]byte, []int) { + return file_stocklet_shipping_v1_service_proto_rawDescGZIP(), []int{3} +} + +func (x *ViewShipmentManifestResponse) GetManifest() []*ShipmentItem { + if x != nil { + return x.Manifest + } + return nil +} + +var File_stocklet_shipping_v1_service_proto protoreflect.FileDescriptor + +var file_stocklet_shipping_v1_service_proto_rawDesc = []byte{ + 0x0a, 0x22, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2f, 0x73, 0x68, 0x69, 0x70, 0x70, + 0x69, 0x6e, 0x67, 0x2f, 0x76, 0x31, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x14, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x73, + 0x68, 0x69, 0x70, 0x70, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x1a, 0x1b, 0x62, 0x75, 0x66, 0x2f, + 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x2f, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, + 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1c, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, + 0x61, 0x70, 0x69, 0x2f, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1b, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x61, 0x70, + 0x69, 0x2f, 0x76, 0x69, 0x73, 0x69, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x1a, 0x1b, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x62, 0x75, 0x66, 0x2f, 0x65, 0x6d, 0x70, 0x74, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, + 0x21, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2f, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, + 0x2f, 0x76, 0x31, 0x2f, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x73, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x1a, 0x20, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2f, 0x65, 0x76, 0x65, + 0x6e, 0x74, 0x73, 0x2f, 0x76, 0x31, 0x2f, 0x70, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x2e, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x22, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2f, 0x65, + 0x76, 0x65, 0x6e, 0x74, 0x73, 0x2f, 0x76, 0x31, 0x2f, 0x77, 0x61, 0x72, 0x65, 0x68, 0x6f, 0x75, + 0x73, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x20, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, + 0x65, 0x74, 0x2f, 0x73, 0x68, 0x69, 0x70, 0x70, 0x69, 0x6e, 0x67, 0x2f, 0x76, 0x31, 0x2f, 0x74, + 0x79, 0x70, 0x65, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x3f, 0x0a, 0x13, 0x56, 0x69, + 0x65, 0x77, 0x53, 0x68, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x12, 0x28, 0x0a, 0x0b, 0x73, 0x68, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x5f, 0x69, 0x64, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, 0x07, 0xba, 0x48, 0x04, 0x72, 0x02, 0x10, 0x01, 0x52, + 0x0a, 0x73, 0x68, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x22, 0x52, 0x0a, 0x14, 0x56, + 0x69, 0x65, 0x77, 0x53, 0x68, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, + 0x6e, 0x73, 0x65, 0x12, 0x3a, 0x0a, 0x08, 0x73, 0x68, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, + 0x2e, 0x73, 0x68, 0x69, 0x70, 0x70, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x68, 0x69, + 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x08, 0x73, 0x68, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x22, + 0x47, 0x0a, 0x1b, 0x56, 0x69, 0x65, 0x77, 0x53, 0x68, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x4d, + 0x61, 0x6e, 0x69, 0x66, 0x65, 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x28, + 0x0a, 0x0b, 0x73, 0x68, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x09, 0x42, 0x07, 0xba, 0x48, 0x04, 0x72, 0x02, 0x10, 0x01, 0x52, 0x0a, 0x73, 0x68, + 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x22, 0x5e, 0x0a, 0x1c, 0x56, 0x69, 0x65, 0x77, + 0x53, 0x68, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x4d, 0x61, 0x6e, 0x69, 0x66, 0x65, 0x73, 0x74, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x3e, 0x0a, 0x08, 0x6d, 0x61, 0x6e, 0x69, + 0x66, 0x65, 0x73, 0x74, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x22, 0x2e, 0x73, 0x74, 0x6f, + 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x73, 0x68, 0x69, 0x70, 0x70, 0x69, 0x6e, 0x67, 0x2e, 0x76, + 0x31, 0x2e, 0x53, 0x68, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x49, 0x74, 0x65, 0x6d, 0x52, 0x08, + 0x6d, 0x61, 0x6e, 0x69, 0x66, 0x65, 0x73, 0x74, 0x32, 0xc4, 0x05, 0x0a, 0x0f, 0x53, 0x68, 0x69, + 0x70, 0x70, 0x69, 0x6e, 0x67, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x7c, 0x0a, 0x0b, + 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x26, 0x2e, 0x73, 0x74, + 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x76, 0x31, + 0x2e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x1a, 0x27, 0x2e, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x63, + 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, + 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x1c, 0x82, 0xd3, + 0xe4, 0x93, 0x02, 0x16, 0x12, 0x14, 0x2f, 0x76, 0x31, 0x2f, 0x73, 0x68, 0x69, 0x70, 0x70, 0x69, + 0x6e, 0x67, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x92, 0x01, 0x0a, 0x0c, 0x56, + 0x69, 0x65, 0x77, 0x53, 0x68, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x12, 0x29, 0x2e, 0x73, 0x74, + 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x73, 0x68, 0x69, 0x70, 0x70, 0x69, 0x6e, 0x67, 0x2e, + 0x76, 0x31, 0x2e, 0x56, 0x69, 0x65, 0x77, 0x53, 0x68, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2a, 0x2e, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, + 0x74, 0x2e, 0x73, 0x68, 0x69, 0x70, 0x70, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x56, 0x69, + 0x65, 0x77, 0x53, 0x68, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x73, 0x65, 0x22, 0x2b, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x25, 0x12, 0x23, 0x2f, 0x76, 0x31, 0x2f, + 0x73, 0x68, 0x69, 0x70, 0x70, 0x69, 0x6e, 0x67, 0x2f, 0x73, 0x68, 0x69, 0x70, 0x6d, 0x65, 0x6e, + 0x74, 0x2f, 0x7b, 0x73, 0x68, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x5f, 0x69, 0x64, 0x7d, 0x12, + 0xb3, 0x01, 0x0a, 0x14, 0x56, 0x69, 0x65, 0x77, 0x53, 0x68, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, + 0x4d, 0x61, 0x6e, 0x69, 0x66, 0x65, 0x73, 0x74, 0x12, 0x31, 0x2e, 0x73, 0x74, 0x6f, 0x63, 0x6b, + 0x6c, 0x65, 0x74, 0x2e, 0x73, 0x68, 0x69, 0x70, 0x70, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, + 0x56, 0x69, 0x65, 0x77, 0x53, 0x68, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x4d, 0x61, 0x6e, 0x69, + 0x66, 0x65, 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x32, 0x2e, 0x73, 0x74, + 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x73, 0x68, 0x69, 0x70, 0x70, 0x69, 0x6e, 0x67, 0x2e, + 0x76, 0x31, 0x2e, 0x56, 0x69, 0x65, 0x77, 0x53, 0x68, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x4d, + 0x61, 0x6e, 0x69, 0x66, 0x65, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, + 0x34, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x2e, 0x12, 0x2c, 0x2f, 0x76, 0x31, 0x2f, 0x73, 0x68, 0x69, + 0x70, 0x70, 0x69, 0x6e, 0x67, 0x2f, 0x73, 0x68, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x2f, 0x7b, + 0x73, 0x68, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x5f, 0x69, 0x64, 0x7d, 0x2f, 0x6d, 0x61, 0x6e, + 0x69, 0x66, 0x65, 0x73, 0x74, 0x12, 0x73, 0x0a, 0x1c, 0x50, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, + 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x52, 0x65, 0x73, 0x65, 0x72, 0x76, 0x61, 0x74, 0x69, 0x6f, 0x6e, + 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x29, 0x2e, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, + 0x2e, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x74, 0x6f, 0x63, 0x6b, + 0x52, 0x65, 0x73, 0x65, 0x72, 0x76, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x45, 0x76, 0x65, 0x6e, 0x74, + 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, + 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x10, 0xfa, 0xd2, 0xe4, 0x93, 0x02, 0x0a, + 0x12, 0x08, 0x49, 0x4e, 0x54, 0x45, 0x52, 0x4e, 0x41, 0x4c, 0x12, 0x73, 0x0a, 0x1c, 0x50, 0x72, + 0x6f, 0x63, 0x65, 0x73, 0x73, 0x50, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x50, 0x72, 0x6f, 0x63, + 0x65, 0x73, 0x73, 0x65, 0x64, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x29, 0x2e, 0x73, 0x74, 0x6f, + 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x2e, 0x76, 0x31, 0x2e, + 0x50, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x50, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, 0x65, 0x64, + 0x45, 0x76, 0x65, 0x6e, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x10, 0xfa, + 0xd2, 0xe4, 0x93, 0x02, 0x0a, 0x12, 0x08, 0x49, 0x4e, 0x54, 0x45, 0x52, 0x4e, 0x41, 0x4c, 0x42, + 0x4b, 0x5a, 0x49, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x68, 0x65, + 0x78, 0x6f, 0x6c, 0x61, 0x6e, 0x2f, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2f, 0x69, + 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x67, 0x65, 0x6e, 0x2f, 0x73, 0x68, 0x69, 0x70, 0x70, 0x69, 0x6e, 0x67, 0x2f, 0x76, 0x31, + 0x3b, 0x73, 0x68, 0x69, 0x70, 0x70, 0x69, 0x6e, 0x67, 0x5f, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_stocklet_shipping_v1_service_proto_rawDescOnce sync.Once + file_stocklet_shipping_v1_service_proto_rawDescData = file_stocklet_shipping_v1_service_proto_rawDesc +) + +func file_stocklet_shipping_v1_service_proto_rawDescGZIP() []byte { + file_stocklet_shipping_v1_service_proto_rawDescOnce.Do(func() { + file_stocklet_shipping_v1_service_proto_rawDescData = protoimpl.X.CompressGZIP(file_stocklet_shipping_v1_service_proto_rawDescData) + }) + return file_stocklet_shipping_v1_service_proto_rawDescData +} + +var file_stocklet_shipping_v1_service_proto_msgTypes = make([]protoimpl.MessageInfo, 4) +var file_stocklet_shipping_v1_service_proto_goTypes = []interface{}{ + (*ViewShipmentRequest)(nil), // 0: stocklet.shipping.v1.ViewShipmentRequest + (*ViewShipmentResponse)(nil), // 1: stocklet.shipping.v1.ViewShipmentResponse + (*ViewShipmentManifestRequest)(nil), // 2: stocklet.shipping.v1.ViewShipmentManifestRequest + (*ViewShipmentManifestResponse)(nil), // 3: stocklet.shipping.v1.ViewShipmentManifestResponse + (*Shipment)(nil), // 4: stocklet.shipping.v1.Shipment + (*ShipmentItem)(nil), // 5: stocklet.shipping.v1.ShipmentItem + (*v1.ServiceInfoRequest)(nil), // 6: stocklet.common.v1.ServiceInfoRequest + (*v11.StockReservationEvent)(nil), // 7: stocklet.events.v1.StockReservationEvent + (*v11.PaymentProcessedEvent)(nil), // 8: stocklet.events.v1.PaymentProcessedEvent + (*v1.ServiceInfoResponse)(nil), // 9: stocklet.common.v1.ServiceInfoResponse + (*emptypb.Empty)(nil), // 10: google.protobuf.Empty +} +var file_stocklet_shipping_v1_service_proto_depIdxs = []int32{ + 4, // 0: stocklet.shipping.v1.ViewShipmentResponse.shipment:type_name -> stocklet.shipping.v1.Shipment + 5, // 1: stocklet.shipping.v1.ViewShipmentManifestResponse.manifest:type_name -> stocklet.shipping.v1.ShipmentItem + 6, // 2: stocklet.shipping.v1.ShippingService.ServiceInfo:input_type -> stocklet.common.v1.ServiceInfoRequest + 0, // 3: stocklet.shipping.v1.ShippingService.ViewShipment:input_type -> stocklet.shipping.v1.ViewShipmentRequest + 2, // 4: stocklet.shipping.v1.ShippingService.ViewShipmentManifest:input_type -> stocklet.shipping.v1.ViewShipmentManifestRequest + 7, // 5: stocklet.shipping.v1.ShippingService.ProcessStockReservationEvent:input_type -> stocklet.events.v1.StockReservationEvent + 8, // 6: stocklet.shipping.v1.ShippingService.ProcessPaymentProcessedEvent:input_type -> stocklet.events.v1.PaymentProcessedEvent + 9, // 7: stocklet.shipping.v1.ShippingService.ServiceInfo:output_type -> stocklet.common.v1.ServiceInfoResponse + 1, // 8: stocklet.shipping.v1.ShippingService.ViewShipment:output_type -> stocklet.shipping.v1.ViewShipmentResponse + 3, // 9: stocklet.shipping.v1.ShippingService.ViewShipmentManifest:output_type -> stocklet.shipping.v1.ViewShipmentManifestResponse + 10, // 10: stocklet.shipping.v1.ShippingService.ProcessStockReservationEvent:output_type -> google.protobuf.Empty + 10, // 11: stocklet.shipping.v1.ShippingService.ProcessPaymentProcessedEvent:output_type -> google.protobuf.Empty + 7, // [7:12] is the sub-list for method output_type + 2, // [2:7] is the sub-list for method input_type + 2, // [2:2] is the sub-list for extension type_name + 2, // [2:2] is the sub-list for extension extendee + 0, // [0:2] is the sub-list for field type_name +} + +func init() { file_stocklet_shipping_v1_service_proto_init() } +func file_stocklet_shipping_v1_service_proto_init() { + if File_stocklet_shipping_v1_service_proto != nil { + return + } + file_stocklet_shipping_v1_types_proto_init() + if !protoimpl.UnsafeEnabled { + file_stocklet_shipping_v1_service_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ViewShipmentRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_stocklet_shipping_v1_service_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ViewShipmentResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_stocklet_shipping_v1_service_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ViewShipmentManifestRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_stocklet_shipping_v1_service_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ViewShipmentManifestResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_stocklet_shipping_v1_service_proto_rawDesc, + NumEnums: 0, + NumMessages: 4, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_stocklet_shipping_v1_service_proto_goTypes, + DependencyIndexes: file_stocklet_shipping_v1_service_proto_depIdxs, + MessageInfos: file_stocklet_shipping_v1_service_proto_msgTypes, + }.Build() + File_stocklet_shipping_v1_service_proto = out.File + file_stocklet_shipping_v1_service_proto_rawDesc = nil + file_stocklet_shipping_v1_service_proto_goTypes = nil + file_stocklet_shipping_v1_service_proto_depIdxs = nil +} diff --git a/internal/pkg/protogen/shipping/v1/service.pb.gw.go b/internal/pkg/protogen/shipping/v1/service.pb.gw.go new file mode 100644 index 0000000..b5b198e --- /dev/null +++ b/internal/pkg/protogen/shipping/v1/service.pb.gw.go @@ -0,0 +1,362 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: stocklet/shipping/v1/service.proto + +/* +Package shipping_v1 is a reverse proxy. + +It translates gRPC into RESTful JSON APIs. +*/ +package shipping_v1 + +import ( + "context" + "io" + "net/http" + + "github.com/grpc-ecosystem/grpc-gateway/v2/runtime" + "github.com/grpc-ecosystem/grpc-gateway/v2/utilities" + "github.com/hexolan/stocklet/internal/pkg/protogen/common/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/status" + "google.golang.org/protobuf/proto" +) + +// Suppress "imported and not used" errors +var _ codes.Code +var _ io.Reader +var _ status.Status +var _ = runtime.String +var _ = utilities.NewDoubleArray +var _ = metadata.Join + +func request_ShippingService_ServiceInfo_0(ctx context.Context, marshaler runtime.Marshaler, client ShippingServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq common_v1.ServiceInfoRequest + var metadata runtime.ServerMetadata + + msg, err := client.ServiceInfo(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_ShippingService_ServiceInfo_0(ctx context.Context, marshaler runtime.Marshaler, server ShippingServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq common_v1.ServiceInfoRequest + var metadata runtime.ServerMetadata + + msg, err := server.ServiceInfo(ctx, &protoReq) + return msg, metadata, err + +} + +func request_ShippingService_ViewShipment_0(ctx context.Context, marshaler runtime.Marshaler, client ShippingServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq ViewShipmentRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["shipment_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "shipment_id") + } + + protoReq.ShipmentId, err = runtime.String(val) + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "shipment_id", err) + } + + msg, err := client.ViewShipment(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_ShippingService_ViewShipment_0(ctx context.Context, marshaler runtime.Marshaler, server ShippingServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq ViewShipmentRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["shipment_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "shipment_id") + } + + protoReq.ShipmentId, err = runtime.String(val) + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "shipment_id", err) + } + + msg, err := server.ViewShipment(ctx, &protoReq) + return msg, metadata, err + +} + +func request_ShippingService_ViewShipmentManifest_0(ctx context.Context, marshaler runtime.Marshaler, client ShippingServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq ViewShipmentManifestRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["shipment_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "shipment_id") + } + + protoReq.ShipmentId, err = runtime.String(val) + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "shipment_id", err) + } + + msg, err := client.ViewShipmentManifest(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_ShippingService_ViewShipmentManifest_0(ctx context.Context, marshaler runtime.Marshaler, server ShippingServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq ViewShipmentManifestRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["shipment_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "shipment_id") + } + + protoReq.ShipmentId, err = runtime.String(val) + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "shipment_id", err) + } + + msg, err := server.ViewShipmentManifest(ctx, &protoReq) + return msg, metadata, err + +} + +// RegisterShippingServiceHandlerServer registers the http handlers for service ShippingService to "mux". +// UnaryRPC :call ShippingServiceServer directly. +// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. +// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterShippingServiceHandlerFromEndpoint instead. +func RegisterShippingServiceHandlerServer(ctx context.Context, mux *runtime.ServeMux, server ShippingServiceServer) error { + + mux.Handle("GET", pattern_ShippingService_ServiceInfo_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/stocklet.shipping.v1.ShippingService/ServiceInfo", runtime.WithHTTPPathPattern("/v1/shipping/service")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_ShippingService_ServiceInfo_0(annotatedContext, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_ShippingService_ServiceInfo_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_ShippingService_ViewShipment_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/stocklet.shipping.v1.ShippingService/ViewShipment", runtime.WithHTTPPathPattern("/v1/shipping/shipment/{shipment_id}")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_ShippingService_ViewShipment_0(annotatedContext, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_ShippingService_ViewShipment_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_ShippingService_ViewShipmentManifest_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/stocklet.shipping.v1.ShippingService/ViewShipmentManifest", runtime.WithHTTPPathPattern("/v1/shipping/shipment/{shipment_id}/manifest")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_ShippingService_ViewShipmentManifest_0(annotatedContext, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_ShippingService_ViewShipmentManifest_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +// RegisterShippingServiceHandlerFromEndpoint is same as RegisterShippingServiceHandler but +// automatically dials to "endpoint" and closes the connection when "ctx" gets done. +func RegisterShippingServiceHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { + conn, err := grpc.DialContext(ctx, endpoint, opts...) + if err != nil { + return err + } + defer func() { + if err != nil { + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + return + } + go func() { + <-ctx.Done() + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + }() + }() + + return RegisterShippingServiceHandler(ctx, mux, conn) +} + +// RegisterShippingServiceHandler registers the http handlers for service ShippingService to "mux". +// The handlers forward requests to the grpc endpoint over "conn". +func RegisterShippingServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { + return RegisterShippingServiceHandlerClient(ctx, mux, NewShippingServiceClient(conn)) +} + +// RegisterShippingServiceHandlerClient registers the http handlers for service ShippingService +// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "ShippingServiceClient". +// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "ShippingServiceClient" +// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in +// "ShippingServiceClient" to call the correct interceptors. +func RegisterShippingServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux, client ShippingServiceClient) error { + + mux.Handle("GET", pattern_ShippingService_ServiceInfo_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/stocklet.shipping.v1.ShippingService/ServiceInfo", runtime.WithHTTPPathPattern("/v1/shipping/service")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_ShippingService_ServiceInfo_0(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_ShippingService_ServiceInfo_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_ShippingService_ViewShipment_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/stocklet.shipping.v1.ShippingService/ViewShipment", runtime.WithHTTPPathPattern("/v1/shipping/shipment/{shipment_id}")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_ShippingService_ViewShipment_0(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_ShippingService_ViewShipment_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_ShippingService_ViewShipmentManifest_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/stocklet.shipping.v1.ShippingService/ViewShipmentManifest", runtime.WithHTTPPathPattern("/v1/shipping/shipment/{shipment_id}/manifest")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_ShippingService_ViewShipmentManifest_0(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_ShippingService_ViewShipmentManifest_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +var ( + pattern_ShippingService_ServiceInfo_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v1", "shipping", "service"}, "")) + + pattern_ShippingService_ViewShipment_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"v1", "shipping", "shipment", "shipment_id"}, "")) + + pattern_ShippingService_ViewShipmentManifest_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3, 2, 4}, []string{"v1", "shipping", "shipment", "shipment_id", "manifest"}, "")) +) + +var ( + forward_ShippingService_ServiceInfo_0 = runtime.ForwardResponseMessage + + forward_ShippingService_ViewShipment_0 = runtime.ForwardResponseMessage + + forward_ShippingService_ViewShipmentManifest_0 = runtime.ForwardResponseMessage +) diff --git a/internal/pkg/protogen/shipping/v1/service_grpc.pb.go b/internal/pkg/protogen/shipping/v1/service_grpc.pb.go new file mode 100644 index 0000000..008f9a7 --- /dev/null +++ b/internal/pkg/protogen/shipping/v1/service_grpc.pb.go @@ -0,0 +1,301 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.3.0 +// - protoc (unknown) +// source: stocklet/shipping/v1/service.proto + +package shipping_v1 + +import ( + context "context" + v1 "github.com/hexolan/stocklet/internal/pkg/protogen/common/v1" + v11 "github.com/hexolan/stocklet/internal/pkg/protogen/events/v1" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + emptypb "google.golang.org/protobuf/types/known/emptypb" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.32.0 or later. +const _ = grpc.SupportPackageIsVersion7 + +const ( + ShippingService_ServiceInfo_FullMethodName = "/stocklet.shipping.v1.ShippingService/ServiceInfo" + ShippingService_ViewShipment_FullMethodName = "/stocklet.shipping.v1.ShippingService/ViewShipment" + ShippingService_ViewShipmentManifest_FullMethodName = "/stocklet.shipping.v1.ShippingService/ViewShipmentManifest" + ShippingService_ProcessStockReservationEvent_FullMethodName = "/stocklet.shipping.v1.ShippingService/ProcessStockReservationEvent" + ShippingService_ProcessPaymentProcessedEvent_FullMethodName = "/stocklet.shipping.v1.ShippingService/ProcessPaymentProcessedEvent" +) + +// ShippingServiceClient is the client API for ShippingService service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +type ShippingServiceClient interface { + // View information about the service. + // + // buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + ServiceInfo(ctx context.Context, in *v1.ServiceInfoRequest, opts ...grpc.CallOption) (*v1.ServiceInfoResponse, error) + ViewShipment(ctx context.Context, in *ViewShipmentRequest, opts ...grpc.CallOption) (*ViewShipmentResponse, error) + ViewShipmentManifest(ctx context.Context, in *ViewShipmentManifestRequest, opts ...grpc.CallOption) (*ViewShipmentManifestResponse, error) + // A consumer will call this method to process events. + // + // buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + // buf:lint:ignore RPC_REQUEST_STANDARD_NAME + // buf:lint:ignore RPC_RESPONSE_STANDARD_NAME + ProcessStockReservationEvent(ctx context.Context, in *v11.StockReservationEvent, opts ...grpc.CallOption) (*emptypb.Empty, error) + // A consumer will call this method to process events. + // + // buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + // buf:lint:ignore RPC_REQUEST_STANDARD_NAME + // buf:lint:ignore RPC_RESPONSE_STANDARD_NAME + ProcessPaymentProcessedEvent(ctx context.Context, in *v11.PaymentProcessedEvent, opts ...grpc.CallOption) (*emptypb.Empty, error) +} + +type shippingServiceClient struct { + cc grpc.ClientConnInterface +} + +func NewShippingServiceClient(cc grpc.ClientConnInterface) ShippingServiceClient { + return &shippingServiceClient{cc} +} + +func (c *shippingServiceClient) ServiceInfo(ctx context.Context, in *v1.ServiceInfoRequest, opts ...grpc.CallOption) (*v1.ServiceInfoResponse, error) { + out := new(v1.ServiceInfoResponse) + err := c.cc.Invoke(ctx, ShippingService_ServiceInfo_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shippingServiceClient) ViewShipment(ctx context.Context, in *ViewShipmentRequest, opts ...grpc.CallOption) (*ViewShipmentResponse, error) { + out := new(ViewShipmentResponse) + err := c.cc.Invoke(ctx, ShippingService_ViewShipment_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shippingServiceClient) ViewShipmentManifest(ctx context.Context, in *ViewShipmentManifestRequest, opts ...grpc.CallOption) (*ViewShipmentManifestResponse, error) { + out := new(ViewShipmentManifestResponse) + err := c.cc.Invoke(ctx, ShippingService_ViewShipmentManifest_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shippingServiceClient) ProcessStockReservationEvent(ctx context.Context, in *v11.StockReservationEvent, opts ...grpc.CallOption) (*emptypb.Empty, error) { + out := new(emptypb.Empty) + err := c.cc.Invoke(ctx, ShippingService_ProcessStockReservationEvent_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shippingServiceClient) ProcessPaymentProcessedEvent(ctx context.Context, in *v11.PaymentProcessedEvent, opts ...grpc.CallOption) (*emptypb.Empty, error) { + out := new(emptypb.Empty) + err := c.cc.Invoke(ctx, ShippingService_ProcessPaymentProcessedEvent_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// ShippingServiceServer is the server API for ShippingService service. +// All implementations must embed UnimplementedShippingServiceServer +// for forward compatibility +type ShippingServiceServer interface { + // View information about the service. + // + // buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + ServiceInfo(context.Context, *v1.ServiceInfoRequest) (*v1.ServiceInfoResponse, error) + ViewShipment(context.Context, *ViewShipmentRequest) (*ViewShipmentResponse, error) + ViewShipmentManifest(context.Context, *ViewShipmentManifestRequest) (*ViewShipmentManifestResponse, error) + // A consumer will call this method to process events. + // + // buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + // buf:lint:ignore RPC_REQUEST_STANDARD_NAME + // buf:lint:ignore RPC_RESPONSE_STANDARD_NAME + ProcessStockReservationEvent(context.Context, *v11.StockReservationEvent) (*emptypb.Empty, error) + // A consumer will call this method to process events. + // + // buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + // buf:lint:ignore RPC_REQUEST_STANDARD_NAME + // buf:lint:ignore RPC_RESPONSE_STANDARD_NAME + ProcessPaymentProcessedEvent(context.Context, *v11.PaymentProcessedEvent) (*emptypb.Empty, error) + mustEmbedUnimplementedShippingServiceServer() +} + +// UnimplementedShippingServiceServer must be embedded to have forward compatible implementations. +type UnimplementedShippingServiceServer struct { +} + +func (UnimplementedShippingServiceServer) ServiceInfo(context.Context, *v1.ServiceInfoRequest) (*v1.ServiceInfoResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method ServiceInfo not implemented") +} +func (UnimplementedShippingServiceServer) ViewShipment(context.Context, *ViewShipmentRequest) (*ViewShipmentResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method ViewShipment not implemented") +} +func (UnimplementedShippingServiceServer) ViewShipmentManifest(context.Context, *ViewShipmentManifestRequest) (*ViewShipmentManifestResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method ViewShipmentManifest not implemented") +} +func (UnimplementedShippingServiceServer) ProcessStockReservationEvent(context.Context, *v11.StockReservationEvent) (*emptypb.Empty, error) { + return nil, status.Errorf(codes.Unimplemented, "method ProcessStockReservationEvent not implemented") +} +func (UnimplementedShippingServiceServer) ProcessPaymentProcessedEvent(context.Context, *v11.PaymentProcessedEvent) (*emptypb.Empty, error) { + return nil, status.Errorf(codes.Unimplemented, "method ProcessPaymentProcessedEvent not implemented") +} +func (UnimplementedShippingServiceServer) mustEmbedUnimplementedShippingServiceServer() {} + +// UnsafeShippingServiceServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to ShippingServiceServer will +// result in compilation errors. +type UnsafeShippingServiceServer interface { + mustEmbedUnimplementedShippingServiceServer() +} + +func RegisterShippingServiceServer(s grpc.ServiceRegistrar, srv ShippingServiceServer) { + s.RegisterService(&ShippingService_ServiceDesc, srv) +} + +func _ShippingService_ServiceInfo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(v1.ServiceInfoRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShippingServiceServer).ServiceInfo(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShippingService_ServiceInfo_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShippingServiceServer).ServiceInfo(ctx, req.(*v1.ServiceInfoRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShippingService_ViewShipment_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ViewShipmentRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShippingServiceServer).ViewShipment(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShippingService_ViewShipment_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShippingServiceServer).ViewShipment(ctx, req.(*ViewShipmentRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShippingService_ViewShipmentManifest_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ViewShipmentManifestRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShippingServiceServer).ViewShipmentManifest(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShippingService_ViewShipmentManifest_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShippingServiceServer).ViewShipmentManifest(ctx, req.(*ViewShipmentManifestRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShippingService_ProcessStockReservationEvent_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(v11.StockReservationEvent) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShippingServiceServer).ProcessStockReservationEvent(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShippingService_ProcessStockReservationEvent_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShippingServiceServer).ProcessStockReservationEvent(ctx, req.(*v11.StockReservationEvent)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShippingService_ProcessPaymentProcessedEvent_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(v11.PaymentProcessedEvent) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShippingServiceServer).ProcessPaymentProcessedEvent(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShippingService_ProcessPaymentProcessedEvent_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShippingServiceServer).ProcessPaymentProcessedEvent(ctx, req.(*v11.PaymentProcessedEvent)) + } + return interceptor(ctx, in, info, handler) +} + +// ShippingService_ServiceDesc is the grpc.ServiceDesc for ShippingService service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var ShippingService_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "stocklet.shipping.v1.ShippingService", + HandlerType: (*ShippingServiceServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "ServiceInfo", + Handler: _ShippingService_ServiceInfo_Handler, + }, + { + MethodName: "ViewShipment", + Handler: _ShippingService_ViewShipment_Handler, + }, + { + MethodName: "ViewShipmentManifest", + Handler: _ShippingService_ViewShipmentManifest_Handler, + }, + { + MethodName: "ProcessStockReservationEvent", + Handler: _ShippingService_ProcessStockReservationEvent_Handler, + }, + { + MethodName: "ProcessPaymentProcessedEvent", + Handler: _ShippingService_ProcessPaymentProcessedEvent_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "stocklet/shipping/v1/service.proto", +} diff --git a/internal/pkg/protogen/shipping/v1/types.pb.go b/internal/pkg/protogen/shipping/v1/types.pb.go new file mode 100644 index 0000000..5ae3df3 --- /dev/null +++ b/internal/pkg/protogen/shipping/v1/types.pb.go @@ -0,0 +1,292 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.31.0 +// protoc (unknown) +// source: stocklet/shipping/v1/types.proto + +package shipping_v1 + +import ( + _ "buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go/buf/validate" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type Shipment struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + OrderId string `protobuf:"bytes,2,opt,name=order_id,json=orderId,proto3" json:"order_id,omitempty"` + Dispatched bool `protobuf:"varint,3,opt,name=dispatched,proto3" json:"dispatched,omitempty"` + CreatedAt int64 `protobuf:"varint,5,opt,name=created_at,json=createdAt,proto3" json:"created_at,omitempty"` + UpdatedAt *int64 `protobuf:"varint,6,opt,name=updated_at,json=updatedAt,proto3,oneof" json:"updated_at,omitempty"` +} + +func (x *Shipment) Reset() { + *x = Shipment{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_shipping_v1_types_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Shipment) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Shipment) ProtoMessage() {} + +func (x *Shipment) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_shipping_v1_types_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Shipment.ProtoReflect.Descriptor instead. +func (*Shipment) Descriptor() ([]byte, []int) { + return file_stocklet_shipping_v1_types_proto_rawDescGZIP(), []int{0} +} + +func (x *Shipment) GetId() string { + if x != nil { + return x.Id + } + return "" +} + +func (x *Shipment) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +func (x *Shipment) GetDispatched() bool { + if x != nil { + return x.Dispatched + } + return false +} + +func (x *Shipment) GetCreatedAt() int64 { + if x != nil { + return x.CreatedAt + } + return 0 +} + +func (x *Shipment) GetUpdatedAt() int64 { + if x != nil && x.UpdatedAt != nil { + return *x.UpdatedAt + } + return 0 +} + +type ShipmentItem struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + ShipmentId string `protobuf:"bytes,1,opt,name=shipment_id,json=shipmentId,proto3" json:"shipment_id,omitempty"` + ProductId string `protobuf:"bytes,2,opt,name=product_id,json=productId,proto3" json:"product_id,omitempty"` + Quantity int32 `protobuf:"varint,3,opt,name=quantity,proto3" json:"quantity,omitempty"` +} + +func (x *ShipmentItem) Reset() { + *x = ShipmentItem{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_shipping_v1_types_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ShipmentItem) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ShipmentItem) ProtoMessage() {} + +func (x *ShipmentItem) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_shipping_v1_types_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ShipmentItem.ProtoReflect.Descriptor instead. +func (*ShipmentItem) Descriptor() ([]byte, []int) { + return file_stocklet_shipping_v1_types_proto_rawDescGZIP(), []int{1} +} + +func (x *ShipmentItem) GetShipmentId() string { + if x != nil { + return x.ShipmentId + } + return "" +} + +func (x *ShipmentItem) GetProductId() string { + if x != nil { + return x.ProductId + } + return "" +} + +func (x *ShipmentItem) GetQuantity() int32 { + if x != nil { + return x.Quantity + } + return 0 +} + +var File_stocklet_shipping_v1_types_proto protoreflect.FileDescriptor + +var file_stocklet_shipping_v1_types_proto_rawDesc = []byte{ + 0x0a, 0x20, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2f, 0x73, 0x68, 0x69, 0x70, 0x70, + 0x69, 0x6e, 0x67, 0x2f, 0x76, 0x31, 0x2f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x12, 0x14, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x73, 0x68, 0x69, + 0x70, 0x70, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x1a, 0x1b, 0x62, 0x75, 0x66, 0x2f, 0x76, 0x61, + 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x2f, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xb9, 0x01, 0x0a, 0x08, 0x53, 0x68, 0x69, 0x70, 0x6d, 0x65, + 0x6e, 0x74, 0x12, 0x17, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, 0x07, + 0xba, 0x48, 0x04, 0x72, 0x02, 0x10, 0x01, 0x52, 0x02, 0x69, 0x64, 0x12, 0x22, 0x0a, 0x08, 0x6f, + 0x72, 0x64, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x42, 0x07, 0xba, + 0x48, 0x04, 0x72, 0x02, 0x10, 0x01, 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x12, + 0x1e, 0x0a, 0x0a, 0x64, 0x69, 0x73, 0x70, 0x61, 0x74, 0x63, 0x68, 0x65, 0x64, 0x18, 0x03, 0x20, + 0x01, 0x28, 0x08, 0x52, 0x0a, 0x64, 0x69, 0x73, 0x70, 0x61, 0x74, 0x63, 0x68, 0x65, 0x64, 0x12, + 0x1d, 0x0a, 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x61, 0x74, 0x18, 0x05, 0x20, + 0x01, 0x28, 0x03, 0x52, 0x09, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x41, 0x74, 0x12, 0x22, + 0x0a, 0x0a, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x61, 0x74, 0x18, 0x06, 0x20, 0x01, + 0x28, 0x03, 0x48, 0x00, 0x52, 0x09, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x41, 0x74, 0x88, + 0x01, 0x01, 0x42, 0x0d, 0x0a, 0x0b, 0x5f, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x61, + 0x74, 0x22, 0x85, 0x01, 0x0a, 0x0c, 0x53, 0x68, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x49, 0x74, + 0x65, 0x6d, 0x12, 0x28, 0x0a, 0x0b, 0x73, 0x68, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x5f, 0x69, + 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, 0x07, 0xba, 0x48, 0x04, 0x72, 0x02, 0x10, 0x01, + 0x52, 0x0a, 0x73, 0x68, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x12, 0x26, 0x0a, 0x0a, + 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, + 0x42, 0x07, 0xba, 0x48, 0x04, 0x72, 0x02, 0x10, 0x01, 0x52, 0x09, 0x70, 0x72, 0x6f, 0x64, 0x75, + 0x63, 0x74, 0x49, 0x64, 0x12, 0x23, 0x0a, 0x08, 0x71, 0x75, 0x61, 0x6e, 0x74, 0x69, 0x74, 0x79, + 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x42, 0x07, 0xba, 0x48, 0x04, 0x1a, 0x02, 0x20, 0x00, 0x52, + 0x08, 0x71, 0x75, 0x61, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x42, 0x4b, 0x5a, 0x49, 0x67, 0x69, 0x74, + 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x68, 0x65, 0x78, 0x6f, 0x6c, 0x61, 0x6e, 0x2f, + 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, + 0x6c, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x67, 0x65, 0x6e, 0x2f, 0x73, + 0x68, 0x69, 0x70, 0x70, 0x69, 0x6e, 0x67, 0x2f, 0x76, 0x31, 0x3b, 0x73, 0x68, 0x69, 0x70, 0x70, + 0x69, 0x6e, 0x67, 0x5f, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_stocklet_shipping_v1_types_proto_rawDescOnce sync.Once + file_stocklet_shipping_v1_types_proto_rawDescData = file_stocklet_shipping_v1_types_proto_rawDesc +) + +func file_stocklet_shipping_v1_types_proto_rawDescGZIP() []byte { + file_stocklet_shipping_v1_types_proto_rawDescOnce.Do(func() { + file_stocklet_shipping_v1_types_proto_rawDescData = protoimpl.X.CompressGZIP(file_stocklet_shipping_v1_types_proto_rawDescData) + }) + return file_stocklet_shipping_v1_types_proto_rawDescData +} + +var file_stocklet_shipping_v1_types_proto_msgTypes = make([]protoimpl.MessageInfo, 2) +var file_stocklet_shipping_v1_types_proto_goTypes = []interface{}{ + (*Shipment)(nil), // 0: stocklet.shipping.v1.Shipment + (*ShipmentItem)(nil), // 1: stocklet.shipping.v1.ShipmentItem +} +var file_stocklet_shipping_v1_types_proto_depIdxs = []int32{ + 0, // [0:0] is the sub-list for method output_type + 0, // [0:0] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_stocklet_shipping_v1_types_proto_init() } +func file_stocklet_shipping_v1_types_proto_init() { + if File_stocklet_shipping_v1_types_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_stocklet_shipping_v1_types_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Shipment); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_stocklet_shipping_v1_types_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ShipmentItem); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + file_stocklet_shipping_v1_types_proto_msgTypes[0].OneofWrappers = []interface{}{} + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_stocklet_shipping_v1_types_proto_rawDesc, + NumEnums: 0, + NumMessages: 2, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_stocklet_shipping_v1_types_proto_goTypes, + DependencyIndexes: file_stocklet_shipping_v1_types_proto_depIdxs, + MessageInfos: file_stocklet_shipping_v1_types_proto_msgTypes, + }.Build() + File_stocklet_shipping_v1_types_proto = out.File + file_stocklet_shipping_v1_types_proto_rawDesc = nil + file_stocklet_shipping_v1_types_proto_goTypes = nil + file_stocklet_shipping_v1_types_proto_depIdxs = nil +} diff --git a/internal/pkg/protogen/stocklet.pb.go b/internal/pkg/protogen/stocklet.pb.go new file mode 100644 index 0000000..9df5443 --- /dev/null +++ b/internal/pkg/protogen/stocklet.pb.go @@ -0,0 +1,96 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.31.0 +// protoc (unknown) +// source: stocklet/stocklet.proto + +// buf:lint:ignore PACKAGE_VERSION_SUFFIX + +package protogen + +import ( + _ "github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2/options" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +var File_stocklet_stocklet_proto protoreflect.FileDescriptor + +var file_stocklet_stocklet_proto_rawDesc = []byte{ + 0x0a, 0x17, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2f, 0x73, 0x74, 0x6f, 0x63, 0x6b, + 0x6c, 0x65, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x08, 0x73, 0x74, 0x6f, 0x63, 0x6b, + 0x6c, 0x65, 0x74, 0x1a, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x2d, 0x67, 0x65, 0x6e, 0x2d, + 0x6f, 0x70, 0x65, 0x6e, 0x61, 0x70, 0x69, 0x76, 0x32, 0x2f, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, + 0x73, 0x2f, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x42, 0xd6, 0x01, 0x92, 0x41, 0x9f, 0x01, 0x12, 0x8e, 0x01, 0x0a, 0x08, 0x53, + 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x22, 0x38, 0x0a, 0x11, 0x47, 0x69, 0x74, 0x48, 0x75, + 0x62, 0x20, 0x52, 0x65, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x6f, 0x72, 0x79, 0x12, 0x23, 0x68, 0x74, + 0x74, 0x70, 0x73, 0x3a, 0x2f, 0x2f, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, + 0x2f, 0x68, 0x65, 0x78, 0x6f, 0x6c, 0x61, 0x6e, 0x2f, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, + 0x74, 0x2a, 0x41, 0x0a, 0x08, 0x41, 0x47, 0x50, 0x4c, 0x2d, 0x33, 0x2e, 0x30, 0x12, 0x35, 0x68, + 0x74, 0x74, 0x70, 0x73, 0x3a, 0x2f, 0x2f, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, + 0x6d, 0x2f, 0x68, 0x65, 0x78, 0x6f, 0x6c, 0x61, 0x6e, 0x2f, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, + 0x65, 0x74, 0x2f, 0x62, 0x6c, 0x6f, 0x62, 0x2f, 0x6d, 0x61, 0x69, 0x6e, 0x2f, 0x4c, 0x49, 0x43, + 0x45, 0x4e, 0x53, 0x45, 0x32, 0x05, 0x30, 0x2e, 0x31, 0x2e, 0x30, 0x1a, 0x09, 0x6c, 0x6f, 0x63, + 0x61, 0x6c, 0x68, 0x6f, 0x73, 0x74, 0x2a, 0x01, 0x01, 0x5a, 0x31, 0x67, 0x69, 0x74, 0x68, 0x75, + 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x68, 0x65, 0x78, 0x6f, 0x6c, 0x61, 0x6e, 0x2f, 0x73, 0x74, + 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, + 0x70, 0x6b, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x67, 0x65, 0x6e, 0x62, 0x06, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x33, +} + +var file_stocklet_stocklet_proto_goTypes = []interface{}{} +var file_stocklet_stocklet_proto_depIdxs = []int32{ + 0, // [0:0] is the sub-list for method output_type + 0, // [0:0] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_stocklet_stocklet_proto_init() } +func file_stocklet_stocklet_proto_init() { + if File_stocklet_stocklet_proto != nil { + return + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_stocklet_stocklet_proto_rawDesc, + NumEnums: 0, + NumMessages: 0, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_stocklet_stocklet_proto_goTypes, + DependencyIndexes: file_stocklet_stocklet_proto_depIdxs, + }.Build() + File_stocklet_stocklet_proto = out.File + file_stocklet_stocklet_proto_rawDesc = nil + file_stocklet_stocklet_proto_goTypes = nil + file_stocklet_stocklet_proto_depIdxs = nil +} diff --git a/internal/pkg/protogen/user/v1/service.pb.go b/internal/pkg/protogen/user/v1/service.pb.go new file mode 100644 index 0000000..aa58958 --- /dev/null +++ b/internal/pkg/protogen/user/v1/service.pb.go @@ -0,0 +1,434 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.31.0 +// protoc (unknown) +// source: stocklet/user/v1/service.proto + +package user_v1 + +import ( + _ "buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go/buf/validate" + v1 "github.com/hexolan/stocklet/internal/pkg/protogen/common/v1" + _ "google.golang.org/genproto/googleapis/api/annotations" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type ViewUserRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` +} + +func (x *ViewUserRequest) Reset() { + *x = ViewUserRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_user_v1_service_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ViewUserRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ViewUserRequest) ProtoMessage() {} + +func (x *ViewUserRequest) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_user_v1_service_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ViewUserRequest.ProtoReflect.Descriptor instead. +func (*ViewUserRequest) Descriptor() ([]byte, []int) { + return file_stocklet_user_v1_service_proto_rawDescGZIP(), []int{0} +} + +func (x *ViewUserRequest) GetId() string { + if x != nil { + return x.Id + } + return "" +} + +type ViewUserResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + User *User `protobuf:"bytes,1,opt,name=user,proto3" json:"user,omitempty"` +} + +func (x *ViewUserResponse) Reset() { + *x = ViewUserResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_user_v1_service_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ViewUserResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ViewUserResponse) ProtoMessage() {} + +func (x *ViewUserResponse) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_user_v1_service_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ViewUserResponse.ProtoReflect.Descriptor instead. +func (*ViewUserResponse) Descriptor() ([]byte, []int) { + return file_stocklet_user_v1_service_proto_rawDescGZIP(), []int{1} +} + +func (x *ViewUserResponse) GetUser() *User { + if x != nil { + return x.User + } + return nil +} + +type RegisterUserRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + FirstName string `protobuf:"bytes,1,opt,name=first_name,json=firstName,proto3" json:"first_name,omitempty"` + LastName string `protobuf:"bytes,2,opt,name=last_name,json=lastName,proto3" json:"last_name,omitempty"` + Email string `protobuf:"bytes,3,opt,name=email,proto3" json:"email,omitempty"` + Password string `protobuf:"bytes,4,opt,name=password,proto3" json:"password,omitempty"` +} + +func (x *RegisterUserRequest) Reset() { + *x = RegisterUserRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_user_v1_service_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *RegisterUserRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*RegisterUserRequest) ProtoMessage() {} + +func (x *RegisterUserRequest) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_user_v1_service_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use RegisterUserRequest.ProtoReflect.Descriptor instead. +func (*RegisterUserRequest) Descriptor() ([]byte, []int) { + return file_stocklet_user_v1_service_proto_rawDescGZIP(), []int{2} +} + +func (x *RegisterUserRequest) GetFirstName() string { + if x != nil { + return x.FirstName + } + return "" +} + +func (x *RegisterUserRequest) GetLastName() string { + if x != nil { + return x.LastName + } + return "" +} + +func (x *RegisterUserRequest) GetEmail() string { + if x != nil { + return x.Email + } + return "" +} + +func (x *RegisterUserRequest) GetPassword() string { + if x != nil { + return x.Password + } + return "" +} + +type RegisterUserResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + User *User `protobuf:"bytes,1,opt,name=user,proto3" json:"user,omitempty"` +} + +func (x *RegisterUserResponse) Reset() { + *x = RegisterUserResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_user_v1_service_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *RegisterUserResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*RegisterUserResponse) ProtoMessage() {} + +func (x *RegisterUserResponse) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_user_v1_service_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use RegisterUserResponse.ProtoReflect.Descriptor instead. +func (*RegisterUserResponse) Descriptor() ([]byte, []int) { + return file_stocklet_user_v1_service_proto_rawDescGZIP(), []int{3} +} + +func (x *RegisterUserResponse) GetUser() *User { + if x != nil { + return x.User + } + return nil +} + +var File_stocklet_user_v1_service_proto protoreflect.FileDescriptor + +var file_stocklet_user_v1_service_proto_rawDesc = []byte{ + 0x0a, 0x1e, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2f, 0x75, 0x73, 0x65, 0x72, 0x2f, + 0x76, 0x31, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x12, 0x10, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, + 0x76, 0x31, 0x1a, 0x1b, 0x62, 0x75, 0x66, 0x2f, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, + 0x2f, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, + 0x1c, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x61, 0x6e, 0x6e, 0x6f, + 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1f, 0x67, + 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x5f, + 0x62, 0x65, 0x68, 0x61, 0x76, 0x69, 0x6f, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x21, + 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2f, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2f, + 0x76, 0x31, 0x2f, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x1a, 0x1c, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2f, 0x75, 0x73, 0x65, 0x72, + 0x2f, 0x76, 0x31, 0x2f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, + 0x2a, 0x0a, 0x0f, 0x56, 0x69, 0x65, 0x77, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x12, 0x17, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, 0x07, + 0xba, 0x48, 0x04, 0x72, 0x02, 0x10, 0x01, 0x52, 0x02, 0x69, 0x64, 0x22, 0x3e, 0x0a, 0x10, 0x56, + 0x69, 0x65, 0x77, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, + 0x2a, 0x0a, 0x04, 0x75, 0x73, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x16, 0x2e, + 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x76, 0x31, + 0x2e, 0x55, 0x73, 0x65, 0x72, 0x52, 0x04, 0x75, 0x73, 0x65, 0x72, 0x22, 0xb9, 0x01, 0x0a, 0x13, + 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x12, 0x2b, 0x0a, 0x0a, 0x66, 0x69, 0x72, 0x73, 0x74, 0x5f, 0x6e, 0x61, 0x6d, + 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, 0x0c, 0xe0, 0x41, 0x02, 0xba, 0x48, 0x06, 0x72, + 0x04, 0x10, 0x01, 0x18, 0x23, 0x52, 0x09, 0x66, 0x69, 0x72, 0x73, 0x74, 0x4e, 0x61, 0x6d, 0x65, + 0x12, 0x29, 0x0a, 0x09, 0x6c, 0x61, 0x73, 0x74, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x09, 0x42, 0x0c, 0xe0, 0x41, 0x02, 0xba, 0x48, 0x06, 0x72, 0x04, 0x10, 0x01, 0x18, + 0x23, 0x52, 0x08, 0x6c, 0x61, 0x73, 0x74, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x20, 0x0a, 0x05, 0x65, + 0x6d, 0x61, 0x69, 0x6c, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x42, 0x0a, 0xe0, 0x41, 0x02, 0xba, + 0x48, 0x04, 0x72, 0x02, 0x60, 0x01, 0x52, 0x05, 0x65, 0x6d, 0x61, 0x69, 0x6c, 0x12, 0x28, 0x0a, + 0x08, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x42, + 0x0c, 0xe0, 0x41, 0x02, 0xba, 0x48, 0x06, 0x72, 0x04, 0x10, 0x01, 0x18, 0x40, 0x52, 0x08, 0x70, + 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x22, 0x42, 0x0a, 0x14, 0x52, 0x65, 0x67, 0x69, 0x73, + 0x74, 0x65, 0x72, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, + 0x2a, 0x0a, 0x04, 0x75, 0x73, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x16, 0x2e, + 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x76, 0x31, + 0x2e, 0x55, 0x73, 0x65, 0x72, 0x52, 0x04, 0x75, 0x73, 0x65, 0x72, 0x32, 0xf1, 0x02, 0x0a, 0x0b, + 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x78, 0x0a, 0x0b, 0x53, + 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x26, 0x2e, 0x73, 0x74, 0x6f, + 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x76, 0x31, 0x2e, + 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x1a, 0x27, 0x2e, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x63, 0x6f, + 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x49, + 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x18, 0x82, 0xd3, 0xe4, + 0x93, 0x02, 0x12, 0x12, 0x10, 0x2f, 0x76, 0x31, 0x2f, 0x75, 0x73, 0x65, 0x72, 0x2f, 0x73, 0x65, + 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x6e, 0x0a, 0x08, 0x56, 0x69, 0x65, 0x77, 0x55, 0x73, 0x65, + 0x72, 0x12, 0x21, 0x2e, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x75, 0x73, 0x65, + 0x72, 0x2e, 0x76, 0x31, 0x2e, 0x56, 0x69, 0x65, 0x77, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x1a, 0x22, 0x2e, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, + 0x75, 0x73, 0x65, 0x72, 0x2e, 0x76, 0x31, 0x2e, 0x56, 0x69, 0x65, 0x77, 0x55, 0x73, 0x65, 0x72, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x1b, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x15, + 0x12, 0x13, 0x2f, 0x76, 0x31, 0x2f, 0x75, 0x73, 0x65, 0x72, 0x2f, 0x75, 0x73, 0x65, 0x72, 0x73, + 0x2f, 0x7b, 0x69, 0x64, 0x7d, 0x12, 0x78, 0x0a, 0x0c, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, + 0x72, 0x55, 0x73, 0x65, 0x72, 0x12, 0x25, 0x2e, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, + 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x76, 0x31, 0x2e, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, + 0x72, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x26, 0x2e, 0x73, + 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x76, 0x31, 0x2e, + 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x19, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x13, 0x22, 0x11, 0x2f, 0x76, + 0x31, 0x2f, 0x75, 0x73, 0x65, 0x72, 0x2f, 0x72, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x42, + 0x43, 0x5a, 0x41, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x68, 0x65, + 0x78, 0x6f, 0x6c, 0x61, 0x6e, 0x2f, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2f, 0x69, + 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x67, 0x65, 0x6e, 0x2f, 0x75, 0x73, 0x65, 0x72, 0x2f, 0x76, 0x31, 0x3b, 0x75, 0x73, 0x65, + 0x72, 0x5f, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_stocklet_user_v1_service_proto_rawDescOnce sync.Once + file_stocklet_user_v1_service_proto_rawDescData = file_stocklet_user_v1_service_proto_rawDesc +) + +func file_stocklet_user_v1_service_proto_rawDescGZIP() []byte { + file_stocklet_user_v1_service_proto_rawDescOnce.Do(func() { + file_stocklet_user_v1_service_proto_rawDescData = protoimpl.X.CompressGZIP(file_stocklet_user_v1_service_proto_rawDescData) + }) + return file_stocklet_user_v1_service_proto_rawDescData +} + +var file_stocklet_user_v1_service_proto_msgTypes = make([]protoimpl.MessageInfo, 4) +var file_stocklet_user_v1_service_proto_goTypes = []interface{}{ + (*ViewUserRequest)(nil), // 0: stocklet.user.v1.ViewUserRequest + (*ViewUserResponse)(nil), // 1: stocklet.user.v1.ViewUserResponse + (*RegisterUserRequest)(nil), // 2: stocklet.user.v1.RegisterUserRequest + (*RegisterUserResponse)(nil), // 3: stocklet.user.v1.RegisterUserResponse + (*User)(nil), // 4: stocklet.user.v1.User + (*v1.ServiceInfoRequest)(nil), // 5: stocklet.common.v1.ServiceInfoRequest + (*v1.ServiceInfoResponse)(nil), // 6: stocklet.common.v1.ServiceInfoResponse +} +var file_stocklet_user_v1_service_proto_depIdxs = []int32{ + 4, // 0: stocklet.user.v1.ViewUserResponse.user:type_name -> stocklet.user.v1.User + 4, // 1: stocklet.user.v1.RegisterUserResponse.user:type_name -> stocklet.user.v1.User + 5, // 2: stocklet.user.v1.UserService.ServiceInfo:input_type -> stocklet.common.v1.ServiceInfoRequest + 0, // 3: stocklet.user.v1.UserService.ViewUser:input_type -> stocklet.user.v1.ViewUserRequest + 2, // 4: stocklet.user.v1.UserService.RegisterUser:input_type -> stocklet.user.v1.RegisterUserRequest + 6, // 5: stocklet.user.v1.UserService.ServiceInfo:output_type -> stocklet.common.v1.ServiceInfoResponse + 1, // 6: stocklet.user.v1.UserService.ViewUser:output_type -> stocklet.user.v1.ViewUserResponse + 3, // 7: stocklet.user.v1.UserService.RegisterUser:output_type -> stocklet.user.v1.RegisterUserResponse + 5, // [5:8] is the sub-list for method output_type + 2, // [2:5] is the sub-list for method input_type + 2, // [2:2] is the sub-list for extension type_name + 2, // [2:2] is the sub-list for extension extendee + 0, // [0:2] is the sub-list for field type_name +} + +func init() { file_stocklet_user_v1_service_proto_init() } +func file_stocklet_user_v1_service_proto_init() { + if File_stocklet_user_v1_service_proto != nil { + return + } + file_stocklet_user_v1_types_proto_init() + if !protoimpl.UnsafeEnabled { + file_stocklet_user_v1_service_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ViewUserRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_stocklet_user_v1_service_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ViewUserResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_stocklet_user_v1_service_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*RegisterUserRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_stocklet_user_v1_service_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*RegisterUserResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_stocklet_user_v1_service_proto_rawDesc, + NumEnums: 0, + NumMessages: 4, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_stocklet_user_v1_service_proto_goTypes, + DependencyIndexes: file_stocklet_user_v1_service_proto_depIdxs, + MessageInfos: file_stocklet_user_v1_service_proto_msgTypes, + }.Build() + File_stocklet_user_v1_service_proto = out.File + file_stocklet_user_v1_service_proto_rawDesc = nil + file_stocklet_user_v1_service_proto_goTypes = nil + file_stocklet_user_v1_service_proto_depIdxs = nil +} diff --git a/internal/pkg/protogen/user/v1/service.pb.gw.go b/internal/pkg/protogen/user/v1/service.pb.gw.go new file mode 100644 index 0000000..6f7c25f --- /dev/null +++ b/internal/pkg/protogen/user/v1/service.pb.gw.go @@ -0,0 +1,346 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: stocklet/user/v1/service.proto + +/* +Package user_v1 is a reverse proxy. + +It translates gRPC into RESTful JSON APIs. +*/ +package user_v1 + +import ( + "context" + "io" + "net/http" + + "github.com/grpc-ecosystem/grpc-gateway/v2/runtime" + "github.com/grpc-ecosystem/grpc-gateway/v2/utilities" + "github.com/hexolan/stocklet/internal/pkg/protogen/common/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/status" + "google.golang.org/protobuf/proto" +) + +// Suppress "imported and not used" errors +var _ codes.Code +var _ io.Reader +var _ status.Status +var _ = runtime.String +var _ = utilities.NewDoubleArray +var _ = metadata.Join + +func request_UserService_ServiceInfo_0(ctx context.Context, marshaler runtime.Marshaler, client UserServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq common_v1.ServiceInfoRequest + var metadata runtime.ServerMetadata + + msg, err := client.ServiceInfo(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_UserService_ServiceInfo_0(ctx context.Context, marshaler runtime.Marshaler, server UserServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq common_v1.ServiceInfoRequest + var metadata runtime.ServerMetadata + + msg, err := server.ServiceInfo(ctx, &protoReq) + return msg, metadata, err + +} + +func request_UserService_ViewUser_0(ctx context.Context, marshaler runtime.Marshaler, client UserServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq ViewUserRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id") + } + + protoReq.Id, err = runtime.String(val) + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err) + } + + msg, err := client.ViewUser(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_UserService_ViewUser_0(ctx context.Context, marshaler runtime.Marshaler, server UserServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq ViewUserRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id") + } + + protoReq.Id, err = runtime.String(val) + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err) + } + + msg, err := server.ViewUser(ctx, &protoReq) + return msg, metadata, err + +} + +var ( + filter_UserService_RegisterUser_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} +) + +func request_UserService_RegisterUser_0(ctx context.Context, marshaler runtime.Marshaler, client UserServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq RegisterUserRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_UserService_RegisterUser_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.RegisterUser(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_UserService_RegisterUser_0(ctx context.Context, marshaler runtime.Marshaler, server UserServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq RegisterUserRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_UserService_RegisterUser_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.RegisterUser(ctx, &protoReq) + return msg, metadata, err + +} + +// RegisterUserServiceHandlerServer registers the http handlers for service UserService to "mux". +// UnaryRPC :call UserServiceServer directly. +// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. +// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterUserServiceHandlerFromEndpoint instead. +func RegisterUserServiceHandlerServer(ctx context.Context, mux *runtime.ServeMux, server UserServiceServer) error { + + mux.Handle("GET", pattern_UserService_ServiceInfo_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/stocklet.user.v1.UserService/ServiceInfo", runtime.WithHTTPPathPattern("/v1/user/service")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_UserService_ServiceInfo_0(annotatedContext, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_UserService_ServiceInfo_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_UserService_ViewUser_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/stocklet.user.v1.UserService/ViewUser", runtime.WithHTTPPathPattern("/v1/user/users/{id}")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_UserService_ViewUser_0(annotatedContext, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_UserService_ViewUser_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("POST", pattern_UserService_RegisterUser_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/stocklet.user.v1.UserService/RegisterUser", runtime.WithHTTPPathPattern("/v1/user/register")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_UserService_RegisterUser_0(annotatedContext, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_UserService_RegisterUser_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +// RegisterUserServiceHandlerFromEndpoint is same as RegisterUserServiceHandler but +// automatically dials to "endpoint" and closes the connection when "ctx" gets done. +func RegisterUserServiceHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { + conn, err := grpc.DialContext(ctx, endpoint, opts...) + if err != nil { + return err + } + defer func() { + if err != nil { + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + return + } + go func() { + <-ctx.Done() + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + }() + }() + + return RegisterUserServiceHandler(ctx, mux, conn) +} + +// RegisterUserServiceHandler registers the http handlers for service UserService to "mux". +// The handlers forward requests to the grpc endpoint over "conn". +func RegisterUserServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { + return RegisterUserServiceHandlerClient(ctx, mux, NewUserServiceClient(conn)) +} + +// RegisterUserServiceHandlerClient registers the http handlers for service UserService +// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "UserServiceClient". +// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "UserServiceClient" +// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in +// "UserServiceClient" to call the correct interceptors. +func RegisterUserServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux, client UserServiceClient) error { + + mux.Handle("GET", pattern_UserService_ServiceInfo_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/stocklet.user.v1.UserService/ServiceInfo", runtime.WithHTTPPathPattern("/v1/user/service")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_UserService_ServiceInfo_0(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_UserService_ServiceInfo_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_UserService_ViewUser_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/stocklet.user.v1.UserService/ViewUser", runtime.WithHTTPPathPattern("/v1/user/users/{id}")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_UserService_ViewUser_0(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_UserService_ViewUser_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("POST", pattern_UserService_RegisterUser_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/stocklet.user.v1.UserService/RegisterUser", runtime.WithHTTPPathPattern("/v1/user/register")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_UserService_RegisterUser_0(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_UserService_RegisterUser_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +var ( + pattern_UserService_ServiceInfo_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v1", "user", "service"}, "")) + + pattern_UserService_ViewUser_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"v1", "user", "users", "id"}, "")) + + pattern_UserService_RegisterUser_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v1", "user", "register"}, "")) +) + +var ( + forward_UserService_ServiceInfo_0 = runtime.ForwardResponseMessage + + forward_UserService_ViewUser_0 = runtime.ForwardResponseMessage + + forward_UserService_RegisterUser_0 = runtime.ForwardResponseMessage +) diff --git a/internal/pkg/protogen/user/v1/service_grpc.pb.go b/internal/pkg/protogen/user/v1/service_grpc.pb.go new file mode 100644 index 0000000..018b21a --- /dev/null +++ b/internal/pkg/protogen/user/v1/service_grpc.pb.go @@ -0,0 +1,205 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.3.0 +// - protoc (unknown) +// source: stocklet/user/v1/service.proto + +package user_v1 + +import ( + context "context" + v1 "github.com/hexolan/stocklet/internal/pkg/protogen/common/v1" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.32.0 or later. +const _ = grpc.SupportPackageIsVersion7 + +const ( + UserService_ServiceInfo_FullMethodName = "/stocklet.user.v1.UserService/ServiceInfo" + UserService_ViewUser_FullMethodName = "/stocklet.user.v1.UserService/ViewUser" + UserService_RegisterUser_FullMethodName = "/stocklet.user.v1.UserService/RegisterUser" +) + +// UserServiceClient is the client API for UserService service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +type UserServiceClient interface { + // View information about the service. + // + // buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + ServiceInfo(ctx context.Context, in *v1.ServiceInfoRequest, opts ...grpc.CallOption) (*v1.ServiceInfoResponse, error) + ViewUser(ctx context.Context, in *ViewUserRequest, opts ...grpc.CallOption) (*ViewUserResponse, error) + RegisterUser(ctx context.Context, in *RegisterUserRequest, opts ...grpc.CallOption) (*RegisterUserResponse, error) +} + +type userServiceClient struct { + cc grpc.ClientConnInterface +} + +func NewUserServiceClient(cc grpc.ClientConnInterface) UserServiceClient { + return &userServiceClient{cc} +} + +func (c *userServiceClient) ServiceInfo(ctx context.Context, in *v1.ServiceInfoRequest, opts ...grpc.CallOption) (*v1.ServiceInfoResponse, error) { + out := new(v1.ServiceInfoResponse) + err := c.cc.Invoke(ctx, UserService_ServiceInfo_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *userServiceClient) ViewUser(ctx context.Context, in *ViewUserRequest, opts ...grpc.CallOption) (*ViewUserResponse, error) { + out := new(ViewUserResponse) + err := c.cc.Invoke(ctx, UserService_ViewUser_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *userServiceClient) RegisterUser(ctx context.Context, in *RegisterUserRequest, opts ...grpc.CallOption) (*RegisterUserResponse, error) { + out := new(RegisterUserResponse) + err := c.cc.Invoke(ctx, UserService_RegisterUser_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// UserServiceServer is the server API for UserService service. +// All implementations must embed UnimplementedUserServiceServer +// for forward compatibility +type UserServiceServer interface { + // View information about the service. + // + // buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + ServiceInfo(context.Context, *v1.ServiceInfoRequest) (*v1.ServiceInfoResponse, error) + ViewUser(context.Context, *ViewUserRequest) (*ViewUserResponse, error) + RegisterUser(context.Context, *RegisterUserRequest) (*RegisterUserResponse, error) + mustEmbedUnimplementedUserServiceServer() +} + +// UnimplementedUserServiceServer must be embedded to have forward compatible implementations. +type UnimplementedUserServiceServer struct { +} + +func (UnimplementedUserServiceServer) ServiceInfo(context.Context, *v1.ServiceInfoRequest) (*v1.ServiceInfoResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method ServiceInfo not implemented") +} +func (UnimplementedUserServiceServer) ViewUser(context.Context, *ViewUserRequest) (*ViewUserResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method ViewUser not implemented") +} +func (UnimplementedUserServiceServer) RegisterUser(context.Context, *RegisterUserRequest) (*RegisterUserResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method RegisterUser not implemented") +} +func (UnimplementedUserServiceServer) mustEmbedUnimplementedUserServiceServer() {} + +// UnsafeUserServiceServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to UserServiceServer will +// result in compilation errors. +type UnsafeUserServiceServer interface { + mustEmbedUnimplementedUserServiceServer() +} + +func RegisterUserServiceServer(s grpc.ServiceRegistrar, srv UserServiceServer) { + s.RegisterService(&UserService_ServiceDesc, srv) +} + +func _UserService_ServiceInfo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(v1.ServiceInfoRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(UserServiceServer).ServiceInfo(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: UserService_ServiceInfo_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(UserServiceServer).ServiceInfo(ctx, req.(*v1.ServiceInfoRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _UserService_ViewUser_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ViewUserRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(UserServiceServer).ViewUser(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: UserService_ViewUser_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(UserServiceServer).ViewUser(ctx, req.(*ViewUserRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _UserService_RegisterUser_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(RegisterUserRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(UserServiceServer).RegisterUser(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: UserService_RegisterUser_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(UserServiceServer).RegisterUser(ctx, req.(*RegisterUserRequest)) + } + return interceptor(ctx, in, info, handler) +} + +// UserService_ServiceDesc is the grpc.ServiceDesc for UserService service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var UserService_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "stocklet.user.v1.UserService", + HandlerType: (*UserServiceServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "ServiceInfo", + Handler: _UserService_ServiceInfo_Handler, + }, + { + MethodName: "ViewUser", + Handler: _UserService_ViewUser_Handler, + }, + { + MethodName: "RegisterUser", + Handler: _UserService_RegisterUser_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "stocklet/user/v1/service.proto", +} diff --git a/internal/pkg/protogen/user/v1/types.pb.go b/internal/pkg/protogen/user/v1/types.pb.go new file mode 100644 index 0000000..9c345e4 --- /dev/null +++ b/internal/pkg/protogen/user/v1/types.pb.go @@ -0,0 +1,217 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.31.0 +// protoc (unknown) +// source: stocklet/user/v1/types.proto + +package user_v1 + +import ( + _ "buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go/buf/validate" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type User struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + Email string `protobuf:"bytes,2,opt,name=email,proto3" json:"email,omitempty"` + FirstName string `protobuf:"bytes,3,opt,name=first_name,json=firstName,proto3" json:"first_name,omitempty"` + LastName string `protobuf:"bytes,4,opt,name=last_name,json=lastName,proto3" json:"last_name,omitempty"` + CreatedAt int64 `protobuf:"varint,5,opt,name=created_at,json=createdAt,proto3" json:"created_at,omitempty"` + UpdatedAt *int64 `protobuf:"varint,6,opt,name=updated_at,json=updatedAt,proto3,oneof" json:"updated_at,omitempty"` +} + +func (x *User) Reset() { + *x = User{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_user_v1_types_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *User) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*User) ProtoMessage() {} + +func (x *User) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_user_v1_types_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use User.ProtoReflect.Descriptor instead. +func (*User) Descriptor() ([]byte, []int) { + return file_stocklet_user_v1_types_proto_rawDescGZIP(), []int{0} +} + +func (x *User) GetId() string { + if x != nil { + return x.Id + } + return "" +} + +func (x *User) GetEmail() string { + if x != nil { + return x.Email + } + return "" +} + +func (x *User) GetFirstName() string { + if x != nil { + return x.FirstName + } + return "" +} + +func (x *User) GetLastName() string { + if x != nil { + return x.LastName + } + return "" +} + +func (x *User) GetCreatedAt() int64 { + if x != nil { + return x.CreatedAt + } + return 0 +} + +func (x *User) GetUpdatedAt() int64 { + if x != nil && x.UpdatedAt != nil { + return *x.UpdatedAt + } + return 0 +} + +var File_stocklet_user_v1_types_proto protoreflect.FileDescriptor + +var file_stocklet_user_v1_types_proto_rawDesc = []byte{ + 0x0a, 0x1c, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2f, 0x75, 0x73, 0x65, 0x72, 0x2f, + 0x76, 0x31, 0x2f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x10, + 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x76, 0x31, + 0x1a, 0x1b, 0x62, 0x75, 0x66, 0x2f, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x2f, 0x76, + 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xe2, 0x01, + 0x0a, 0x04, 0x55, 0x73, 0x65, 0x72, 0x12, 0x17, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x09, 0x42, 0x07, 0xba, 0x48, 0x04, 0x72, 0x02, 0x10, 0x01, 0x52, 0x02, 0x69, 0x64, 0x12, + 0x1d, 0x0a, 0x05, 0x65, 0x6d, 0x61, 0x69, 0x6c, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x42, 0x07, + 0xba, 0x48, 0x04, 0x72, 0x02, 0x60, 0x01, 0x52, 0x05, 0x65, 0x6d, 0x61, 0x69, 0x6c, 0x12, 0x28, + 0x0a, 0x0a, 0x66, 0x69, 0x72, 0x73, 0x74, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01, + 0x28, 0x09, 0x42, 0x09, 0xba, 0x48, 0x06, 0x72, 0x04, 0x10, 0x01, 0x18, 0x23, 0x52, 0x09, 0x66, + 0x69, 0x72, 0x73, 0x74, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x26, 0x0a, 0x09, 0x6c, 0x61, 0x73, 0x74, + 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x42, 0x09, 0xba, 0x48, 0x06, + 0x72, 0x04, 0x10, 0x01, 0x18, 0x23, 0x52, 0x08, 0x6c, 0x61, 0x73, 0x74, 0x4e, 0x61, 0x6d, 0x65, + 0x12, 0x1d, 0x0a, 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x61, 0x74, 0x18, 0x05, + 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x41, 0x74, 0x12, + 0x22, 0x0a, 0x0a, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x61, 0x74, 0x18, 0x06, 0x20, + 0x01, 0x28, 0x03, 0x48, 0x00, 0x52, 0x09, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x41, 0x74, + 0x88, 0x01, 0x01, 0x42, 0x0d, 0x0a, 0x0b, 0x5f, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x5f, + 0x61, 0x74, 0x42, 0x43, 0x5a, 0x41, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, + 0x2f, 0x68, 0x65, 0x78, 0x6f, 0x6c, 0x61, 0x6e, 0x2f, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, + 0x74, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x67, 0x65, 0x6e, 0x2f, 0x75, 0x73, 0x65, 0x72, 0x2f, 0x76, 0x31, 0x3b, + 0x75, 0x73, 0x65, 0x72, 0x5f, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_stocklet_user_v1_types_proto_rawDescOnce sync.Once + file_stocklet_user_v1_types_proto_rawDescData = file_stocklet_user_v1_types_proto_rawDesc +) + +func file_stocklet_user_v1_types_proto_rawDescGZIP() []byte { + file_stocklet_user_v1_types_proto_rawDescOnce.Do(func() { + file_stocklet_user_v1_types_proto_rawDescData = protoimpl.X.CompressGZIP(file_stocklet_user_v1_types_proto_rawDescData) + }) + return file_stocklet_user_v1_types_proto_rawDescData +} + +var file_stocklet_user_v1_types_proto_msgTypes = make([]protoimpl.MessageInfo, 1) +var file_stocklet_user_v1_types_proto_goTypes = []interface{}{ + (*User)(nil), // 0: stocklet.user.v1.User +} +var file_stocklet_user_v1_types_proto_depIdxs = []int32{ + 0, // [0:0] is the sub-list for method output_type + 0, // [0:0] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_stocklet_user_v1_types_proto_init() } +func file_stocklet_user_v1_types_proto_init() { + if File_stocklet_user_v1_types_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_stocklet_user_v1_types_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*User); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + file_stocklet_user_v1_types_proto_msgTypes[0].OneofWrappers = []interface{}{} + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_stocklet_user_v1_types_proto_rawDesc, + NumEnums: 0, + NumMessages: 1, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_stocklet_user_v1_types_proto_goTypes, + DependencyIndexes: file_stocklet_user_v1_types_proto_depIdxs, + MessageInfos: file_stocklet_user_v1_types_proto_msgTypes, + }.Build() + File_stocklet_user_v1_types_proto = out.File + file_stocklet_user_v1_types_proto_rawDesc = nil + file_stocklet_user_v1_types_proto_goTypes = nil + file_stocklet_user_v1_types_proto_depIdxs = nil +} diff --git a/internal/pkg/protogen/warehouse/v1/service.pb.go b/internal/pkg/protogen/warehouse/v1/service.pb.go new file mode 100644 index 0000000..c1601fa --- /dev/null +++ b/internal/pkg/protogen/warehouse/v1/service.pb.go @@ -0,0 +1,472 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.31.0 +// protoc (unknown) +// source: stocklet/warehouse/v1/service.proto + +package warehouse_v1 + +import ( + _ "buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go/buf/validate" + v1 "github.com/hexolan/stocklet/internal/pkg/protogen/common/v1" + v11 "github.com/hexolan/stocklet/internal/pkg/protogen/events/v1" + _ "google.golang.org/genproto/googleapis/api/annotations" + _ "google.golang.org/genproto/googleapis/api/visibility" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + emptypb "google.golang.org/protobuf/types/known/emptypb" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type ViewProductStockRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + ProductId string `protobuf:"bytes,1,opt,name=product_id,json=productId,proto3" json:"product_id,omitempty"` +} + +func (x *ViewProductStockRequest) Reset() { + *x = ViewProductStockRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_warehouse_v1_service_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ViewProductStockRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ViewProductStockRequest) ProtoMessage() {} + +func (x *ViewProductStockRequest) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_warehouse_v1_service_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ViewProductStockRequest.ProtoReflect.Descriptor instead. +func (*ViewProductStockRequest) Descriptor() ([]byte, []int) { + return file_stocklet_warehouse_v1_service_proto_rawDescGZIP(), []int{0} +} + +func (x *ViewProductStockRequest) GetProductId() string { + if x != nil { + return x.ProductId + } + return "" +} + +type ViewProductStockResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Stock *ProductStock `protobuf:"bytes,1,opt,name=stock,proto3" json:"stock,omitempty"` +} + +func (x *ViewProductStockResponse) Reset() { + *x = ViewProductStockResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_warehouse_v1_service_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ViewProductStockResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ViewProductStockResponse) ProtoMessage() {} + +func (x *ViewProductStockResponse) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_warehouse_v1_service_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ViewProductStockResponse.ProtoReflect.Descriptor instead. +func (*ViewProductStockResponse) Descriptor() ([]byte, []int) { + return file_stocklet_warehouse_v1_service_proto_rawDescGZIP(), []int{1} +} + +func (x *ViewProductStockResponse) GetStock() *ProductStock { + if x != nil { + return x.Stock + } + return nil +} + +type ViewReservationRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + ReservationId string `protobuf:"bytes,1,opt,name=reservation_id,json=reservationId,proto3" json:"reservation_id,omitempty"` +} + +func (x *ViewReservationRequest) Reset() { + *x = ViewReservationRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_warehouse_v1_service_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ViewReservationRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ViewReservationRequest) ProtoMessage() {} + +func (x *ViewReservationRequest) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_warehouse_v1_service_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ViewReservationRequest.ProtoReflect.Descriptor instead. +func (*ViewReservationRequest) Descriptor() ([]byte, []int) { + return file_stocklet_warehouse_v1_service_proto_rawDescGZIP(), []int{2} +} + +func (x *ViewReservationRequest) GetReservationId() string { + if x != nil { + return x.ReservationId + } + return "" +} + +type ViewReservationResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Reservation *Reservation `protobuf:"bytes,1,opt,name=reservation,proto3" json:"reservation,omitempty"` +} + +func (x *ViewReservationResponse) Reset() { + *x = ViewReservationResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_warehouse_v1_service_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ViewReservationResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ViewReservationResponse) ProtoMessage() {} + +func (x *ViewReservationResponse) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_warehouse_v1_service_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ViewReservationResponse.ProtoReflect.Descriptor instead. +func (*ViewReservationResponse) Descriptor() ([]byte, []int) { + return file_stocklet_warehouse_v1_service_proto_rawDescGZIP(), []int{3} +} + +func (x *ViewReservationResponse) GetReservation() *Reservation { + if x != nil { + return x.Reservation + } + return nil +} + +var File_stocklet_warehouse_v1_service_proto protoreflect.FileDescriptor + +var file_stocklet_warehouse_v1_service_proto_rawDesc = []byte{ + 0x0a, 0x23, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2f, 0x77, 0x61, 0x72, 0x65, 0x68, + 0x6f, 0x75, 0x73, 0x65, 0x2f, 0x76, 0x31, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x15, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, + 0x77, 0x61, 0x72, 0x65, 0x68, 0x6f, 0x75, 0x73, 0x65, 0x2e, 0x76, 0x31, 0x1a, 0x1b, 0x62, 0x75, + 0x66, 0x2f, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x2f, 0x76, 0x61, 0x6c, 0x69, 0x64, + 0x61, 0x74, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1c, 0x67, 0x6f, 0x6f, 0x67, 0x6c, + 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, + 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1b, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, + 0x61, 0x70, 0x69, 0x2f, 0x76, 0x69, 0x73, 0x69, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x2e, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1b, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x65, 0x6d, 0x70, 0x74, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x1a, 0x21, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2f, 0x63, 0x6f, 0x6d, 0x6d, + 0x6f, 0x6e, 0x2f, 0x76, 0x31, 0x2f, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x73, 0x2e, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1e, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2f, 0x65, + 0x76, 0x65, 0x6e, 0x74, 0x73, 0x2f, 0x76, 0x31, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x2e, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x20, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2f, 0x65, + 0x76, 0x65, 0x6e, 0x74, 0x73, 0x2f, 0x76, 0x31, 0x2f, 0x70, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, + 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x20, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, + 0x2f, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x2f, 0x76, 0x31, 0x2f, 0x70, 0x72, 0x6f, 0x64, 0x75, + 0x63, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x21, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, + 0x65, 0x74, 0x2f, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x2f, 0x76, 0x31, 0x2f, 0x73, 0x68, 0x69, + 0x70, 0x70, 0x69, 0x6e, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x21, 0x73, 0x74, 0x6f, + 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2f, 0x77, 0x61, 0x72, 0x65, 0x68, 0x6f, 0x75, 0x73, 0x65, 0x2f, + 0x76, 0x31, 0x2f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x41, + 0x0a, 0x17, 0x56, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x53, 0x74, 0x6f, + 0x63, 0x6b, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x26, 0x0a, 0x0a, 0x70, 0x72, 0x6f, + 0x64, 0x75, 0x63, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, 0x07, 0xba, + 0x48, 0x04, 0x72, 0x02, 0x10, 0x01, 0x52, 0x09, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x49, + 0x64, 0x22, 0x55, 0x0a, 0x18, 0x56, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, + 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x39, 0x0a, + 0x05, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x23, 0x2e, 0x73, + 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x77, 0x61, 0x72, 0x65, 0x68, 0x6f, 0x75, 0x73, + 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x53, 0x74, 0x6f, 0x63, + 0x6b, 0x52, 0x05, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x22, 0x48, 0x0a, 0x16, 0x56, 0x69, 0x65, 0x77, + 0x52, 0x65, 0x73, 0x65, 0x72, 0x76, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x12, 0x2e, 0x0a, 0x0e, 0x72, 0x65, 0x73, 0x65, 0x72, 0x76, 0x61, 0x74, 0x69, 0x6f, + 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, 0x07, 0xba, 0x48, 0x04, 0x72, + 0x02, 0x10, 0x01, 0x52, 0x0d, 0x72, 0x65, 0x73, 0x65, 0x72, 0x76, 0x61, 0x74, 0x69, 0x6f, 0x6e, + 0x49, 0x64, 0x22, 0x5f, 0x0a, 0x17, 0x56, 0x69, 0x65, 0x77, 0x52, 0x65, 0x73, 0x65, 0x72, 0x76, + 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x44, 0x0a, + 0x0b, 0x72, 0x65, 0x73, 0x65, 0x72, 0x76, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x0b, 0x32, 0x22, 0x2e, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x77, 0x61, + 0x72, 0x65, 0x68, 0x6f, 0x75, 0x73, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x52, 0x65, 0x73, 0x65, 0x72, + 0x76, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x0b, 0x72, 0x65, 0x73, 0x65, 0x72, 0x76, 0x61, 0x74, + 0x69, 0x6f, 0x6e, 0x32, 0xa6, 0x07, 0x0a, 0x10, 0x57, 0x61, 0x72, 0x65, 0x68, 0x6f, 0x75, 0x73, + 0x65, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x7d, 0x0a, 0x0b, 0x53, 0x65, 0x72, 0x76, + 0x69, 0x63, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x26, 0x2e, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, + 0x65, 0x74, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x65, 0x72, + 0x76, 0x69, 0x63, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, + 0x27, 0x2e, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, + 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x49, 0x6e, 0x66, 0x6f, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x1d, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x17, + 0x12, 0x15, 0x2f, 0x76, 0x31, 0x2f, 0x77, 0x61, 0x72, 0x65, 0x68, 0x6f, 0x75, 0x73, 0x65, 0x2f, + 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x9f, 0x01, 0x0a, 0x10, 0x56, 0x69, 0x65, 0x77, + 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x12, 0x2e, 0x2e, 0x73, + 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x77, 0x61, 0x72, 0x65, 0x68, 0x6f, 0x75, 0x73, + 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x56, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, + 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2f, 0x2e, 0x73, + 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x77, 0x61, 0x72, 0x65, 0x68, 0x6f, 0x75, 0x73, + 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x56, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, + 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x2a, 0x82, + 0xd3, 0xe4, 0x93, 0x02, 0x24, 0x12, 0x22, 0x2f, 0x76, 0x31, 0x2f, 0x77, 0x61, 0x72, 0x65, 0x68, + 0x6f, 0x75, 0x73, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x2f, 0x7b, 0x70, 0x72, + 0x6f, 0x64, 0x75, 0x63, 0x74, 0x5f, 0x69, 0x64, 0x7d, 0x12, 0xa4, 0x01, 0x0a, 0x0f, 0x56, 0x69, + 0x65, 0x77, 0x52, 0x65, 0x73, 0x65, 0x72, 0x76, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x2d, 0x2e, + 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x77, 0x61, 0x72, 0x65, 0x68, 0x6f, 0x75, + 0x73, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x56, 0x69, 0x65, 0x77, 0x52, 0x65, 0x73, 0x65, 0x72, 0x76, + 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2e, 0x2e, 0x73, + 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x77, 0x61, 0x72, 0x65, 0x68, 0x6f, 0x75, 0x73, + 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x56, 0x69, 0x65, 0x77, 0x52, 0x65, 0x73, 0x65, 0x72, 0x76, 0x61, + 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x32, 0x82, 0xd3, + 0xe4, 0x93, 0x02, 0x2c, 0x12, 0x2a, 0x2f, 0x76, 0x31, 0x2f, 0x77, 0x61, 0x72, 0x65, 0x68, 0x6f, + 0x75, 0x73, 0x65, 0x2f, 0x72, 0x65, 0x73, 0x65, 0x72, 0x76, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2f, + 0x7b, 0x72, 0x65, 0x73, 0x65, 0x72, 0x76, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x69, 0x64, 0x7d, + 0x12, 0x6f, 0x0a, 0x1a, 0x50, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, 0x50, 0x72, 0x6f, 0x64, 0x75, + 0x63, 0x74, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x27, + 0x2e, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, + 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x43, 0x72, 0x65, 0x61, 0x74, + 0x65, 0x64, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, + 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, + 0x10, 0xfa, 0xd2, 0xe4, 0x93, 0x02, 0x0a, 0x12, 0x08, 0x49, 0x4e, 0x54, 0x45, 0x52, 0x4e, 0x41, + 0x4c, 0x12, 0x6b, 0x0a, 0x18, 0x50, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, 0x4f, 0x72, 0x64, 0x65, + 0x72, 0x50, 0x65, 0x6e, 0x64, 0x69, 0x6e, 0x67, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x25, 0x2e, + 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x2e, + 0x76, 0x31, 0x2e, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x50, 0x65, 0x6e, 0x64, 0x69, 0x6e, 0x67, 0x45, + 0x76, 0x65, 0x6e, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x10, 0xfa, 0xd2, + 0xe4, 0x93, 0x02, 0x0a, 0x12, 0x08, 0x49, 0x4e, 0x54, 0x45, 0x52, 0x4e, 0x41, 0x4c, 0x12, 0x77, + 0x0a, 0x1e, 0x50, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, 0x53, 0x68, 0x69, 0x70, 0x6d, 0x65, 0x6e, + 0x74, 0x41, 0x6c, 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x45, 0x76, 0x65, 0x6e, 0x74, + 0x12, 0x2b, 0x2e, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x65, 0x76, 0x65, 0x6e, + 0x74, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x68, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x41, 0x6c, + 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x1a, 0x16, 0x2e, + 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, + 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x10, 0xfa, 0xd2, 0xe4, 0x93, 0x02, 0x0a, 0x12, 0x08, 0x49, + 0x4e, 0x54, 0x45, 0x52, 0x4e, 0x41, 0x4c, 0x12, 0x73, 0x0a, 0x1c, 0x50, 0x72, 0x6f, 0x63, 0x65, + 0x73, 0x73, 0x50, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x50, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, + 0x65, 0x64, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x29, 0x2e, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, + 0x65, 0x74, 0x2e, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x61, 0x79, + 0x6d, 0x65, 0x6e, 0x74, 0x50, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, 0x65, 0x64, 0x45, 0x76, 0x65, + 0x6e, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x10, 0xfa, 0xd2, 0xe4, 0x93, + 0x02, 0x0a, 0x12, 0x08, 0x49, 0x4e, 0x54, 0x45, 0x52, 0x4e, 0x41, 0x4c, 0x42, 0x4d, 0x5a, 0x4b, + 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x68, 0x65, 0x78, 0x6f, 0x6c, + 0x61, 0x6e, 0x2f, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2f, 0x69, 0x6e, 0x74, 0x65, + 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x67, 0x65, + 0x6e, 0x2f, 0x77, 0x61, 0x72, 0x65, 0x68, 0x6f, 0x75, 0x73, 0x65, 0x2f, 0x76, 0x31, 0x3b, 0x77, + 0x61, 0x72, 0x65, 0x68, 0x6f, 0x75, 0x73, 0x65, 0x5f, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x33, +} + +var ( + file_stocklet_warehouse_v1_service_proto_rawDescOnce sync.Once + file_stocklet_warehouse_v1_service_proto_rawDescData = file_stocklet_warehouse_v1_service_proto_rawDesc +) + +func file_stocklet_warehouse_v1_service_proto_rawDescGZIP() []byte { + file_stocklet_warehouse_v1_service_proto_rawDescOnce.Do(func() { + file_stocklet_warehouse_v1_service_proto_rawDescData = protoimpl.X.CompressGZIP(file_stocklet_warehouse_v1_service_proto_rawDescData) + }) + return file_stocklet_warehouse_v1_service_proto_rawDescData +} + +var file_stocklet_warehouse_v1_service_proto_msgTypes = make([]protoimpl.MessageInfo, 4) +var file_stocklet_warehouse_v1_service_proto_goTypes = []interface{}{ + (*ViewProductStockRequest)(nil), // 0: stocklet.warehouse.v1.ViewProductStockRequest + (*ViewProductStockResponse)(nil), // 1: stocklet.warehouse.v1.ViewProductStockResponse + (*ViewReservationRequest)(nil), // 2: stocklet.warehouse.v1.ViewReservationRequest + (*ViewReservationResponse)(nil), // 3: stocklet.warehouse.v1.ViewReservationResponse + (*ProductStock)(nil), // 4: stocklet.warehouse.v1.ProductStock + (*Reservation)(nil), // 5: stocklet.warehouse.v1.Reservation + (*v1.ServiceInfoRequest)(nil), // 6: stocklet.common.v1.ServiceInfoRequest + (*v11.ProductCreatedEvent)(nil), // 7: stocklet.events.v1.ProductCreatedEvent + (*v11.OrderPendingEvent)(nil), // 8: stocklet.events.v1.OrderPendingEvent + (*v11.ShipmentAllocationEvent)(nil), // 9: stocklet.events.v1.ShipmentAllocationEvent + (*v11.PaymentProcessedEvent)(nil), // 10: stocklet.events.v1.PaymentProcessedEvent + (*v1.ServiceInfoResponse)(nil), // 11: stocklet.common.v1.ServiceInfoResponse + (*emptypb.Empty)(nil), // 12: google.protobuf.Empty +} +var file_stocklet_warehouse_v1_service_proto_depIdxs = []int32{ + 4, // 0: stocklet.warehouse.v1.ViewProductStockResponse.stock:type_name -> stocklet.warehouse.v1.ProductStock + 5, // 1: stocklet.warehouse.v1.ViewReservationResponse.reservation:type_name -> stocklet.warehouse.v1.Reservation + 6, // 2: stocklet.warehouse.v1.WarehouseService.ServiceInfo:input_type -> stocklet.common.v1.ServiceInfoRequest + 0, // 3: stocklet.warehouse.v1.WarehouseService.ViewProductStock:input_type -> stocklet.warehouse.v1.ViewProductStockRequest + 2, // 4: stocklet.warehouse.v1.WarehouseService.ViewReservation:input_type -> stocklet.warehouse.v1.ViewReservationRequest + 7, // 5: stocklet.warehouse.v1.WarehouseService.ProcessProductCreatedEvent:input_type -> stocklet.events.v1.ProductCreatedEvent + 8, // 6: stocklet.warehouse.v1.WarehouseService.ProcessOrderPendingEvent:input_type -> stocklet.events.v1.OrderPendingEvent + 9, // 7: stocklet.warehouse.v1.WarehouseService.ProcessShipmentAllocationEvent:input_type -> stocklet.events.v1.ShipmentAllocationEvent + 10, // 8: stocklet.warehouse.v1.WarehouseService.ProcessPaymentProcessedEvent:input_type -> stocklet.events.v1.PaymentProcessedEvent + 11, // 9: stocklet.warehouse.v1.WarehouseService.ServiceInfo:output_type -> stocklet.common.v1.ServiceInfoResponse + 1, // 10: stocklet.warehouse.v1.WarehouseService.ViewProductStock:output_type -> stocklet.warehouse.v1.ViewProductStockResponse + 3, // 11: stocklet.warehouse.v1.WarehouseService.ViewReservation:output_type -> stocklet.warehouse.v1.ViewReservationResponse + 12, // 12: stocklet.warehouse.v1.WarehouseService.ProcessProductCreatedEvent:output_type -> google.protobuf.Empty + 12, // 13: stocklet.warehouse.v1.WarehouseService.ProcessOrderPendingEvent:output_type -> google.protobuf.Empty + 12, // 14: stocklet.warehouse.v1.WarehouseService.ProcessShipmentAllocationEvent:output_type -> google.protobuf.Empty + 12, // 15: stocklet.warehouse.v1.WarehouseService.ProcessPaymentProcessedEvent:output_type -> google.protobuf.Empty + 9, // [9:16] is the sub-list for method output_type + 2, // [2:9] is the sub-list for method input_type + 2, // [2:2] is the sub-list for extension type_name + 2, // [2:2] is the sub-list for extension extendee + 0, // [0:2] is the sub-list for field type_name +} + +func init() { file_stocklet_warehouse_v1_service_proto_init() } +func file_stocklet_warehouse_v1_service_proto_init() { + if File_stocklet_warehouse_v1_service_proto != nil { + return + } + file_stocklet_warehouse_v1_types_proto_init() + if !protoimpl.UnsafeEnabled { + file_stocklet_warehouse_v1_service_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ViewProductStockRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_stocklet_warehouse_v1_service_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ViewProductStockResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_stocklet_warehouse_v1_service_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ViewReservationRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_stocklet_warehouse_v1_service_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ViewReservationResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_stocklet_warehouse_v1_service_proto_rawDesc, + NumEnums: 0, + NumMessages: 4, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_stocklet_warehouse_v1_service_proto_goTypes, + DependencyIndexes: file_stocklet_warehouse_v1_service_proto_depIdxs, + MessageInfos: file_stocklet_warehouse_v1_service_proto_msgTypes, + }.Build() + File_stocklet_warehouse_v1_service_proto = out.File + file_stocklet_warehouse_v1_service_proto_rawDesc = nil + file_stocklet_warehouse_v1_service_proto_goTypes = nil + file_stocklet_warehouse_v1_service_proto_depIdxs = nil +} diff --git a/internal/pkg/protogen/warehouse/v1/service.pb.gw.go b/internal/pkg/protogen/warehouse/v1/service.pb.gw.go new file mode 100644 index 0000000..14757c5 --- /dev/null +++ b/internal/pkg/protogen/warehouse/v1/service.pb.gw.go @@ -0,0 +1,362 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: stocklet/warehouse/v1/service.proto + +/* +Package warehouse_v1 is a reverse proxy. + +It translates gRPC into RESTful JSON APIs. +*/ +package warehouse_v1 + +import ( + "context" + "io" + "net/http" + + "github.com/grpc-ecosystem/grpc-gateway/v2/runtime" + "github.com/grpc-ecosystem/grpc-gateway/v2/utilities" + "github.com/hexolan/stocklet/internal/pkg/protogen/common/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/status" + "google.golang.org/protobuf/proto" +) + +// Suppress "imported and not used" errors +var _ codes.Code +var _ io.Reader +var _ status.Status +var _ = runtime.String +var _ = utilities.NewDoubleArray +var _ = metadata.Join + +func request_WarehouseService_ServiceInfo_0(ctx context.Context, marshaler runtime.Marshaler, client WarehouseServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq common_v1.ServiceInfoRequest + var metadata runtime.ServerMetadata + + msg, err := client.ServiceInfo(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_WarehouseService_ServiceInfo_0(ctx context.Context, marshaler runtime.Marshaler, server WarehouseServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq common_v1.ServiceInfoRequest + var metadata runtime.ServerMetadata + + msg, err := server.ServiceInfo(ctx, &protoReq) + return msg, metadata, err + +} + +func request_WarehouseService_ViewProductStock_0(ctx context.Context, marshaler runtime.Marshaler, client WarehouseServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq ViewProductStockRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["product_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "product_id") + } + + protoReq.ProductId, err = runtime.String(val) + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "product_id", err) + } + + msg, err := client.ViewProductStock(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_WarehouseService_ViewProductStock_0(ctx context.Context, marshaler runtime.Marshaler, server WarehouseServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq ViewProductStockRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["product_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "product_id") + } + + protoReq.ProductId, err = runtime.String(val) + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "product_id", err) + } + + msg, err := server.ViewProductStock(ctx, &protoReq) + return msg, metadata, err + +} + +func request_WarehouseService_ViewReservation_0(ctx context.Context, marshaler runtime.Marshaler, client WarehouseServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq ViewReservationRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["reservation_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "reservation_id") + } + + protoReq.ReservationId, err = runtime.String(val) + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "reservation_id", err) + } + + msg, err := client.ViewReservation(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_WarehouseService_ViewReservation_0(ctx context.Context, marshaler runtime.Marshaler, server WarehouseServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq ViewReservationRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["reservation_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "reservation_id") + } + + protoReq.ReservationId, err = runtime.String(val) + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "reservation_id", err) + } + + msg, err := server.ViewReservation(ctx, &protoReq) + return msg, metadata, err + +} + +// RegisterWarehouseServiceHandlerServer registers the http handlers for service WarehouseService to "mux". +// UnaryRPC :call WarehouseServiceServer directly. +// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. +// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterWarehouseServiceHandlerFromEndpoint instead. +func RegisterWarehouseServiceHandlerServer(ctx context.Context, mux *runtime.ServeMux, server WarehouseServiceServer) error { + + mux.Handle("GET", pattern_WarehouseService_ServiceInfo_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/stocklet.warehouse.v1.WarehouseService/ServiceInfo", runtime.WithHTTPPathPattern("/v1/warehouse/service")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_WarehouseService_ServiceInfo_0(annotatedContext, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_WarehouseService_ServiceInfo_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_WarehouseService_ViewProductStock_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/stocklet.warehouse.v1.WarehouseService/ViewProductStock", runtime.WithHTTPPathPattern("/v1/warehouse/product/{product_id}")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_WarehouseService_ViewProductStock_0(annotatedContext, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_WarehouseService_ViewProductStock_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_WarehouseService_ViewReservation_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/stocklet.warehouse.v1.WarehouseService/ViewReservation", runtime.WithHTTPPathPattern("/v1/warehouse/reservation/{reservation_id}")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_WarehouseService_ViewReservation_0(annotatedContext, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_WarehouseService_ViewReservation_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +// RegisterWarehouseServiceHandlerFromEndpoint is same as RegisterWarehouseServiceHandler but +// automatically dials to "endpoint" and closes the connection when "ctx" gets done. +func RegisterWarehouseServiceHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { + conn, err := grpc.DialContext(ctx, endpoint, opts...) + if err != nil { + return err + } + defer func() { + if err != nil { + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + return + } + go func() { + <-ctx.Done() + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + }() + }() + + return RegisterWarehouseServiceHandler(ctx, mux, conn) +} + +// RegisterWarehouseServiceHandler registers the http handlers for service WarehouseService to "mux". +// The handlers forward requests to the grpc endpoint over "conn". +func RegisterWarehouseServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { + return RegisterWarehouseServiceHandlerClient(ctx, mux, NewWarehouseServiceClient(conn)) +} + +// RegisterWarehouseServiceHandlerClient registers the http handlers for service WarehouseService +// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "WarehouseServiceClient". +// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "WarehouseServiceClient" +// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in +// "WarehouseServiceClient" to call the correct interceptors. +func RegisterWarehouseServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux, client WarehouseServiceClient) error { + + mux.Handle("GET", pattern_WarehouseService_ServiceInfo_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/stocklet.warehouse.v1.WarehouseService/ServiceInfo", runtime.WithHTTPPathPattern("/v1/warehouse/service")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_WarehouseService_ServiceInfo_0(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_WarehouseService_ServiceInfo_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_WarehouseService_ViewProductStock_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/stocklet.warehouse.v1.WarehouseService/ViewProductStock", runtime.WithHTTPPathPattern("/v1/warehouse/product/{product_id}")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_WarehouseService_ViewProductStock_0(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_WarehouseService_ViewProductStock_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_WarehouseService_ViewReservation_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/stocklet.warehouse.v1.WarehouseService/ViewReservation", runtime.WithHTTPPathPattern("/v1/warehouse/reservation/{reservation_id}")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_WarehouseService_ViewReservation_0(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_WarehouseService_ViewReservation_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +var ( + pattern_WarehouseService_ServiceInfo_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v1", "warehouse", "service"}, "")) + + pattern_WarehouseService_ViewProductStock_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"v1", "warehouse", "product", "product_id"}, "")) + + pattern_WarehouseService_ViewReservation_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"v1", "warehouse", "reservation", "reservation_id"}, "")) +) + +var ( + forward_WarehouseService_ServiceInfo_0 = runtime.ForwardResponseMessage + + forward_WarehouseService_ViewProductStock_0 = runtime.ForwardResponseMessage + + forward_WarehouseService_ViewReservation_0 = runtime.ForwardResponseMessage +) diff --git a/internal/pkg/protogen/warehouse/v1/service_grpc.pb.go b/internal/pkg/protogen/warehouse/v1/service_grpc.pb.go new file mode 100644 index 0000000..cdbd80d --- /dev/null +++ b/internal/pkg/protogen/warehouse/v1/service_grpc.pb.go @@ -0,0 +1,395 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.3.0 +// - protoc (unknown) +// source: stocklet/warehouse/v1/service.proto + +package warehouse_v1 + +import ( + context "context" + v1 "github.com/hexolan/stocklet/internal/pkg/protogen/common/v1" + v11 "github.com/hexolan/stocklet/internal/pkg/protogen/events/v1" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + emptypb "google.golang.org/protobuf/types/known/emptypb" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.32.0 or later. +const _ = grpc.SupportPackageIsVersion7 + +const ( + WarehouseService_ServiceInfo_FullMethodName = "/stocklet.warehouse.v1.WarehouseService/ServiceInfo" + WarehouseService_ViewProductStock_FullMethodName = "/stocklet.warehouse.v1.WarehouseService/ViewProductStock" + WarehouseService_ViewReservation_FullMethodName = "/stocklet.warehouse.v1.WarehouseService/ViewReservation" + WarehouseService_ProcessProductCreatedEvent_FullMethodName = "/stocklet.warehouse.v1.WarehouseService/ProcessProductCreatedEvent" + WarehouseService_ProcessOrderPendingEvent_FullMethodName = "/stocklet.warehouse.v1.WarehouseService/ProcessOrderPendingEvent" + WarehouseService_ProcessShipmentAllocationEvent_FullMethodName = "/stocklet.warehouse.v1.WarehouseService/ProcessShipmentAllocationEvent" + WarehouseService_ProcessPaymentProcessedEvent_FullMethodName = "/stocklet.warehouse.v1.WarehouseService/ProcessPaymentProcessedEvent" +) + +// WarehouseServiceClient is the client API for WarehouseService service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +type WarehouseServiceClient interface { + // View information about the service. + // + // buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + ServiceInfo(ctx context.Context, in *v1.ServiceInfoRequest, opts ...grpc.CallOption) (*v1.ServiceInfoResponse, error) + ViewProductStock(ctx context.Context, in *ViewProductStockRequest, opts ...grpc.CallOption) (*ViewProductStockResponse, error) + ViewReservation(ctx context.Context, in *ViewReservationRequest, opts ...grpc.CallOption) (*ViewReservationResponse, error) + // A consumer will call this method to process events. + // + // buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + // buf:lint:ignore RPC_REQUEST_STANDARD_NAME + // buf:lint:ignore RPC_RESPONSE_STANDARD_NAME + ProcessProductCreatedEvent(ctx context.Context, in *v11.ProductCreatedEvent, opts ...grpc.CallOption) (*emptypb.Empty, error) + // A consumer will call this method to process events. + // + // buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + // buf:lint:ignore RPC_REQUEST_STANDARD_NAME + // buf:lint:ignore RPC_RESPONSE_STANDARD_NAME + ProcessOrderPendingEvent(ctx context.Context, in *v11.OrderPendingEvent, opts ...grpc.CallOption) (*emptypb.Empty, error) + // A consumer will call this method to process events. + // + // buf:lint:ignore RPC_REQUEST_STANDARD_NAME + // buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + // buf:lint:ignore RPC_RESPONSE_STANDARD_NAME + ProcessShipmentAllocationEvent(ctx context.Context, in *v11.ShipmentAllocationEvent, opts ...grpc.CallOption) (*emptypb.Empty, error) + // A consumer will call this method to process events. + // + // buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + // buf:lint:ignore RPC_REQUEST_STANDARD_NAME + // buf:lint:ignore RPC_RESPONSE_STANDARD_NAME + ProcessPaymentProcessedEvent(ctx context.Context, in *v11.PaymentProcessedEvent, opts ...grpc.CallOption) (*emptypb.Empty, error) +} + +type warehouseServiceClient struct { + cc grpc.ClientConnInterface +} + +func NewWarehouseServiceClient(cc grpc.ClientConnInterface) WarehouseServiceClient { + return &warehouseServiceClient{cc} +} + +func (c *warehouseServiceClient) ServiceInfo(ctx context.Context, in *v1.ServiceInfoRequest, opts ...grpc.CallOption) (*v1.ServiceInfoResponse, error) { + out := new(v1.ServiceInfoResponse) + err := c.cc.Invoke(ctx, WarehouseService_ServiceInfo_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *warehouseServiceClient) ViewProductStock(ctx context.Context, in *ViewProductStockRequest, opts ...grpc.CallOption) (*ViewProductStockResponse, error) { + out := new(ViewProductStockResponse) + err := c.cc.Invoke(ctx, WarehouseService_ViewProductStock_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *warehouseServiceClient) ViewReservation(ctx context.Context, in *ViewReservationRequest, opts ...grpc.CallOption) (*ViewReservationResponse, error) { + out := new(ViewReservationResponse) + err := c.cc.Invoke(ctx, WarehouseService_ViewReservation_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *warehouseServiceClient) ProcessProductCreatedEvent(ctx context.Context, in *v11.ProductCreatedEvent, opts ...grpc.CallOption) (*emptypb.Empty, error) { + out := new(emptypb.Empty) + err := c.cc.Invoke(ctx, WarehouseService_ProcessProductCreatedEvent_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *warehouseServiceClient) ProcessOrderPendingEvent(ctx context.Context, in *v11.OrderPendingEvent, opts ...grpc.CallOption) (*emptypb.Empty, error) { + out := new(emptypb.Empty) + err := c.cc.Invoke(ctx, WarehouseService_ProcessOrderPendingEvent_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *warehouseServiceClient) ProcessShipmentAllocationEvent(ctx context.Context, in *v11.ShipmentAllocationEvent, opts ...grpc.CallOption) (*emptypb.Empty, error) { + out := new(emptypb.Empty) + err := c.cc.Invoke(ctx, WarehouseService_ProcessShipmentAllocationEvent_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *warehouseServiceClient) ProcessPaymentProcessedEvent(ctx context.Context, in *v11.PaymentProcessedEvent, opts ...grpc.CallOption) (*emptypb.Empty, error) { + out := new(emptypb.Empty) + err := c.cc.Invoke(ctx, WarehouseService_ProcessPaymentProcessedEvent_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// WarehouseServiceServer is the server API for WarehouseService service. +// All implementations must embed UnimplementedWarehouseServiceServer +// for forward compatibility +type WarehouseServiceServer interface { + // View information about the service. + // + // buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + ServiceInfo(context.Context, *v1.ServiceInfoRequest) (*v1.ServiceInfoResponse, error) + ViewProductStock(context.Context, *ViewProductStockRequest) (*ViewProductStockResponse, error) + ViewReservation(context.Context, *ViewReservationRequest) (*ViewReservationResponse, error) + // A consumer will call this method to process events. + // + // buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + // buf:lint:ignore RPC_REQUEST_STANDARD_NAME + // buf:lint:ignore RPC_RESPONSE_STANDARD_NAME + ProcessProductCreatedEvent(context.Context, *v11.ProductCreatedEvent) (*emptypb.Empty, error) + // A consumer will call this method to process events. + // + // buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + // buf:lint:ignore RPC_REQUEST_STANDARD_NAME + // buf:lint:ignore RPC_RESPONSE_STANDARD_NAME + ProcessOrderPendingEvent(context.Context, *v11.OrderPendingEvent) (*emptypb.Empty, error) + // A consumer will call this method to process events. + // + // buf:lint:ignore RPC_REQUEST_STANDARD_NAME + // buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + // buf:lint:ignore RPC_RESPONSE_STANDARD_NAME + ProcessShipmentAllocationEvent(context.Context, *v11.ShipmentAllocationEvent) (*emptypb.Empty, error) + // A consumer will call this method to process events. + // + // buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + // buf:lint:ignore RPC_REQUEST_STANDARD_NAME + // buf:lint:ignore RPC_RESPONSE_STANDARD_NAME + ProcessPaymentProcessedEvent(context.Context, *v11.PaymentProcessedEvent) (*emptypb.Empty, error) + mustEmbedUnimplementedWarehouseServiceServer() +} + +// UnimplementedWarehouseServiceServer must be embedded to have forward compatible implementations. +type UnimplementedWarehouseServiceServer struct { +} + +func (UnimplementedWarehouseServiceServer) ServiceInfo(context.Context, *v1.ServiceInfoRequest) (*v1.ServiceInfoResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method ServiceInfo not implemented") +} +func (UnimplementedWarehouseServiceServer) ViewProductStock(context.Context, *ViewProductStockRequest) (*ViewProductStockResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method ViewProductStock not implemented") +} +func (UnimplementedWarehouseServiceServer) ViewReservation(context.Context, *ViewReservationRequest) (*ViewReservationResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method ViewReservation not implemented") +} +func (UnimplementedWarehouseServiceServer) ProcessProductCreatedEvent(context.Context, *v11.ProductCreatedEvent) (*emptypb.Empty, error) { + return nil, status.Errorf(codes.Unimplemented, "method ProcessProductCreatedEvent not implemented") +} +func (UnimplementedWarehouseServiceServer) ProcessOrderPendingEvent(context.Context, *v11.OrderPendingEvent) (*emptypb.Empty, error) { + return nil, status.Errorf(codes.Unimplemented, "method ProcessOrderPendingEvent not implemented") +} +func (UnimplementedWarehouseServiceServer) ProcessShipmentAllocationEvent(context.Context, *v11.ShipmentAllocationEvent) (*emptypb.Empty, error) { + return nil, status.Errorf(codes.Unimplemented, "method ProcessShipmentAllocationEvent not implemented") +} +func (UnimplementedWarehouseServiceServer) ProcessPaymentProcessedEvent(context.Context, *v11.PaymentProcessedEvent) (*emptypb.Empty, error) { + return nil, status.Errorf(codes.Unimplemented, "method ProcessPaymentProcessedEvent not implemented") +} +func (UnimplementedWarehouseServiceServer) mustEmbedUnimplementedWarehouseServiceServer() {} + +// UnsafeWarehouseServiceServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to WarehouseServiceServer will +// result in compilation errors. +type UnsafeWarehouseServiceServer interface { + mustEmbedUnimplementedWarehouseServiceServer() +} + +func RegisterWarehouseServiceServer(s grpc.ServiceRegistrar, srv WarehouseServiceServer) { + s.RegisterService(&WarehouseService_ServiceDesc, srv) +} + +func _WarehouseService_ServiceInfo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(v1.ServiceInfoRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(WarehouseServiceServer).ServiceInfo(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: WarehouseService_ServiceInfo_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(WarehouseServiceServer).ServiceInfo(ctx, req.(*v1.ServiceInfoRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _WarehouseService_ViewProductStock_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ViewProductStockRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(WarehouseServiceServer).ViewProductStock(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: WarehouseService_ViewProductStock_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(WarehouseServiceServer).ViewProductStock(ctx, req.(*ViewProductStockRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _WarehouseService_ViewReservation_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ViewReservationRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(WarehouseServiceServer).ViewReservation(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: WarehouseService_ViewReservation_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(WarehouseServiceServer).ViewReservation(ctx, req.(*ViewReservationRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _WarehouseService_ProcessProductCreatedEvent_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(v11.ProductCreatedEvent) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(WarehouseServiceServer).ProcessProductCreatedEvent(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: WarehouseService_ProcessProductCreatedEvent_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(WarehouseServiceServer).ProcessProductCreatedEvent(ctx, req.(*v11.ProductCreatedEvent)) + } + return interceptor(ctx, in, info, handler) +} + +func _WarehouseService_ProcessOrderPendingEvent_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(v11.OrderPendingEvent) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(WarehouseServiceServer).ProcessOrderPendingEvent(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: WarehouseService_ProcessOrderPendingEvent_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(WarehouseServiceServer).ProcessOrderPendingEvent(ctx, req.(*v11.OrderPendingEvent)) + } + return interceptor(ctx, in, info, handler) +} + +func _WarehouseService_ProcessShipmentAllocationEvent_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(v11.ShipmentAllocationEvent) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(WarehouseServiceServer).ProcessShipmentAllocationEvent(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: WarehouseService_ProcessShipmentAllocationEvent_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(WarehouseServiceServer).ProcessShipmentAllocationEvent(ctx, req.(*v11.ShipmentAllocationEvent)) + } + return interceptor(ctx, in, info, handler) +} + +func _WarehouseService_ProcessPaymentProcessedEvent_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(v11.PaymentProcessedEvent) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(WarehouseServiceServer).ProcessPaymentProcessedEvent(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: WarehouseService_ProcessPaymentProcessedEvent_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(WarehouseServiceServer).ProcessPaymentProcessedEvent(ctx, req.(*v11.PaymentProcessedEvent)) + } + return interceptor(ctx, in, info, handler) +} + +// WarehouseService_ServiceDesc is the grpc.ServiceDesc for WarehouseService service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var WarehouseService_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "stocklet.warehouse.v1.WarehouseService", + HandlerType: (*WarehouseServiceServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "ServiceInfo", + Handler: _WarehouseService_ServiceInfo_Handler, + }, + { + MethodName: "ViewProductStock", + Handler: _WarehouseService_ViewProductStock_Handler, + }, + { + MethodName: "ViewReservation", + Handler: _WarehouseService_ViewReservation_Handler, + }, + { + MethodName: "ProcessProductCreatedEvent", + Handler: _WarehouseService_ProcessProductCreatedEvent_Handler, + }, + { + MethodName: "ProcessOrderPendingEvent", + Handler: _WarehouseService_ProcessOrderPendingEvent_Handler, + }, + { + MethodName: "ProcessShipmentAllocationEvent", + Handler: _WarehouseService_ProcessShipmentAllocationEvent_Handler, + }, + { + MethodName: "ProcessPaymentProcessedEvent", + Handler: _WarehouseService_ProcessPaymentProcessedEvent_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "stocklet/warehouse/v1/service.proto", +} diff --git a/internal/pkg/protogen/warehouse/v1/types.pb.go b/internal/pkg/protogen/warehouse/v1/types.pb.go new file mode 100644 index 0000000..4670f32 --- /dev/null +++ b/internal/pkg/protogen/warehouse/v1/types.pb.go @@ -0,0 +1,348 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.31.0 +// protoc (unknown) +// source: stocklet/warehouse/v1/types.proto + +package warehouse_v1 + +import ( + _ "buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go/buf/validate" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type ProductStock struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + ProductId string `protobuf:"bytes,1,opt,name=product_id,json=productId,proto3" json:"product_id,omitempty"` + Quantity int32 `protobuf:"varint,2,opt,name=quantity,proto3" json:"quantity,omitempty"` +} + +func (x *ProductStock) Reset() { + *x = ProductStock{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_warehouse_v1_types_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ProductStock) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ProductStock) ProtoMessage() {} + +func (x *ProductStock) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_warehouse_v1_types_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ProductStock.ProtoReflect.Descriptor instead. +func (*ProductStock) Descriptor() ([]byte, []int) { + return file_stocklet_warehouse_v1_types_proto_rawDescGZIP(), []int{0} +} + +func (x *ProductStock) GetProductId() string { + if x != nil { + return x.ProductId + } + return "" +} + +func (x *ProductStock) GetQuantity() int32 { + if x != nil { + return x.Quantity + } + return 0 +} + +type Reservation struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + OrderId string `protobuf:"bytes,2,opt,name=order_id,json=orderId,proto3" json:"order_id,omitempty"` + ReservedStock []*ReservationStock `protobuf:"bytes,3,rep,name=reserved_stock,json=reservedStock,proto3" json:"reserved_stock,omitempty"` + CreatedAt int64 `protobuf:"varint,4,opt,name=created_at,json=createdAt,proto3" json:"created_at,omitempty"` +} + +func (x *Reservation) Reset() { + *x = Reservation{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_warehouse_v1_types_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Reservation) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Reservation) ProtoMessage() {} + +func (x *Reservation) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_warehouse_v1_types_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Reservation.ProtoReflect.Descriptor instead. +func (*Reservation) Descriptor() ([]byte, []int) { + return file_stocklet_warehouse_v1_types_proto_rawDescGZIP(), []int{1} +} + +func (x *Reservation) GetId() string { + if x != nil { + return x.Id + } + return "" +} + +func (x *Reservation) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +func (x *Reservation) GetReservedStock() []*ReservationStock { + if x != nil { + return x.ReservedStock + } + return nil +} + +func (x *Reservation) GetCreatedAt() int64 { + if x != nil { + return x.CreatedAt + } + return 0 +} + +type ReservationStock struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + ProductId string `protobuf:"bytes,1,opt,name=product_id,json=productId,proto3" json:"product_id,omitempty"` + Quantity int32 `protobuf:"varint,2,opt,name=quantity,proto3" json:"quantity,omitempty"` +} + +func (x *ReservationStock) Reset() { + *x = ReservationStock{} + if protoimpl.UnsafeEnabled { + mi := &file_stocklet_warehouse_v1_types_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ReservationStock) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ReservationStock) ProtoMessage() {} + +func (x *ReservationStock) ProtoReflect() protoreflect.Message { + mi := &file_stocklet_warehouse_v1_types_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ReservationStock.ProtoReflect.Descriptor instead. +func (*ReservationStock) Descriptor() ([]byte, []int) { + return file_stocklet_warehouse_v1_types_proto_rawDescGZIP(), []int{2} +} + +func (x *ReservationStock) GetProductId() string { + if x != nil { + return x.ProductId + } + return "" +} + +func (x *ReservationStock) GetQuantity() int32 { + if x != nil { + return x.Quantity + } + return 0 +} + +var File_stocklet_warehouse_v1_types_proto protoreflect.FileDescriptor + +var file_stocklet_warehouse_v1_types_proto_rawDesc = []byte{ + 0x0a, 0x21, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2f, 0x77, 0x61, 0x72, 0x65, 0x68, + 0x6f, 0x75, 0x73, 0x65, 0x2f, 0x76, 0x31, 0x2f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x12, 0x15, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x77, 0x61, + 0x72, 0x65, 0x68, 0x6f, 0x75, 0x73, 0x65, 0x2e, 0x76, 0x31, 0x1a, 0x1b, 0x62, 0x75, 0x66, 0x2f, + 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x2f, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, + 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x5b, 0x0a, 0x0c, 0x50, 0x72, 0x6f, 0x64, 0x75, + 0x63, 0x74, 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x12, 0x26, 0x0a, 0x0a, 0x70, 0x72, 0x6f, 0x64, 0x75, + 0x63, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, 0x07, 0xba, 0x48, 0x04, + 0x72, 0x02, 0x10, 0x01, 0x52, 0x09, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x49, 0x64, 0x12, + 0x23, 0x0a, 0x08, 0x71, 0x75, 0x61, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x05, 0x42, 0x07, 0xba, 0x48, 0x04, 0x1a, 0x02, 0x28, 0x00, 0x52, 0x08, 0x71, 0x75, 0x61, 0x6e, + 0x74, 0x69, 0x74, 0x79, 0x22, 0xb9, 0x01, 0x0a, 0x0b, 0x52, 0x65, 0x73, 0x65, 0x72, 0x76, 0x61, + 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x17, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, + 0x42, 0x07, 0xba, 0x48, 0x04, 0x72, 0x02, 0x10, 0x01, 0x52, 0x02, 0x69, 0x64, 0x12, 0x22, 0x0a, + 0x08, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x42, + 0x07, 0xba, 0x48, 0x04, 0x72, 0x02, 0x10, 0x01, 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, + 0x64, 0x12, 0x4e, 0x0a, 0x0e, 0x72, 0x65, 0x73, 0x65, 0x72, 0x76, 0x65, 0x64, 0x5f, 0x73, 0x74, + 0x6f, 0x63, 0x6b, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x27, 0x2e, 0x73, 0x74, 0x6f, 0x63, + 0x6b, 0x6c, 0x65, 0x74, 0x2e, 0x77, 0x61, 0x72, 0x65, 0x68, 0x6f, 0x75, 0x73, 0x65, 0x2e, 0x76, + 0x31, 0x2e, 0x52, 0x65, 0x73, 0x65, 0x72, 0x76, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x53, 0x74, 0x6f, + 0x63, 0x6b, 0x52, 0x0d, 0x72, 0x65, 0x73, 0x65, 0x72, 0x76, 0x65, 0x64, 0x53, 0x74, 0x6f, 0x63, + 0x6b, 0x12, 0x1d, 0x0a, 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x61, 0x74, 0x18, + 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x41, 0x74, + 0x22, 0x5f, 0x0a, 0x10, 0x52, 0x65, 0x73, 0x65, 0x72, 0x76, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x53, + 0x74, 0x6f, 0x63, 0x6b, 0x12, 0x26, 0x0a, 0x0a, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x5f, + 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, 0x07, 0xba, 0x48, 0x04, 0x72, 0x02, 0x10, + 0x01, 0x52, 0x09, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x49, 0x64, 0x12, 0x23, 0x0a, 0x08, + 0x71, 0x75, 0x61, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x42, 0x07, + 0xba, 0x48, 0x04, 0x1a, 0x02, 0x28, 0x00, 0x52, 0x08, 0x71, 0x75, 0x61, 0x6e, 0x74, 0x69, 0x74, + 0x79, 0x42, 0x4d, 0x5a, 0x4b, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, + 0x68, 0x65, 0x78, 0x6f, 0x6c, 0x61, 0x6e, 0x2f, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x6c, 0x65, 0x74, + 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x67, 0x65, 0x6e, 0x2f, 0x77, 0x61, 0x72, 0x65, 0x68, 0x6f, 0x75, 0x73, 0x65, + 0x2f, 0x76, 0x31, 0x3b, 0x77, 0x61, 0x72, 0x65, 0x68, 0x6f, 0x75, 0x73, 0x65, 0x5f, 0x76, 0x31, + 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_stocklet_warehouse_v1_types_proto_rawDescOnce sync.Once + file_stocklet_warehouse_v1_types_proto_rawDescData = file_stocklet_warehouse_v1_types_proto_rawDesc +) + +func file_stocklet_warehouse_v1_types_proto_rawDescGZIP() []byte { + file_stocklet_warehouse_v1_types_proto_rawDescOnce.Do(func() { + file_stocklet_warehouse_v1_types_proto_rawDescData = protoimpl.X.CompressGZIP(file_stocklet_warehouse_v1_types_proto_rawDescData) + }) + return file_stocklet_warehouse_v1_types_proto_rawDescData +} + +var file_stocklet_warehouse_v1_types_proto_msgTypes = make([]protoimpl.MessageInfo, 3) +var file_stocklet_warehouse_v1_types_proto_goTypes = []interface{}{ + (*ProductStock)(nil), // 0: stocklet.warehouse.v1.ProductStock + (*Reservation)(nil), // 1: stocklet.warehouse.v1.Reservation + (*ReservationStock)(nil), // 2: stocklet.warehouse.v1.ReservationStock +} +var file_stocklet_warehouse_v1_types_proto_depIdxs = []int32{ + 2, // 0: stocklet.warehouse.v1.Reservation.reserved_stock:type_name -> stocklet.warehouse.v1.ReservationStock + 1, // [1:1] is the sub-list for method output_type + 1, // [1:1] is the sub-list for method input_type + 1, // [1:1] is the sub-list for extension type_name + 1, // [1:1] is the sub-list for extension extendee + 0, // [0:1] is the sub-list for field type_name +} + +func init() { file_stocklet_warehouse_v1_types_proto_init() } +func file_stocklet_warehouse_v1_types_proto_init() { + if File_stocklet_warehouse_v1_types_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_stocklet_warehouse_v1_types_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ProductStock); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_stocklet_warehouse_v1_types_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Reservation); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_stocklet_warehouse_v1_types_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ReservationStock); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_stocklet_warehouse_v1_types_proto_rawDesc, + NumEnums: 0, + NumMessages: 3, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_stocklet_warehouse_v1_types_proto_goTypes, + DependencyIndexes: file_stocklet_warehouse_v1_types_proto_depIdxs, + MessageInfos: file_stocklet_warehouse_v1_types_proto_msgTypes, + }.Build() + File_stocklet_warehouse_v1_types_proto = out.File + file_stocklet_warehouse_v1_types_proto_rawDesc = nil + file_stocklet_warehouse_v1_types_proto_goTypes = nil + file_stocklet_warehouse_v1_types_proto_depIdxs = nil +} diff --git a/internal/pkg/serve/gateway.go b/internal/pkg/serve/gateway.go new file mode 100644 index 0000000..8eb9005 --- /dev/null +++ b/internal/pkg/serve/gateway.go @@ -0,0 +1,114 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package serve + +import ( + "context" + "net/http" + + "github.com/grpc-ecosystem/grpc-gateway/v2/runtime" + "github.com/rs/zerolog/log" + "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc" + "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp" + "google.golang.org/grpc" + "google.golang.org/grpc/credentials/insecure" + "google.golang.org/grpc/metadata" + + "github.com/hexolan/stocklet/internal/pkg/config" + "github.com/hexolan/stocklet/internal/pkg/gwauth" +) + +func withGatewayErrorHandler() runtime.ServeMuxOption { + return runtime.WithErrorHandler( + func(ctx context.Context, mux *runtime.ServeMux, marshaler runtime.Marshaler, w http.ResponseWriter, r *http.Request, err error) { + runtime.DefaultHTTPErrorHandler(ctx, mux, marshaler, w, r, err) + log.Error().Err(err).Stack().Str("path", r.URL.Path).Str("reqURI", r.RequestURI).Str("remoteAddr", r.RemoteAddr).Msg("") + }, + ) +} + +func withGatewayMetadataOpt() runtime.ServeMuxOption { + return runtime.WithMetadata( + func(ctx context.Context, req *http.Request) metadata.MD { + return metadata.MD{"from-gateway": {"true"}} + }, + ) +} + +func withGatewayHeaderOpt() runtime.ServeMuxOption { + return runtime.WithIncomingHeaderMatcher( + func(key string) (string, bool) { + switch key { + case gwauth.JWTPayloadHeader: + // Envoy will validate JWT tokens and provide a payload header + // containing a base64 string of the token claims. + return "jwt-payload", true + default: + return key, false + } + }, + ) +} + +func withGatewayLogger(h http.Handler) http.Handler { + return http.HandlerFunc( + func(w http.ResponseWriter, r *http.Request) { + h.ServeHTTP(w, r) + log.Info().Str("path", r.URL.Path).Str("reqURI", r.RequestURI).Str("remoteAddr", r.RemoteAddr).Msg("") + }, + ) +} + +func NewGatewayServeBase(cfg *config.SharedConfig) (*runtime.ServeMux, []grpc.DialOption) { + // Create the base runtime ServeMux + mux := runtime.NewServeMux( + withGatewayErrorHandler(), + withGatewayMetadataOpt(), + withGatewayHeaderOpt(), + ) + + // Attach open telemetry instrumentation through the gRPC client options + clientOpts := []grpc.DialOption{ + grpc.WithStatsHandler( + otelgrpc.NewClientHandler(), + ), + + grpc.WithTransportCredentials(insecure.NewCredentials()), + } + + return mux, clientOpts +} + +func Gateway(mux *runtime.ServeMux) error { + // Create OTEL instrumentation handler + handler := otelhttp.NewHandler( + mux, + "grpc-gateway", + otelhttp.WithSpanNameFormatter( + func(operation string, r *http.Request) string { + return operation + ": " + r.RequestURI + }, + ), + ) + + // Create gateway HTTP server + svr := &http.Server{ + Addr: GetAddrToGateway("0.0.0.0"), + Handler: withGatewayLogger(handler), + } + + return svr.ListenAndServe() +} diff --git a/internal/pkg/serve/grpc.go b/internal/pkg/serve/grpc.go new file mode 100644 index 0000000..4042b77 --- /dev/null +++ b/internal/pkg/serve/grpc.go @@ -0,0 +1,62 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package serve + +import ( + "net" + + "github.com/rs/zerolog/log" + "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc" + "google.golang.org/grpc" + "google.golang.org/grpc/health" + "google.golang.org/grpc/health/grpc_health_v1" + "google.golang.org/grpc/reflection" + + "github.com/hexolan/stocklet/internal/pkg/config" +) + +func NewGrpcServeBase(cfg *config.SharedConfig) *grpc.Server { + // Attach OTEL metrics middleware + svr := grpc.NewServer( + grpc.StatsHandler( + otelgrpc.NewServerHandler(), + ), + ) + + // Attach the health service + svc := health.NewServer() + grpc_health_v1.RegisterHealthServer(svr, svc) + + // Enable reflection in dev mode + // Eases usage of tools like grpcurl and grpcui + if cfg.DevMode { + reflection.Register(svr) + } + + return svr +} + +func Grpc(svr *grpc.Server) { + lis, err := net.Listen("tcp", GetAddrToGrpc("0.0.0.0")) + if err != nil { + log.Panic().Err(err).Str("port", grpcPort).Msg("failed to listen on gRPC port") + } + + err = svr.Serve(lis) + if err != nil { + log.Panic().Err(err).Msg("failed to serve gRPC server") + } +} diff --git a/internal/pkg/serve/serve.go b/internal/pkg/serve/serve.go new file mode 100644 index 0000000..25b9507 --- /dev/null +++ b/internal/pkg/serve/serve.go @@ -0,0 +1,32 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package serve + +// Port Definitions +const ( + grpcPort string = "9090" + gatewayPort string = "90" +) + +// Get an address to a gRPC server using the standard port +func GetAddrToGrpc(host string) string { + return host + ":" + grpcPort +} + +// Get an address to a gRPC-gateway interface using the standard port +func GetAddrToGateway(host string) string { + return host + ":" + gatewayPort +} diff --git a/internal/pkg/storage/postgres.go b/internal/pkg/storage/postgres.go new file mode 100644 index 0000000..984d134 --- /dev/null +++ b/internal/pkg/storage/postgres.go @@ -0,0 +1,37 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package storage + +import ( + "context" + "time" + + "github.com/jackc/pgx/v5/pgxpool" + + "github.com/hexolan/stocklet/internal/pkg/config" + "github.com/hexolan/stocklet/internal/pkg/errors" +) + +func NewPostgresConn(conf *config.PostgresConfig) (*pgxpool.Pool, error) { + ctx, cancel := context.WithTimeout(context.Background(), time.Second*45) + defer cancel() + + pCl, err := pgxpool.New(ctx, conf.GetDSN()) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeExtService, "failed to connect to postgres", err) + } + return pCl, nil +} diff --git a/internal/svc/auth/api/gateway.go b/internal/svc/auth/api/gateway.go new file mode 100644 index 0000000..35e37d1 --- /dev/null +++ b/internal/svc/auth/api/gateway.go @@ -0,0 +1,39 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package api + +import ( + "context" + + "github.com/grpc-ecosystem/grpc-gateway/v2/runtime" + "github.com/rs/zerolog/log" + + pb "github.com/hexolan/stocklet/internal/pkg/protogen/auth/v1" + "github.com/hexolan/stocklet/internal/pkg/serve" + "github.com/hexolan/stocklet/internal/svc/auth" +) + +func PrepareGateway(cfg *auth.ServiceConfig) *runtime.ServeMux { + mux, clientOpts := serve.NewGatewayServeBase(&cfg.Shared) + + ctx := context.Background() + err := pb.RegisterAuthServiceHandlerFromEndpoint(ctx, mux, serve.GetAddrToGrpc("localhost"), clientOpts) + if err != nil { + log.Panic().Err(err).Msg("failed to register endpoint for gateway") + } + + return mux +} diff --git a/internal/svc/auth/api/grpc.go b/internal/svc/auth/api/grpc.go new file mode 100644 index 0000000..aa4ee96 --- /dev/null +++ b/internal/svc/auth/api/grpc.go @@ -0,0 +1,30 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package api + +import ( + "google.golang.org/grpc" + + pb "github.com/hexolan/stocklet/internal/pkg/protogen/auth/v1" + "github.com/hexolan/stocklet/internal/pkg/serve" + "github.com/hexolan/stocklet/internal/svc/auth" +) + +func PrepareGrpc(cfg *auth.ServiceConfig, svc *auth.AuthService) *grpc.Server { + svr := serve.NewGrpcServeBase(&cfg.Shared) + pb.RegisterAuthServiceServer(svr, svc) + return svr +} diff --git a/internal/svc/auth/auth.go b/internal/svc/auth/auth.go new file mode 100644 index 0000000..db3c19b --- /dev/null +++ b/internal/svc/auth/auth.go @@ -0,0 +1,157 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package auth + +import ( + "context" + + "github.com/bufbuild/protovalidate-go" + "github.com/rs/zerolog/log" + "google.golang.org/protobuf/types/known/emptypb" + + "github.com/hexolan/stocklet/internal/pkg/errors" + "github.com/hexolan/stocklet/internal/pkg/gwauth" + "github.com/hexolan/stocklet/internal/pkg/messaging" + pb "github.com/hexolan/stocklet/internal/pkg/protogen/auth/v1" + commonpb "github.com/hexolan/stocklet/internal/pkg/protogen/common/v1" + eventpb "github.com/hexolan/stocklet/internal/pkg/protogen/events/v1" +) + +// Interface for the service +type AuthService struct { + pb.UnimplementedAuthServiceServer + + cfg *ServiceConfig + + store StorageController + pbVal *protovalidate.Validator +} + +// Interface for database methods +// Allows implementing seperate controllers for different databases (e.g. Postgres, MongoDB, etc) +type StorageController interface { + SetPassword(ctx context.Context, userId string, password string) error + VerifyPassword(ctx context.Context, userId string, password string) (bool, error) + + DeleteAuthMethods(ctx context.Context, userId string) error +} + +// Interface for event consumption +// Flexibility for seperate controllers for different messaging systems (e.g. Kafka, NATS, etc) +type ConsumerController interface { + messaging.ConsumerController + + Attach(svc pb.AuthServiceServer) +} + +// Create the auth service +func NewAuthService(cfg *ServiceConfig, store StorageController) *AuthService { + // Initialise the protobuf validator + pbVal, err := protovalidate.New() + if err != nil { + log.Panic().Err(err).Msg("failed to initialise protobuf validator") + } + + svc := &AuthService{ + cfg: cfg, + store: store, + pbVal: pbVal, + } + + return svc +} + +func (svc AuthService) ServiceInfo(ctx context.Context, req *commonpb.ServiceInfoRequest) (*commonpb.ServiceInfoResponse, error) { + return &commonpb.ServiceInfoResponse{ + Name: "auth", + Source: "https://github.com/hexolan/stocklet", + SourceLicense: "AGPL-3.0", + }, nil +} + +func (svc AuthService) LoginPassword(ctx context.Context, req *pb.LoginPasswordRequest) (*pb.LoginPasswordResponse, error) { + // Validate the request args + if err := svc.pbVal.Validate(req); err != nil { + // provide validation err context to user + return nil, errors.NewServiceError(errors.ErrCodeInvalidArgument, "invalid request: "+err.Error()) + } + + // Verify password + match, err := svc.store.VerifyPassword(ctx, req.UserId, req.Password) + if err != nil || match == false { + return nil, errors.WrapServiceError(errors.ErrCodeForbidden, "invalid user id or password", err) + } + + // Issue token for the user + token, err := issueToken(svc.cfg, req.UserId) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeService, "error issuing token", err) + } + + return &pb.LoginPasswordResponse{Detail: "Success", Data: token}, nil +} + +func (svc AuthService) SetPassword(ctx context.Context, req *pb.SetPasswordRequest) (*pb.SetPasswordResponse, error) { + // If the request is through the gateway, + // then perform permission checking + gatewayRequest, gwMd := gwauth.IsGatewayRequest(ctx) + if gatewayRequest { + log.Info().Msg("is a gateway request") + // Ensure user is authenticated + claims, err := gwauth.GetGatewayUser(gwMd) + if err != nil { + return nil, err + } + + // Only allow changing of own password + req.UserId = claims.Subject + } + + // Validate the request args + if err := svc.pbVal.Validate(req); err != nil { + // provide validation err context to user + return nil, errors.NewServiceError(errors.ErrCodeInvalidArgument, "invalid request: "+err.Error()) + } + + // Set the password + err := svc.store.SetPassword(ctx, req.UserId, req.Password) + if err != nil { + return nil, err + } + + return &pb.SetPasswordResponse{Detail: "Successfully updated password"}, nil +} + +func (svc AuthService) ProcessUserDeletedEvent(ctx context.Context, req *eventpb.UserDeletedEvent) (*emptypb.Empty, error) { + // Validate the request args + if err := svc.pbVal.Validate(req); err != nil { + // provide validation err context to user + return nil, errors.NewServiceError(errors.ErrCodeInvalidArgument, "invalid request: "+err.Error()) + } + + err := svc.store.DeleteAuthMethods(ctx, req.UserId) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeService, "failed to process event", err) + } + + return &emptypb.Empty{}, nil +} + +// Provide the JWK ECDSA public key as part of a JSON Web Key set. +// This method is called by the API gateway for usage when validating inbound JWT tokens. +func (svc AuthService) GetJwks(ctx context.Context, req *pb.GetJwksRequest) (*pb.GetJwksResponse, error) { + return &pb.GetJwksResponse{Keys: []*pb.PublicEcJWK{svc.cfg.ServiceOpts.PublicJwk}}, nil +} diff --git a/internal/svc/auth/config.go b/internal/svc/auth/config.go new file mode 100644 index 0000000..8966a69 --- /dev/null +++ b/internal/svc/auth/config.go @@ -0,0 +1,156 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package auth + +import ( + "crypto/ecdsa" + "crypto/x509" + "encoding/base64" + "encoding/json" + "encoding/pem" + "fmt" + + "github.com/lestrrat-go/jwx/v2/jwk" + "github.com/rs/zerolog/log" + "google.golang.org/protobuf/encoding/protojson" + + "github.com/hexolan/stocklet/internal/pkg/config" + "github.com/hexolan/stocklet/internal/pkg/errors" + pb "github.com/hexolan/stocklet/internal/pkg/protogen/auth/v1" +) + +// Auth Service Configuration +type ServiceConfig struct { + // Core configuration + Shared config.SharedConfig + ServiceOpts ServiceConfigOpts + + // Dynamically loaded configuration + Postgres config.PostgresConfig + Kafka config.KafkaConfig +} + +// load the service configuration +func NewServiceConfig() (*ServiceConfig, error) { + cfg := ServiceConfig{} + + // load the shared config options + if err := cfg.Shared.Load(); err != nil { + return nil, err + } + + // load the service config opts + if err := cfg.ServiceOpts.Load(); err != nil { + return nil, err + } + + return &cfg, nil +} + +// Service specific config options +type ServiceConfigOpts struct { + // Env Var: "AUTH_PRIVATE_KEY" + // to be provided in base64 format + PrivateKey *ecdsa.PrivateKey + + // Generated from PrivateKey + PublicJwk *pb.PublicEcJWK +} + +// Load the ServiceConfigOpts +// +// PrivateKey is loaded and decoded from the base64 +// encoded PEM file exposed in the 'AUTH_PRIVATE_KEY' +// environment variable. +func (opts *ServiceConfigOpts) Load() error { + // load the private key + if err := opts.loadPrivateKey(); err != nil { + return err + } + + // prepare the JWK public key + opts.PublicJwk = preparePublicJwk(opts.PrivateKey) + + return nil +} + +// Load the ECDSA private key. +// +// Used for signing JWT tokens. +// The public key is also served in JWK format, from this service, +// for use when validating the tokens at the API ingress. +func (opts *ServiceConfigOpts) loadPrivateKey() error { + // PEM private key file exposed as an environment variable encoded in base64 + opt, err := config.RequireFromEnv("AUTH_PRIVATE_KEY") + if err != nil { + return err + } + + // Decode from base64 + pkBytes, err := base64.StdEncoding.DecodeString(opt) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeService, "the provided 'AUTH_PRIVATE_KEY' is not valid base64", err) + } + + // Decode the PEM key + pkBlock, _ := pem.Decode(pkBytes) + if pkBlock == nil { + return errors.NewServiceError(errors.ErrCodeService, "the provided 'AUTH_PRIVATE_KEY' is not valid PEM format") + } + + // Parse the block to a ecdsa.PrivateKey object + privKey, err := x509.ParseECPrivateKey(pkBlock.Bytes) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeService, "failed to parse the provided 'AUTH_PRIVATE_KEY' to an EC private key", err) + } + + opts.PrivateKey = privKey + return nil +} + +// Converts the ECDSA key to a public JWK. +func preparePublicJwk(privateKey *ecdsa.PrivateKey) *pb.PublicEcJWK { + // Assemble the public JWK + jwk, err := jwk.FromRaw(privateKey.PublicKey) + if err != nil { + log.Panic().Err(err).Msg("something went wrong parsing public key from private key") + } + + // denote use for signatures + jwk.Set("use", "sig") + + // envoy includes support for ES256, ES384 and ES512 + alg := fmt.Sprintf("ES%v", privateKey.Curve.Params().BitSize) + if alg != "ES256" && alg != "ES384" && alg != "ES512" { + log.Panic().Err(err).Msg("unsupported bitsize for private key") + } + jwk.Set("alg", alg) + + // Convert the JWK to JSON + jwkBytes, err := json.Marshal(jwk) + if err != nil { + log.Panic().Err(err).Msg("something went wrong preparing the public JWK (json marshal)") + } + + // Unmarshal the JSON to Protobuf format + publicJwkPB := pb.PublicEcJWK{} + err = protojson.Unmarshal(jwkBytes, &publicJwkPB) + if err != nil { + log.Panic().Err(err).Msg("something went wrong preparing the public JWK (protonjson unmarshal)") + } + + return &publicJwkPB +} diff --git a/internal/svc/auth/controller/kafka.go b/internal/svc/auth/controller/kafka.go new file mode 100644 index 0000000..6e4fbcb --- /dev/null +++ b/internal/svc/auth/controller/kafka.go @@ -0,0 +1,109 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package controller + +import ( + "context" + + "github.com/rs/zerolog/log" + "github.com/twmb/franz-go/pkg/kgo" + "google.golang.org/protobuf/proto" + + "github.com/hexolan/stocklet/internal/pkg/messaging" + pb "github.com/hexolan/stocklet/internal/pkg/protogen/auth/v1" + eventpb "github.com/hexolan/stocklet/internal/pkg/protogen/events/v1" + "github.com/hexolan/stocklet/internal/svc/auth" +) + +type kafkaController struct { + cl *kgo.Client + + svc pb.AuthServiceServer + + ctx context.Context + ctxCancel context.CancelFunc +} + +func NewKafkaController(cl *kgo.Client) auth.ConsumerController { + // Create a cancellable context for the consumer + ctx, ctxCancel := context.WithCancel(context.Background()) + + // Ensure the required Kafka topics exist + err := messaging.EnsureKafkaTopics( + cl, + + messaging.User_State_Deleted_Topic, + ) + if err != nil { + log.Warn().Err(err).Msg("kafka: raised attempting to ensure svc topics") + } + + // Add the consumption topics + cl.AddConsumeTopics( + messaging.User_State_Deleted_Topic, + ) + + return &kafkaController{cl: cl, ctx: ctx, ctxCancel: ctxCancel} +} + +func (c *kafkaController) Attach(svc pb.AuthServiceServer) { + c.svc = svc +} + +func (c *kafkaController) Start() { + if c.svc == nil { + log.Panic().Msg("consumer: no service interface attached") + } + + for { + fetches := c.cl.PollFetches(c.ctx) + if errs := fetches.Errors(); len(errs) > 0 { + log.Panic().Any("kafka-errs", errs).Msg("consumer: unrecoverable kafka errors") + } + + fetches.EachTopic(func(ft kgo.FetchTopic) { + switch ft.Topic { + case messaging.User_State_Deleted_Topic: + c.consumeUserDeletedEventTopic(ft) + default: + log.Warn().Str("topic", ft.Topic).Msg("consumer: recieved records from unexpected topic") + } + }) + } +} + +func (c *kafkaController) Stop() { + // Cancel the consumer context + c.ctxCancel() +} + +func (c *kafkaController) consumeUserDeletedEventTopic(ft kgo.FetchTopic) { + log.Info().Str("topic", ft.Topic).Msg("consumer: recieved records from topic") + + // Process each message from the topic + ft.EachRecord(func(record *kgo.Record) { + // Unmarshal the event + var event eventpb.UserDeletedEvent + err := proto.Unmarshal(record.Value, &event) + if err != nil { + log.Panic().Err(err).Msg("consumer: failed to unmarshal event") + } + + // Process the event + ctx := context.Background() + c.svc.ProcessUserDeletedEvent(ctx, &event) + }) +} diff --git a/internal/svc/auth/controller/postgres.go b/internal/svc/auth/controller/postgres.go new file mode 100644 index 0000000..a12f839 --- /dev/null +++ b/internal/svc/auth/controller/postgres.go @@ -0,0 +1,97 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package controller + +import ( + "context" + + "github.com/jackc/pgx/v5/pgxpool" + + "github.com/hexolan/stocklet/internal/pkg/errors" + "github.com/hexolan/stocklet/internal/svc/auth" +) + +type postgresController struct { + cl *pgxpool.Pool +} + +func NewPostgresController(cl *pgxpool.Pool) auth.StorageController { + return postgresController{cl: cl} +} + +func (c postgresController) getPasswordAuthMethod(ctx context.Context, userId string) (string, error) { + var hashedPassword string + err := c.cl.QueryRow(ctx, "SELECT hashed_password FROM auth_methods WHERE user_id=$1", userId).Scan(&hashedPassword) + if err != nil { + return "", errors.WrapServiceError(errors.ErrCodeNotFound, "unknown user id", err) + } + + return hashedPassword, nil +} + +func (c postgresController) SetPassword(ctx context.Context, userId string, password string) error { + hashedPassword, err := auth.HashPassword(password) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeInvalidArgument, "unable to hash password", err) + } + + // Check if auth method already exists + var statement string + _, err = c.getPasswordAuthMethod(ctx, userId) + if err != nil { + // Auth method does not exist + statement = "INSERT INTO auth_methods (user_id, hashed_password) VALUES ($1, $2)" + } else { + // Auth method already exists + statement = "UPDATE auth_methods SET hashed_password=$2 WHERE user_id=$1" + } + + // Execute statement + result, err := c.cl.Exec(ctx, statement, userId, hashedPassword) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to set password", err) + } + + // Ensure a row was affected + if result.RowsAffected() != 1 { + return errors.WrapServiceError(errors.ErrCodeExtService, "auth methods unaffected", err) + } + + return nil +} + +func (c postgresController) VerifyPassword(ctx context.Context, userId string, password string) (bool, error) { + hashedPassword, err := c.getPasswordAuthMethod(ctx, userId) + if err != nil { + return false, err + } + + match := auth.CompareHashAndPassword(password, hashedPassword) + if !match { + return false, errors.WrapServiceError(errors.ErrCodeForbidden, "invalid user id or password", err) + } + + return true, nil +} + +func (c postgresController) DeleteAuthMethods(ctx context.Context, userId string) error { + _, err := c.cl.Exec(ctx, "DELETE FROM auth_methods WHERE user_id=$1", userId) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to delete", err) + } + + return nil +} diff --git a/internal/svc/auth/hashing.go b/internal/svc/auth/hashing.go new file mode 100644 index 0000000..582dcb2 --- /dev/null +++ b/internal/svc/auth/hashing.go @@ -0,0 +1,40 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package auth + +import ( + "golang.org/x/crypto/bcrypt" +) + +func HashPassword(password string) (string, error) { + // bcrypt has a 72 byte limitation on password length + // passwords are already validated to ensure no greater than 64 chars + hashedPasswordB, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost) + if err != nil { + return "", err + } + + return string(hashedPasswordB), nil +} + +func CompareHashAndPassword(password string, hashedPassword string) bool { + err := bcrypt.CompareHashAndPassword([]byte(hashedPassword), []byte(password)) + if err != nil { + return false + } + + return true +} diff --git a/internal/svc/auth/jwt.go b/internal/svc/auth/jwt.go new file mode 100644 index 0000000..ca25fe7 --- /dev/null +++ b/internal/svc/auth/jwt.go @@ -0,0 +1,56 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package auth + +import ( + "time" + + "github.com/lestrrat-go/jwx/v2/jwa" + "github.com/lestrrat-go/jwx/v2/jwt" + + "github.com/hexolan/stocklet/internal/pkg/errors" + "github.com/hexolan/stocklet/internal/pkg/gwauth" + pb "github.com/hexolan/stocklet/internal/pkg/protogen/auth/v1" +) + +// Issues a JWT token +func issueToken(cfg *ServiceConfig, sub string) (*pb.AuthToken, error) { + const expiryTime = 86400 // 1 day + + // Set token claims + token := jwt.New() + claims := &gwauth.JWTClaims{ + Subject: sub, + IssuedAt: time.Now().Unix(), + Expiry: time.Now().Unix() + expiryTime, + } + + token.Set("sub", claims.Subject) + token.Set("iat", claims.IssuedAt) + token.Set("exp", claims.Expiry) + + // Sign token + accessToken, err := jwt.Sign(token, jwt.WithKey(jwa.KeyAlgorithmFrom(cfg.ServiceOpts.PrivateKey), cfg.ServiceOpts.PrivateKey)) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeService, "failed to sign JWT token", err) + } + + return &pb.AuthToken{ + TokenType: "Bearer", + AccessToken: string(accessToken), + ExpiresIn: expiryTime, + }, nil +} diff --git a/internal/svc/order/api/gateway.go b/internal/svc/order/api/gateway.go new file mode 100644 index 0000000..bf7cf18 --- /dev/null +++ b/internal/svc/order/api/gateway.go @@ -0,0 +1,39 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package api + +import ( + "context" + + "github.com/grpc-ecosystem/grpc-gateway/v2/runtime" + "github.com/rs/zerolog/log" + + pb "github.com/hexolan/stocklet/internal/pkg/protogen/order/v1" + "github.com/hexolan/stocklet/internal/pkg/serve" + "github.com/hexolan/stocklet/internal/svc/order" +) + +func PrepareGateway(cfg *order.ServiceConfig) *runtime.ServeMux { + mux, clientOpts := serve.NewGatewayServeBase(&cfg.Shared) + + ctx := context.Background() + err := pb.RegisterOrderServiceHandlerFromEndpoint(ctx, mux, serve.GetAddrToGrpc("localhost"), clientOpts) + if err != nil { + log.Panic().Err(err).Msg("failed to register endpoint for gateway") + } + + return mux +} diff --git a/internal/svc/order/api/grpc.go b/internal/svc/order/api/grpc.go new file mode 100644 index 0000000..7c2a2ef --- /dev/null +++ b/internal/svc/order/api/grpc.go @@ -0,0 +1,30 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package api + +import ( + "google.golang.org/grpc" + + pb "github.com/hexolan/stocklet/internal/pkg/protogen/order/v1" + "github.com/hexolan/stocklet/internal/pkg/serve" + "github.com/hexolan/stocklet/internal/svc/order" +) + +func PrepareGrpc(cfg *order.ServiceConfig, svc *order.OrderService) *grpc.Server { + svr := serve.NewGrpcServeBase(&cfg.Shared) + pb.RegisterOrderServiceServer(svr, svc) + return svr +} diff --git a/internal/svc/order/config.go b/internal/svc/order/config.go new file mode 100644 index 0000000..5c1df36 --- /dev/null +++ b/internal/svc/order/config.go @@ -0,0 +1,42 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package order + +import ( + "github.com/hexolan/stocklet/internal/pkg/config" +) + +// Order Service Configuration +type ServiceConfig struct { + // Core Configuration + Shared config.SharedConfig + + // Dynamically loaded configuration + Postgres config.PostgresConfig + Kafka config.KafkaConfig +} + +// load the base service configuration +func NewServiceConfig() (*ServiceConfig, error) { + cfg := ServiceConfig{} + + // Load the core configuration + if err := cfg.Shared.Load(); err != nil { + return nil, err + } + + return &cfg, nil +} diff --git a/internal/svc/order/controller/kafka.go b/internal/svc/order/controller/kafka.go new file mode 100644 index 0000000..42cb49d --- /dev/null +++ b/internal/svc/order/controller/kafka.go @@ -0,0 +1,179 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package controller + +import ( + "context" + + "github.com/rs/zerolog/log" + "github.com/twmb/franz-go/pkg/kgo" + "google.golang.org/protobuf/proto" + + "github.com/hexolan/stocklet/internal/pkg/messaging" + eventpb "github.com/hexolan/stocklet/internal/pkg/protogen/events/v1" + pb "github.com/hexolan/stocklet/internal/pkg/protogen/order/v1" + "github.com/hexolan/stocklet/internal/svc/order" +) + +type kafkaController struct { + cl *kgo.Client + + svc pb.OrderServiceServer + + ctx context.Context + ctxCancel context.CancelFunc +} + +func NewKafkaController(cl *kgo.Client) order.ConsumerController { + // Create a cancellable context for the consumer + ctx, ctxCancel := context.WithCancel(context.Background()) + + // Ensure the required Kafka topics exist + err := messaging.EnsureKafkaTopics( + cl, + + messaging.Order_State_Created_Topic, + messaging.Order_State_Pending_Topic, + messaging.Order_State_Rejected_Topic, + messaging.Order_State_Approved_Topic, + + messaging.Warehouse_Reservation_Failed_Topic, + messaging.Shipping_Shipment_Allocation_Topic, + messaging.Payment_Processing_Topic, + ) + if err != nil { + log.Warn().Err(err).Msg("kafka: raised attempting to ensure svc topics") + } + + // Add the consumption topics + cl.AddConsumeTopics( + messaging.Product_PriceQuotation_Topic, + messaging.Warehouse_Reservation_Failed_Topic, + messaging.Shipping_Shipment_Allocation_Topic, + messaging.Payment_Processing_Topic, + ) + + return &kafkaController{cl: cl, ctx: ctx, ctxCancel: ctxCancel} +} + +func (c *kafkaController) Attach(svc pb.OrderServiceServer) { + c.svc = svc +} + +func (c *kafkaController) Start() { + if c.svc == nil { + log.Panic().Msg("consumer: no service interface attached") + } + + for { + fetches := c.cl.PollFetches(c.ctx) + if errs := fetches.Errors(); len(errs) > 0 { + log.Panic().Any("kafka-errs", errs).Msg("consumer: unrecoverable kafka errors") + } + + fetches.EachTopic(func(ft kgo.FetchTopic) { + switch ft.Topic { + case messaging.Product_PriceQuotation_Topic: + c.consumeProductPriceQuoteEventTopic(ft) + case messaging.Warehouse_Reservation_Failed_Topic: + c.consumeStockReservationEventTopic(ft) + case messaging.Shipping_Shipment_Allocation_Topic: + c.consumeShipmentAllocationEventTopic(ft) + case messaging.Payment_Processing_Topic: + c.consumePaymentProcessedEventTopic(ft) + default: + log.Warn().Str("topic", ft.Topic).Msg("consumer: recieved records from unexpected topic") + } + }) + } +} + +func (c *kafkaController) Stop() { + // Cancel the consumer context + c.ctxCancel() +} + +func (c *kafkaController) consumeProductPriceQuoteEventTopic(ft kgo.FetchTopic) { + log.Info().Str("topic", ft.Topic).Msg("consumer: recieved records from topic") + + // Process each message from the topic + ft.EachRecord(func(record *kgo.Record) { + // Unmarshal the event + var event eventpb.ProductPriceQuoteEvent + err := proto.Unmarshal(record.Value, &event) + if err != nil { + log.Panic().Err(err).Msg("consumer: failed to unmarshal event") + } + + // Process the event + ctx := context.Background() + c.svc.ProcessProductPriceQuoteEvent(ctx, &event) + }) +} + +func (c *kafkaController) consumeStockReservationEventTopic(ft kgo.FetchTopic) { + log.Info().Str("topic", ft.Topic).Msg("consumer: recieved records from topic") + + // Process each message from the topic + ft.EachRecord(func(record *kgo.Record) { + // Unmarshal the event + var event eventpb.StockReservationEvent + err := proto.Unmarshal(record.Value, &event) + if err != nil { + log.Panic().Err(err).Msg("consumer: failed to unmarshal event") + } + + // Process the event + ctx := context.Background() + c.svc.ProcessStockReservationEvent(ctx, &event) + }) +} + +func (c *kafkaController) consumeShipmentAllocationEventTopic(ft kgo.FetchTopic) { + log.Info().Str("topic", ft.Topic).Msg("consumer: recieved records from topic") + + // Process each message from the topic + ft.EachRecord(func(record *kgo.Record) { + // Unmarshal the event + var event eventpb.ShipmentAllocationEvent + err := proto.Unmarshal(record.Value, &event) + if err != nil { + log.Panic().Err(err).Msg("consumer: failed to unmarshal event") + } + + // Process the event + ctx := context.Background() + c.svc.ProcessShipmentAllocationEvent(ctx, &event) + }) +} + +func (c *kafkaController) consumePaymentProcessedEventTopic(ft kgo.FetchTopic) { + log.Info().Str("topic", ft.Topic).Msg("consumer: recieved records from topic") + + // Process each message from the topic + ft.EachRecord(func(record *kgo.Record) { + // Unmarshal the event + var event eventpb.PaymentProcessedEvent + err := proto.Unmarshal(record.Value, &event) + if err != nil { + log.Panic().Err(err).Msg("consumer: failed to unmarshal event") + } + + // Process the event + ctx := context.Background() + c.svc.ProcessPaymentProcessedEvent(ctx, &event) + }) +} diff --git a/internal/svc/order/controller/postgres.go b/internal/svc/order/controller/postgres.go new file mode 100644 index 0000000..ae9c0ac --- /dev/null +++ b/internal/svc/order/controller/postgres.go @@ -0,0 +1,458 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package controller + +import ( + "context" + "time" + + "github.com/doug-martin/goqu/v9" + _ "github.com/doug-martin/goqu/v9/dialect/postgres" + "github.com/jackc/pgx/v5" + "github.com/jackc/pgx/v5/pgtype" + "github.com/jackc/pgx/v5/pgxpool" + + "github.com/hexolan/stocklet/internal/pkg/errors" + pb "github.com/hexolan/stocklet/internal/pkg/protogen/order/v1" + "github.com/hexolan/stocklet/internal/svc/order" +) + +const ( + pgOrderBaseQuery string = "SELECT id, status, customer_id, shipping_id, transaction_id, created_at, updated_at FROM orders" + pgOrderItemsBaseQuery string = "SELECT product_id, quantity FROM order_items" +) + +// The postgres controller is responsible for implementing the StorageController interface +// to store and retrieve the requested items from the Postgres database. +// +// Other controllers can be implemented to interface with different database systems. +type postgresController struct { + cl *pgxpool.Pool +} + +// Creates a new postgresController that implements the StorageController interface. +func NewPostgresController(cl *pgxpool.Pool) order.StorageController { + return postgresController{cl: cl} +} + +// Internal method - Validation is assumed to have taken place already +// Gets an order by its specified id from the database +func (c postgresController) GetOrder(ctx context.Context, orderId string) (*pb.Order, error) { + return c.getOrder(ctx, nil, orderId) +} + +func (c postgresController) getOrder(ctx context.Context, tx *pgx.Tx, orderId string) (*pb.Order, error) { + // Query order + var row pgx.Row + if tx == nil { + row = c.cl.QueryRow(ctx, pgOrderBaseQuery+" WHERE id=$1", orderId) + } else { + row = (*tx).QueryRow(ctx, pgOrderBaseQuery+" WHERE id=$1", orderId) + } + + // Scan row to protobuf order + order, err := scanRowToOrder(row) + if err != nil { + return nil, err + } + + // Append the order items + order, err = c.appendItemsToOrderObj(ctx, tx, order) + if err != nil { + return nil, err + } + + return order, nil +} + +// Internal method - Inputs are assumed valid +// Create a new order in the database +func (c postgresController) CreateOrder(ctx context.Context, orderObj *pb.Order) (*pb.Order, error) { + // Begin a DB transaction + tx, err := c.cl.Begin(ctx) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeExtService, "failed to begin transaction", err) + } + defer tx.Rollback(ctx) + + // Prepare and perform insert query + newOrder := pb.Order{ + Items: orderObj.Items, + Status: orderObj.Status, + CustomerId: orderObj.CustomerId, + CreatedAt: time.Now().Unix(), + } + err = tx.QueryRow( + ctx, + "INSERT INTO orders (status, customer_id) VALUES ($1, $2) RETURNING id", + newOrder.Status, + newOrder.CustomerId, + ).Scan(&newOrder.Id) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeExtService, "failed to create order", err) + } + + // Create records for any order items + err = c.createOrderItems(ctx, tx, newOrder.Id, newOrder.Items) + if err != nil { + // The deffered rollback will be called (so the transaction will not be commited) + return nil, err + } + + // Prepare a created event. + // + // Then add the event to the outbox table with the transaction + // to ensure that the event will be dispatched if + // the transaction succeeds. + evt, evtTopic, err := order.PrepareOrderCreatedEvent(&newOrder) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeService, "failed to create order event", err) + } + + _, err = tx.Exec(ctx, "INSERT INTO event_outbox (aggregateid, aggregatetype, payload) VALUES ($1, $2, $3)", newOrder.Id, evtTopic, evt) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeExtService, "failed to insert order event", err) + } + + // Commit the transaction + err = tx.Commit(ctx) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeExtService, "failed to commit transaction", err) + } + + return &newOrder, nil +} + +// Get all orders related to a specified customer. +// TODO: implement pagination +func (c postgresController) GetCustomerOrders(ctx context.Context, customerId string) ([]*pb.Order, error) { + rows, err := c.cl.Query(ctx, pgOrderBaseQuery+" WHERE customer_id=$1 LIMIT 10", customerId) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeService, "query error whilst fetching customer orders", err) + } + + orders := []*pb.Order{} + for rows.Next() { + orderObj, err := scanRowToOrder(rows) + if err != nil { + return nil, err + } + + // Append the order's items + orderObj, err = c.appendItemsToOrderObj(ctx, nil, orderObj) + if err != nil { + return nil, err + } + + orders = append(orders, orderObj) + } + + if rows.Err() != nil { + return nil, errors.WrapServiceError(errors.ErrCodeService, "error whilst scanning order rows", rows.Err()) + } + + return orders, nil +} + +// Set order status to approved +// Dispatch OrderApprovedEvent +func (c postgresController) ApproveOrder(ctx context.Context, orderId string, transactionId string) (*pb.Order, error) { + // Begin a DB transaction + tx, err := c.cl.Begin(ctx) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeExtService, "failed to begin transaction", err) + } + defer tx.Rollback(ctx) + + // Execute update query + _, err = tx.Exec( + ctx, + "UPDATE orders SET status = $1, transaction_id = $2 WHERE id = $3", + pb.OrderStatus_ORDER_STATUS_APPROVED, + transactionId, + orderId, + ) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeExtService, "failed to approve order", err) + } + + orderObj, err := c.getOrder(ctx, &tx, orderId) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeExtService, "failed to approve order", err) + } + + // Then add the event to the outbox table with the transaction. + evt, evtTopic, err := order.PrepareOrderApprovedEvent(orderObj) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeService, "failed to create event", err) + } + + _, err = tx.Exec(ctx, "INSERT INTO event_outbox (aggregateid, aggregatetype, payload) VALUES ($1, $2, $3)", orderObj.Id, evtTopic, evt) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeExtService, "failed to insert event", err) + } + + // Commit the transaction + err = tx.Commit(ctx) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeExtService, "failed to commit transaction", err) + } + + return orderObj, nil +} + +// Set order status to processing +// Dispatch OrderProcessingEvent +func (c postgresController) ProcessOrder(ctx context.Context, orderId string, itemsPrice float32) (*pb.Order, error) { + // Begin a DB transaction + tx, err := c.cl.Begin(ctx) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeExtService, "failed to begin transaction", err) + } + defer tx.Rollback(ctx) + + // Execute update query + _, err = tx.Exec( + ctx, + "UPDATE orders SET status = $1, items_price = $2, total_price = $3 WHERE id = $4", + pb.OrderStatus_ORDER_STATUS_PROCESSING, + itemsPrice, + itemsPrice, + orderId, + ) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeExtService, "failed to update order", err) + } + + orderObj, err := c.getOrder(ctx, &tx, orderId) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeExtService, "failed to update order", err) + } + + // Then add the event to the outbox table with the transaction. + // todo: fix name discrepency (mixed up processing and pending in my wording) + evt, evtTopic, err := order.PrepareOrderPendingEvent(orderObj) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeService, "failed to create event", err) + } + + _, err = tx.Exec(ctx, "INSERT INTO event_outbox (aggregateid, aggregatetype, payload) VALUES ($1, $2, $3)", orderObj.Id, evtTopic, evt) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeExtService, "failed to insert event", err) + } + + // Commit the transaction + err = tx.Commit(ctx) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeExtService, "failed to commit transaction", err) + } + + return orderObj, nil +} + +// Set order status to rejected (from processing) +// Dispatch OrderRejectedEvent +func (c postgresController) RejectOrder(ctx context.Context, orderId string) (*pb.Order, error) { + // Begin a DB transaction + tx, err := c.cl.Begin(ctx) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeExtService, "failed to begin transaction", err) + } + defer tx.Rollback(ctx) + + // Execute update query + _, err = tx.Exec( + ctx, + "UPDATE orders SET status = $1 WHERE id = $2", + pb.OrderStatus_ORDER_STATUS_REJECTED, + orderId, + ) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeExtService, "failed to approve order", err) + } + + orderObj, err := c.getOrder(ctx, &tx, orderId) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeExtService, "failed to approve order", err) + } + + // Then add the event to the outbox table with the transaction. + evt, evtTopic, err := order.PrepareOrderRejectedEvent(orderObj) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeService, "failed to create event", err) + } + + _, err = tx.Exec(ctx, "INSERT INTO event_outbox (aggregateid, aggregatetype, payload) VALUES ($1, $2, $3)", orderObj.Id, evtTopic, evt) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeExtService, "failed to insert event", err) + } + + // Commit the transaction + err = tx.Commit(ctx) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeExtService, "failed to commit transaction", err) + } + + return orderObj, nil +} + +// Append shipment id to order +func (c postgresController) SetOrderShipmentId(ctx context.Context, orderId string, shippingId string) error { + // Execute update query + _, err := c.cl.Exec( + ctx, + "UPDATE orders SET shipment_id = $1 WHERE id = $2", + shippingId, + orderId, + ) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to approve order", err) + } + + return nil +} + +// Build and exec an insert statement for a map of order items +func (c postgresController) createOrderItems(ctx context.Context, tx pgx.Tx, orderId string, items map[string]int32) error { + // check there are items to add + if len(items) > 1 { + vals := [][]interface{}{} + for productId, quantity := range items { + vals = append( + vals, + goqu.Vals{orderId, productId, quantity}, + ) + } + + statement, args, err := goqu.Dialect("postgres").From( + "order_items", + ).Insert().Cols( + "order_id", + "product_id", + "quantity", + ).Vals( + vals..., + ).Prepared( + true, + ).ToSQL() + if err != nil { + return errors.WrapServiceError(errors.ErrCodeService, "failed to build SQL statement", err) + } + + // Execute the statement on the transaction + _, err = tx.Exec(ctx, statement, args...) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to add items to order", err) + } + } + + return nil +} + +func (c postgresController) getOrderItems(ctx context.Context, tx *pgx.Tx, orderId string) (*map[string]int32, error) { + // Determine if transaction is being used. + var rows pgx.Rows + var err error + if tx == nil { + rows, err = c.cl.Query(ctx, pgOrderItemsBaseQuery+" WHERE order_id=$1", orderId) + } else { + rows, err = (*tx).Query(ctx, pgOrderItemsBaseQuery+" WHERE order_id=$1", orderId) + } + + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeService, "query error whilst fetching order items", err) + } + + items := make(map[string]int32) + for rows.Next() { + var ( + itemId string + quantity int32 + ) + err := rows.Scan( + &itemId, + &quantity, + ) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeService, "failed to scan an order item", err) + } + + items[itemId] = quantity + } + + if rows.Err() != nil { + return nil, errors.WrapServiceError(errors.ErrCodeService, "error whilst scanning order item rows", rows.Err()) + } + + return &items, nil +} + +// Appends order items to an order object. +func (c postgresController) appendItemsToOrderObj(ctx context.Context, tx *pgx.Tx, orderObj *pb.Order) (*pb.Order, error) { + // Load the order items + orderItems, err := c.getOrderItems(ctx, tx, orderObj.Id) + if err != nil { + return nil, err + } + + // Add the order items to the order protobuf + orderObj.Items = *orderItems + + // Return the order + return orderObj, nil +} + +// Scan a postgres row to a protobuf order object. +func scanRowToOrder(row pgx.Row) (*pb.Order, error) { + var order pb.Order + + // Temporary variables that require conversion + var tmpCreatedAt pgtype.Timestamp + var tmpUpdatedAt pgtype.Timestamp + + err := row.Scan( + &order.Id, + &order.Status, + &order.CustomerId, + &order.ShippingId, + &order.TransactionId, + &tmpCreatedAt, + &tmpUpdatedAt, + ) + if err != nil { + if err == pgx.ErrNoRows { + return nil, errors.WrapServiceError(errors.ErrCodeNotFound, "order not found", err) + } else { + return nil, errors.WrapServiceError(errors.ErrCodeExtService, "something went wrong scanning order", err) + } + } + + // Convert the temporary variables + // + // This includes converting postgres timestamps to unix format + if tmpCreatedAt.Valid { + order.CreatedAt = tmpCreatedAt.Time.Unix() + } else { + return nil, errors.NewServiceError(errors.ErrCodeUnknown, "failed to convert order (created_at) timestamp") + } + + if tmpUpdatedAt.Valid { + unixUpdated := tmpUpdatedAt.Time.Unix() + order.UpdatedAt = &unixUpdated + } + + return &order, nil +} diff --git a/internal/svc/order/event.go b/internal/svc/order/event.go new file mode 100644 index 0000000..5e2979c --- /dev/null +++ b/internal/svc/order/event.go @@ -0,0 +1,74 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package order + +import ( + "github.com/hexolan/stocklet/internal/pkg/messaging" + eventspb "github.com/hexolan/stocklet/internal/pkg/protogen/events/v1" + pb "github.com/hexolan/stocklet/internal/pkg/protogen/order/v1" +) + +func PrepareOrderCreatedEvent(order *pb.Order) ([]byte, string, error) { + topic := messaging.Order_State_Created_Topic + event := &eventspb.OrderCreatedEvent{ + Revision: 1, + + OrderId: order.Id, + CustomerId: order.CustomerId, + ItemQuantities: order.Items, + } + + return messaging.MarshalEvent(event, topic) +} + +func PrepareOrderPendingEvent(order *pb.Order) ([]byte, string, error) { + topic := messaging.Order_State_Pending_Topic + event := &eventspb.OrderPendingEvent{ + Revision: 1, + + OrderId: order.Id, + CustomerId: order.CustomerId, + ItemQuantities: order.Items, + } + + return messaging.MarshalEvent(event, topic) +} + +func PrepareOrderRejectedEvent(order *pb.Order) ([]byte, string, error) { + topic := messaging.Order_State_Rejected_Topic + event := &eventspb.OrderRejectedEvent{ + Revision: 1, + + OrderId: order.Id, + TransactionId: order.TransactionId, + ShippingId: order.ShippingId, + } + + return messaging.MarshalEvent(event, topic) +} + +func PrepareOrderApprovedEvent(order *pb.Order) ([]byte, string, error) { + topic := messaging.Order_State_Approved_Topic + event := &eventspb.OrderApprovedEvent{ + Revision: 1, + + OrderId: order.Id, + TransactionId: order.GetTransactionId(), + ShippingId: order.GetShippingId(), + } + + return messaging.MarshalEvent(event, topic) +} diff --git a/internal/svc/order/order.go b/internal/svc/order/order.go new file mode 100644 index 0000000..592c20d --- /dev/null +++ b/internal/svc/order/order.go @@ -0,0 +1,229 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package order + +import ( + "context" + + "github.com/bufbuild/protovalidate-go" + "github.com/rs/zerolog/log" + "google.golang.org/protobuf/types/known/emptypb" + + "github.com/hexolan/stocklet/internal/pkg/errors" + "github.com/hexolan/stocklet/internal/pkg/gwauth" + "github.com/hexolan/stocklet/internal/pkg/messaging" + commonpb "github.com/hexolan/stocklet/internal/pkg/protogen/common/v1" + eventpb "github.com/hexolan/stocklet/internal/pkg/protogen/events/v1" + pb "github.com/hexolan/stocklet/internal/pkg/protogen/order/v1" +) + +// Interface for the service +type OrderService struct { + pb.UnimplementedOrderServiceServer + + store StorageController + pbVal *protovalidate.Validator +} + +// Interface for database methods +// Flexibility for implementing seperate controllers for different databases (e.g. Postgres, MongoDB, etc) +type StorageController interface { + GetOrder(ctx context.Context, orderId string) (*pb.Order, error) + GetCustomerOrders(ctx context.Context, customerId string) ([]*pb.Order, error) + + CreateOrder(ctx context.Context, order *pb.Order) (*pb.Order, error) + ApproveOrder(ctx context.Context, orderId string, transactionId string) (*pb.Order, error) + ProcessOrder(ctx context.Context, orderId string, itemsPrice float32) (*pb.Order, error) + RejectOrder(ctx context.Context, orderId string) (*pb.Order, error) + SetOrderShipmentId(ctx context.Context, orderId string, shippingId string) error +} + +// Interface for event consumption +// Flexibility for seperate controllers for different messaging systems (e.g. Kafka, NATS, etc) +type ConsumerController interface { + messaging.ConsumerController + + Attach(svc pb.OrderServiceServer) +} + +// Create the order service +func NewOrderService(cfg *ServiceConfig, store StorageController) *OrderService { + // Initialise the protobuf validator + pbVal, err := protovalidate.New() + if err != nil { + log.Panic().Err(err).Msg("failed to initialise protobuf validator") + } + + // Initialise the service + return &OrderService{ + store: store, + pbVal: pbVal, + } +} + +func (svc OrderService) ServiceInfo(ctx context.Context, req *commonpb.ServiceInfoRequest) (*commonpb.ServiceInfoResponse, error) { + return &commonpb.ServiceInfoResponse{ + Name: "order", + Source: "https://github.com/hexolan/stocklet", + SourceLicense: "AGPL-3.0", + }, nil +} + +func (svc OrderService) ViewOrder(ctx context.Context, req *pb.ViewOrderRequest) (*pb.ViewOrderResponse, error) { + // Validate the request args + if err := svc.pbVal.Validate(req); err != nil { + // Provide the validation error to the user. + return nil, errors.NewServiceError(errors.ErrCodeInvalidArgument, "invalid request: "+err.Error()) + } + + // Get the order from the DB + order, err := svc.store.GetOrder(ctx, req.OrderId) + if err != nil { + return nil, err + } + + return &pb.ViewOrderResponse{Order: order}, nil +} + +func (svc OrderService) ViewOrders(ctx context.Context, req *pb.ViewOrdersRequest) (*pb.ViewOrdersResponse, error) { + // Validate the request args + if err := svc.pbVal.Validate(req); err != nil { + // provide validation err context to user + return nil, errors.NewServiceError(errors.ErrCodeInvalidArgument, "invalid request: "+err.Error()) + } + + // Get the orders from the storage controller + orders, err := svc.store.GetCustomerOrders(ctx, req.CustomerId) + if err != nil { + return nil, err + } + + return &pb.ViewOrdersResponse{Orders: orders}, nil +} + +func (svc OrderService) PlaceOrder(ctx context.Context, req *pb.PlaceOrderRequest) (*pb.PlaceOrderResponse, error) { + // If the request is through the gateway, then substitute req.CustomerId for current user + gatewayRequest, gwMd := gwauth.IsGatewayRequest(ctx) + if gatewayRequest { + // ensure user is authenticated + claims, err := gwauth.GetGatewayUser(gwMd) + if err != nil { + return nil, err + } + + req.CustomerId = claims.Subject + } + + // Validate the request args + if err := svc.pbVal.Validate(req); err != nil { + // provide validation err context to user + return nil, errors.NewServiceError(errors.ErrCodeInvalidArgument, "invalid request: "+err.Error()) + } + + // Create the order. + // + // This will initiate a SAGA process involving + // all the services required to create the order + order, err := svc.store.CreateOrder( + ctx, + &pb.Order{ + Status: pb.OrderStatus_ORDER_STATUS_PROCESSING, + Items: req.Cart, + CustomerId: req.CustomerId, + }, + ) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeUnknown, "failed to create order", err) + } + + // Return the pending order + return &pb.PlaceOrderResponse{Order: order}, nil +} + +func (svc OrderService) ProcessProductPriceQuoteEvent(ctx context.Context, req *eventpb.ProductPriceQuoteEvent) (*emptypb.Empty, error) { + if req.Type == eventpb.ProductPriceQuoteEvent_TYPE_AVALIABLE { + // Set order status to processing (from pending) + // Dispatch OrderProcessingEvent + _, err := svc.store.ProcessOrder(ctx, req.OrderId, req.TotalPrice) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeExtService, "failed to update in response to event", err) + } + + } else if req.Type == eventpb.ProductPriceQuoteEvent_TYPE_UNAVALIABLE { + // Set order status to rejected (from pending) + // Dispatch OrderRejectedEvent + _, err := svc.store.RejectOrder(ctx, req.OrderId) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeExtService, "failed to update in response to event", err) + } + } else { + return nil, errors.NewServiceError(errors.ErrCodeInvalidArgument, "invalid event type") + } + + return &emptypb.Empty{}, nil +} + +func (svc OrderService) ProcessStockReservationEvent(ctx context.Context, req *eventpb.StockReservationEvent) (*emptypb.Empty, error) { + if req.Type == eventpb.StockReservationEvent_TYPE_INSUFFICIENT_STOCK { + // Set order status to rejected (from processing) + // Dispatch OrderRejectedEvent + _, err := svc.store.RejectOrder(ctx, req.OrderId) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeExtService, "failed to update in response to event", err) + } + } + + return &emptypb.Empty{}, nil +} + +func (svc OrderService) ProcessShipmentAllocationEvent(ctx context.Context, req *eventpb.ShipmentAllocationEvent) (*emptypb.Empty, error) { + if req.Type == eventpb.ShipmentAllocationEvent_TYPE_FAILED { + // Set order status to rejected (from processing) + // Dispatch OrderRejectedEvent + _, err := svc.store.RejectOrder(ctx, req.OrderId) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeExtService, "failed to update in response to event", err) + } + } else if req.Type == eventpb.ShipmentAllocationEvent_TYPE_ALLOCATED { + // Append shipment id to order + err := svc.store.SetOrderShipmentId(ctx, req.OrderId, req.ShipmentId) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeExtService, "failed to update in response to event", err) + } + } + + return &emptypb.Empty{}, nil +} + +func (svc OrderService) ProcessPaymentProcessedEvent(ctx context.Context, req *eventpb.PaymentProcessedEvent) (*emptypb.Empty, error) { + if req.Type == eventpb.PaymentProcessedEvent_TYPE_SUCCESS { + // Set order status to approved (from processing) + // Dispatch OrderApprovedEvent + _, err := svc.store.ApproveOrder(ctx, req.OrderId, *req.TransactionId) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeExtService, "failed to update in response to event", err) + } + } else if req.Type == eventpb.PaymentProcessedEvent_TYPE_FAILED { + // Set order status to rejected (from processing) + // Dispatch OrderRejectedEvent + _, err := svc.store.RejectOrder(ctx, req.OrderId) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeExtService, "failed to update in response to event", err) + } + } + + return &emptypb.Empty{}, nil +} diff --git a/internal/svc/payment/api/gateway.go b/internal/svc/payment/api/gateway.go new file mode 100644 index 0000000..bdc1345 --- /dev/null +++ b/internal/svc/payment/api/gateway.go @@ -0,0 +1,39 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package api + +import ( + "context" + + "github.com/grpc-ecosystem/grpc-gateway/v2/runtime" + "github.com/rs/zerolog/log" + + pb "github.com/hexolan/stocklet/internal/pkg/protogen/payment/v1" + "github.com/hexolan/stocklet/internal/pkg/serve" + "github.com/hexolan/stocklet/internal/svc/payment" +) + +func PrepareGateway(cfg *payment.ServiceConfig) *runtime.ServeMux { + mux, clientOpts := serve.NewGatewayServeBase(&cfg.Shared) + + ctx := context.Background() + err := pb.RegisterPaymentServiceHandlerFromEndpoint(ctx, mux, serve.GetAddrToGrpc("localhost"), clientOpts) + if err != nil { + log.Panic().Err(err).Msg("failed to register endpoint for gateway") + } + + return mux +} diff --git a/internal/svc/payment/api/grpc.go b/internal/svc/payment/api/grpc.go new file mode 100644 index 0000000..eb9ea71 --- /dev/null +++ b/internal/svc/payment/api/grpc.go @@ -0,0 +1,30 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package api + +import ( + "google.golang.org/grpc" + + pb "github.com/hexolan/stocklet/internal/pkg/protogen/payment/v1" + "github.com/hexolan/stocklet/internal/pkg/serve" + "github.com/hexolan/stocklet/internal/svc/payment" +) + +func PrepareGrpc(cfg *payment.ServiceConfig, svc *payment.PaymentService) *grpc.Server { + svr := serve.NewGrpcServeBase(&cfg.Shared) + pb.RegisterPaymentServiceServer(svr, svc) + return svr +} diff --git a/internal/svc/payment/config.go b/internal/svc/payment/config.go new file mode 100644 index 0000000..6345b96 --- /dev/null +++ b/internal/svc/payment/config.go @@ -0,0 +1,42 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package payment + +import ( + "github.com/hexolan/stocklet/internal/pkg/config" +) + +// Order Service Configuration +type ServiceConfig struct { + // Core Configuration + Shared config.SharedConfig + + // Dynamically loaded configuration + Postgres config.PostgresConfig + Kafka config.KafkaConfig +} + +// load the base service configuration +func NewServiceConfig() (*ServiceConfig, error) { + cfg := ServiceConfig{} + + // Load the core configuration + if err := cfg.Shared.Load(); err != nil { + return nil, err + } + + return &cfg, nil +} diff --git a/internal/svc/payment/controller/kafka.go b/internal/svc/payment/controller/kafka.go new file mode 100644 index 0000000..cbb7583 --- /dev/null +++ b/internal/svc/payment/controller/kafka.go @@ -0,0 +1,140 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package controller + +import ( + "context" + + "github.com/rs/zerolog/log" + "github.com/twmb/franz-go/pkg/kgo" + "google.golang.org/protobuf/proto" + + "github.com/hexolan/stocklet/internal/pkg/messaging" + eventpb "github.com/hexolan/stocklet/internal/pkg/protogen/events/v1" + pb "github.com/hexolan/stocklet/internal/pkg/protogen/payment/v1" + "github.com/hexolan/stocklet/internal/svc/payment" +) + +type kafkaController struct { + cl *kgo.Client + + svc pb.PaymentServiceServer + + ctx context.Context + ctxCancel context.CancelFunc +} + +func NewKafkaController(cl *kgo.Client) payment.ConsumerController { + // Create a cancellable context for the consumer + ctx, ctxCancel := context.WithCancel(context.Background()) + + // Ensure the required Kafka topics exist + err := messaging.EnsureKafkaTopics( + cl, + + messaging.Payment_Balance_Created_Topic, + messaging.Payment_Balance_Credited_Topic, + messaging.Payment_Balance_Debited_Topic, + messaging.Payment_Balance_Closed_Topic, + messaging.Payment_Transaction_Created_Topic, + messaging.Payment_Transaction_Reversed_Topic, + messaging.Payment_Processing_Topic, + + messaging.User_State_Created_Topic, + + messaging.Shipping_Shipment_Allocation_Topic, + ) + if err != nil { + log.Warn().Err(err).Msg("kafka: raised attempting to ensure svc topics") + } + + // Add the consumption topics + cl.AddConsumeTopics( + messaging.User_State_Created_Topic, + messaging.Shipping_Shipment_Allocation_Topic, + ) + + return &kafkaController{cl: cl, ctx: ctx, ctxCancel: ctxCancel} +} + +func (c *kafkaController) Attach(svc pb.PaymentServiceServer) { + c.svc = svc +} + +func (c *kafkaController) Start() { + if c.svc == nil { + log.Panic().Msg("consumer: no service interface attached") + } + + for { + fetches := c.cl.PollFetches(c.ctx) + if errs := fetches.Errors(); len(errs) > 0 { + log.Panic().Any("kafka-errs", errs).Msg("consumer: unrecoverable kafka errors") + } + + fetches.EachTopic(func(ft kgo.FetchTopic) { + switch ft.Topic { + case messaging.User_State_Created_Topic: + c.consumeUserCreatedEventTopic(ft) + case messaging.Shipping_Shipment_Allocation_Topic: + c.consumeShipmentAllocationEventTopic(ft) + default: + log.Warn().Str("topic", ft.Topic).Msg("consumer: recieved records from unexpected topic") + } + }) + } +} + +func (c *kafkaController) Stop() { + // Cancel the consumer context + c.ctxCancel() +} + +func (c *kafkaController) consumeUserCreatedEventTopic(ft kgo.FetchTopic) { + log.Info().Str("topic", ft.Topic).Msg("consumer: recieved records from topic") + + // Process each message from the topic + ft.EachRecord(func(record *kgo.Record) { + // Unmarshal the event + var event eventpb.UserCreatedEvent + err := proto.Unmarshal(record.Value, &event) + if err != nil { + log.Panic().Err(err).Msg("consumer: failed to unmarshal event") + } + + // Process the event + ctx := context.Background() + c.svc.ProcessUserCreatedEvent(ctx, &event) + }) +} + +func (c *kafkaController) consumeShipmentAllocationEventTopic(ft kgo.FetchTopic) { + log.Info().Str("topic", ft.Topic).Msg("consumer: recieved records from topic") + + // Process each message from the topic + ft.EachRecord(func(record *kgo.Record) { + // Unmarshal the event + var event eventpb.ShipmentAllocationEvent + err := proto.Unmarshal(record.Value, &event) + if err != nil { + log.Panic().Err(err).Msg("consumer: failed to unmarshal event") + } + + // Process the event + ctx := context.Background() + c.svc.ProcessShipmentAllocationEvent(ctx, &event) + }) +} diff --git a/internal/svc/payment/controller/postgres.go b/internal/svc/payment/controller/postgres.go new file mode 100644 index 0000000..55d97fb --- /dev/null +++ b/internal/svc/payment/controller/postgres.go @@ -0,0 +1,458 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package controller + +import ( + "context" + "strings" + + "github.com/jackc/pgx/v5" + "github.com/jackc/pgx/v5/pgtype" + "github.com/jackc/pgx/v5/pgxpool" + + "github.com/hexolan/stocklet/internal/pkg/errors" + pb "github.com/hexolan/stocklet/internal/pkg/protogen/payment/v1" + "github.com/hexolan/stocklet/internal/svc/payment" +) + +const ( + pgTransactionBaseQuery string = "SELECT id, order_id, customer_id, amount, reversed_at, processed_at FROM transactions" + pgCustomerBalanceBaseQuery string = "SELECT customer_id, balance FROM customer_balances" +) + +type postgresController struct { + cl *pgxpool.Pool +} + +func NewPostgresController(cl *pgxpool.Pool) payment.StorageController { + return postgresController{cl: cl} +} + +func (c postgresController) GetBalance(ctx context.Context, customerId string) (*pb.CustomerBalance, error) { + return c.getBalance(ctx, nil, customerId) +} + +func (c postgresController) getBalance(ctx context.Context, tx *pgx.Tx, customerId string) (*pb.CustomerBalance, error) { + // Determine if a db transaction is being used + var row pgx.Row + const query = pgCustomerBalanceBaseQuery + " WHERE customer_id=$1" + if tx == nil { + row = c.cl.QueryRow(ctx, query, customerId) + } else { + row = (*tx).QueryRow(ctx, query, customerId) + } + + // Scan row to protobuf obj + balance, err := scanRowToCustomerBalance(row) + if err != nil { + return nil, err + } + + return balance, nil +} + +func (c postgresController) GetTransaction(ctx context.Context, transactionId string) (*pb.Transaction, error) { + return c.getTransaction(ctx, nil, transactionId) +} + +func (c postgresController) getTransaction(ctx context.Context, tx *pgx.Tx, transactionId string) (*pb.Transaction, error) { + // Determine if a db transaction is being used + var row pgx.Row + const query = pgTransactionBaseQuery + " WHERE id=$1" + if tx == nil { + row = c.cl.QueryRow(ctx, query, transactionId) + } else { + row = (*tx).QueryRow(ctx, query, transactionId) + } + + // Scan row to protobuf obj + transaction, err := scanRowToTransaction(row) + if err != nil { + return nil, err + } + + return transaction, nil +} + +func (c postgresController) CreateBalance(ctx context.Context, customerId string) error { + // Begin a DB transaction + tx, err := c.cl.Begin(ctx) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to begin transaction", err) + } + defer tx.Rollback(ctx) + + _, err = tx.Exec( + ctx, + "INSERT INTO customer_balances (customer_id, balance) VALUES ($1, $2)", + customerId, + 0.00, + ) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to create balance", err) + } + + // Add the event to the outbox table with the transaction + evt, evtTopic, err := payment.PrepareBalanceCreatedEvent(&pb.CustomerBalance{CustomerId: customerId, Balance: 0.00}) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeService, "failed to create event", err) + } + + _, err = tx.Exec(ctx, "INSERT INTO event_outbox (aggregateid, aggregatetype, payload) VALUES ($1, $2, $3)", customerId, evtTopic, evt) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to insert event", err) + } + + // Commit the transaction + err = tx.Commit(ctx) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to commit transaction", err) + } + + return nil +} + +func (c postgresController) CreditBalance(ctx context.Context, customerId string, amount float32) error { + // Begin a DB transaction + tx, err := c.cl.Begin(ctx) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to begin transaction", err) + } + defer tx.Rollback(ctx) + + // Add to balance + _, err = tx.Exec( + ctx, + "UPDATE customer_balances SET balance = balance + $1 WHERE customer_id=$2", + amount, + customerId, + ) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to update balance", err) + } + + // Get updated balance + balance, err := c.getBalance(ctx, &tx, customerId) + if err != nil { + return err + } + + // Add the event to the outbox table with the transaction + evt, evtTopic, err := payment.PrepareBalanceCreditedEvent( + balance.CustomerId, + amount, + balance.Balance, + ) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeService, "failed to create event", err) + } + + _, err = tx.Exec(ctx, "INSERT INTO event_outbox (aggregateid, aggregatetype, payload) VALUES ($1, $2, $3)", balance.CustomerId, evtTopic, evt) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to insert event", err) + } + + // Commit the transaction + err = tx.Commit(ctx) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to commit transaction", err) + } + + return nil +} + +func (c postgresController) DebitBalance(ctx context.Context, customerId string, amount float32, orderId *string) (*pb.Transaction, error) { + return c.debitBalance(ctx, nil, customerId, amount, orderId) +} + +func (c postgresController) debitBalance(ctx context.Context, tx *pgx.Tx, customerId string, amount float32, orderId *string) (*pb.Transaction, error) { + // Determine if a transaction has already been provided + var ( + funcTx pgx.Tx + err error + ) + if tx != nil { + funcTx = *tx + } else { + funcTx, err = c.cl.Begin(ctx) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeExtService, "failed to begin transaction", err) + } + defer funcTx.Rollback(ctx) + } + + // Subtract from balance + _, err = funcTx.Exec( + ctx, + "UPDATE customer_balances SET balance = balance - $1 WHERE customer_id=$2", + amount, + customerId, + ) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeExtService, "failed to update balance", err) + } + + // Get updated balance + balance, err := c.getBalance(ctx, &funcTx, customerId) + if err != nil { + return nil, err + } + + // Ensure that the balance is not negative + if balance.Balance < 0.00 { + return nil, errors.NewServiceError(errors.ErrCodeInvalidArgument, "insufficient balance") + } + + // Add the balance event to the outbox table with the transaction + evt, evtTopic, err := payment.PrepareBalanceDebitedEvent( + balance.CustomerId, + amount, + balance.Balance, + ) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeService, "failed to create event", err) + } + + _, err = funcTx.Exec(ctx, "INSERT INTO event_outbox (aggregateid, aggregatetype, payload) VALUES ($1, $2, $3)", balance.CustomerId, evtTopic, evt) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeExtService, "failed to insert event", err) + } + + // Create a payment transaction record + transaction, err := c.createTransaction(ctx, &funcTx, orderId, customerId, amount) + if err != nil { + return nil, err + } + + // Commit the transaction (if created in this func) + if tx == nil { + err = funcTx.Commit(ctx) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeExtService, "failed to commit transaction", err) + } + } + + return transaction, nil +} + +func (c postgresController) CloseBalance(ctx context.Context, customerId string) error { + // Begin a DB transaction + tx, err := c.cl.Begin(ctx) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to begin transaction", err) + } + defer tx.Rollback(ctx) + + // Get current balance + balance, err := c.getBalance(ctx, &tx, customerId) + if err != nil { + return err + } + + // Delete balance + _, err = tx.Exec(ctx, "DELETE FROM customer_balances WHERE customer_id=$1", customerId) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to delete balance", err) + } + + // Add the event to the outbox table with the transaction + evt, evtTopic, err := payment.PrepareBalanceClosedEvent(balance) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeService, "failed to create event", err) + } + + _, err = tx.Exec(ctx, "INSERT INTO event_outbox (aggregateid, aggregatetype, payload) VALUES ($1, $2, $3)", balance.CustomerId, evtTopic, evt) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to insert event", err) + } + + // Commit the transaction + err = tx.Commit(ctx) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to commit transaction", err) + } + + return nil +} + +func (c postgresController) PaymentForOrder(ctx context.Context, orderId string, customerId string, amount float32) error { + // Begin a DB transaction + tx, err := c.cl.Begin(ctx) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to begin transaction", err) + } + defer tx.Rollback(ctx) + + // Attempt to debit balance for the order + transaction, err := c.debitBalance(ctx, &tx, customerId, amount, &orderId) + if err != nil { + // check that error is not a result of insufficient balance + // - or the customer not having a balance + errText := err.Error() + if errText != "insufficient balance" && !strings.HasPrefix(errText, "failed to update balance") { + return err + } + } + + // Prepare response event + var ( + evt []byte + evtTopic string + ) + if transaction != nil { + // Succesful + evt, evtTopic, err = payment.PreparePaymentProcessedEvent_Success(transaction) + } else { + // Failure + // - result of insufficient/non-existent balance + evt, evtTopic, err = payment.PreparePaymentProcessedEvent_Failure(orderId, customerId, amount) + } + + // Ensure the event was prepared succesfully + if err != nil { + return errors.WrapServiceError(errors.ErrCodeService, "failed to create event", err) + } + + // Add the event to the outbox table + _, err = tx.Exec(ctx, "INSERT INTO event_outbox (aggregateid, aggregatetype, payload) VALUES ($1, $2, $3)", orderId, evtTopic, evt) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to insert event", err) + } + + // Commit the transaction + err = tx.Commit(ctx) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to commit transaction", err) + } + + return nil +} + +func (c postgresController) createTransaction(ctx context.Context, tx *pgx.Tx, orderId *string, customerId string, amount float32) (*pb.Transaction, error) { + // Determine if a transaction has already been provided + var ( + funcTx pgx.Tx + err error + ) + if tx != nil { + funcTx = *tx + } else { + funcTx, err = c.cl.Begin(ctx) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeExtService, "failed to begin transaction", err) + } + defer funcTx.Rollback(ctx) + } + + // Insert the transaction + var transactionId string + err = funcTx.QueryRow( + ctx, + "INSERT INTO transactions (order_id, customer_id, amount) VALUES ($1, $2, $3) RETURNING id", + orderId, + customerId, + amount, + ).Scan(&transactionId) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeExtService, "failed to insert transaction", err) + } + + // Get the transaction obj + transaction, err := c.getTransaction(ctx, &funcTx, transactionId) + if err != nil { + return nil, err + } + + // Add the event to the outbox table with the transaction + evt, evtTopic, err := payment.PrepareTransactionLoggedEvent(transaction) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeService, "failed to create event", err) + } + + _, err = funcTx.Exec(ctx, "INSERT INTO event_outbox (aggregateid, aggregatetype, payload) VALUES ($1, $2, $3)", transaction.Id, evtTopic, evt) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeExtService, "failed to insert event", err) + } + + // Commit the transaction (if created in this func) + if tx == nil { + err = funcTx.Commit(ctx) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeExtService, "failed to commit transaction", err) + } + } + + return transaction, nil +} + +// Scan a postgres row to a protobuf object +func scanRowToTransaction(row pgx.Row) (*pb.Transaction, error) { + var transaction pb.Transaction + + // Temporary variables that require conversion + var tmpProcessedAt pgtype.Timestamp + var tmpReversedAt pgtype.Timestamp + + err := row.Scan( + &transaction.Id, + &transaction.OrderId, + &transaction.CustomerId, + &transaction.Amount, + &tmpReversedAt, + &tmpProcessedAt, + ) + if err != nil { + if err == pgx.ErrNoRows { + return nil, errors.WrapServiceError(errors.ErrCodeNotFound, "transaction not found", err) + } else { + return nil, errors.WrapServiceError(errors.ErrCodeExtService, "failed to scan object from database", err) + } + } + + // Convert the temporary variables + // - converting postgres timestamps to unix format + if tmpProcessedAt.Valid { + transaction.ProcessedAt = tmpProcessedAt.Time.Unix() + } else { + return nil, errors.NewServiceError(errors.ErrCodeUnknown, "failed to scan object from database (timestamp conversion)") + } + + if tmpReversedAt.Valid { + unixReversed := tmpReversedAt.Time.Unix() + transaction.ReversedAt = &unixReversed + } + + return &transaction, nil +} + +// Scan a postgres row to a protobuf object +func scanRowToCustomerBalance(row pgx.Row) (*pb.CustomerBalance, error) { + var balance pb.CustomerBalance + + err := row.Scan( + &balance.CustomerId, + &balance.Balance, + ) + if err != nil { + if err == pgx.ErrNoRows { + return nil, errors.WrapServiceError(errors.ErrCodeNotFound, "balance not found", err) + } else { + return nil, errors.WrapServiceError(errors.ErrCodeExtService, "failed to scan object from database", err) + } + } + + return &balance, nil +} diff --git a/internal/svc/payment/event.go b/internal/svc/payment/event.go new file mode 100644 index 0000000..b6ae88b --- /dev/null +++ b/internal/svc/payment/event.go @@ -0,0 +1,129 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package payment + +import ( + "github.com/hexolan/stocklet/internal/pkg/messaging" + eventspb "github.com/hexolan/stocklet/internal/pkg/protogen/events/v1" + pb "github.com/hexolan/stocklet/internal/pkg/protogen/payment/v1" +) + +func PrepareBalanceCreatedEvent(bal *pb.CustomerBalance) ([]byte, string, error) { + topic := messaging.Payment_Balance_Created_Topic + event := &eventspb.BalanceCreatedEvent{ + Revision: 1, + + CustomerId: bal.CustomerId, + Balance: bal.Balance, + } + + return messaging.MarshalEvent(event, topic) +} + +func PrepareBalanceCreditedEvent(customerId string, amount float32, newBalance float32) ([]byte, string, error) { + topic := messaging.Payment_Balance_Credited_Topic + event := &eventspb.BalanceCreditedEvent{ + Revision: 1, + + CustomerId: customerId, + Amount: amount, + NewBalance: newBalance, + } + + return messaging.MarshalEvent(event, topic) +} + +func PrepareBalanceDebitedEvent(customerId string, amount float32, newBalance float32) ([]byte, string, error) { + topic := messaging.Payment_Balance_Debited_Topic + event := &eventspb.BalanceDebitedEvent{ + Revision: 1, + + CustomerId: customerId, + Amount: amount, + NewBalance: newBalance, + } + + return messaging.MarshalEvent(event, topic) +} + +func PrepareBalanceClosedEvent(bal *pb.CustomerBalance) ([]byte, string, error) { + topic := messaging.Payment_Balance_Closed_Topic + event := &eventspb.BalanceClosedEvent{ + Revision: 1, + + CustomerId: bal.CustomerId, + Balance: bal.Balance, + } + + return messaging.MarshalEvent(event, topic) +} + +func PrepareTransactionLoggedEvent(transaction *pb.Transaction) ([]byte, string, error) { + topic := messaging.Payment_Transaction_Created_Topic + event := &eventspb.TransactionLoggedEvent{ + Revision: 1, + + TransactionId: transaction.Id, + Amount: transaction.Amount, + OrderId: transaction.OrderId, + CustomerId: transaction.CustomerId, + } + + return messaging.MarshalEvent(event, topic) +} + +func PrepareTransactionReversedEvent(transaction *pb.Transaction) ([]byte, string, error) { + topic := messaging.Payment_Transaction_Reversed_Topic + event := &eventspb.TransactionReversedEvent{ + Revision: 1, + + TransactionId: transaction.Id, + Amount: transaction.Amount, + OrderId: transaction.OrderId, + CustomerId: transaction.CustomerId, + } + + return messaging.MarshalEvent(event, topic) +} + +func PreparePaymentProcessedEvent_Success(transaction *pb.Transaction) ([]byte, string, error) { + topic := messaging.Payment_Processing_Topic + event := &eventspb.PaymentProcessedEvent{ + Revision: 1, + + Type: eventspb.PaymentProcessedEvent_TYPE_SUCCESS, + OrderId: transaction.OrderId, + CustomerId: transaction.CustomerId, + Amount: transaction.Amount, + TransactionId: &transaction.Id, + } + + return messaging.MarshalEvent(event, topic) +} + +func PreparePaymentProcessedEvent_Failure(orderId string, customerId string, amount float32) ([]byte, string, error) { + topic := messaging.Payment_Processing_Topic + event := &eventspb.PaymentProcessedEvent{ + Revision: 1, + + Type: eventspb.PaymentProcessedEvent_TYPE_FAILED, + OrderId: orderId, + CustomerId: customerId, + Amount: amount, + } + + return messaging.MarshalEvent(event, topic) +} diff --git a/internal/svc/payment/payment.go b/internal/svc/payment/payment.go new file mode 100644 index 0000000..9f3a12f --- /dev/null +++ b/internal/svc/payment/payment.go @@ -0,0 +1,132 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package payment + +import ( + "context" + + "github.com/bufbuild/protovalidate-go" + "github.com/rs/zerolog/log" + "google.golang.org/protobuf/types/known/emptypb" + + "github.com/hexolan/stocklet/internal/pkg/errors" + "github.com/hexolan/stocklet/internal/pkg/messaging" + commonpb "github.com/hexolan/stocklet/internal/pkg/protogen/common/v1" + eventpb "github.com/hexolan/stocklet/internal/pkg/protogen/events/v1" + pb "github.com/hexolan/stocklet/internal/pkg/protogen/payment/v1" +) + +// Interface for the service +type PaymentService struct { + pb.UnimplementedPaymentServiceServer + + store StorageController + pbVal *protovalidate.Validator +} + +// Interface for database methods +// Flexibility for implementing seperate controllers for different databases (e.g. Postgres, MongoDB, etc) +type StorageController interface { + GetBalance(ctx context.Context, customerId string) (*pb.CustomerBalance, error) + GetTransaction(ctx context.Context, transactionId string) (*pb.Transaction, error) + + CreateBalance(ctx context.Context, customerId string) error + CreditBalance(ctx context.Context, customerId string, amount float32) error + DebitBalance(ctx context.Context, customerId string, amount float32, orderId *string) (*pb.Transaction, error) + CloseBalance(ctx context.Context, customerId string) error + + PaymentForOrder(ctx context.Context, orderId string, customerId string, amount float32) error +} + +// Interface for event consumption +// Flexibility for seperate controllers for different messaging systems (e.g. Kafka, NATS, etc) +type ConsumerController interface { + messaging.ConsumerController + + Attach(svc pb.PaymentServiceServer) +} + +// Create the payment service +func NewPaymentService(cfg *ServiceConfig, store StorageController) *PaymentService { + // Initialise the protobuf validator + pbVal, err := protovalidate.New() + if err != nil { + log.Panic().Err(err).Msg("failed to initialise protobuf validator") + } + + // Initialise the service + return &PaymentService{ + store: store, + pbVal: pbVal, + } +} + +func (svc PaymentService) ServiceInfo(ctx context.Context, req *commonpb.ServiceInfoRequest) (*commonpb.ServiceInfoResponse, error) { + return &commonpb.ServiceInfoResponse{ + Name: "payment", + Source: "https://github.com/hexolan/stocklet", + SourceLicense: "AGPL-3.0", + }, nil +} + +func (svc PaymentService) ViewTransaction(ctx context.Context, req *pb.ViewTransactionRequest) (*pb.ViewTransactionResponse, error) { + // Attempt to get the transaction from the db + transaction, err := svc.store.GetTransaction(ctx, req.TransactionId) + if err != nil { + return nil, err + } + + return &pb.ViewTransactionResponse{Transaction: transaction}, nil +} + +func (svc PaymentService) ViewBalance(ctx context.Context, req *pb.ViewBalanceRequest) (*pb.ViewBalanceResponse, error) { + // todo: permission checking + + // Attempt to get the balance from the db + balance, err := svc.store.GetBalance(ctx, req.CustomerId) + if err != nil { + return nil, err + } + + return &pb.ViewBalanceResponse{Balance: balance}, nil +} + +func (svc PaymentService) ProcessUserCreatedEvent(ctx context.Context, req *eventpb.UserCreatedEvent) (*emptypb.Empty, error) { + err := svc.store.CreateBalance(ctx, req.UserId) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeExtService, "error processing event", err) + } + + return &emptypb.Empty{}, nil +} + +func (svc PaymentService) ProcessUserDeletedEvent(ctx context.Context, req *eventpb.UserDeletedEvent) (*emptypb.Empty, error) { + err := svc.store.CloseBalance(ctx, req.UserId) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeExtService, "error processing event", err) + } + + return &emptypb.Empty{}, nil +} + +func (svc PaymentService) ProcessShipmentAllocationEvent(ctx context.Context, req *eventpb.ShipmentAllocationEvent) (*emptypb.Empty, error) { + err := svc.store.PaymentForOrder(ctx, req.OrderId, req.OrderMetadata.CustomerId, req.OrderMetadata.TotalPrice) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeExtService, "error processing event", err) + } + + return &emptypb.Empty{}, nil +} diff --git a/internal/svc/product/api/gateway.go b/internal/svc/product/api/gateway.go new file mode 100644 index 0000000..987bfa0 --- /dev/null +++ b/internal/svc/product/api/gateway.go @@ -0,0 +1,39 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package api + +import ( + "context" + + "github.com/grpc-ecosystem/grpc-gateway/v2/runtime" + "github.com/rs/zerolog/log" + + pb "github.com/hexolan/stocklet/internal/pkg/protogen/product/v1" + "github.com/hexolan/stocklet/internal/pkg/serve" + "github.com/hexolan/stocklet/internal/svc/product" +) + +func PrepareGateway(cfg *product.ServiceConfig) *runtime.ServeMux { + mux, clientOpts := serve.NewGatewayServeBase(&cfg.Shared) + + ctx := context.Background() + err := pb.RegisterProductServiceHandlerFromEndpoint(ctx, mux, serve.GetAddrToGrpc("localhost"), clientOpts) + if err != nil { + log.Panic().Err(err).Msg("failed to register endpoint for gateway") + } + + return mux +} diff --git a/internal/svc/product/api/grpc.go b/internal/svc/product/api/grpc.go new file mode 100644 index 0000000..9d5afd5 --- /dev/null +++ b/internal/svc/product/api/grpc.go @@ -0,0 +1,30 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package api + +import ( + "google.golang.org/grpc" + + pb "github.com/hexolan/stocklet/internal/pkg/protogen/product/v1" + "github.com/hexolan/stocklet/internal/pkg/serve" + "github.com/hexolan/stocklet/internal/svc/product" +) + +func PrepareGrpc(cfg *product.ServiceConfig, svc *product.ProductService) *grpc.Server { + svr := serve.NewGrpcServeBase(&cfg.Shared) + pb.RegisterProductServiceServer(svr, svc) + return svr +} diff --git a/internal/svc/product/config.go b/internal/svc/product/config.go new file mode 100644 index 0000000..d6cec92 --- /dev/null +++ b/internal/svc/product/config.go @@ -0,0 +1,42 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package product + +import ( + "github.com/hexolan/stocklet/internal/pkg/config" +) + +// Order Service Configuration +type ServiceConfig struct { + // Core Configuration + Shared config.SharedConfig + + // Dynamically loaded configuration + Postgres config.PostgresConfig + Kafka config.KafkaConfig +} + +// load the base service configuration +func NewServiceConfig() (*ServiceConfig, error) { + cfg := ServiceConfig{} + + // Load the core configuration + if err := cfg.Shared.Load(); err != nil { + return nil, err + } + + return &cfg, nil +} diff --git a/internal/svc/product/controller/kafka.go b/internal/svc/product/controller/kafka.go new file mode 100644 index 0000000..5908be4 --- /dev/null +++ b/internal/svc/product/controller/kafka.go @@ -0,0 +1,114 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package controller + +import ( + "context" + + "github.com/rs/zerolog/log" + "github.com/twmb/franz-go/pkg/kgo" + "google.golang.org/protobuf/proto" + + "github.com/hexolan/stocklet/internal/pkg/messaging" + eventpb "github.com/hexolan/stocklet/internal/pkg/protogen/events/v1" + pb "github.com/hexolan/stocklet/internal/pkg/protogen/product/v1" + "github.com/hexolan/stocklet/internal/svc/product" +) + +type kafkaController struct { + cl *kgo.Client + + svc pb.ProductServiceServer + + ctx context.Context + ctxCancel context.CancelFunc +} + +func NewKafkaController(cl *kgo.Client) product.ConsumerController { + // Create a cancellable context for the consumer + ctx, ctxCancel := context.WithCancel(context.Background()) + + // Ensure the required Kafka topics exist + err := messaging.EnsureKafkaTopics( + cl, + + messaging.Product_State_Created_Topic, + messaging.Product_State_Deleted_Topic, + messaging.Product_Attribute_Price_Topic, + messaging.Product_PriceQuotation_Topic, + + messaging.Order_State_Created_Topic, + ) + if err != nil { + log.Warn().Err(err).Msg("kafka: raised attempting to ensure svc topics") + } + + // Add the consumption topics + cl.AddConsumeTopics( + messaging.Order_State_Created_Topic, + ) + + return &kafkaController{cl: cl, ctx: ctx, ctxCancel: ctxCancel} +} + +func (c *kafkaController) Attach(svc pb.ProductServiceServer) { + c.svc = svc +} + +func (c *kafkaController) Start() { + if c.svc == nil { + log.Panic().Msg("consumer: no service interface attached") + } + + for { + fetches := c.cl.PollFetches(c.ctx) + if errs := fetches.Errors(); len(errs) > 0 { + log.Panic().Any("kafka-errs", errs).Msg("consumer: unrecoverable kafka errors") + } + + fetches.EachTopic(func(ft kgo.FetchTopic) { + switch ft.Topic { + case messaging.Order_State_Created_Topic: + c.consumeOrderCreatedEventTopic(ft) + default: + log.Warn().Str("topic", ft.Topic).Msg("consumer: recieved records from unexpected topic") + } + }) + } +} + +func (c *kafkaController) Stop() { + // Cancel the consumer context + c.ctxCancel() +} + +func (c *kafkaController) consumeOrderCreatedEventTopic(ft kgo.FetchTopic) { + log.Info().Str("topic", ft.Topic).Msg("consumer: recieved records from topic") + + // Process each message from the topic + ft.EachRecord(func(record *kgo.Record) { + // Unmarshal the event + var event eventpb.OrderCreatedEvent + err := proto.Unmarshal(record.Value, &event) + if err != nil { + log.Panic().Err(err).Msg("consumer: failed to unmarshal event") + } + + // Process the event + ctx := context.Background() + c.svc.ProcessOrderCreatedEvent(ctx, &event) + }) +} diff --git a/internal/svc/product/controller/postgres.go b/internal/svc/product/controller/postgres.go new file mode 100644 index 0000000..0541925 --- /dev/null +++ b/internal/svc/product/controller/postgres.go @@ -0,0 +1,294 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package controller + +import ( + "context" + "golang.org/x/exp/maps" + + "github.com/doug-martin/goqu/v9" + _ "github.com/doug-martin/goqu/v9/dialect/postgres" + "github.com/jackc/pgx/v5" + "github.com/jackc/pgx/v5/pgtype" + "github.com/jackc/pgx/v5/pgxpool" + + "github.com/hexolan/stocklet/internal/pkg/errors" + pb "github.com/hexolan/stocklet/internal/pkg/protogen/product/v1" + "github.com/hexolan/stocklet/internal/svc/product" +) + +const pgProductBaseQuery string = "SELECT id, name, description, price, created_at, updated_at FROM products" + +type postgresController struct { + cl *pgxpool.Pool +} + +func NewPostgresController(cl *pgxpool.Pool) product.StorageController { + return postgresController{cl: cl} +} + +func (c postgresController) GetProduct(ctx context.Context, productId string) (*pb.Product, error) { + return c.getProduct(ctx, nil, productId) +} + +func (c postgresController) getProduct(ctx context.Context, tx *pgx.Tx, productId string) (*pb.Product, error) { + // Determine if a db transaction is being used + var row pgx.Row + const query = pgProductBaseQuery + " WHERE id=$1" + if tx == nil { + row = c.cl.QueryRow(ctx, query, productId) + } else { + row = (*tx).QueryRow(ctx, query, productId) + } + + // Scan row to protobuf obj + product, err := scanRowToProduct(row) + if err != nil { + return nil, err + } + + return product, nil +} + +// todo: implementing pagination mechanism +func (c postgresController) GetProducts(ctx context.Context) ([]*pb.Product, error) { + rows, err := c.cl.Query(ctx, pgProductBaseQuery+" LIMIT 10") + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeService, "query error", err) + } + + products := []*pb.Product{} + for rows.Next() { + productObj, err := scanRowToProduct(rows) + if err != nil { + return nil, err + } + + products = append(products, productObj) + } + + if rows.Err() != nil { + return nil, errors.WrapServiceError(errors.ErrCodeService, "error whilst scanning rows", rows.Err()) + } + + return products, nil +} + +// Update a product price. +func (c postgresController) UpdateProductPrice(ctx context.Context, productId string, price float32) (*pb.Product, error) { + // Begin a DB transaction + tx, err := c.cl.Begin(ctx) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeExtService, "failed to begin transaction", err) + } + defer tx.Rollback(ctx) + + // Update product price + _, err = tx.Exec(ctx, "UPDATE products SET price=$1 WHERE id=$2", price, productId) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeExtService, "failed to update product price", err) + } + + // Get updated product + productObj, err := c.getProduct(ctx, &tx, productId) + if err != nil { + return nil, err + } + + // Add the event to the outbox table with the transaction + evt, evtTopic, err := product.PrepareProductPriceUpdatedEvent(productObj) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeService, "failed to create event", err) + } + + _, err = tx.Exec(ctx, "INSERT INTO event_outbox (aggregateid, aggregatetype, payload) VALUES ($1, $2, $3)", productObj.Id, evtTopic, evt) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeExtService, "failed to insert event", err) + } + + // Commit the transaction + err = tx.Commit(ctx) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeExtService, "failed to commit transaction", err) + } + + return productObj, nil +} + +// Delete a product by its specified id. +func (c postgresController) DeleteProduct(ctx context.Context, productId string) error { + // Begin a DB transaction + tx, err := c.cl.Begin(ctx) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to begin transaction", err) + } + defer tx.Rollback(ctx) + + // Get product + productObj, err := c.getProduct(ctx, &tx, productId) + if err != nil { + return err + } + + // Delete product + _, err = tx.Exec(ctx, "DELETE FROM products WHERE id=$1", productId) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to delete product", err) + } + + // Add the event to the outbox table with the transaction + evt, evtTopic, err := product.PrepareProductDeletedEvent(productObj) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeService, "failed to create event", err) + } + + _, err = tx.Exec(ctx, "INSERT INTO event_outbox (aggregateid, aggregatetype, payload) VALUES ($1, $2, $3)", productObj.Id, evtTopic, evt) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to insert event", err) + } + + // Commit the transaction + err = tx.Commit(ctx) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to commit transaction", err) + } + + return nil +} + +func (c postgresController) PriceOrderProducts(ctx context.Context, orderId string, customerId string, productQuantities map[string]int32) error { + // Begin a DB transaction + tx, err := c.cl.Begin(ctx) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to begin transaction", err) + } + defer tx.Rollback(ctx) + + // Get prices of all specified products (in productQuantities) + productIds := maps.Keys(productQuantities) + statement, args, err := goqu.Dialect("postgres").From("products").Select("id", "price").Where(goqu.C("id").In(productIds)).Prepared(true).ToSQL() + if err != nil { + return errors.WrapServiceError(errors.ErrCodeService, "failed to build statement", err) + } + + rows, err := tx.Query(ctx, statement, args...) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to fetch price quotes", err) + } + + var productPrices map[string]float32 + for rows.Next() { + var productId string + var productPrice float32 + err := rows.Scan(&productId, &productPrice) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeNotFound, "failed to fetch price quotes: error whilst scanning row", err) + } + + productPrices[productId] = productPrice + } + + if rows.Err() != nil { + return errors.WrapServiceError(errors.ErrCodeService, "failed to fetch price quotes: error whilst scanning rows", rows.Err()) + } + + // Calculate total price + // Also ensuring that all items in the itemQuantities have a fetched price + var totalPrice float32 + for productId, quantity := range productQuantities { + productPrice, ok := productPrices[productId] + if !ok { + // Prepare and dispatch failure product pricing event + evt, evtTopic, err := product.PrepareProductPriceQuoteEvent_Unavaliable(orderId) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeService, "failed to create event", err) + } + + _, err = c.cl.Exec(ctx, "INSERT INTO event_outbox (aggregateid, aggregatetype, payload) VALUES ($1, $2, $3)", orderId, evtTopic, evt) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to insert event", err) + } + + return nil + } + + // Add to total price + totalPrice += productPrice * float32(quantity) + } + + // Prepare and dispatch succesful product pricing event + evt, evtTopic, err := product.PrepareProductPriceQuoteEvent_Avaliable( + orderId, + productQuantities, + productPrices, + totalPrice, + ) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeService, "failed to create event", err) + } + + _, err = tx.Exec(ctx, "INSERT INTO event_outbox (aggregateid, aggregatetype, payload) VALUES ($1, $2, $3)", orderId, evtTopic, evt) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to insert event", err) + } + + // Commit the transaction + err = tx.Commit(ctx) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to commit transaction", err) + } + + return nil +} + +// Scan a postgres row to a protobuf object +func scanRowToProduct(row pgx.Row) (*pb.Product, error) { + var productObj pb.Product + + // Temporary variables that require conversion + var tmpCreatedAt pgtype.Timestamp + var tmpUpdatedAt pgtype.Timestamp + + err := row.Scan( + &productObj.Id, + &productObj.Name, + &productObj.Description, + &productObj.Price, + &tmpCreatedAt, + &tmpUpdatedAt, + ) + if err != nil { + if err == pgx.ErrNoRows { + return nil, errors.WrapServiceError(errors.ErrCodeNotFound, "product not found", err) + } else { + return nil, errors.WrapServiceError(errors.ErrCodeExtService, "failed to scan object from database", err) + } + } + + // convert postgres timestamps to unix format + if tmpCreatedAt.Valid { + productObj.CreatedAt = tmpCreatedAt.Time.Unix() + } else { + return nil, errors.NewServiceError(errors.ErrCodeUnknown, "failed to scan object from database (timestamp conversion)") + } + + if tmpUpdatedAt.Valid { + unixUpdated := tmpUpdatedAt.Time.Unix() + productObj.UpdatedAt = &unixUpdated + } + + return &productObj, nil +} diff --git a/internal/svc/product/event.go b/internal/svc/product/event.go new file mode 100644 index 0000000..0625155 --- /dev/null +++ b/internal/svc/product/event.go @@ -0,0 +1,86 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package product + +import ( + "github.com/hexolan/stocklet/internal/pkg/messaging" + eventspb "github.com/hexolan/stocklet/internal/pkg/protogen/events/v1" + pb "github.com/hexolan/stocklet/internal/pkg/protogen/product/v1" +) + +func PrepareProductCreatedEvent(product *pb.Product) ([]byte, string, error) { + topic := messaging.Product_State_Created_Topic + event := &eventspb.ProductCreatedEvent{ + Revision: 1, + + ProductId: product.Id, + Name: product.Name, + Description: product.Description, + Price: product.Price, + } + + return messaging.MarshalEvent(event, topic) +} + +func PrepareProductPriceUpdatedEvent(product *pb.Product) ([]byte, string, error) { + topic := messaging.Product_Attribute_Price_Topic + event := &eventspb.ProductPriceUpdatedEvent{ + Revision: 1, + + ProductId: product.Id, + Price: product.Price, + } + + return messaging.MarshalEvent(event, topic) +} + +func PrepareProductDeletedEvent(product *pb.Product) ([]byte, string, error) { + topic := messaging.Product_State_Deleted_Topic + event := &eventspb.ProductDeletedEvent{ + Revision: 1, + + ProductId: product.Id, + } + + return messaging.MarshalEvent(event, topic) +} + +func PrepareProductPriceQuoteEvent_Avaliable(orderId string, productQuantities map[string]int32, productPrices map[string]float32, totalPrice float32) ([]byte, string, error) { + topic := messaging.Product_PriceQuotation_Topic + event := &eventspb.ProductPriceQuoteEvent{ + Revision: 1, + + Type: eventspb.ProductPriceQuoteEvent_TYPE_AVALIABLE, + OrderId: orderId, + ProductQuantities: productQuantities, + ProductPrices: productPrices, + TotalPrice: totalPrice, + } + + return messaging.MarshalEvent(event, topic) +} + +func PrepareProductPriceQuoteEvent_Unavaliable(orderId string) ([]byte, string, error) { + topic := messaging.Product_PriceQuotation_Topic + event := &eventspb.ProductPriceQuoteEvent{ + Revision: 1, + + Type: eventspb.ProductPriceQuoteEvent_TYPE_UNAVALIABLE, + OrderId: orderId, + } + + return messaging.MarshalEvent(event, topic) +} diff --git a/internal/svc/product/product.go b/internal/svc/product/product.go new file mode 100644 index 0000000..d74cd64 --- /dev/null +++ b/internal/svc/product/product.go @@ -0,0 +1,116 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package product + +import ( + "context" + + "github.com/bufbuild/protovalidate-go" + "github.com/rs/zerolog/log" + "google.golang.org/protobuf/types/known/emptypb" + + "github.com/hexolan/stocklet/internal/pkg/errors" + "github.com/hexolan/stocklet/internal/pkg/messaging" + commonpb "github.com/hexolan/stocklet/internal/pkg/protogen/common/v1" + eventpb "github.com/hexolan/stocklet/internal/pkg/protogen/events/v1" + pb "github.com/hexolan/stocklet/internal/pkg/protogen/product/v1" +) + +// Interface for the service +type ProductService struct { + pb.UnimplementedProductServiceServer + + store StorageController + pbVal *protovalidate.Validator +} + +// Interface for database methods +// Flexibility for implementing seperate controllers for different databases (e.g. Postgres, MongoDB, etc) +type StorageController interface { + GetProduct(ctx context.Context, productId string) (*pb.Product, error) + GetProducts(ctx context.Context) ([]*pb.Product, error) + + UpdateProductPrice(ctx context.Context, productId string, price float32) (*pb.Product, error) + DeleteProduct(ctx context.Context, productId string) error + + PriceOrderProducts(ctx context.Context, orderId string, customerId string, productQuantities map[string]int32) error +} + +// Interface for event consumption +// Flexibility for seperate controllers for different messaging systems (e.g. Kafka, NATS, etc) +type ConsumerController interface { + messaging.ConsumerController + + Attach(svc pb.ProductServiceServer) +} + +// Create the product service +func NewProductService(cfg *ServiceConfig, store StorageController) *ProductService { + // Initialise the protobuf validator + pbVal, err := protovalidate.New() + if err != nil { + log.Panic().Err(err).Msg("failed to initialise protobuf validator") + } + + // Initialise the service + return &ProductService{ + store: store, + pbVal: pbVal, + } +} + +func (svc ProductService) ServiceInfo(ctx context.Context, req *commonpb.ServiceInfoRequest) (*commonpb.ServiceInfoResponse, error) { + return &commonpb.ServiceInfoResponse{ + Name: "product", + Source: "https://github.com/hexolan/stocklet", + SourceLicense: "AGPL-3.0", + }, nil +} + +func (svc ProductService) ViewProduct(ctx context.Context, req *pb.ViewProductRequest) (*pb.ViewProductResponse, error) { + // Validate the request args + if err := svc.pbVal.Validate(req); err != nil { + // Provide the validation error to the user. + return nil, errors.NewServiceError(errors.ErrCodeInvalidArgument, "invalid request: "+err.Error()) + } + + // Get product from DB + product, err := svc.store.GetProduct(ctx, req.Id) + if err != nil { + return nil, err + } + + return &pb.ViewProductResponse{Product: product}, nil +} + +func (svc ProductService) ViewProducts(ctx context.Context, req *pb.ViewProductsRequest) (*pb.ViewProductsResponse, error) { + // todo: pagination mechanism + products, err := svc.store.GetProducts(ctx) + if err != nil { + return nil, err + } + + return &pb.ViewProductsResponse{Products: products}, nil +} + +func (svc ProductService) ProcessOrderCreatedEvent(ctx context.Context, req *eventpb.OrderCreatedEvent) (*emptypb.Empty, error) { + err := svc.store.PriceOrderProducts(ctx, req.OrderId, req.CustomerId, req.ItemQuantities) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeExtService, "error processing event", err) + } + + return &emptypb.Empty{}, nil +} diff --git a/internal/svc/shipping/api/gateway.go b/internal/svc/shipping/api/gateway.go new file mode 100644 index 0000000..9d1e0bf --- /dev/null +++ b/internal/svc/shipping/api/gateway.go @@ -0,0 +1,39 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package api + +import ( + "context" + + "github.com/grpc-ecosystem/grpc-gateway/v2/runtime" + "github.com/rs/zerolog/log" + + pb "github.com/hexolan/stocklet/internal/pkg/protogen/shipping/v1" + "github.com/hexolan/stocklet/internal/pkg/serve" + "github.com/hexolan/stocklet/internal/svc/shipping" +) + +func PrepareGateway(cfg *shipping.ServiceConfig) *runtime.ServeMux { + mux, clientOpts := serve.NewGatewayServeBase(&cfg.Shared) + + ctx := context.Background() + err := pb.RegisterShippingServiceHandlerFromEndpoint(ctx, mux, serve.GetAddrToGrpc("localhost"), clientOpts) + if err != nil { + log.Panic().Err(err).Msg("failed to register endpoint for gateway") + } + + return mux +} diff --git a/internal/svc/shipping/api/grpc.go b/internal/svc/shipping/api/grpc.go new file mode 100644 index 0000000..1257727 --- /dev/null +++ b/internal/svc/shipping/api/grpc.go @@ -0,0 +1,30 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package api + +import ( + "google.golang.org/grpc" + + pb "github.com/hexolan/stocklet/internal/pkg/protogen/shipping/v1" + "github.com/hexolan/stocklet/internal/pkg/serve" + "github.com/hexolan/stocklet/internal/svc/shipping" +) + +func PrepareGrpc(cfg *shipping.ServiceConfig, svc *shipping.ShippingService) *grpc.Server { + svr := serve.NewGrpcServeBase(&cfg.Shared) + pb.RegisterShippingServiceServer(svr, svc) + return svr +} diff --git a/internal/svc/shipping/config.go b/internal/svc/shipping/config.go new file mode 100644 index 0000000..140f321 --- /dev/null +++ b/internal/svc/shipping/config.go @@ -0,0 +1,42 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package shipping + +import ( + "github.com/hexolan/stocklet/internal/pkg/config" +) + +// Order Service Configuration +type ServiceConfig struct { + // Core Configuration + Shared config.SharedConfig + + // Dynamically loaded configuration + Postgres config.PostgresConfig + Kafka config.KafkaConfig +} + +// load the base service configuration +func NewServiceConfig() (*ServiceConfig, error) { + cfg := ServiceConfig{} + + // Load the core configuration + if err := cfg.Shared.Load(); err != nil { + return nil, err + } + + return &cfg, nil +} diff --git a/internal/svc/shipping/controller/kafka.go b/internal/svc/shipping/controller/kafka.go new file mode 100644 index 0000000..144b42c --- /dev/null +++ b/internal/svc/shipping/controller/kafka.go @@ -0,0 +1,135 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package controller + +import ( + "context" + + "github.com/rs/zerolog/log" + "github.com/twmb/franz-go/pkg/kgo" + "google.golang.org/protobuf/proto" + + "github.com/hexolan/stocklet/internal/pkg/messaging" + eventpb "github.com/hexolan/stocklet/internal/pkg/protogen/events/v1" + pb "github.com/hexolan/stocklet/internal/pkg/protogen/shipping/v1" + "github.com/hexolan/stocklet/internal/svc/shipping" +) + +type kafkaController struct { + cl *kgo.Client + + svc pb.ShippingServiceServer + + ctx context.Context + ctxCancel context.CancelFunc +} + +func NewKafkaController(cl *kgo.Client) shipping.ConsumerController { + // Create a cancellable context for the consumer + ctx, ctxCancel := context.WithCancel(context.Background()) + + // Ensure the required Kafka topics exist + err := messaging.EnsureKafkaTopics( + cl, + + messaging.Shipping_Shipment_Allocation_Topic, + messaging.Shipping_Shipment_Dispatched_Topic, + + messaging.Warehouse_Reservation_Reserved_Topic, + + messaging.Payment_Processing_Topic, + ) + if err != nil { + log.Warn().Err(err).Msg("kafka: raised attempting to ensure svc topics") + } + + // Add the consumption topics + cl.AddConsumeTopics( + messaging.Warehouse_Reservation_Reserved_Topic, + messaging.Payment_Processing_Topic, + ) + + return &kafkaController{cl: cl, ctx: ctx, ctxCancel: ctxCancel} +} + +func (c *kafkaController) Attach(svc pb.ShippingServiceServer) { + c.svc = svc +} + +func (c *kafkaController) Start() { + if c.svc == nil { + log.Panic().Msg("consumer: no service interface attached") + } + + for { + fetches := c.cl.PollFetches(c.ctx) + if errs := fetches.Errors(); len(errs) > 0 { + log.Panic().Any("kafka-errs", errs).Msg("consumer: unrecoverable kafka errors") + } + + fetches.EachTopic(func(ft kgo.FetchTopic) { + switch ft.Topic { + case messaging.Warehouse_Reservation_Reserved_Topic: + c.consumeStockReservationEventTopic(ft) + case messaging.Payment_Processing_Topic: + c.consumePaymentProcessedEventTopic(ft) + default: + log.Warn().Str("topic", ft.Topic).Msg("consumer: recieved records from unexpected topic") + } + }) + } +} + +func (c *kafkaController) Stop() { + // Cancel the consumer context + c.ctxCancel() +} + +func (c *kafkaController) consumeStockReservationEventTopic(ft kgo.FetchTopic) { + log.Info().Str("topic", ft.Topic).Msg("consumer: recieved records from topic") + + // Process each message from the topic + ft.EachRecord(func(record *kgo.Record) { + // Unmarshal the event + var event eventpb.StockReservationEvent + err := proto.Unmarshal(record.Value, &event) + if err != nil { + log.Panic().Err(err).Msg("consumer: failed to unmarshal event") + } + + // Process the event + ctx := context.Background() + c.svc.ProcessStockReservationEvent(ctx, &event) + }) +} + +func (c *kafkaController) consumePaymentProcessedEventTopic(ft kgo.FetchTopic) { + log.Info().Str("topic", ft.Topic).Msg("consumer: recieved records from topic") + + // Process each message from the topic + ft.EachRecord(func(record *kgo.Record) { + // Unmarshal the event + var event eventpb.PaymentProcessedEvent + err := proto.Unmarshal(record.Value, &event) + if err != nil { + log.Panic().Err(err).Msg("consumer: failed to unmarshal event") + } + + // Process the event + ctx := context.Background() + c.svc.ProcessPaymentProcessedEvent(ctx, &event) + }) +} diff --git a/internal/svc/shipping/controller/postgres.go b/internal/svc/shipping/controller/postgres.go new file mode 100644 index 0000000..80129fb --- /dev/null +++ b/internal/svc/shipping/controller/postgres.go @@ -0,0 +1,256 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package controller + +import ( + "context" + + "github.com/doug-martin/goqu/v9" + _ "github.com/doug-martin/goqu/v9/dialect/postgres" + "github.com/jackc/pgx/v5" + "github.com/jackc/pgx/v5/pgtype" + "github.com/jackc/pgx/v5/pgxpool" + + "github.com/hexolan/stocklet/internal/pkg/errors" + pb "github.com/hexolan/stocklet/internal/pkg/protogen/shipping/v1" + "github.com/hexolan/stocklet/internal/svc/shipping" +) + +const ( + pgShipmentBaseQuery string = "SELECT id, order_id, dispatched, created_at FROM shipments" + pgShipmentItemsBaseQuery string = "SELECT shipment_id, product_id, quantity FROM shipment_items" +) + +type postgresController struct { + cl *pgxpool.Pool +} + +func NewPostgresController(cl *pgxpool.Pool) shipping.StorageController { + return postgresController{cl: cl} +} + +func (c postgresController) GetShipment(ctx context.Context, shipmentId string) (*pb.Shipment, error) { + return c.getShipment(ctx, nil, shipmentId) +} + +func (c postgresController) getShipment(ctx context.Context, tx *pgx.Tx, shipmentId string) (*pb.Shipment, error) { + // Determine if a db transaction is being used + var row pgx.Row + const query = pgShipmentBaseQuery + " WHERE id=$1" + if tx == nil { + row = c.cl.QueryRow(ctx, query, shipmentId) + } else { + row = (*tx).QueryRow(ctx, query, shipmentId) + } + + // Scan row to protobuf obj + shipment, err := scanRowToShipment(row) + if err != nil { + return nil, err + } + + return shipment, nil +} + +func (c postgresController) getShipmentByOrderId(ctx context.Context, tx *pgx.Tx, orderId string) (*pb.Shipment, error) { + // Determine if a db transaction is being used + var row pgx.Row + const query = pgShipmentBaseQuery + " WHERE order_id=$1" + if tx == nil { + row = c.cl.QueryRow(ctx, query, orderId) + } else { + row = (*tx).QueryRow(ctx, query, orderId) + } + + // Scan row to protobuf obj + shipment, err := scanRowToShipment(row) + if err != nil { + return nil, err + } + + return shipment, nil +} + +func (c postgresController) GetShipmentItems(ctx context.Context, shipmentId string) ([]*pb.ShipmentItem, error) { + return c.getShipmentItems(ctx, nil, shipmentId) +} + +func (c postgresController) getShipmentItems(ctx context.Context, tx *pgx.Tx, shipmentId string) ([]*pb.ShipmentItem, error) { + // Determine if transaction is being used + var rows pgx.Rows + var err error + if tx == nil { + rows, err = c.cl.Query(ctx, pgShipmentItemsBaseQuery+" WHERE shipment_id=$1", shipmentId) + } else { + rows, err = (*tx).Query(ctx, pgShipmentItemsBaseQuery+" WHERE shipment_id=$1", shipmentId) + } + + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeService, "query error whilst fetching items", err) + } + + shipmentItems := []*pb.ShipmentItem{} + for rows.Next() { + var shipmentItem pb.ShipmentItem + shipmentItem.ShipmentId = shipmentId + err := rows.Scan( + &shipmentItem.ProductId, + &shipmentItem.Quantity, + ) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeService, "failed to scan an order item", err) + } + + shipmentItems = append(shipmentItems, &shipmentItem) + } + + if rows.Err() != nil { + return nil, errors.WrapServiceError(errors.ErrCodeService, "error whilst scanning order item rows", rows.Err()) + } + + return shipmentItems, nil +} + +func (c postgresController) AllocateOrderShipment(ctx context.Context, orderId string, orderMetadata shipping.EventOrderMetadata, productQuantities map[string]int32) error { + // Begin a DB transaction + tx, err := c.cl.Begin(ctx) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to begin transaction", err) + } + defer tx.Rollback(ctx) + + // Create shipment + var shipmentId string + err = tx.QueryRow(ctx, "INSERT INTO shipments (order_id) VALUES ($1) RETURNING id", orderId).Scan(&shipmentId) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to create shipment", err) + } + + // Add shipment items + vals := [][]interface{}{} + for productId, quantity := range productQuantities { + vals = append( + vals, + goqu.Vals{shipmentId, productId, quantity}, + ) + } + + statement, args, err := goqu.Dialect("postgres").From("shipment_items").Insert().Cols("shipment_id", "product_id", "quantity").Vals(vals...).Prepared(true).ToSQL() + if err != nil { + return errors.WrapServiceError(errors.ErrCodeService, "failed to build statement", err) + } + + _, err = tx.Exec(ctx, statement, args...) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to add shipment items", err) + } + + // Prepare and append shipment allocated event to transaction + evt, evtTopic, err := shipping.PrepareShipmentAllocationEvent_Allocated(orderId, orderMetadata, shipmentId, productQuantities) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeService, "failed to create event", err) + } + + _, err = tx.Exec(ctx, "INSERT INTO event_outbox (aggregateid, aggregatetype, payload) VALUES ($1, $2, $3)", shipmentId, evtTopic, evt) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to insert event", err) + } + + // Commit the transaction + err = tx.Commit(ctx) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to commit transaction", err) + } + + return nil +} + +func (c postgresController) CancelOrderShipment(ctx context.Context, orderId string) error { + // Begin a DB transaction + tx, err := c.cl.Begin(ctx) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to begin transaction", err) + } + defer tx.Rollback(ctx) + + // Get the shipment + shipment, err := c.getShipmentByOrderId(ctx, &tx, orderId) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to fetch shipment info", err) + } + + // Get the shipment items + shipmentItems, err := c.getShipmentItems(ctx, &tx, shipment.Id) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to fetch shipment manifest", err) + } + + // Delete shipment + _, err = tx.Exec(ctx, "DELETE FROM shipments WHERE id=$1", shipment.Id) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to delete shipment", err) + } + + // Add the event to the outbox table with the transaction + evt, evtTopic, err := shipping.PrepareShipmentAllocationEvent_AllocationReleased(orderId, shipment.Id, shipmentItems) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeService, "failed to create event", err) + } + + _, err = tx.Exec(ctx, "INSERT INTO event_outbox (aggregateid, aggregatetype, payload) VALUES ($1, $2, $3)", shipment.Id, evtTopic, evt) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to insert event", err) + } + + // Commit the transaction + err = tx.Commit(ctx) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to commit transaction", err) + } + + return nil +} + +// Scan a postgres row to a protobuf object +func scanRowToShipment(row pgx.Row) (*pb.Shipment, error) { + var shipment pb.Shipment + + // Temporary variables that require conversion + var tmpCreatedAt pgtype.Timestamp + + err := row.Scan( + &shipment.Id, + &shipment.OrderId, + &shipment.Dispatched, + &tmpCreatedAt, + ) + if err != nil { + if err == pgx.ErrNoRows { + return nil, errors.WrapServiceError(errors.ErrCodeNotFound, "shipment not found", err) + } else { + return nil, errors.WrapServiceError(errors.ErrCodeExtService, "something went wrong scanning object", err) + } + } + + // convert postgres timestamps to unix format + if tmpCreatedAt.Valid { + shipment.CreatedAt = tmpCreatedAt.Time.Unix() + } else { + return nil, errors.NewServiceError(errors.ErrCodeUnknown, "something went wrong scanning object (timestamp conversion error)") + } + + return &shipment, nil +} diff --git a/internal/svc/shipping/event.go b/internal/svc/shipping/event.go new file mode 100644 index 0000000..94bded2 --- /dev/null +++ b/internal/svc/shipping/event.go @@ -0,0 +1,97 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package shipping + +import ( + "github.com/hexolan/stocklet/internal/pkg/messaging" + eventspb "github.com/hexolan/stocklet/internal/pkg/protogen/events/v1" + pb "github.com/hexolan/stocklet/internal/pkg/protogen/shipping/v1" +) + +type EventOrderMetadata struct { + CustomerId string + ItemsPrice float32 + TotalPrice float32 +} + +func PrepareShipmentAllocationEvent_Failed(orderId string, orderMetadata EventOrderMetadata, productQuantities map[string]int32) ([]byte, string, error) { + topic := messaging.Shipping_Shipment_Allocation_Topic + event := &eventspb.ShipmentAllocationEvent{ + Revision: 1, + + Type: eventspb.ShipmentAllocationEvent_TYPE_FAILED, + OrderId: orderId, + OrderMetadata: &eventspb.ShipmentAllocationEvent_OrderMetadata{ + CustomerId: orderMetadata.CustomerId, + ItemsPrice: orderMetadata.ItemsPrice, + TotalPrice: orderMetadata.TotalPrice, + }, + ProductQuantities: productQuantities, + } + + return messaging.MarshalEvent(event, topic) +} + +func PrepareShipmentAllocationEvent_Allocated(orderId string, orderMetadata EventOrderMetadata, shipmentId string, productQuantities map[string]int32) ([]byte, string, error) { + topic := messaging.Shipping_Shipment_Allocation_Topic + event := &eventspb.ShipmentAllocationEvent{ + Revision: 1, + + Type: eventspb.ShipmentAllocationEvent_TYPE_ALLOCATED, + OrderId: orderId, + OrderMetadata: &eventspb.ShipmentAllocationEvent_OrderMetadata{ + CustomerId: orderMetadata.CustomerId, + ItemsPrice: orderMetadata.ItemsPrice, + TotalPrice: orderMetadata.TotalPrice, + }, + ShipmentId: shipmentId, + ProductQuantities: productQuantities, + } + + return messaging.MarshalEvent(event, topic) +} + +func PrepareShipmentAllocationEvent_AllocationReleased(orderId string, shipmentId string, shipmentItems []*pb.ShipmentItem) ([]byte, string, error) { + productQuantities := make(map[string]int32) + for _, item := range shipmentItems { + productQuantities[item.ProductId] = item.Quantity + } + + topic := messaging.Shipping_Shipment_Allocation_Topic + event := &eventspb.ShipmentAllocationEvent{ + Revision: 1, + + Type: eventspb.ShipmentAllocationEvent_TYPE_ALLOCATION_RELEASED, + OrderId: orderId, + ShipmentId: shipmentId, + ProductQuantities: productQuantities, + } + + return messaging.MarshalEvent(event, topic) +} + +func PrepareShipmentDispatchedEvent(orderId string, shipmentId string, productQuantities map[string]int32) ([]byte, string, error) { + topic := messaging.Shipping_Shipment_Dispatched_Topic + event := &eventspb.ShipmentDispatchedEvent{ + Revision: 1, + + OrderId: orderId, + ShipmentId: shipmentId, + ProductQuantities: productQuantities, + } + + return messaging.MarshalEvent(event, topic) +} diff --git a/internal/svc/shipping/shipping.go b/internal/svc/shipping/shipping.go new file mode 100644 index 0000000..9db0c4a --- /dev/null +++ b/internal/svc/shipping/shipping.go @@ -0,0 +1,147 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package shipping + +import ( + "context" + + "github.com/bufbuild/protovalidate-go" + "github.com/rs/zerolog/log" + "google.golang.org/protobuf/types/known/emptypb" + + "github.com/hexolan/stocklet/internal/pkg/errors" + "github.com/hexolan/stocklet/internal/pkg/messaging" + commonpb "github.com/hexolan/stocklet/internal/pkg/protogen/common/v1" + eventpb "github.com/hexolan/stocklet/internal/pkg/protogen/events/v1" + pb "github.com/hexolan/stocklet/internal/pkg/protogen/shipping/v1" +) + +// Interface for the service +type ShippingService struct { + pb.UnimplementedShippingServiceServer + + store StorageController + pbVal *protovalidate.Validator +} + +// Interface for database methods +// Flexibility for implementing seperate controllers for different databases (e.g. Postgres, MongoDB, etc) +type StorageController interface { + GetShipment(ctx context.Context, shipmentId string) (*pb.Shipment, error) + GetShipmentItems(ctx context.Context, shipmentId string) ([]*pb.ShipmentItem, error) + + AllocateOrderShipment(ctx context.Context, orderId string, orderMetadata EventOrderMetadata, productQuantities map[string]int32) error + CancelOrderShipment(ctx context.Context, orderId string) error +} + +// Interface for event consumption +// Flexibility for seperate controllers for different messaging systems (e.g. Kafka, NATS, etc) +type ConsumerController interface { + messaging.ConsumerController + + Attach(svc pb.ShippingServiceServer) +} + +// Create the shipping service +func NewShippingService(cfg *ServiceConfig, store StorageController) *ShippingService { + // Initialise the protobuf validator + pbVal, err := protovalidate.New() + if err != nil { + log.Panic().Err(err).Msg("failed to initialise protobuf validator") + } + + // Initialise the service + return &ShippingService{ + store: store, + pbVal: pbVal, + } +} + +func (svc ShippingService) ServiceInfo(ctx context.Context, req *commonpb.ServiceInfoRequest) (*commonpb.ServiceInfoResponse, error) { + return &commonpb.ServiceInfoResponse{ + Name: "shipping", + Source: "https://github.com/hexolan/stocklet", + SourceLicense: "AGPL-3.0", + }, nil +} + +func (svc ShippingService) ViewShipment(ctx context.Context, req *pb.ViewShipmentRequest) (*pb.ViewShipmentResponse, error) { + // Validate the request args + if err := svc.pbVal.Validate(req); err != nil { + // Provide the validation error to the user. + return nil, errors.NewServiceError(errors.ErrCodeInvalidArgument, "invalid request: "+err.Error()) + } + + // todo: permission checking? + + // Get shipment from DB + shipment, err := svc.store.GetShipment(ctx, req.ShipmentId) + if err != nil { + return nil, err + } + + return &pb.ViewShipmentResponse{Shipment: shipment}, nil +} + +func (svc ShippingService) ViewShipmentManifest(ctx context.Context, req *pb.ViewShipmentManifestRequest) (*pb.ViewShipmentManifestResponse, error) { + // Validate the request args + if err := svc.pbVal.Validate(req); err != nil { + // Provide the validation error to the user. + return nil, errors.NewServiceError(errors.ErrCodeInvalidArgument, "invalid request: "+err.Error()) + } + + // todo: permission checking? + + shipmentItems, err := svc.store.GetShipmentItems(ctx, req.ShipmentId) + if err != nil { + return nil, err + } + + return &pb.ViewShipmentManifestResponse{Manifest: shipmentItems}, nil +} + +func (svc ShippingService) ProcessStockReservationEvent(ctx context.Context, req *eventpb.StockReservationEvent) (*emptypb.Empty, error) { + if req.Type == eventpb.StockReservationEvent_TYPE_STOCK_RESERVED { + err := svc.store.AllocateOrderShipment( + ctx, + req.OrderId, + EventOrderMetadata{ + CustomerId: req.OrderMetadata.CustomerId, + ItemsPrice: req.OrderMetadata.ItemsPrice, + TotalPrice: req.OrderMetadata.TotalPrice, + }, + req.ReservationStock, + ) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeExtService, "failed to update in response to event", err) + } + + } + + return &emptypb.Empty{}, nil +} + +func (svc ShippingService) ProcessPaymentProcessedEvent(ctx context.Context, req *eventpb.PaymentProcessedEvent) (*emptypb.Empty, error) { + if req.Type == eventpb.PaymentProcessedEvent_TYPE_FAILED { + err := svc.store.CancelOrderShipment(ctx, req.OrderId) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeExtService, "failed to update in response to event", err) + } + + } + + return &emptypb.Empty{}, nil +} diff --git a/internal/svc/user/api/gateway.go b/internal/svc/user/api/gateway.go new file mode 100644 index 0000000..6523a59 --- /dev/null +++ b/internal/svc/user/api/gateway.go @@ -0,0 +1,39 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package api + +import ( + "context" + + "github.com/grpc-ecosystem/grpc-gateway/v2/runtime" + "github.com/rs/zerolog/log" + + pb "github.com/hexolan/stocklet/internal/pkg/protogen/user/v1" + "github.com/hexolan/stocklet/internal/pkg/serve" + "github.com/hexolan/stocklet/internal/svc/user" +) + +func PrepareGateway(cfg *user.ServiceConfig) *runtime.ServeMux { + mux, clientOpts := serve.NewGatewayServeBase(&cfg.Shared) + + ctx := context.Background() + err := pb.RegisterUserServiceHandlerFromEndpoint(ctx, mux, serve.GetAddrToGrpc("localhost"), clientOpts) + if err != nil { + log.Panic().Err(err).Msg("failed to register endpoint for gateway") + } + + return mux +} diff --git a/internal/svc/user/api/grpc.go b/internal/svc/user/api/grpc.go new file mode 100644 index 0000000..9c28aa9 --- /dev/null +++ b/internal/svc/user/api/grpc.go @@ -0,0 +1,30 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package api + +import ( + "google.golang.org/grpc" + + pb "github.com/hexolan/stocklet/internal/pkg/protogen/user/v1" + "github.com/hexolan/stocklet/internal/pkg/serve" + "github.com/hexolan/stocklet/internal/svc/user" +) + +func PrepareGrpc(cfg *user.ServiceConfig, svc *user.UserService) *grpc.Server { + svr := serve.NewGrpcServeBase(&cfg.Shared) + pb.RegisterUserServiceServer(svr, svc) + return svr +} diff --git a/internal/svc/user/config.go b/internal/svc/user/config.go new file mode 100644 index 0000000..a6a7dd9 --- /dev/null +++ b/internal/svc/user/config.go @@ -0,0 +1,65 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package user + +import ( + "github.com/hexolan/stocklet/internal/pkg/config" +) + +// Order Service Configuration +type ServiceConfig struct { + // Core Configuration + Shared config.SharedConfig + ServiceOpts ServiceConfigOpts + + // Dynamically loaded configuration + Postgres config.PostgresConfig +} + +// load the base service configuration +func NewServiceConfig() (*ServiceConfig, error) { + cfg := ServiceConfig{} + + // Load the core configuration + if err := cfg.Shared.Load(); err != nil { + return nil, err + } + + // load the service config opts + if err := cfg.ServiceOpts.Load(); err != nil { + return nil, err + } + + return &cfg, nil +} + +// Service specific config options +type ServiceConfigOpts struct { + // Env Var: "AUTH_SERVICE_GRPC" + AuthServiceGrpc string +} + +// Load the ServiceConfigOpts +func (opts *ServiceConfigOpts) Load() error { + // Load configurations from env + if authServiceGrpc, err := config.RequireFromEnv("AUTH_SERVICE_GRPC"); err == nil { + opts.AuthServiceGrpc = authServiceGrpc + } else { + return err + } + + return nil +} diff --git a/internal/svc/user/controller/postgres.go b/internal/svc/user/controller/postgres.go new file mode 100644 index 0000000..1055ce6 --- /dev/null +++ b/internal/svc/user/controller/postgres.go @@ -0,0 +1,247 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package controller + +import ( + "context" + "time" + + "github.com/jackc/pgx/v5" + "github.com/jackc/pgx/v5/pgtype" + "github.com/jackc/pgx/v5/pgxpool" + "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc" + "google.golang.org/grpc" + "google.golang.org/grpc/credentials/insecure" + + "github.com/hexolan/stocklet/internal/pkg/errors" + authpb "github.com/hexolan/stocklet/internal/pkg/protogen/auth/v1" + pb "github.com/hexolan/stocklet/internal/pkg/protogen/user/v1" + "github.com/hexolan/stocklet/internal/svc/user" +) + +const pgUserBaseQuery string = "SELECT id, first_name, last_name, email, created_at, updated_at FROM users" + +type postgresController struct { + cl *pgxpool.Pool + serviceOpts *user.ServiceConfigOpts +} + +func NewPostgresController(cl *pgxpool.Pool, serviceOpts *user.ServiceConfigOpts) user.StorageController { + return postgresController{cl: cl, serviceOpts: serviceOpts} +} + +func (c postgresController) GetUser(ctx context.Context, userId string) (*pb.User, error) { + return c.getUser(ctx, nil, userId) +} + +func (c postgresController) getUser(ctx context.Context, tx *pgx.Tx, userId string) (*pb.User, error) { + // Determine if a db transaction is being used + var row pgx.Row + const query = pgUserBaseQuery + " WHERE id=$1" + if tx == nil { + row = c.cl.QueryRow(ctx, query, userId) + } else { + row = (*tx).QueryRow(ctx, query, userId) + } + + // Scan row to protobuf obj + userObj, err := scanRowToUser(row) + if err != nil { + return nil, err + } + + return userObj, nil +} + +func (c postgresController) RegisterUser(ctx context.Context, email string, password string, firstName string, lastName string) (*pb.User, error) { + // Establish connection with auth service + authConn, err := grpc.Dial( + c.serviceOpts.AuthServiceGrpc, + grpc.WithTransportCredentials(insecure.NewCredentials()), + grpc.WithStatsHandler(otelgrpc.NewClientHandler()), + ) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeExtService, "failed to establish connection to auth service", err) + } + defer authConn.Close() + authCl := authpb.NewAuthServiceClient(authConn) + + // Begin a DB transaction + tx, err := c.cl.Begin(ctx) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeExtService, "failed to begin db transaction", err) + } + defer tx.Rollback(ctx) + + // Create user in database + var userId string + err = tx.QueryRow( + ctx, + "INSERT INTO users (first_name, last_name, email) VALUES ($1, $2, $3) RETURNING id", + firstName, + lastName, + email, + ).Scan(&userId) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeExtService, "failed to create user", err) + } + + // Get the newly created user obj + userObj, err := c.getUser(ctx, &tx, userId) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeExtService, "failed to register user", err) + } + + // Prepare user created event and append to transaction + evt, evtTopic, err := user.PrepareUserCreatedEvent(userObj) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeService, "failed to create event", err) + } + + _, err = tx.Exec(ctx, "INSERT INTO event_outbox (aggregateid, aggregatetype, payload) VALUES ($1, $2, $3)", userObj.Id, evtTopic, evt) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeExtService, "failed to insert event", err) + } + + // Attempt to add auth method for user + authCtx, authCtxCancel := context.WithTimeout(context.Background(), time.Second*10) + defer authCtxCancel() + _, err = authCl.SetPassword(authCtx, &authpb.SetPasswordRequest{UserId: userObj.Id, Password: password}) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeExtService, "error registering user: failed to set auth method", err) + } + + // Commit the transaction + err = tx.Commit(ctx) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeExtService, "failed to commit transaction", err) + } + + return userObj, nil +} + +func (c postgresController) UpdateUserEmail(ctx context.Context, userId string, email string) error { + // Begin a DB transaction + tx, err := c.cl.Begin(ctx) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to begin transaction", err) + } + defer tx.Rollback(ctx) + + // Update email + _, err = tx.Exec(ctx, "UPDATE users SET email=$1 WHERE id=$2", email, userId) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to update email", err) + } + + // Add the event to the outbox table with the transaction + evt, evtTopic, err := user.PrepareUserEmailUpdatedEvent(userId, email) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeService, "failed to create event", err) + } + + _, err = tx.Exec(ctx, "INSERT INTO event_outbox (aggregateid, aggregatetype, payload) VALUES ($1, $2, $3)", userId, evtTopic, evt) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to insert event", err) + } + + // Commit the transaction + err = tx.Commit(ctx) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to commit transaction", err) + } + + return nil +} + +func (c postgresController) DeleteUser(ctx context.Context, userId string) (*pb.User, error) { + // Begin a DB transaction + tx, err := c.cl.Begin(ctx) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeExtService, "failed to begin transaction", err) + } + defer tx.Rollback(ctx) + + // Get the user + userObj, err := c.getUser(ctx, &tx, userId) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeExtService, "failed to fetch user", err) + } + + // Delete user + _, err = tx.Exec(ctx, "DELETE FROM users WHERE id=$1", userId) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeExtService, "failed to delete user", err) + } + + // Add the event to the outbox table with the transaction + evt, evtTopic, err := user.PrepareUserDeletedEvent(userObj) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeService, "failed to create event", err) + } + + _, err = tx.Exec(ctx, "INSERT INTO event_outbox (aggregateid, aggregatetype, payload) VALUES ($1, $2, $3)", userObj.Id, evtTopic, evt) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeExtService, "failed to insert event", err) + } + + // Commit the transaction + err = tx.Commit(ctx) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeExtService, "failed to commit transaction", err) + } + + return userObj, nil +} + +// Scan a postgres row to a protobuf object +func scanRowToUser(row pgx.Row) (*pb.User, error) { + var user pb.User + + // Temporary variables that require conversion + var tmpCreatedAt pgtype.Timestamp + var tmpUpdatedAt pgtype.Timestamp + + err := row.Scan( + &user.Id, + &user.FirstName, + &user.LastName, + &user.Email, + &tmpCreatedAt, + &tmpUpdatedAt, + ) + if err != nil { + if err == pgx.ErrNoRows { + return nil, errors.WrapServiceError(errors.ErrCodeNotFound, "user not found", err) + } else { + return nil, errors.WrapServiceError(errors.ErrCodeExtService, "failed to scan object from database", err) + } + } + + // convert postgres timestamps to unix format + if tmpCreatedAt.Valid { + user.CreatedAt = tmpCreatedAt.Time.Unix() + } else { + return nil, errors.NewServiceError(errors.ErrCodeUnknown, "failed to scan object from database (timestamp conversion)") + } + + if tmpUpdatedAt.Valid { + unixUpdated := tmpUpdatedAt.Time.Unix() + user.UpdatedAt = &unixUpdated + } + + return &user, nil +} diff --git a/internal/svc/user/event.go b/internal/svc/user/event.go new file mode 100644 index 0000000..89ef6c4 --- /dev/null +++ b/internal/svc/user/event.go @@ -0,0 +1,60 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package user + +import ( + "github.com/hexolan/stocklet/internal/pkg/messaging" + eventspb "github.com/hexolan/stocklet/internal/pkg/protogen/events/v1" + pb "github.com/hexolan/stocklet/internal/pkg/protogen/user/v1" +) + +func PrepareUserCreatedEvent(user *pb.User) ([]byte, string, error) { + topic := messaging.User_State_Created_Topic + event := &eventspb.UserCreatedEvent{ + Revision: 1, + + UserId: user.Id, + Email: user.Email, + FirstName: user.FirstName, + LastName: user.LastName, + } + + return messaging.MarshalEvent(event, topic) +} + +func PrepareUserEmailUpdatedEvent(userId string, email string) ([]byte, string, error) { + topic := messaging.User_Attribute_Email_Topic + event := &eventspb.UserEmailUpdatedEvent{ + Revision: 1, + + UserId: userId, + Email: email, + } + + return messaging.MarshalEvent(event, topic) +} + +func PrepareUserDeletedEvent(user *pb.User) ([]byte, string, error) { + topic := messaging.User_State_Deleted_Topic + event := &eventspb.UserDeletedEvent{ + Revision: 1, + + UserId: user.Id, + Email: user.Email, + } + + return messaging.MarshalEvent(event, topic) +} diff --git a/internal/svc/user/user.go b/internal/svc/user/user.go new file mode 100644 index 0000000..a3ab951 --- /dev/null +++ b/internal/svc/user/user.go @@ -0,0 +1,111 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package user + +import ( + "context" + + "github.com/bufbuild/protovalidate-go" + "github.com/rs/zerolog/log" + + "github.com/hexolan/stocklet/internal/pkg/errors" + "github.com/hexolan/stocklet/internal/pkg/messaging" + commonpb "github.com/hexolan/stocklet/internal/pkg/protogen/common/v1" + pb "github.com/hexolan/stocklet/internal/pkg/protogen/user/v1" +) + +// Interface for the service +type UserService struct { + pb.UnimplementedUserServiceServer + + store StorageController + pbVal *protovalidate.Validator +} + +// Interface for database methods +// Flexibility for implementing seperate controllers for different databases (e.g. Postgres, MongoDB, etc) +type StorageController interface { + GetUser(ctx context.Context, userId string) (*pb.User, error) + + RegisterUser(ctx context.Context, email string, password string, firstName string, lastName string) (*pb.User, error) + UpdateUserEmail(ctx context.Context, userId string, email string) error + + DeleteUser(ctx context.Context, userId string) (*pb.User, error) +} + +// Interface for event consumption +// Flexibility for seperate controllers for different messaging systems (e.g. Kafka, NATS, etc) +type ConsumerController interface { + messaging.ConsumerController + + Attach(svc pb.UserServiceServer) +} + +// Create the shipping service +func NewUserService(cfg *ServiceConfig, store StorageController) *UserService { + // Initialise the protobuf validator + pbVal, err := protovalidate.New() + if err != nil { + log.Panic().Err(err).Msg("failed to initialise protobuf validator") + } + + // Initialise the service + return &UserService{ + store: store, + pbVal: pbVal, + } +} + +func (svc UserService) ServiceInfo(ctx context.Context, req *commonpb.ServiceInfoRequest) (*commonpb.ServiceInfoResponse, error) { + return &commonpb.ServiceInfoResponse{ + Name: "user", + Source: "https://github.com/hexolan/stocklet", + SourceLicense: "AGPL-3.0", + }, nil +} + +func (svc UserService) ViewUser(ctx context.Context, req *pb.ViewUserRequest) (*pb.ViewUserResponse, error) { + // Validate the request args + if err := svc.pbVal.Validate(req); err != nil { + // Provide the validation error to the user. + return nil, errors.NewServiceError(errors.ErrCodeInvalidArgument, "invalid request: "+err.Error()) + } + + // Get user from DB + user, err := svc.store.GetUser(ctx, req.Id) + if err != nil { + return nil, err + } + + return &pb.ViewUserResponse{User: user}, nil +} + +func (svc UserService) RegisterUser(ctx context.Context, req *pb.RegisterUserRequest) (*pb.RegisterUserResponse, error) { + // Validate the request args + if err := svc.pbVal.Validate(req); err != nil { + // Provide the validation error to the user. + return nil, errors.NewServiceError(errors.ErrCodeInvalidArgument, "invalid request: "+err.Error()) + } + + // Attempt to register the user + // This process involves calling the auth service to add an auth method for the user + user, err := svc.store.RegisterUser(ctx, req.Email, req.Password, req.FirstName, req.LastName) + if err != nil { + return nil, err + } + + return &pb.RegisterUserResponse{User: user}, nil +} diff --git a/internal/svc/warehouse/api/gateway.go b/internal/svc/warehouse/api/gateway.go new file mode 100644 index 0000000..cba839a --- /dev/null +++ b/internal/svc/warehouse/api/gateway.go @@ -0,0 +1,39 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package api + +import ( + "context" + + "github.com/grpc-ecosystem/grpc-gateway/v2/runtime" + "github.com/rs/zerolog/log" + + pb "github.com/hexolan/stocklet/internal/pkg/protogen/warehouse/v1" + "github.com/hexolan/stocklet/internal/pkg/serve" + "github.com/hexolan/stocklet/internal/svc/warehouse" +) + +func PrepareGateway(cfg *warehouse.ServiceConfig) *runtime.ServeMux { + mux, clientOpts := serve.NewGatewayServeBase(&cfg.Shared) + + ctx := context.Background() + err := pb.RegisterWarehouseServiceHandlerFromEndpoint(ctx, mux, serve.GetAddrToGrpc("localhost"), clientOpts) + if err != nil { + log.Panic().Err(err).Msg("failed to register endpoint for gateway") + } + + return mux +} diff --git a/internal/svc/warehouse/api/grpc.go b/internal/svc/warehouse/api/grpc.go new file mode 100644 index 0000000..189a643 --- /dev/null +++ b/internal/svc/warehouse/api/grpc.go @@ -0,0 +1,30 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package api + +import ( + "google.golang.org/grpc" + + pb "github.com/hexolan/stocklet/internal/pkg/protogen/warehouse/v1" + "github.com/hexolan/stocklet/internal/pkg/serve" + "github.com/hexolan/stocklet/internal/svc/warehouse" +) + +func PrepareGrpc(cfg *warehouse.ServiceConfig, svc *warehouse.WarehouseService) *grpc.Server { + svr := serve.NewGrpcServeBase(&cfg.Shared) + pb.RegisterWarehouseServiceServer(svr, svc) + return svr +} diff --git a/internal/svc/warehouse/config.go b/internal/svc/warehouse/config.go new file mode 100644 index 0000000..66f6709 --- /dev/null +++ b/internal/svc/warehouse/config.go @@ -0,0 +1,42 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package warehouse + +import ( + "github.com/hexolan/stocklet/internal/pkg/config" +) + +// Order Service Configuration +type ServiceConfig struct { + // Core Configuration + Shared config.SharedConfig + + // Dynamically loaded configuration + Postgres config.PostgresConfig + Kafka config.KafkaConfig +} + +// load the base service configuration +func NewServiceConfig() (*ServiceConfig, error) { + cfg := ServiceConfig{} + + // Load the core configuration + if err := cfg.Shared.Load(); err != nil { + return nil, err + } + + return &cfg, nil +} diff --git a/internal/svc/warehouse/controller/kafka.go b/internal/svc/warehouse/controller/kafka.go new file mode 100644 index 0000000..79e0745 --- /dev/null +++ b/internal/svc/warehouse/controller/kafka.go @@ -0,0 +1,161 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package controller + +import ( + "context" + + "github.com/rs/zerolog/log" + "github.com/twmb/franz-go/pkg/kgo" + "google.golang.org/protobuf/proto" + + "github.com/hexolan/stocklet/internal/pkg/messaging" + eventpb "github.com/hexolan/stocklet/internal/pkg/protogen/events/v1" + pb "github.com/hexolan/stocklet/internal/pkg/protogen/warehouse/v1" + "github.com/hexolan/stocklet/internal/svc/warehouse" +) + +type kafkaController struct { + cl *kgo.Client + + svc pb.WarehouseServiceServer + + ctx context.Context + ctxCancel context.CancelFunc +} + +func NewKafkaController(cl *kgo.Client) warehouse.ConsumerController { + // Create a cancellable context for the consumer + ctx, ctxCancel := context.WithCancel(context.Background()) + + // Ensure the required Kafka topics exist + err := messaging.EnsureKafkaTopics( + cl, + + messaging.Warehouse_Stock_Created_Topic, + messaging.Warehouse_Stock_Added_Topic, + messaging.Warehouse_Stock_Removed_Topic, + messaging.Warehouse_Reservation_Failed_Topic, + messaging.Warehouse_Reservation_Reserved_Topic, + messaging.Warehouse_Reservation_Returned_Topic, + messaging.Warehouse_Reservation_Consumed_Topic, + + messaging.Order_State_Pending_Topic, + messaging.Shipping_Shipment_Allocation_Topic, + messaging.Payment_Processing_Topic, + ) + if err != nil { + log.Warn().Err(err).Msg("kafka: raised attempting to ensure svc topics") + } + + // Add the consumption topics + cl.AddConsumeTopics( + messaging.Order_State_Pending_Topic, + messaging.Shipping_Shipment_Allocation_Topic, + messaging.Payment_Processing_Topic, + ) + + return &kafkaController{cl: cl, ctx: ctx, ctxCancel: ctxCancel} +} + +func (c *kafkaController) Attach(svc pb.WarehouseServiceServer) { + c.svc = svc +} + +func (c *kafkaController) Start() { + if c.svc == nil { + log.Panic().Msg("consumer: no service interface attached") + } + + for { + fetches := c.cl.PollFetches(c.ctx) + if errs := fetches.Errors(); len(errs) > 0 { + log.Panic().Any("kafka-errs", errs).Msg("consumer: unrecoverable kafka errors") + } + + fetches.EachTopic(func(ft kgo.FetchTopic) { + switch ft.Topic { + case messaging.Order_State_Pending_Topic: + c.consumeOrderPendingEventTopic(ft) + case messaging.Shipping_Shipment_Allocation_Topic: + c.consumeShipmentAllocationEventTopic(ft) + case messaging.Payment_Processing_Topic: + c.consumePaymentProcessedEventTopic(ft) + default: + log.Warn().Str("topic", ft.Topic).Msg("consumer: recieved records from unexpected topic") + } + }) + } +} + +func (c *kafkaController) Stop() { + // Cancel the consumer context + c.ctxCancel() +} + +func (c *kafkaController) consumeOrderPendingEventTopic(ft kgo.FetchTopic) { + log.Info().Str("topic", ft.Topic).Msg("consumer: recieved records from topic") + + // Process each message from the topic + ft.EachRecord(func(record *kgo.Record) { + // Unmarshal the event + var event eventpb.OrderPendingEvent + err := proto.Unmarshal(record.Value, &event) + if err != nil { + log.Panic().Err(err).Msg("consumer: failed to unmarshal event") + } + + // Process the event + ctx := context.Background() + c.svc.ProcessOrderPendingEvent(ctx, &event) + }) +} + +func (c *kafkaController) consumeShipmentAllocationEventTopic(ft kgo.FetchTopic) { + log.Info().Str("topic", ft.Topic).Msg("consumer: recieved records from topic") + + // Process each message from the topic + ft.EachRecord(func(record *kgo.Record) { + // Unmarshal the event + var event eventpb.ShipmentAllocationEvent + err := proto.Unmarshal(record.Value, &event) + if err != nil { + log.Panic().Err(err).Msg("consumer: failed to unmarshal event") + } + + // Process the event + ctx := context.Background() + c.svc.ProcessShipmentAllocationEvent(ctx, &event) + }) +} + +func (c *kafkaController) consumePaymentProcessedEventTopic(ft kgo.FetchTopic) { + log.Info().Str("topic", ft.Topic).Msg("consumer: recieved records from topic") + + // Process each message from the topic + ft.EachRecord(func(record *kgo.Record) { + // Unmarshal the event + var event eventpb.PaymentProcessedEvent + err := proto.Unmarshal(record.Value, &event) + if err != nil { + log.Panic().Err(err).Msg("consumer: failed to unmarshal event") + } + + // Process the event + ctx := context.Background() + c.svc.ProcessPaymentProcessedEvent(ctx, &event) + }) +} diff --git a/internal/svc/warehouse/controller/postgres.go b/internal/svc/warehouse/controller/postgres.go new file mode 100644 index 0000000..2210a50 --- /dev/null +++ b/internal/svc/warehouse/controller/postgres.go @@ -0,0 +1,500 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package controller + +import ( + "context" + + "github.com/jackc/pgx/v5" + "github.com/jackc/pgx/v5/pgtype" + "github.com/jackc/pgx/v5/pgxpool" + + "github.com/hexolan/stocklet/internal/pkg/errors" + pb "github.com/hexolan/stocklet/internal/pkg/protogen/warehouse/v1" + "github.com/hexolan/stocklet/internal/svc/warehouse" +) + +const ( + pgProductStockBaseQuery string = "SELECT product_id, quantity FROM product_stock" + pgReservationBaseQuery string = "SELECT id, order_id, created_at FROM reservations" + pgReservationItemsBaseQuery string = "SELECT product_id, quantity FROM reservation_items" +) + +type postgresController struct { + cl *pgxpool.Pool +} + +func NewPostgresController(cl *pgxpool.Pool) warehouse.StorageController { + return postgresController{cl: cl} +} + +func (c postgresController) GetProductStock(ctx context.Context, productId string) (*pb.ProductStock, error) { + return c.getProductStock(ctx, nil, productId) +} + +func (c postgresController) getProductStock(ctx context.Context, tx *pgx.Tx, productId string) (*pb.ProductStock, error) { + // Determine if a db transaction is being used + var row pgx.Row + const query = pgProductStockBaseQuery + " WHERE product_id=$1" + if tx == nil { + row = c.cl.QueryRow(ctx, query, productId) + } else { + row = (*tx).QueryRow(ctx, query, productId) + } + + // Scan row to protobuf obj + stock, err := scanRowToProductStock(row) + if err != nil { + return nil, err + } + + return stock, nil +} + +func (c postgresController) GetReservation(ctx context.Context, reservationId string) (*pb.Reservation, error) { + return c.getReservation(ctx, nil, reservationId) +} + +func (c postgresController) getReservation(ctx context.Context, tx *pgx.Tx, reservationId string) (*pb.Reservation, error) { + // Determine if a db transaction is being used + var row pgx.Row + const query = pgReservationBaseQuery + " WHERE id=$1" + if tx == nil { + row = c.cl.QueryRow(ctx, query, reservationId) + } else { + row = (*tx).QueryRow(ctx, query, reservationId) + } + + // Scan row to protobuf obj + reservation, err := scanRowToReservation(row) + if err != nil { + return nil, err + } + + // Append items to reservation + reservation, err = c.appendItemsToReservation(ctx, tx, reservation) + if err != nil { + return nil, err + } + + return reservation, nil +} + +func (c postgresController) getReservationByOrderId(ctx context.Context, tx *pgx.Tx, orderId string) (*pb.Reservation, error) { + // Determine if a db transaction is being used + var row pgx.Row + const query = pgReservationBaseQuery + " WHERE order_id=$1" + if tx == nil { + row = c.cl.QueryRow(ctx, query, orderId) + } else { + row = (*tx).QueryRow(ctx, query, orderId) + } + + // Scan row to protobuf obj + reservation, err := scanRowToReservation(row) + if err != nil { + return nil, err + } + + // Append items to reservation + reservation, err = c.appendItemsToReservation(ctx, tx, reservation) + if err != nil { + return nil, err + } + + return reservation, nil +} + +func (c postgresController) CreateProductStock(ctx context.Context, productId string, startingQuantity int32) error { + // Begin a DB transaction + tx, err := c.cl.Begin(ctx) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to begin transaction", err) + } + defer tx.Rollback(ctx) + + // Create stock + _, err = tx.Exec(ctx, "INSERT INTO product_stock (product_id, quantity) VALUES ($1, $2)", productId, startingQuantity) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to create product stock", err) + } + + // Add the event to the outbox table with the transaction + evt, evtTopic, err := warehouse.PrepareStockCreatedEvent(&pb.ProductStock{ProductId: productId, Quantity: startingQuantity}) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeService, "failed to create event", err) + } + + _, err = tx.Exec(ctx, "INSERT INTO event_outbox (aggregateid, aggregatetype, payload) VALUES ($1, $2, $3)", productId, evtTopic, evt) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to insert event", err) + } + + // Commit the transaction + err = tx.Commit(ctx) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to commit transaction", err) + } + + return nil +} + +func (c postgresController) ReserveOrderStock(ctx context.Context, orderId string, orderMetadata warehouse.EventOrderMetadata, productQuantities map[string]int32) error { + // Begin a DB transaction + tx, err := c.cl.Begin(ctx) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to begin transaction", err) + } + defer tx.Rollback(ctx) + + // Create reservation + var reservationId string + err = tx.QueryRow(ctx, "INSERT INTO reservations (order_id) VALUES ($1) RETURNING id", orderId).Scan(&reservationId) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to create reservation", err) + } + + // Reserve the items + insufficientStockProductIds := []string{} + for productId, quantity := range productQuantities { + err = c.reserveStock(ctx, &tx, reservationId, productId, quantity) + if err != nil { + insufficientStockProductIds = append(insufficientStockProductIds, productId) + } + } + + // Ensure that all of the stock was reserved + if len(insufficientStockProductIds) > 0 { + // Add the event to the outbox table with the transaction + evt, evtTopic, err := warehouse.PrepareStockReservationEvent_Failed(orderId, orderMetadata, insufficientStockProductIds) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeService, "failed to create event", err) + } + + _, err = c.cl.Exec(ctx, "INSERT INTO event_outbox (aggregateid, aggregatetype, payload) VALUES ($1, $2, $3)", orderId, evtTopic, evt) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to insert event", err) + } + + return nil + } + + // Add the event to the outbox table with the transaction + evt, evtTopic, err := warehouse.PrepareStockReservationEvent_Reserved(orderId, orderMetadata, reservationId, productQuantities) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeService, "failed to create event", err) + } + + _, err = tx.Exec(ctx, "INSERT INTO event_outbox (aggregateid, aggregatetype, payload) VALUES ($1, $2, $3)", reservationId, evtTopic, evt) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to insert event", err) + } + + // Commit the transaction + err = tx.Commit(ctx) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to commit transaction", err) + } + + return nil +} + +func (c postgresController) reserveStock(ctx context.Context, tx *pgx.Tx, reservationId string, productId string, quantity int32) error { + // Determine if a transaction has already been provided + var ( + funcTx pgx.Tx + err error + ) + if tx != nil { + funcTx = *tx + } else { + funcTx, err = c.cl.Begin(ctx) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to begin transaction", err) + } + defer funcTx.Rollback(ctx) + } + + // Subtract from quantity + _, err = funcTx.Exec(ctx, "UPDATE product_stock SET quantity = quantity - $1 WHERE product_id=$2", quantity, productId) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to update product stock", err) + } + + // Get updated stock + stock, err := c.getProductStock(ctx, tx, productId) + if err != nil { + return err + } + + // Ensure that the stock is not negative + if stock.Quantity < 0 { + return errors.NewServiceError(errors.ErrCodeInvalidArgument, "insufficient stock") + } + + // Add as reservation item + _, err = funcTx.Exec(ctx, "INSERT INTO reservation_items (reservation_id, product_id, quantity) VALUES ($1, $2, $3)", reservationId, productId, quantity) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to add as reservation item", err) + } + + // Commit the transaction (if created in this func) + if tx == nil { + err = funcTx.Commit(ctx) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to commit transaction", err) + } + } + + return nil +} + +func (c postgresController) ReturnReservedOrderStock(ctx context.Context, orderId string) error { + // Begin a DB transaction + tx, err := c.cl.Begin(ctx) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to begin transaction", err) + } + defer tx.Rollback(ctx) + + // Get the reservation + reservation, err := c.getReservationByOrderId(ctx, &tx, orderId) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to locate order reservation", err) + } + + // Return all of the reserved stock + for _, reservedStock := range reservation.ReservedStock { + err = c.returnReservedStock(ctx, &tx, reservation.Id, reservedStock.ProductId, reservedStock.Quantity) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to return reserved stock", err) + } + } + + // Delete the reservation + _, err = tx.Exec(ctx, "DELETE FROM reservations WHERE id=$1", reservation.Id) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to delete reservation", err) + } + + // Prepare and add reservation consumed event to outbox + evt, evtTopic, err := warehouse.PrepareStockReservationEvent_Returned(reservation.OrderId, reservation.Id, reservation.ReservedStock) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeService, "failed to create event", err) + } + + _, err = tx.Exec(ctx, "INSERT INTO event_outbox (aggregateid, aggregatetype, payload) VALUES ($1, $2, $3)", reservation.Id, evtTopic, evt) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to insert event", err) + } + + // Commit the transaction + err = tx.Commit(ctx) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to commit transaction", err) + } + + return nil +} + +func (c postgresController) returnReservedStock(ctx context.Context, tx *pgx.Tx, reservationId string, productId string, quantity int32) error { + // Determine if a transaction has already been provided + var ( + funcTx pgx.Tx + err error + ) + if tx != nil { + funcTx = *tx + } else { + funcTx, err = c.cl.Begin(ctx) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to begin transaction", err) + } + defer funcTx.Rollback(ctx) + } + + // Add back to stock quantity + _, err = funcTx.Exec(ctx, "UPDATE product_stock SET quantity = quantity + $1 WHERE product_id=$2", quantity, productId) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to update product stock", err) + } + + // Delete reservation item + _, err = funcTx.Exec(ctx, "DELETE FROM reservation_items WHERE reservation_id=$1 AND product_id=$2", reservationId, productId) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to add as reservation item", err) + } + + // Commit the transaction (if created in this func) + if tx == nil { + err = funcTx.Commit(ctx) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to commit transaction", err) + } + } + + return nil +} + +func (c postgresController) ConsumeReservedOrderStock(ctx context.Context, orderId string) error { + // Begin a DB transaction + tx, err := c.cl.Begin(ctx) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to begin transaction", err) + } + defer tx.Rollback(ctx) + + // Get the reservation + reservation, err := c.getReservationByOrderId(ctx, &tx, orderId) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to locate order reservation", err) + } + + // Delete the reservation + _, err = tx.Exec(ctx, "DELETE FROM reservations WHERE id=$1", reservation.Id) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to delete reservation", err) + } + + // Dispatch stock removed events + for _, reservedStock := range reservation.ReservedStock { + evt, evtTopic, err := warehouse.PrepareStockRemovedEvent(reservedStock.ProductId, reservedStock.Quantity, &reservation.Id) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeService, "failed to create event", err) + } + + _, err = tx.Exec(ctx, "INSERT INTO event_outbox (aggregateid, aggregatetype, payload) VALUES ($1, $2, $3)", reservedStock.ProductId, evtTopic, evt) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to insert event", err) + } + } + + // Prepare and add reservation consumed event to outbox + evt, evtTopic, err := warehouse.PrepareStockReservationEvent_Consumed(reservation.OrderId, reservation.Id, reservation.ReservedStock) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeService, "failed to create event", err) + } + + _, err = tx.Exec(ctx, "INSERT INTO event_outbox (aggregateid, aggregatetype, payload) VALUES ($1, $2, $3)", reservation.Id, evtTopic, evt) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to insert event", err) + } + + // Commit the transaction + err = tx.Commit(ctx) + if err != nil { + return errors.WrapServiceError(errors.ErrCodeExtService, "failed to commit transaction", err) + } + + return nil +} + +func (c postgresController) getReservationItems(ctx context.Context, tx *pgx.Tx, reservationId string) ([]*pb.ReservationStock, error) { + // Determine if transaction is being used. + var rows pgx.Rows + var err error + const query = pgReservationItemsBaseQuery + " WHERE reservation_id=$1" + if tx == nil { + rows, err = c.cl.Query(ctx, query, reservationId) + } else { + rows, err = (*tx).Query(ctx, query, reservationId) + } + + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeService, "query error whilst fetching reserved items", err) + } + + items := []*pb.ReservationStock{} + for rows.Next() { + var reservStock pb.ReservationStock + + err := rows.Scan( + &reservStock.ProductId, + &reservStock.Quantity, + ) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeService, "failed to scan a reservation item", err) + } + + items = append(items, &reservStock) + } + + if rows.Err() != nil { + return nil, errors.WrapServiceError(errors.ErrCodeService, "error scanning item rows", rows.Err()) + } + + return items, nil +} + +// Append items to the reservation +func (c postgresController) appendItemsToReservation(ctx context.Context, tx *pgx.Tx, reservation *pb.Reservation) (*pb.Reservation, error) { + reservedItems, err := c.getReservationItems(ctx, tx, reservation.Id) + if err != nil { + return nil, err + } + + // Add the items to the reservation protobuf + reservation.ReservedStock = reservedItems + + return reservation, nil +} + +// Scan a postgres row to a protobuf object +func scanRowToProductStock(row pgx.Row) (*pb.ProductStock, error) { + var stock pb.ProductStock + + err := row.Scan( + &stock.ProductId, + &stock.Quantity, + ) + if err != nil { + if err == pgx.ErrNoRows { + return nil, errors.WrapServiceError(errors.ErrCodeNotFound, "stock not found", err) + } else { + return nil, errors.WrapServiceError(errors.ErrCodeExtService, "something went wrong scanning object", err) + } + } + + return &stock, nil +} + +// Scan a postgres row to a protobuf object +func scanRowToReservation(row pgx.Row) (*pb.Reservation, error) { + var reservation pb.Reservation + + // Temporary variables that require conversion + var tmpCreatedAt pgtype.Timestamp + + err := row.Scan( + &reservation.Id, + &reservation.OrderId, + &tmpCreatedAt, + ) + if err != nil { + if err == pgx.ErrNoRows { + return nil, errors.WrapServiceError(errors.ErrCodeNotFound, "reservation not found", err) + } else { + return nil, errors.WrapServiceError(errors.ErrCodeExtService, "something went wrong scanning object", err) + } + } + + // convert postgres timestamps to unix format + if tmpCreatedAt.Valid { + reservation.CreatedAt = tmpCreatedAt.Time.Unix() + } + + return &reservation, nil +} diff --git a/internal/svc/warehouse/event.go b/internal/svc/warehouse/event.go new file mode 100644 index 0000000..4c4ae17 --- /dev/null +++ b/internal/svc/warehouse/event.go @@ -0,0 +1,141 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package warehouse + +import ( + "github.com/hexolan/stocklet/internal/pkg/messaging" + eventspb "github.com/hexolan/stocklet/internal/pkg/protogen/events/v1" + pb "github.com/hexolan/stocklet/internal/pkg/protogen/warehouse/v1" +) + +type EventOrderMetadata struct { + CustomerId string + ItemsPrice float32 + TotalPrice float32 +} + +func PrepareStockCreatedEvent(productStock *pb.ProductStock) ([]byte, string, error) { + topic := messaging.Warehouse_Stock_Created_Topic + event := &eventspb.StockCreatedEvent{ + Revision: 1, + + ProductId: productStock.ProductId, + Quantity: productStock.Quantity, + } + + return messaging.MarshalEvent(event, topic) +} + +func PrepareStockAddedEvent(productId string, amount int32, reservationId *string) ([]byte, string, error) { + topic := messaging.Warehouse_Stock_Added_Topic + event := &eventspb.StockAddedEvent{ + Revision: 1, + + ProductId: productId, + Amount: amount, + ReservationId: reservationId, + } + + return messaging.MarshalEvent(event, topic) +} + +func PrepareStockRemovedEvent(productId string, amount int32, reservationId *string) ([]byte, string, error) { + topic := messaging.Warehouse_Stock_Removed_Topic + event := &eventspb.StockRemovedEvent{ + Revision: 1, + + ProductId: productId, + Amount: amount, + ReservationId: reservationId, + } + + return messaging.MarshalEvent(event, topic) +} + +func PrepareStockReservationEvent_Failed(orderId string, orderMetadata EventOrderMetadata, insufficientStockProductIds []string) ([]byte, string, error) { + topic := messaging.Warehouse_Reservation_Failed_Topic + event := &eventspb.StockReservationEvent{ + Revision: 1, + + Type: eventspb.StockReservationEvent_TYPE_INSUFFICIENT_STOCK, + OrderId: orderId, + OrderMetadata: &eventspb.StockReservationEvent_OrderMetadata{ + CustomerId: orderMetadata.CustomerId, + ItemsPrice: orderMetadata.ItemsPrice, + TotalPrice: orderMetadata.TotalPrice, + }, + InsufficientStock: insufficientStockProductIds, + } + + return messaging.MarshalEvent(event, topic) +} + +func PrepareStockReservationEvent_Reserved(orderId string, orderMetadata EventOrderMetadata, reservationId string, reservationStock map[string]int32) ([]byte, string, error) { + topic := messaging.Warehouse_Reservation_Reserved_Topic + event := &eventspb.StockReservationEvent{ + Revision: 1, + + Type: eventspb.StockReservationEvent_TYPE_STOCK_RESERVED, + OrderId: orderId, + OrderMetadata: &eventspb.StockReservationEvent_OrderMetadata{ + CustomerId: orderMetadata.CustomerId, + ItemsPrice: orderMetadata.ItemsPrice, + TotalPrice: orderMetadata.TotalPrice, + }, + ReservationId: reservationId, + ReservationStock: reservationStock, + } + + return messaging.MarshalEvent(event, topic) +} + +func PrepareStockReservationEvent_Returned(orderId string, reservationId string, reservedStock []*pb.ReservationStock) ([]byte, string, error) { + reservationStock := make(map[string]int32) + for _, item := range reservedStock { + reservationStock[item.ProductId] = item.Quantity + } + + topic := messaging.Warehouse_Reservation_Returned_Topic + event := &eventspb.StockReservationEvent{ + Revision: 1, + + Type: eventspb.StockReservationEvent_TYPE_STOCK_RESERVED, + OrderId: orderId, + ReservationId: reservationId, + ReservationStock: reservationStock, + } + + return messaging.MarshalEvent(event, topic) +} + +func PrepareStockReservationEvent_Consumed(orderId string, reservationId string, reservedStock []*pb.ReservationStock) ([]byte, string, error) { + reservationStock := make(map[string]int32) + for _, item := range reservedStock { + reservationStock[item.ProductId] = item.Quantity + } + + topic := messaging.Warehouse_Reservation_Consumed_Topic + event := &eventspb.StockReservationEvent{ + Revision: 1, + + Type: eventspb.StockReservationEvent_TYPE_STOCK_CONSUMED, + OrderId: orderId, + ReservationId: reservationId, + ReservationStock: reservationStock, + } + + return messaging.MarshalEvent(event, topic) +} diff --git a/internal/svc/warehouse/warehouse.go b/internal/svc/warehouse/warehouse.go new file mode 100644 index 0000000..f5ce6c9 --- /dev/null +++ b/internal/svc/warehouse/warehouse.go @@ -0,0 +1,168 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package warehouse + +import ( + "context" + + "github.com/bufbuild/protovalidate-go" + "github.com/rs/zerolog/log" + "google.golang.org/protobuf/types/known/emptypb" + + "github.com/hexolan/stocklet/internal/pkg/errors" + "github.com/hexolan/stocklet/internal/pkg/messaging" + commonpb "github.com/hexolan/stocklet/internal/pkg/protogen/common/v1" + eventpb "github.com/hexolan/stocklet/internal/pkg/protogen/events/v1" + pb "github.com/hexolan/stocklet/internal/pkg/protogen/warehouse/v1" +) + +// Interface for the service +type WarehouseService struct { + pb.UnimplementedWarehouseServiceServer + + store StorageController + pbVal *protovalidate.Validator +} + +// Interface for database methods +// Flexibility for implementing seperate controllers for different databases (e.g. Postgres, MongoDB, etc) +type StorageController interface { + GetProductStock(ctx context.Context, productId string) (*pb.ProductStock, error) + GetReservation(ctx context.Context, reservationId string) (*pb.Reservation, error) + + CreateProductStock(ctx context.Context, productId string, startingQuantity int32) error + + ReserveOrderStock(ctx context.Context, orderId string, orderMetadata EventOrderMetadata, productQuantities map[string]int32) error + ReturnReservedOrderStock(ctx context.Context, orderId string) error + ConsumeReservedOrderStock(ctx context.Context, orderId string) error +} + +// Interface for event consumption +// Flexibility for seperate controllers for different messaging systems (e.g. Kafka, NATS, etc) +type ConsumerController interface { + messaging.ConsumerController + + Attach(svc pb.WarehouseServiceServer) +} + +// Create the shipping service +func NewWarehouseService(cfg *ServiceConfig, store StorageController) *WarehouseService { + // Initialise the protobuf validator + pbVal, err := protovalidate.New() + if err != nil { + log.Panic().Err(err).Msg("failed to initialise protobuf validator") + } + + // Initialise the service + return &WarehouseService{ + store: store, + pbVal: pbVal, + } +} + +func (svc WarehouseService) ServiceInfo(ctx context.Context, req *commonpb.ServiceInfoRequest) (*commonpb.ServiceInfoResponse, error) { + return &commonpb.ServiceInfoResponse{ + Name: "warehouse", + Source: "https://github.com/hexolan/stocklet", + SourceLicense: "AGPL-3.0", + }, nil +} + +func (svc WarehouseService) ViewProductStock(ctx context.Context, req *pb.ViewProductStockRequest) (*pb.ViewProductStockResponse, error) { + // Validate the request args + if err := svc.pbVal.Validate(req); err != nil { + // Provide the validation error to the user. + return nil, errors.NewServiceError(errors.ErrCodeInvalidArgument, "invalid request: "+err.Error()) + } + + // Get stock from db + stock, err := svc.store.GetProductStock(ctx, req.ProductId) + if err != nil { + return nil, err + } + + return &pb.ViewProductStockResponse{Stock: stock}, nil +} + +func (svc WarehouseService) ViewReservation(ctx context.Context, req *pb.ViewReservationRequest) (*pb.ViewReservationResponse, error) { + // Validate the request args + if err := svc.pbVal.Validate(req); err != nil { + // Provide the validation error to the user. + return nil, errors.NewServiceError(errors.ErrCodeInvalidArgument, "invalid request: "+err.Error()) + } + + // Get reservation from db + reservation, err := svc.store.GetReservation(ctx, req.ReservationId) + if err != nil { + return nil, err + } + + return &pb.ViewReservationResponse{Reservation: reservation}, nil +} + +func (svc WarehouseService) ProcessProductCreatedEvent(ctx context.Context, req *eventpb.ProductCreatedEvent) (*emptypb.Empty, error) { + err := svc.store.CreateProductStock(ctx, req.ProductId, 0) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeExtService, "error processing event", err) + } + + return &emptypb.Empty{}, nil +} + +func (svc WarehouseService) ProcessOrderPendingEvent(ctx context.Context, req *eventpb.OrderPendingEvent) (*emptypb.Empty, error) { + err := svc.store.ReserveOrderStock( + ctx, + req.OrderId, + EventOrderMetadata{ + CustomerId: req.CustomerId, + ItemsPrice: req.ItemsPrice, + TotalPrice: req.TotalPrice, + }, + req.ItemQuantities, + ) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeExtService, "error processing event", err) + } + + return &emptypb.Empty{}, nil +} + +func (svc WarehouseService) ProcessShipmentAllocationEvent(ctx context.Context, req *eventpb.ShipmentAllocationEvent) (*emptypb.Empty, error) { + if req.Type == eventpb.ShipmentAllocationEvent_TYPE_FAILED { + err := svc.store.ReturnReservedOrderStock(ctx, req.OrderId) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeExtService, "error processing event", err) + } + } + + return &emptypb.Empty{}, nil +} + +func (svc WarehouseService) ProcessPaymentProcessedEvent(ctx context.Context, req *eventpb.PaymentProcessedEvent) (*emptypb.Empty, error) { + if req.Type == eventpb.PaymentProcessedEvent_TYPE_FAILED { + err := svc.store.ReturnReservedOrderStock(ctx, req.OrderId) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeExtService, "error processing event", err) + } + } else if req.Type == eventpb.PaymentProcessedEvent_TYPE_SUCCESS { + err := svc.store.ConsumeReservedOrderStock(ctx, req.OrderId) + if err != nil { + return nil, errors.WrapServiceError(errors.ErrCodeExtService, "error processing event", err) + } + } + + return &emptypb.Empty{}, nil +} diff --git a/schema/openapi/services.swagger.yaml b/schema/openapi/services.swagger.yaml new file mode 100644 index 0000000..951b4bd --- /dev/null +++ b/schema/openapi/services.swagger.yaml @@ -0,0 +1,781 @@ +swagger: "2.0" +info: + title: Stocklet + version: 0.1.0 + contact: + name: GitHub Repository + url: https://github.com/hexolan/stocklet + license: + name: AGPL-3.0 + url: https://github.com/hexolan/stocklet/blob/main/LICENSE +tags: + - name: AuthService + - name: OrderService + - name: PaymentService + - name: ProductService + - name: ShippingService + - name: UserService + - name: WarehouseService +host: localhost +schemes: + - http +consumes: + - application/json +produces: + - application/json +paths: + /v1/auth/jwks: + get: + operationId: AuthService_GetJwks + responses: + "200": + description: A successful response. + schema: + $ref: '#/definitions/v1GetJwksResponse' + default: + description: An unexpected error response. + schema: + $ref: '#/definitions/rpcStatus' + tags: + - AuthService + /v1/auth/login: + post: + operationId: AuthService_LoginPassword + responses: + "200": + description: A successful response. + schema: + $ref: '#/definitions/v1LoginPasswordResponse' + default: + description: An unexpected error response. + schema: + $ref: '#/definitions/rpcStatus' + parameters: + - name: body + in: body + required: true + schema: + $ref: '#/definitions/v1LoginPasswordRequest' + tags: + - AuthService + /v1/auth/password: + post: + operationId: AuthService_SetPassword + responses: + "200": + description: A successful response. + schema: + $ref: '#/definitions/v1SetPasswordResponse' + default: + description: An unexpected error response. + schema: + $ref: '#/definitions/rpcStatus' + parameters: + - name: body + in: body + required: true + schema: + $ref: '#/definitions/v1SetPasswordRequest' + tags: + - AuthService + /v1/auth/service: + get: + summary: View information about the service. + description: buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + operationId: AuthService_ServiceInfo + responses: + "200": + description: A successful response. + schema: + $ref: '#/definitions/v1ServiceInfoResponse' + default: + description: An unexpected error response. + schema: + $ref: '#/definitions/rpcStatus' + tags: + - AuthService + /v1/order/list: + get: + summary: |- + Get a list of a customer's orders. + If accessed through the gateway - shows the current user's orders. + operationId: OrderService_ViewOrders + responses: + "200": + description: A successful response. + schema: + $ref: '#/definitions/v1ViewOrdersResponse' + default: + description: An unexpected error response. + schema: + $ref: '#/definitions/rpcStatus' + parameters: + - name: customerId + in: query + required: false + type: string + tags: + - OrderService + /v1/order/orders/{orderId}: + get: + operationId: OrderService_ViewOrder + responses: + "200": + description: A successful response. + schema: + $ref: '#/definitions/v1ViewOrderResponse' + default: + description: An unexpected error response. + schema: + $ref: '#/definitions/rpcStatus' + parameters: + - name: orderId + in: path + required: true + type: string + tags: + - OrderService + /v1/order/place: + post: + operationId: OrderService_PlaceOrder + responses: + "200": + description: A successful response. + schema: + $ref: '#/definitions/v1PlaceOrderResponse' + default: + description: An unexpected error response. + schema: + $ref: '#/definitions/rpcStatus' + parameters: + - name: cart + in: body + required: true + schema: + type: object + additionalProperties: + type: integer + format: int32 + - name: customerId + in: query + required: false + type: string + tags: + - OrderService + /v1/order/service: + get: + summary: View information about the service. + description: buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + operationId: OrderService_ServiceInfo + responses: + "200": + description: A successful response. + schema: + $ref: '#/definitions/v1ServiceInfoResponse' + default: + description: An unexpected error response. + schema: + $ref: '#/definitions/rpcStatus' + tags: + - OrderService + /v1/payment/balance/{customerId}: + get: + operationId: PaymentService_ViewBalance + responses: + "200": + description: A successful response. + schema: + $ref: '#/definitions/v1ViewBalanceResponse' + default: + description: An unexpected error response. + schema: + $ref: '#/definitions/rpcStatus' + parameters: + - name: customerId + in: path + required: true + type: string + tags: + - PaymentService + /v1/payment/service: + get: + summary: View information about the service. + description: buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + operationId: PaymentService_ServiceInfo + responses: + "200": + description: A successful response. + schema: + $ref: '#/definitions/v1ServiceInfoResponse' + default: + description: An unexpected error response. + schema: + $ref: '#/definitions/rpcStatus' + tags: + - PaymentService + /v1/payment/transaction/{transactionId}: + get: + operationId: PaymentService_ViewTransaction + responses: + "200": + description: A successful response. + schema: + $ref: '#/definitions/v1ViewTransactionResponse' + default: + description: An unexpected error response. + schema: + $ref: '#/definitions/rpcStatus' + parameters: + - name: transactionId + in: path + required: true + type: string + tags: + - PaymentService + /v1/product/list: + get: + operationId: ProductService_ViewProducts + responses: + "200": + description: A successful response. + schema: + $ref: '#/definitions/v1ViewProductsResponse' + default: + description: An unexpected error response. + schema: + $ref: '#/definitions/rpcStatus' + tags: + - ProductService + /v1/product/service: + get: + summary: View information about the service. + description: buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + operationId: ProductService_ServiceInfo + responses: + "200": + description: A successful response. + schema: + $ref: '#/definitions/v1ServiceInfoResponse' + default: + description: An unexpected error response. + schema: + $ref: '#/definitions/rpcStatus' + tags: + - ProductService + /v1/product/{id}: + get: + operationId: ProductService_ViewProduct + responses: + "200": + description: A successful response. + schema: + $ref: '#/definitions/v1ViewProductResponse' + default: + description: An unexpected error response. + schema: + $ref: '#/definitions/rpcStatus' + parameters: + - name: id + in: path + required: true + type: string + tags: + - ProductService + /v1/shipping/service: + get: + summary: View information about the service. + description: buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + operationId: ShippingService_ServiceInfo + responses: + "200": + description: A successful response. + schema: + $ref: '#/definitions/v1ServiceInfoResponse' + default: + description: An unexpected error response. + schema: + $ref: '#/definitions/rpcStatus' + tags: + - ShippingService + /v1/shipping/shipment/{shipmentId}: + get: + operationId: ShippingService_ViewShipment + responses: + "200": + description: A successful response. + schema: + $ref: '#/definitions/v1ViewShipmentResponse' + default: + description: An unexpected error response. + schema: + $ref: '#/definitions/rpcStatus' + parameters: + - name: shipmentId + in: path + required: true + type: string + tags: + - ShippingService + /v1/shipping/shipment/{shipmentId}/manifest: + get: + operationId: ShippingService_ViewShipmentManifest + responses: + "200": + description: A successful response. + schema: + $ref: '#/definitions/v1ViewShipmentManifestResponse' + default: + description: An unexpected error response. + schema: + $ref: '#/definitions/rpcStatus' + parameters: + - name: shipmentId + in: path + required: true + type: string + tags: + - ShippingService + /v1/user/register: + post: + operationId: UserService_RegisterUser + responses: + "200": + description: A successful response. + schema: + $ref: '#/definitions/v1RegisterUserResponse' + default: + description: An unexpected error response. + schema: + $ref: '#/definitions/rpcStatus' + parameters: + - name: firstName + in: query + required: true + type: string + - name: lastName + in: query + required: true + type: string + - name: email + in: query + required: true + type: string + - name: password + in: query + required: true + type: string + tags: + - UserService + /v1/user/service: + get: + summary: View information about the service. + description: buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + operationId: UserService_ServiceInfo + responses: + "200": + description: A successful response. + schema: + $ref: '#/definitions/v1ServiceInfoResponse' + default: + description: An unexpected error response. + schema: + $ref: '#/definitions/rpcStatus' + tags: + - UserService + /v1/user/users/{id}: + get: + operationId: UserService_ViewUser + responses: + "200": + description: A successful response. + schema: + $ref: '#/definitions/v1ViewUserResponse' + default: + description: An unexpected error response. + schema: + $ref: '#/definitions/rpcStatus' + parameters: + - name: id + in: path + required: true + type: string + tags: + - UserService + /v1/warehouse/product/{productId}: + get: + operationId: WarehouseService_ViewProductStock + responses: + "200": + description: A successful response. + schema: + $ref: '#/definitions/v1ViewProductStockResponse' + default: + description: An unexpected error response. + schema: + $ref: '#/definitions/rpcStatus' + parameters: + - name: productId + in: path + required: true + type: string + tags: + - WarehouseService + /v1/warehouse/reservation/{reservationId}: + get: + operationId: WarehouseService_ViewReservation + responses: + "200": + description: A successful response. + schema: + $ref: '#/definitions/v1ViewReservationResponse' + default: + description: An unexpected error response. + schema: + $ref: '#/definitions/rpcStatus' + parameters: + - name: reservationId + in: path + required: true + type: string + tags: + - WarehouseService + /v1/warehouse/service: + get: + summary: View information about the service. + description: buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + operationId: WarehouseService_ServiceInfo + responses: + "200": + description: A successful response. + schema: + $ref: '#/definitions/v1ServiceInfoResponse' + default: + description: An unexpected error response. + schema: + $ref: '#/definitions/rpcStatus' + tags: + - WarehouseService +definitions: + protobufAny: + type: object + properties: + '@type': + type: string + additionalProperties: {} + rpcStatus: + type: object + properties: + code: + type: integer + format: int32 + message: + type: string + details: + type: array + items: + type: object + $ref: '#/definitions/protobufAny' + v1AuthToken: + type: object + properties: + tokenType: + type: string + accessToken: + type: string + expiresIn: + type: string + format: int64 + v1CustomerBalance: + type: object + properties: + customerId: + type: string + balance: + type: number + format: float + v1GetJwksResponse: + type: object + properties: + keys: + type: array + items: + type: object + $ref: '#/definitions/v1PublicEcJWK' + v1LoginPasswordRequest: + type: object + properties: + userId: + type: string + password: + type: string + required: + - userId + - password + v1LoginPasswordResponse: + type: object + properties: + detail: + type: string + data: + $ref: '#/definitions/v1AuthToken' + v1Order: + type: object + properties: + id: + type: string + status: + $ref: '#/definitions/v1OrderStatus' + items: + type: object + additionalProperties: + type: integer + format: int32 + description: '''items'' consists of a mapping of Product ID to Quantity.' + customerId: + type: string + transactionId: + type: string + shippingId: + type: string + createdAt: + type: string + format: int64 + updatedAt: + type: string + format: int64 + v1OrderStatus: + type: string + enum: + - ORDER_STATUS_UNSPECIFIED + - ORDER_STATUS_PROCESSING + - ORDER_STATUS_PENDING + - ORDER_STATUS_REJECTED + - ORDER_STATUS_APPROVED + - ORDER_STATUS_COMPLETED + default: ORDER_STATUS_UNSPECIFIED + title: |- + - ORDER_STATUS_PROCESSING: awaiting price quotes for products + - ORDER_STATUS_PENDING: awaiting stock allocation, shipping allotment and payment + v1PlaceOrderResponse: + type: object + properties: + order: + $ref: '#/definitions/v1Order' + v1Product: + type: object + properties: + id: + type: string + name: + type: string + description: + type: string + price: + type: number + format: float + createdAt: + type: string + format: int64 + updatedAt: + type: string + format: int64 + v1ProductStock: + type: object + properties: + productId: + type: string + quantity: + type: integer + format: int32 + v1PublicEcJWK: + type: object + properties: + kty: + type: string + use: + type: string + alg: + type: string + crv: + type: string + x: + type: string + "y": + type: string + v1RegisterUserResponse: + type: object + properties: + user: + $ref: '#/definitions/v1User' + v1Reservation: + type: object + properties: + id: + type: string + orderId: + type: string + reservedStock: + type: array + items: + type: object + $ref: '#/definitions/v1ReservationStock' + createdAt: + type: string + format: int64 + v1ReservationStock: + type: object + properties: + productId: + type: string + quantity: + type: integer + format: int32 + v1ServiceInfoResponse: + type: object + properties: + name: + type: string + source: + type: string + sourceLicense: + type: string + v1SetPasswordRequest: + type: object + properties: + userId: + type: string + password: + type: string + required: + - userId + - password + v1SetPasswordResponse: + type: object + properties: + detail: + type: string + v1Shipment: + type: object + properties: + id: + type: string + orderId: + type: string + dispatched: + type: boolean + createdAt: + type: string + format: int64 + updatedAt: + type: string + format: int64 + v1ShipmentItem: + type: object + properties: + shipmentId: + type: string + productId: + type: string + quantity: + type: integer + format: int32 + v1Transaction: + type: object + properties: + id: + type: string + amount: + type: number + format: float + orderId: + type: string + customerId: + type: string + reversedAt: + type: string + format: int64 + description: Optional - If set, then the transaction has been refunded. + processedAt: + type: string + format: int64 + v1User: + type: object + properties: + id: + type: string + email: + type: string + firstName: + type: string + lastName: + type: string + createdAt: + type: string + format: int64 + updatedAt: + type: string + format: int64 + v1ViewBalanceResponse: + type: object + properties: + balance: + $ref: '#/definitions/v1CustomerBalance' + v1ViewOrderResponse: + type: object + properties: + order: + $ref: '#/definitions/v1Order' + v1ViewOrdersResponse: + type: object + properties: + orders: + type: array + items: + type: object + $ref: '#/definitions/v1Order' + v1ViewProductResponse: + type: object + properties: + product: + $ref: '#/definitions/v1Product' + v1ViewProductStockResponse: + type: object + properties: + stock: + $ref: '#/definitions/v1ProductStock' + v1ViewProductsResponse: + type: object + properties: + products: + type: array + items: + type: object + $ref: '#/definitions/v1Product' + v1ViewReservationResponse: + type: object + properties: + reservation: + $ref: '#/definitions/v1Reservation' + v1ViewShipmentManifestResponse: + type: object + properties: + manifest: + type: array + items: + type: object + $ref: '#/definitions/v1ShipmentItem' + v1ViewShipmentResponse: + type: object + properties: + shipment: + $ref: '#/definitions/v1Shipment' + v1ViewTransactionResponse: + type: object + properties: + transaction: + $ref: '#/definitions/v1Transaction' + v1ViewUserResponse: + type: object + properties: + user: + $ref: '#/definitions/v1User' diff --git a/schema/protobufs/buf.lock b/schema/protobufs/buf.lock new file mode 100644 index 0000000..7961304 --- /dev/null +++ b/schema/protobufs/buf.lock @@ -0,0 +1,18 @@ +# Generated by buf. DO NOT EDIT. +version: v1 +deps: + - remote: buf.build + owner: bufbuild + repository: protovalidate + commit: e097f827e65240ac9fd4b1158849a8fc + digest: shake256:f19252436fd9ded945631e2ffaaed28247a92c9015ccf55ae99db9fb3d9600c4fdb00fd2d3bd7701026ec2fd4715c5129e6ae517c25a59ba690020cfe80bf8ad + - remote: buf.build + owner: googleapis + repository: googleapis + commit: b30c5775bfb3485d9da2e87b26590ac9 + digest: shake256:9d0caaf056949a0e1c883b9849d8a2fa66e22f18a2a48f867d1a8c700aa22abee50ad3ef0d8171637457cadc43c584998bdf3adac55da0f9e4614c72686b057d + - remote: buf.build + owner: grpc-ecosystem + repository: grpc-gateway + commit: 3f42134f4c564983838425bc43c7a65f + digest: shake256:3d11d4c0fe5e05fda0131afefbce233940e27f0c31c5d4e385686aea58ccd30f72053f61af432fa83f1fc11cda57f5f18ca3da26a29064f73c5a0d076bba8d92 diff --git a/schema/protobufs/buf.yaml b/schema/protobufs/buf.yaml new file mode 100644 index 0000000..e971b7e --- /dev/null +++ b/schema/protobufs/buf.yaml @@ -0,0 +1,12 @@ +version: v1 +deps: + - buf.build/googleapis/googleapis + - buf.build/grpc-ecosystem/grpc-gateway + - buf.build/bufbuild/protovalidate +lint: + use: + - DEFAULT + allow_comment_ignores: true +breaking: + use: + - FILE \ No newline at end of file diff --git a/schema/protobufs/stocklet/auth/v1/service.proto b/schema/protobufs/stocklet/auth/v1/service.proto new file mode 100644 index 0000000..121479d --- /dev/null +++ b/schema/protobufs/stocklet/auth/v1/service.proto @@ -0,0 +1,110 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +syntax = "proto3"; + +package stocklet.auth.v1; + +import "buf/validate/validate.proto"; +import "google/api/annotations.proto"; +import "google/api/field_behavior.proto"; +import "google/api/visibility.proto"; +import "google/protobuf/empty.proto"; +import "stocklet/auth/v1/types.proto"; +import "stocklet/common/v1/requests.proto"; +import "stocklet/events/v1/user.proto"; + +option go_package = "github.com/hexolan/stocklet/internal/pkg/protogen/auth/v1;auth_v1"; + +service AuthService { + // View information about the service. + // + // buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + rpc ServiceInfo(stocklet.common.v1.ServiceInfoRequest) returns (stocklet.common.v1.ServiceInfoResponse) { + option (google.api.http) = {get: "/v1/auth/service"}; + } + + rpc GetJwks(GetJwksRequest) returns (GetJwksResponse) { + option (google.api.http) = {get: "/v1/auth/jwks"}; + } + + rpc LoginPassword(LoginPasswordRequest) returns (LoginPasswordResponse) { + option (google.api.http) = { + post: "/v1/auth/login" + body: "*" + }; + } + + rpc SetPassword(SetPasswordRequest) returns (SetPasswordResponse) { + option (google.api.http) = { + post: "/v1/auth/password" + body: "*" + }; + } + + // A consumer will call this method to process events. + // + // buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + // buf:lint:ignore RPC_REQUEST_STANDARD_NAME + // buf:lint:ignore RPC_RESPONSE_STANDARD_NAME + rpc ProcessUserDeletedEvent(stocklet.events.v1.UserDeletedEvent) returns (google.protobuf.Empty) { + option (google.api.method_visibility).restriction = "INTERNAL"; + } +} + +message GetJwksRequest {} + +message GetJwksResponse { + repeated PublicEcJWK keys = 1; +} + +message LoginPasswordRequest { + string user_id = 1 [ + (google.api.field_behavior) = REQUIRED, + (buf.validate.field).string.min_len = 1 + ]; + + string password = 2 [ + (google.api.field_behavior) = REQUIRED, + (buf.validate.field).string = { + min_len: 1; + max_len: 64; + } + ]; +} + +message LoginPasswordResponse { + string detail = 1; + AuthToken data = 2; +} + +message SetPasswordRequest { + string user_id = 1 [ + (google.api.field_behavior) = REQUIRED, + (buf.validate.field).string.min_len = 1 + ]; + + string password = 2 [ + (google.api.field_behavior) = REQUIRED, + (buf.validate.field).string = { + min_len: 1; + max_len: 64; + } + ]; +} + +message SetPasswordResponse { + string detail = 1; +} diff --git a/schema/protobufs/stocklet/auth/v1/types.proto b/schema/protobufs/stocklet/auth/v1/types.proto new file mode 100644 index 0000000..54ac81b --- /dev/null +++ b/schema/protobufs/stocklet/auth/v1/types.proto @@ -0,0 +1,35 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +syntax = "proto3"; + +package stocklet.auth.v1; + +option go_package = "github.com/hexolan/stocklet/internal/pkg/protogen/auth/v1;auth_v1"; + +message PublicEcJWK { + string kty = 1; + string use = 2; + string alg = 3; + string crv = 4; + string x = 5; + string y = 6; +} + +message AuthToken { + string token_type = 1; + string access_token = 2; + int64 expires_in = 3; +} diff --git a/schema/protobufs/stocklet/common/v1/requests.proto b/schema/protobufs/stocklet/common/v1/requests.proto new file mode 100644 index 0000000..292768d --- /dev/null +++ b/schema/protobufs/stocklet/common/v1/requests.proto @@ -0,0 +1,28 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +syntax = "proto3"; + +package stocklet.common.v1; + +option go_package = "github.com/hexolan/stocklet/internal/pkg/protogen/common/v1;common_v1"; + +message ServiceInfoRequest {} + +message ServiceInfoResponse { + string name = 1; + string source = 2; + string source_license = 3; +} diff --git a/schema/protobufs/stocklet/events/v1/order.proto b/schema/protobufs/stocklet/events/v1/order.proto new file mode 100644 index 0000000..0c662b5 --- /dev/null +++ b/schema/protobufs/stocklet/events/v1/order.proto @@ -0,0 +1,63 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +syntax = "proto3"; + +package stocklet.events.v1; + +option go_package = "github.com/hexolan/stocklet/internal/pkg/protogen/events/v1;events_v1"; + +// Order Status = processing +message OrderCreatedEvent { + int32 revision = 1; + + string order_id = 2; + string customer_id = 3; + + map item_quantities = 4; +} + +// Order Status = pending +message OrderPendingEvent { + int32 revision = 1; + + string order_id = 2; + string customer_id = 3; + + map item_quantities = 4; + + float items_price = 5; + float total_price = 6; +} + +// Order Status = rejected +message OrderRejectedEvent { + int32 revision = 1; + + string order_id = 2; + + optional string transaction_id = 3; + optional string shipping_id = 4; +} + +// Order Status = approved +message OrderApprovedEvent { + int32 revision = 1; + + string order_id = 2; + + string transaction_id = 3; + string shipping_id = 4; +} diff --git a/schema/protobufs/stocklet/events/v1/payment.proto b/schema/protobufs/stocklet/events/v1/payment.proto new file mode 100644 index 0000000..225b62b --- /dev/null +++ b/schema/protobufs/stocklet/events/v1/payment.proto @@ -0,0 +1,88 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +syntax = "proto3"; + +package stocklet.events.v1; + +option go_package = "github.com/hexolan/stocklet/internal/pkg/protogen/events/v1;events_v1"; + +message BalanceCreatedEvent { + int32 revision = 1; + + string customer_id = 2; + float balance = 3; +} + +message BalanceCreditedEvent { + int32 revision = 1; + + string customer_id = 2; + float amount = 3; + float new_balance = 4; +} + +message BalanceDebitedEvent { + int32 revision = 1; + + string customer_id = 2; + float amount = 3; + float new_balance = 4; +} + +message BalanceClosedEvent { + int32 revision = 1; + + string customer_id = 2; + float balance = 3; +} + +message TransactionLoggedEvent { + int32 revision = 1; + + string transaction_id = 2; + float amount = 3; + + string order_id = 4; + string customer_id = 5; +} + +message TransactionReversedEvent { + int32 revision = 1; + + string transaction_id = 2; + float amount = 3; + + string order_id = 4; + string customer_id = 5; +} + +message PaymentProcessedEvent { + enum Type { + TYPE_UNSPECIFIED = 0; + TYPE_FAILED = 1; + TYPE_SUCCESS = 2; + } + + int32 revision = 1; + Type type = 2; + + string order_id = 3; + string customer_id = 4; + + float amount = 5; + + optional string transaction_id = 6; +} diff --git a/schema/protobufs/stocklet/events/v1/product.proto b/schema/protobufs/stocklet/events/v1/product.proto new file mode 100644 index 0000000..29bbd73 --- /dev/null +++ b/schema/protobufs/stocklet/events/v1/product.proto @@ -0,0 +1,63 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +syntax = "proto3"; + +package stocklet.events.v1; + +option go_package = "github.com/hexolan/stocklet/internal/pkg/protogen/events/v1;events_v1"; + +message ProductCreatedEvent { + int32 revision = 1; + + string product_id = 2; + string name = 3; + string description = 4; + float price = 5; +} + +message ProductPriceUpdatedEvent { + int32 revision = 1; + + string product_id = 2; + float price = 3; +} + +message ProductDeletedEvent { + int32 revision = 1; + + string product_id = 2; +} + +message ProductPriceQuoteEvent { + enum Type { + TYPE_UNSPECIFIED = 0; + TYPE_UNAVALIABLE = 1; + TYPE_AVALIABLE = 2; + } + + int32 revision = 1; + Type type = 2; + + string order_id = 3; + + // Product ID: Quantity + map product_quantities = 4; + + // Product ID: Unit Price + map product_prices = 5; + + float total_price = 6; +} diff --git a/schema/protobufs/stocklet/events/v1/shipping.proto b/schema/protobufs/stocklet/events/v1/shipping.proto new file mode 100644 index 0000000..c5a50c0 --- /dev/null +++ b/schema/protobufs/stocklet/events/v1/shipping.proto @@ -0,0 +1,52 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +syntax = "proto3"; + +package stocklet.events.v1; + +option go_package = "github.com/hexolan/stocklet/internal/pkg/protogen/events/v1;events_v1"; + +message ShipmentAllocationEvent { + enum Type { + TYPE_UNSPECIFIED = 0; + TYPE_FAILED = 1; + TYPE_ALLOCATED = 2; + TYPE_ALLOCATION_RELEASED = 3; + } + + int32 revision = 1; + Type type = 2; + + message OrderMetadata { + string customer_id = 1; + float items_price = 2; + float total_price = 3; + } + + string order_id = 3; + OrderMetadata order_metadata = 4; + + string shipment_id = 5; // provided with type enum value 2+ + map product_quantities = 6; +} + +message ShipmentDispatchedEvent { + int32 revision = 1; + + string shipment_id = 2; + string order_id = 3; + map product_quantities = 4; +} diff --git a/schema/protobufs/stocklet/events/v1/user.proto b/schema/protobufs/stocklet/events/v1/user.proto new file mode 100644 index 0000000..134e531 --- /dev/null +++ b/schema/protobufs/stocklet/events/v1/user.proto @@ -0,0 +1,43 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +syntax = "proto3"; + +package stocklet.events.v1; + +option go_package = "github.com/hexolan/stocklet/internal/pkg/protogen/events/v1;events_v1"; + +message UserCreatedEvent { + int32 revision = 1; + + string user_id = 2; + string email = 3; + string first_name = 4; + string last_name = 5; +} + +message UserEmailUpdatedEvent { + int32 revision = 1; + + string user_id = 2; + string email = 3; +} + +message UserDeletedEvent { + int32 revision = 1; + + string user_id = 2; + string email = 3; +} diff --git a/schema/protobufs/stocklet/events/v1/warehouse.proto b/schema/protobufs/stocklet/events/v1/warehouse.proto new file mode 100644 index 0000000..3ba2002 --- /dev/null +++ b/schema/protobufs/stocklet/events/v1/warehouse.proto @@ -0,0 +1,75 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +syntax = "proto3"; + +package stocklet.events.v1; + +option go_package = "github.com/hexolan/stocklet/internal/pkg/protogen/events/v1;events_v1"; + +message StockCreatedEvent { + int32 revision = 1; + + string product_id = 2; + int32 quantity = 3; +} + +message StockAddedEvent { + int32 revision = 1; + + string product_id = 2; + int32 amount = 3; + + // If the stock is returned as a result of a stock reservation outcome, + // then the reservation id will be included for reference. + optional string reservation_id = 4; +} + +message StockRemovedEvent { + int32 revision = 1; + + string product_id = 2; + int32 amount = 3; + + // If the stock is removed as a result of a stock reservation being closed, + // then the reservation id will be included for reference. + optional string reservation_id = 4; +} + +message StockReservationEvent { + enum Type { + TYPE_UNSPECIFIED = 0; + TYPE_INSUFFICIENT_STOCK = 1; + TYPE_STOCK_RESERVED = 2; + TYPE_STOCK_RETURNED = 3; + TYPE_STOCK_CONSUMED = 4; + } + + int32 revision = 1; + Type type = 2; + + message OrderMetadata { + string customer_id = 1; + float items_price = 2; + float total_price = 3; + } + + string order_id = 3; + OrderMetadata order_metadata = 4; + + string reservation_id = 5; // provided with type enum value 2+ + map reservation_stock = 6; // Product ID: Quantity (provided with type enum value 2+) + repeated string insufficient_stock = 7; // Product IDs (only provided with TYPE_INSUFFICIENT_STOCK) +} diff --git a/schema/protobufs/stocklet/order/v1/service.proto b/schema/protobufs/stocklet/order/v1/service.proto new file mode 100644 index 0000000..99161a1 --- /dev/null +++ b/schema/protobufs/stocklet/order/v1/service.proto @@ -0,0 +1,126 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +syntax = "proto3"; + +package stocklet.order.v1; + +import "buf/validate/validate.proto"; +import "google/api/annotations.proto"; +import "google/api/visibility.proto"; +import "google/protobuf/empty.proto"; +import "stocklet/common/v1/requests.proto"; +import "stocklet/events/v1/payment.proto"; +import "stocklet/events/v1/product.proto"; +import "stocklet/events/v1/shipping.proto"; +import "stocklet/events/v1/warehouse.proto"; +import "stocklet/order/v1/types.proto"; + +option go_package = "github.com/hexolan/stocklet/internal/pkg/protogen/order/v1;order_v1"; + +service OrderService { + // View information about the service. + // + // buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + rpc ServiceInfo(stocklet.common.v1.ServiceInfoRequest) returns (stocklet.common.v1.ServiceInfoResponse) { + option (google.api.http) = {get: "/v1/order/service"}; + } + + rpc ViewOrder(ViewOrderRequest) returns (ViewOrderResponse) { + option (google.api.http) = {get: "/v1/order/orders/{order_id}"}; + } + + // Get a list of a customer's orders. + // If accessed through the gateway - shows the current user's orders. + rpc ViewOrders(ViewOrdersRequest) returns (ViewOrdersResponse) { + option (google.api.http) = {get: "/v1/order/list"}; + } + + rpc PlaceOrder(PlaceOrderRequest) returns (PlaceOrderResponse) { + option (google.api.http) = { + post: "/v1/order/place" + body: "cart" + }; + } + + // A consumer will call this method to process events. + // + // buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + // buf:lint:ignore RPC_REQUEST_STANDARD_NAME + // buf:lint:ignore RPC_RESPONSE_STANDARD_NAME + rpc ProcessProductPriceQuoteEvent(stocklet.events.v1.ProductPriceQuoteEvent) returns (google.protobuf.Empty) { + option (google.api.method_visibility).restriction = "INTERNAL"; + } + + // A consumer will call this method to process events. + // + // buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + // buf:lint:ignore RPC_REQUEST_STANDARD_NAME + // buf:lint:ignore RPC_RESPONSE_STANDARD_NAME + rpc ProcessStockReservationEvent(stocklet.events.v1.StockReservationEvent) returns (google.protobuf.Empty) { + option (google.api.method_visibility).restriction = "INTERNAL"; + } + + // A consumer will call this method to process events. + // + // buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + // buf:lint:ignore RPC_REQUEST_STANDARD_NAME + // buf:lint:ignore RPC_RESPONSE_STANDARD_NAME + rpc ProcessShipmentAllocationEvent(stocklet.events.v1.ShipmentAllocationEvent) returns (google.protobuf.Empty) { + option (google.api.method_visibility).restriction = "INTERNAL"; + } + + // A consumer will call this method to process events. + // + // buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + // buf:lint:ignore RPC_REQUEST_STANDARD_NAME + // buf:lint:ignore RPC_RESPONSE_STANDARD_NAME + rpc ProcessPaymentProcessedEvent(stocklet.events.v1.PaymentProcessedEvent) returns (google.protobuf.Empty) { + option (google.api.method_visibility).restriction = "INTERNAL"; + } +} + +message ViewOrderRequest { + string order_id = 1 [(buf.validate.field).string.min_len = 1]; +} + +message ViewOrderResponse { + Order order = 1; +} + +message ViewOrdersRequest { + string customer_id = 1 [(buf.validate.field).string.min_len = 1]; +} + +message ViewOrdersResponse { + repeated Order orders = 1; +} + +message GetOrderItemsRequest { + string id = 1 [(buf.validate.field).string.min_len = 1]; +} + +message GetOrderItemsResponse { + map items = 1 [(buf.validate.field).map.values.int32.gt = 0]; +} + +message PlaceOrderRequest { + map cart = 1 [(buf.validate.field).map.values.int32.gt = 0]; + string customer_id = 2; +} + +message PlaceOrderResponse { + Order order = 1; +} diff --git a/schema/protobufs/stocklet/order/v1/types.proto b/schema/protobufs/stocklet/order/v1/types.proto new file mode 100644 index 0000000..89d0204 --- /dev/null +++ b/schema/protobufs/stocklet/order/v1/types.proto @@ -0,0 +1,51 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +syntax = "proto3"; + +package stocklet.order.v1; + +import "buf/validate/validate.proto"; + +option go_package = "github.com/hexolan/stocklet/internal/pkg/protogen/order/v1;order_v1"; + +enum OrderStatus { + ORDER_STATUS_UNSPECIFIED = 0; + ORDER_STATUS_PROCESSING = 1; // awaiting price quotes for products + ORDER_STATUS_PENDING = 2; // awaiting stock allocation, shipping allotment and payment + ORDER_STATUS_REJECTED = 3; + ORDER_STATUS_APPROVED = 4; + ORDER_STATUS_COMPLETED = 5; +} + +message Order { + string id = 1 [(buf.validate.field).string.min_len = 1]; + + OrderStatus status = 2 [(buf.validate.field).enum = { + defined_only: true, + not_in: [0] + }]; + + // 'items' consists of a mapping of Product ID to Quantity. + map items = 3 [(buf.validate.field).map.values.int32.gt = 0]; + + string customer_id = 4 [(buf.validate.field).string.min_len = 1]; + + optional string transaction_id = 5 [(buf.validate.field).string.min_len = 1]; + optional string shipping_id = 6 [(buf.validate.field).string.min_len = 1]; + + int64 created_at = 7; + optional int64 updated_at = 8; +} diff --git a/schema/protobufs/stocklet/payment/v1/service.proto b/schema/protobufs/stocklet/payment/v1/service.proto new file mode 100644 index 0000000..a65e45d --- /dev/null +++ b/schema/protobufs/stocklet/payment/v1/service.proto @@ -0,0 +1,89 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +syntax = "proto3"; + +package stocklet.payment.v1; + +import "buf/validate/validate.proto"; +import "google/api/annotations.proto"; +import "google/api/visibility.proto"; +import "google/protobuf/empty.proto"; +import "stocklet/common/v1/requests.proto"; +import "stocklet/events/v1/shipping.proto"; +import "stocklet/events/v1/user.proto"; +import "stocklet/payment/v1/types.proto"; + +option go_package = "github.com/hexolan/stocklet/internal/pkg/protogen/payment/v1;payment_v1"; + +service PaymentService { + // View information about the service. + // + // buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + rpc ServiceInfo(stocklet.common.v1.ServiceInfoRequest) returns (stocklet.common.v1.ServiceInfoResponse) { + option (google.api.http) = {get: "/v1/payment/service"}; + } + + rpc ViewTransaction(ViewTransactionRequest) returns (ViewTransactionResponse) { + option (google.api.http) = {get: "/v1/payment/transaction/{transaction_id}"}; + } + + rpc ViewBalance(ViewBalanceRequest) returns (ViewBalanceResponse) { + option (google.api.http) = {get: "/v1/payment/balance/{customer_id}"}; + } + + // A consumer will call this method to process events. + // + // buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + // buf:lint:ignore RPC_REQUEST_STANDARD_NAME + // buf:lint:ignore RPC_RESPONSE_STANDARD_NAME + rpc ProcessUserCreatedEvent(stocklet.events.v1.UserCreatedEvent) returns (google.protobuf.Empty) { + option (google.api.method_visibility).restriction = "INTERNAL"; + } + + // A consumer will call this method to process events. + // + // buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + // buf:lint:ignore RPC_REQUEST_STANDARD_NAME + // buf:lint:ignore RPC_RESPONSE_STANDARD_NAME + rpc ProcessUserDeletedEvent(stocklet.events.v1.UserDeletedEvent) returns (google.protobuf.Empty) { + option (google.api.method_visibility).restriction = "INTERNAL"; + } + + // A consumer will call this method to process events. + // + // buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + // buf:lint:ignore RPC_REQUEST_STANDARD_NAME + // buf:lint:ignore RPC_RESPONSE_STANDARD_NAME + rpc ProcessShipmentAllocationEvent(stocklet.events.v1.ShipmentAllocationEvent) returns (google.protobuf.Empty) { + option (google.api.method_visibility).restriction = "INTERNAL"; + } +} + +message ViewTransactionRequest { + string transaction_id = 1 [(buf.validate.field).string.min_len = 1]; +} + +message ViewTransactionResponse { + Transaction transaction = 1; +} + +message ViewBalanceRequest { + string customer_id = 1 [(buf.validate.field).string.min_len = 1]; +} + +message ViewBalanceResponse { + CustomerBalance balance = 1; +} diff --git a/schema/protobufs/stocklet/payment/v1/types.proto b/schema/protobufs/stocklet/payment/v1/types.proto new file mode 100644 index 0000000..4637733 --- /dev/null +++ b/schema/protobufs/stocklet/payment/v1/types.proto @@ -0,0 +1,41 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +syntax = "proto3"; + +package stocklet.payment.v1; + +import "buf/validate/validate.proto"; + +option go_package = "github.com/hexolan/stocklet/internal/pkg/protogen/payment/v1;payment_v1"; + +message Transaction { + string id = 1 [(buf.validate.field).string.min_len = 1]; + + float amount = 2 [(buf.validate.field).float.gte = 0.0]; + + string order_id = 3 [(buf.validate.field).string.min_len = 1]; + string customer_id = 4 [(buf.validate.field).string.min_len = 1]; + + // Optional - If set, then the transaction has been refunded. + optional int64 reversed_at = 5; + + int64 processed_at = 6; +} + +message CustomerBalance { + string customer_id = 1 [(buf.validate.field).string.min_len = 1]; + float balance = 2 [(buf.validate.field).float.gte = 0.0]; +} diff --git a/schema/protobufs/stocklet/product/v1/service.proto b/schema/protobufs/stocklet/product/v1/service.proto new file mode 100644 index 0000000..f5e8559 --- /dev/null +++ b/schema/protobufs/stocklet/product/v1/service.proto @@ -0,0 +1,68 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +syntax = "proto3"; + +package stocklet.product.v1; + +import "buf/validate/validate.proto"; +import "google/api/annotations.proto"; +import "google/api/visibility.proto"; +import "google/protobuf/empty.proto"; +import "stocklet/common/v1/requests.proto"; +import "stocklet/events/v1/order.proto"; +import "stocklet/product/v1/types.proto"; + +option go_package = "github.com/hexolan/stocklet/internal/pkg/protogen/product/v1;product_v1"; + +service ProductService { + // View information about the service. + // + // buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + rpc ServiceInfo(stocklet.common.v1.ServiceInfoRequest) returns (stocklet.common.v1.ServiceInfoResponse) { + option (google.api.http) = {get: "/v1/product/service"}; + } + + rpc ViewProduct(ViewProductRequest) returns (ViewProductResponse) { + option (google.api.http) = {get: "/v1/product/{id}"}; + } + + rpc ViewProducts(ViewProductsRequest) returns (ViewProductsResponse) { + option (google.api.http) = {get: "/v1/product/list"}; + } + + // A consumer will call this method to process events. + // + // buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + // buf:lint:ignore RPC_REQUEST_STANDARD_NAME + // buf:lint:ignore RPC_RESPONSE_STANDARD_NAME + rpc ProcessOrderCreatedEvent(stocklet.events.v1.OrderCreatedEvent) returns (google.protobuf.Empty) { + option (google.api.method_visibility).restriction = "INTERNAL"; + } +} + +message ViewProductRequest { + string id = 1 [(buf.validate.field).string.min_len = 1]; +} + +message ViewProductResponse { + Product product = 1; +} + +message ViewProductsRequest {} + +message ViewProductsResponse { + repeated Product products = 1; +} diff --git a/schema/protobufs/stocklet/product/v1/types.proto b/schema/protobufs/stocklet/product/v1/types.proto new file mode 100644 index 0000000..5a176d7 --- /dev/null +++ b/schema/protobufs/stocklet/product/v1/types.proto @@ -0,0 +1,34 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +syntax = "proto3"; + +package stocklet.product.v1; + +import "buf/validate/validate.proto"; + +option go_package = "github.com/hexolan/stocklet/internal/pkg/protogen/product/v1;product_v1"; + +message Product { + string id = 1 [(buf.validate.field).string.min_len = 1]; + + string name = 2 [(buf.validate.field).string.min_len = 1]; + string description = 3 [(buf.validate.field).string.min_len = 1]; + + float price = 4 [(buf.validate.field).float.gte = 0.0]; + + int64 created_at = 5; + optional int64 updated_at = 6; +} diff --git a/schema/protobufs/stocklet/shipping/v1/service.proto b/schema/protobufs/stocklet/shipping/v1/service.proto new file mode 100644 index 0000000..5870783 --- /dev/null +++ b/schema/protobufs/stocklet/shipping/v1/service.proto @@ -0,0 +1,80 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +syntax = "proto3"; + +package stocklet.shipping.v1; + +import "buf/validate/validate.proto"; +import "google/api/annotations.proto"; +import "google/api/visibility.proto"; +import "google/protobuf/empty.proto"; +import "stocklet/common/v1/requests.proto"; +import "stocklet/events/v1/payment.proto"; +import "stocklet/events/v1/warehouse.proto"; +import "stocklet/shipping/v1/types.proto"; + +option go_package = "github.com/hexolan/stocklet/internal/pkg/protogen/shipping/v1;shipping_v1"; + +service ShippingService { + // View information about the service. + // + // buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + rpc ServiceInfo(stocklet.common.v1.ServiceInfoRequest) returns (stocklet.common.v1.ServiceInfoResponse) { + option (google.api.http) = {get: "/v1/shipping/service"}; + } + + rpc ViewShipment(ViewShipmentRequest) returns (ViewShipmentResponse) { + option (google.api.http) = {get: "/v1/shipping/shipment/{shipment_id}"}; + } + + rpc ViewShipmentManifest(ViewShipmentManifestRequest) returns (ViewShipmentManifestResponse) { + option (google.api.http) = {get: "/v1/shipping/shipment/{shipment_id}/manifest"}; + } + + // A consumer will call this method to process events. + // + // buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + // buf:lint:ignore RPC_REQUEST_STANDARD_NAME + // buf:lint:ignore RPC_RESPONSE_STANDARD_NAME + rpc ProcessStockReservationEvent(stocklet.events.v1.StockReservationEvent) returns (google.protobuf.Empty) { + option (google.api.method_visibility).restriction = "INTERNAL"; + } + + // A consumer will call this method to process events. + // + // buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + // buf:lint:ignore RPC_REQUEST_STANDARD_NAME + // buf:lint:ignore RPC_RESPONSE_STANDARD_NAME + rpc ProcessPaymentProcessedEvent(stocklet.events.v1.PaymentProcessedEvent) returns (google.protobuf.Empty) { + option (google.api.method_visibility).restriction = "INTERNAL"; + } +} + +message ViewShipmentRequest { + string shipment_id = 1 [(buf.validate.field).string.min_len = 1]; +} + +message ViewShipmentResponse { + Shipment shipment = 1; +} + +message ViewShipmentManifestRequest { + string shipment_id = 1 [(buf.validate.field).string.min_len = 1]; +} + +message ViewShipmentManifestResponse { + repeated ShipmentItem manifest = 1; +} diff --git a/schema/protobufs/stocklet/shipping/v1/types.proto b/schema/protobufs/stocklet/shipping/v1/types.proto new file mode 100644 index 0000000..f665ef8 --- /dev/null +++ b/schema/protobufs/stocklet/shipping/v1/types.proto @@ -0,0 +1,39 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +syntax = "proto3"; + +package stocklet.shipping.v1; + +import "buf/validate/validate.proto"; + +option go_package = "github.com/hexolan/stocklet/internal/pkg/protogen/shipping/v1;shipping_v1"; + +message Shipment { + string id = 1 [(buf.validate.field).string.min_len = 1]; + string order_id = 2 [(buf.validate.field).string.min_len = 1]; + + bool dispatched = 3; + + int64 created_at = 5; + optional int64 updated_at = 6; +} + +message ShipmentItem { + string shipment_id = 1 [(buf.validate.field).string.min_len = 1]; + + string product_id = 2 [(buf.validate.field).string.min_len = 1]; + int32 quantity = 3 [(buf.validate.field).int32.gt = 0]; +} diff --git a/schema/protobufs/stocklet/stocklet.proto b/schema/protobufs/stocklet/stocklet.proto new file mode 100644 index 0000000..3f3805f --- /dev/null +++ b/schema/protobufs/stocklet/stocklet.proto @@ -0,0 +1,39 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +syntax = "proto3"; + +// buf:lint:ignore PACKAGE_VERSION_SUFFIX +package stocklet; + +import "protoc-gen-openapiv2/options/annotations.proto"; + +option go_package = "github.com/hexolan/stocklet/internal/pkg/protogen"; +option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger) = { + info: { + title: "Stocklet"; + version: "0.1.0"; + contact: { + name: "GitHub Repository"; + url: "https://github.com/hexolan/stocklet"; + }; + license: { + name: "AGPL-3.0"; + url: "https://github.com/hexolan/stocklet/blob/main/LICENSE"; + } + }; + host: "localhost"; + schemes: HTTP; +}; diff --git a/schema/protobufs/stocklet/user/v1/service.proto b/schema/protobufs/stocklet/user/v1/service.proto new file mode 100644 index 0000000..9ecc347 --- /dev/null +++ b/schema/protobufs/stocklet/user/v1/service.proto @@ -0,0 +1,86 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +syntax = "proto3"; + +package stocklet.user.v1; + +import "buf/validate/validate.proto"; +import "google/api/annotations.proto"; +import "google/api/field_behavior.proto"; +import "stocklet/common/v1/requests.proto"; +import "stocklet/user/v1/types.proto"; + +option go_package = "github.com/hexolan/stocklet/internal/pkg/protogen/user/v1;user_v1"; + +service UserService { + // View information about the service. + // + // buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + rpc ServiceInfo(stocklet.common.v1.ServiceInfoRequest) returns (stocklet.common.v1.ServiceInfoResponse) { + option (google.api.http) = {get: "/v1/user/service"}; + } + + rpc ViewUser(ViewUserRequest) returns (ViewUserResponse) { + option (google.api.http) = {get: "/v1/user/users/{id}"}; + } + + rpc RegisterUser(RegisterUserRequest) returns (RegisterUserResponse) { + option (google.api.http) = {post: "/v1/user/register"}; + } +} + +message ViewUserRequest { + string id = 1 [(buf.validate.field).string.min_len = 1]; +} + +message ViewUserResponse { + User user = 1; +} + +message RegisterUserRequest { + string first_name = 1 [ + (google.api.field_behavior) = REQUIRED, + (buf.validate.field).string = { + min_len: 1; + max_len: 35; + } + ]; + + string last_name = 2 [ + (google.api.field_behavior) = REQUIRED, + (buf.validate.field).string = { + min_len: 1; + max_len: 35; + } + ]; + + string email = 3 [ + (google.api.field_behavior) = REQUIRED, + (buf.validate.field).string.email = true + ]; + + string password = 4 [ + (google.api.field_behavior) = REQUIRED, + (buf.validate.field).string = { + min_len: 1; + max_len: 64; + } + ]; +} + +message RegisterUserResponse { + User user = 1; +} diff --git a/schema/protobufs/stocklet/user/v1/types.proto b/schema/protobufs/stocklet/user/v1/types.proto new file mode 100644 index 0000000..eacec4e --- /dev/null +++ b/schema/protobufs/stocklet/user/v1/types.proto @@ -0,0 +1,40 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +syntax = "proto3"; + +package stocklet.user.v1; + +import "buf/validate/validate.proto"; + +option go_package = "github.com/hexolan/stocklet/internal/pkg/protogen/user/v1;user_v1"; + +message User { + string id = 1 [(buf.validate.field).string.min_len = 1]; + + string email = 2 [(buf.validate.field).string.email = true]; + + string first_name = 3 [(buf.validate.field).string = { + min_len: 1; + max_len: 35; + }]; + string last_name = 4 [(buf.validate.field).string = { + min_len: 1; + max_len: 35; + }]; + + int64 created_at = 5; + optional int64 updated_at = 6; +} diff --git a/schema/protobufs/stocklet/warehouse/v1/service.proto b/schema/protobufs/stocklet/warehouse/v1/service.proto new file mode 100644 index 0000000..e1e49dc --- /dev/null +++ b/schema/protobufs/stocklet/warehouse/v1/service.proto @@ -0,0 +1,100 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +syntax = "proto3"; + +package stocklet.warehouse.v1; + +import "buf/validate/validate.proto"; +import "google/api/annotations.proto"; +import "google/api/visibility.proto"; +import "google/protobuf/empty.proto"; +import "stocklet/common/v1/requests.proto"; +import "stocklet/events/v1/order.proto"; +import "stocklet/events/v1/payment.proto"; +import "stocklet/events/v1/product.proto"; +import "stocklet/events/v1/shipping.proto"; +import "stocklet/warehouse/v1/types.proto"; + +option go_package = "github.com/hexolan/stocklet/internal/pkg/protogen/warehouse/v1;warehouse_v1"; + +service WarehouseService { + // View information about the service. + // + // buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + rpc ServiceInfo(stocklet.common.v1.ServiceInfoRequest) returns (stocklet.common.v1.ServiceInfoResponse) { + option (google.api.http) = {get: "/v1/warehouse/service"}; + } + + rpc ViewProductStock(ViewProductStockRequest) returns (ViewProductStockResponse) { + option (google.api.http) = {get: "/v1/warehouse/product/{product_id}"}; + } + + rpc ViewReservation(ViewReservationRequest) returns (ViewReservationResponse) { + option (google.api.http) = {get: "/v1/warehouse/reservation/{reservation_id}"}; + } + + // A consumer will call this method to process events. + // + // buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + // buf:lint:ignore RPC_REQUEST_STANDARD_NAME + // buf:lint:ignore RPC_RESPONSE_STANDARD_NAME + rpc ProcessProductCreatedEvent(stocklet.events.v1.ProductCreatedEvent) returns (google.protobuf.Empty) { + option (google.api.method_visibility).restriction = "INTERNAL"; + } + + // A consumer will call this method to process events. + // + // buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + // buf:lint:ignore RPC_REQUEST_STANDARD_NAME + // buf:lint:ignore RPC_RESPONSE_STANDARD_NAME + rpc ProcessOrderPendingEvent(stocklet.events.v1.OrderPendingEvent) returns (google.protobuf.Empty) { + option (google.api.method_visibility).restriction = "INTERNAL"; + } + + // A consumer will call this method to process events. + // + // buf:lint:ignore RPC_REQUEST_STANDARD_NAME + // buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + // buf:lint:ignore RPC_RESPONSE_STANDARD_NAME + rpc ProcessShipmentAllocationEvent(stocklet.events.v1.ShipmentAllocationEvent) returns (google.protobuf.Empty) { + option (google.api.method_visibility).restriction = "INTERNAL"; + } + + // A consumer will call this method to process events. + // + // buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE + // buf:lint:ignore RPC_REQUEST_STANDARD_NAME + // buf:lint:ignore RPC_RESPONSE_STANDARD_NAME + rpc ProcessPaymentProcessedEvent(stocklet.events.v1.PaymentProcessedEvent) returns (google.protobuf.Empty) { + option (google.api.method_visibility).restriction = "INTERNAL"; + } +} + +message ViewProductStockRequest { + string product_id = 1 [(buf.validate.field).string.min_len = 1]; +} + +message ViewProductStockResponse { + ProductStock stock = 1; +} + +message ViewReservationRequest { + string reservation_id = 1 [(buf.validate.field).string.min_len = 1]; +} + +message ViewReservationResponse { + Reservation reservation = 1; +} diff --git a/schema/protobufs/stocklet/warehouse/v1/types.proto b/schema/protobufs/stocklet/warehouse/v1/types.proto new file mode 100644 index 0000000..d504233 --- /dev/null +++ b/schema/protobufs/stocklet/warehouse/v1/types.proto @@ -0,0 +1,41 @@ +// Copyright (C) 2024 Declan Teevan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +syntax = "proto3"; + +package stocklet.warehouse.v1; + +import "buf/validate/validate.proto"; + +option go_package = "github.com/hexolan/stocklet/internal/pkg/protogen/warehouse/v1;warehouse_v1"; + +message ProductStock { + string product_id = 1 [(buf.validate.field).string.min_len = 1]; + int32 quantity = 2 [(buf.validate.field).int32.gte = 0]; +} + +message Reservation { + string id = 1 [(buf.validate.field).string.min_len = 1]; + + string order_id = 2 [(buf.validate.field).string.min_len = 1]; + repeated ReservationStock reserved_stock = 3; + + int64 created_at = 4; +} + +message ReservationStock { + string product_id = 1 [(buf.validate.field).string.min_len = 1]; + int32 quantity = 2 [(buf.validate.field).int32.gte = 0]; +} diff --git a/schema/sql/auth/000001_init_auth.down.sql b/schema/sql/auth/000001_init_auth.down.sql new file mode 100644 index 0000000..88c4384 --- /dev/null +++ b/schema/sql/auth/000001_init_auth.down.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS auth_methods CASCADE; \ No newline at end of file diff --git a/schema/sql/auth/000001_init_auth.up.sql b/schema/sql/auth/000001_init_auth.up.sql new file mode 100644 index 0000000..6770150 --- /dev/null +++ b/schema/sql/auth/000001_init_auth.up.sql @@ -0,0 +1,4 @@ +CREATE TABLE auth_methods ( + user_id varchar(64) PRIMARY KEY, + hashed_password varchar(128) NOT NULL +); \ No newline at end of file diff --git a/schema/sql/order/000001_init_order.down.sql b/schema/sql/order/000001_init_order.down.sql new file mode 100644 index 0000000..f5770aa --- /dev/null +++ b/schema/sql/order/000001_init_order.down.sql @@ -0,0 +1,3 @@ +DROP TABLE IF EXISTS orders CASCADE; +DROP TABLE IF EXISTS order_items CASCADE; +DROP TABLE IF EXISTS event_outbox CASCADE; \ No newline at end of file diff --git a/schema/sql/order/000001_init_order.up.sql b/schema/sql/order/000001_init_order.up.sql new file mode 100644 index 0000000..511820f --- /dev/null +++ b/schema/sql/order/000001_init_order.up.sql @@ -0,0 +1,32 @@ +CREATE TABLE orders ( + id bigserial PRIMARY KEY, + status smallint NOT NULL, + + customer_id varchar(64) NOT NULL, + shipment_id varchar(64), + transaction_id varchar(64), + + items_price money, + total_price money, + + created_at timestamp NOT NULL DEFAULT timezone('utc', now()), + updated_at timestamp +); + +CREATE TABLE order_items ( + order_id bigserial, + product_id varchar(64), + + quantity integer NOT NULL, + + PRIMARY KEY (order_id, product_id), + FOREIGN KEY (order_id) REFERENCES orders (id) ON DELETE CASCADE +); + +CREATE TABLE event_outbox ( + id bigserial PRIMARY KEY, + + aggregateid varchar(128) NOT NULL, + aggregatetype varchar(128) NOT NULL, + payload bytea NOT NULL +); \ No newline at end of file diff --git a/schema/sql/payment/000001_init_payment.down.sql b/schema/sql/payment/000001_init_payment.down.sql new file mode 100644 index 0000000..7ba5df1 --- /dev/null +++ b/schema/sql/payment/000001_init_payment.down.sql @@ -0,0 +1,3 @@ +DROP TABLE IF EXISTS transactions CASCADE; +DROP TABLE IF EXISTS customer_balances CASCADE; +DROP TABLE IF EXISTS event_outbox CASCADE; \ No newline at end of file diff --git a/schema/sql/payment/000001_init_payment.up.sql b/schema/sql/payment/000001_init_payment.up.sql new file mode 100644 index 0000000..d3864d3 --- /dev/null +++ b/schema/sql/payment/000001_init_payment.up.sql @@ -0,0 +1,24 @@ +CREATE TABLE transactions ( + id bigserial PRIMARY KEY, + + order_id varchar(64), + customer_id varchar(64) NOT NULL, + + amount money NOT NULL, + + reversed_at timestamp, + processed_at timestamp NOT NULL DEFAULT timezone('utc', now()) +); + +CREATE TABLE customer_balances ( + customer_id varchar(64) PRIMARY KEY, + balance money NOT NULL +); + +CREATE TABLE event_outbox ( + id bigserial PRIMARY KEY, + + aggregateid varchar(128) NOT NULL, + aggregatetype varchar(128) NOT NULL, + payload bytea NOT NULL +); \ No newline at end of file diff --git a/schema/sql/product/000001_init_product.down.sql b/schema/sql/product/000001_init_product.down.sql new file mode 100644 index 0000000..b33fb42 --- /dev/null +++ b/schema/sql/product/000001_init_product.down.sql @@ -0,0 +1,2 @@ +DROP TABLE IF EXISTS products CASCADE; +DROP TABLE IF EXISTS event_outbox CASCADE; \ No newline at end of file diff --git a/schema/sql/product/000001_init_product.up.sql b/schema/sql/product/000001_init_product.up.sql new file mode 100644 index 0000000..97ebbdb --- /dev/null +++ b/schema/sql/product/000001_init_product.up.sql @@ -0,0 +1,18 @@ +CREATE TABLE products ( + id bigserial PRIMARY KEY, + + name varchar(128) NOT NULL, + description varchar(256) NOT NULL, + price money NOT NULL, + + created_at timestamp NOT NULL DEFAULT timezone('utc', now()), + updated_at timestamp +); + +CREATE TABLE event_outbox ( + id bigserial PRIMARY KEY, + + aggregateid varchar(128) NOT NULL, + aggregatetype varchar(128) NOT NULL, + payload bytea NOT NULL +); \ No newline at end of file diff --git a/schema/sql/shipping/000001_init_shipping.down.sql b/schema/sql/shipping/000001_init_shipping.down.sql new file mode 100644 index 0000000..7888489 --- /dev/null +++ b/schema/sql/shipping/000001_init_shipping.down.sql @@ -0,0 +1,3 @@ +DROP TABLE IF EXISTS shipments CASCADE; +DROP TABLE IF EXISTS shipment_items CASCADE; +DROP TABLE IF EXISTS event_outbox CASCADE; \ No newline at end of file diff --git a/schema/sql/shipping/000001_init_shipping.up.sql b/schema/sql/shipping/000001_init_shipping.up.sql new file mode 100644 index 0000000..529876f --- /dev/null +++ b/schema/sql/shipping/000001_init_shipping.up.sql @@ -0,0 +1,26 @@ +CREATE TABLE shipments ( + id bigserial PRIMARY KEY, + order_id varchar(64) NOT NULL, + + dispatched boolean DEFAULT FALSE, + + created_at timestamp NOT NULL DEFAULT timezone('utc', now()) +); + +CREATE TABLE shipment_items ( + shipment_id bigserial, + product_id varchar(64), + + quantity integer NOT NULL, + + PRIMARY KEY (shipment_id, product_id), + FOREIGN KEY (shipment_id) REFERENCES shipments (id) ON DELETE CASCADE +); + +CREATE TABLE event_outbox ( + id bigserial PRIMARY KEY, + + aggregateid varchar(128) NOT NULL, + aggregatetype varchar(128) NOT NULL, + payload bytea NOT NULL +); \ No newline at end of file diff --git a/schema/sql/user/000001_init_user.down.sql b/schema/sql/user/000001_init_user.down.sql new file mode 100644 index 0000000..79c494a --- /dev/null +++ b/schema/sql/user/000001_init_user.down.sql @@ -0,0 +1,2 @@ +DROP TABLE IF EXISTS users CASCADE; +DROP TABLE IF EXISTS event_outbox CASCADE; \ No newline at end of file diff --git a/schema/sql/user/000001_init_user.up.sql b/schema/sql/user/000001_init_user.up.sql new file mode 100644 index 0000000..bd174a7 --- /dev/null +++ b/schema/sql/user/000001_init_user.up.sql @@ -0,0 +1,19 @@ +CREATE TABLE users ( + id bigserial PRIMARY KEY, + + first_name varchar(64) NOT NULL, + last_name varchar(64) NOT NULL, + + email varchar NOT NULL UNIQUE, + + created_at timestamp NOT NULL DEFAULT timezone('utc', now()), + updated_at timestamp +); + +CREATE TABLE event_outbox ( + id bigserial PRIMARY KEY, + + aggregateid varchar(128) NOT NULL, + aggregatetype varchar(128) NOT NULL, + payload bytea NOT NULL +); \ No newline at end of file diff --git a/schema/sql/warehouse/000001_init_warehouse.down.sql b/schema/sql/warehouse/000001_init_warehouse.down.sql new file mode 100644 index 0000000..9ce6b8b --- /dev/null +++ b/schema/sql/warehouse/000001_init_warehouse.down.sql @@ -0,0 +1,4 @@ +DROP TABLE IF EXISTS product_stock CASCADE; +DROP TABLE IF EXISTS reservations CASCADE; +DROP TABLE IF EXISTS reservation_items CASCADE; +DROP TABLE IF EXISTS event_outbox CASCADE; \ No newline at end of file diff --git a/schema/sql/warehouse/000001_init_warehouse.up.sql b/schema/sql/warehouse/000001_init_warehouse.up.sql new file mode 100644 index 0000000..e3e08cd --- /dev/null +++ b/schema/sql/warehouse/000001_init_warehouse.up.sql @@ -0,0 +1,30 @@ +CREATE TABLE product_stock ( + product_id varchar(64) PRIMARY KEY, + quantity integer NOT NULL +); + +CREATE TABLE reservations ( + id bigserial PRIMARY KEY, + + order_id varchar(64) NOT NULL, + + created_at timestamp NOT NULL DEFAULT timezone('utc', now()) +); + +CREATE TABLE reservation_items ( + reservation_id bigserial, + product_id varchar(64), + + quantity integer NOT NULL, + + PRIMARY KEY (reservation_id, product_id), + FOREIGN KEY (reservation_id) REFERENCES reservations (id) ON DELETE CASCADE +); + +CREATE TABLE event_outbox ( + id bigserial PRIMARY KEY, + + aggregateid varchar(128) NOT NULL, + aggregatetype varchar(128) NOT NULL, + payload bytea NOT NULL +); \ No newline at end of file