├── README.md ├── LICENCE ├── employee.go └── security.md /README.md: -------------------------------------------------------------------------------- 1 | # 🦁 Hazrat Ali 2 | 3 | # 🦫 Programmer || Software Engineering 4 | 5 | # 🦋 Go Programming Learning 6 | -------------------------------------------------------------------------------- /LICENCE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Hazrat Ali 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /employee.go: -------------------------------------------------------------------------------- 1 | package controllers 2 | 3 | import ( 4 | "CRUD_API/app/https/domain" 5 | "database/sql" 6 | "fmt" 7 | "net/http" 8 | 9 | ) 10 | 11 | var db *sql.DB 12 | 13 | func NewSystemController(e *echo.Echo, Db *sql.DB) { 14 | db = Db 15 | e.GET("/employee/:id", GetEmployeeById) 16 | e.POST("/employee", InsertEmployee) 17 | e.PUT("/employee/:id", UpdateEmployee) 18 | e.DELETE("/employee/:id", DeleteEmployee) 19 | } 20 | 21 | func GetEmployeeById(c echo.Context) error { 22 | requested_id := c.Param("id") 23 | fmt.Println(requested_id) 24 | 25 | var ( 26 | name string 27 | id string 28 | salary string 29 | age string 30 | ) 31 | err := db.QueryRow("SELECT id,employee_name, employee_salary, employee_age FROM employee WHERE id = ?", requested_id).Scan(&id, &name, &salary, &age) 32 | if err != nil { 33 | fmt.Println(err) 34 | } 35 | 36 | response := domain.Employee{Id: id, Name: name, Salary: salary, Age: age} 37 | return c.JSON(http.StatusOK, response) 38 | } 39 | 40 | func InsertEmployee(c echo.Context) error { 41 | 42 | emp := new(domain.Employee) 43 | if err := c.Bind(emp); err != nil { 44 | return err 45 | } 46 | sql := "INSERT INTO employee(employee_name, employee_salary, employee_age ) VALUES( ?, ?, ?)" 47 | stmt, err := db.Prepare(sql) 48 | 49 | if err != nil { 50 | fmt.Print(err.Error()) 51 | } 52 | defer stmt.Close() 53 | result, err2 := stmt.Exec(emp.Name, emp.Salary, emp.Age) 54 | 55 | if err2 != nil { 56 | panic(err2) 57 | } 58 | fmt.Println(result.LastInsertId()) 59 | return c.JSON(http.StatusCreated, emp.Name) 60 | } 61 | 62 | func UpdateEmployee(c echo.Context) error { 63 | 64 | requested_id := c.Param("id") 65 | emp := new(domain.Employee) 66 | 67 | if err := c.Bind(emp); err != nil { 68 | return err 69 | } 70 | sql := "UPDATE employee SET employee_name = ? ,employee_salary= ?, employee_age = ? WHERE id= ? " 71 | stmt, err := db.Prepare(sql) 72 | 73 | if err != nil { 74 | fmt.Print(err.Error()) 75 | } 76 | defer stmt.Close() 77 | 78 | result, err2 := stmt.Exec(emp.Name, emp.Salary, emp.Age, requested_id) 79 | 80 | if err2 != nil { 81 | panic(err2) 82 | } 83 | fmt.Println(result.LastInsertId()) 84 | return c.JSON(http.StatusCreated, emp.Name) 85 | } 86 | 87 | func DeleteEmployee(c echo.Context) error { 88 | requested_id := c.Param("id") 89 | sql := "Delete FROM employee Where id = ?" 90 | stmt, err := db.Prepare(sql) 91 | if err != nil { 92 | fmt.Println(err) 93 | } 94 | result, err2 := stmt.Exec(requested_id) 95 | if err2 != nil { 96 | panic(err2) 97 | } 98 | fmt.Println(result.RowsAffected()) 99 | 100 | return c.JSON(http.StatusOK, "Deleted") 101 | } 102 | -------------------------------------------------------------------------------- /security.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## Security 4 | 5 | Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/Microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet), [Xamarin](https://github.com/xamarin), and [our GitHub organizations](https://opensource.microsoft.com/). 6 | 7 | If you believe you have found a security vulnerability in any Microsoft-owned repository that meets [Microsoft's definition of a security vulnerability](https://aka.ms/opensource/security/definition), please report it to us as described below. 8 | 9 | ## Reporting Security Issues 10 | 11 | **Please do not report security vulnerabilities through public GitHub issues.** 12 | 13 | Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://aka.ms/opensource/security/create-report). 14 | 15 | If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://aka.ms/opensource/security/pgpkey). 16 | 17 | You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://aka.ms/opensource/security/msrc). 18 | 19 | Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue: 20 | 21 | * Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.) 22 | * Full paths of source file(s) related to the manifestation of the issue 23 | * The location of the affected source code (tag/branch/commit or direct URL) 24 | * Any special configuration required to reproduce the issue 25 | * Step-by-step instructions to reproduce the issue 26 | * Proof-of-concept or exploit code (if possible) 27 | * Impact of the issue, including how an attacker might exploit the issue 28 | 29 | This information will help us triage your report more quickly. 30 | 31 | If you are reporting for a bug bounty, more complete reports can contribute to a higher bounty award. Please visit our [Microsoft Bug Bounty Program](https://aka.ms/opensource/security/bounty) page for more details about our active programs. 32 | 33 | ## Preferred Languages 34 | 35 | We prefer all communications to be in English. 36 | 37 | ## Policy 38 | 39 | Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://aka.ms/opensource/security/cvd). 40 | 41 | 42 | 43 | 44 | 45 | --------------------------------------------------------------------------------