Changed the data types to be able to hold a companys NIF
This commit is contained in:
+12
-1
@@ -2,9 +2,9 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
// TODO: configure the logging
|
// TODO: configure the logging
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
// _ "net/http/pprof"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
sw "github.com/ESilva15/PTInvCertSWDB/sw"
|
sw "github.com/ESilva15/PTInvCertSWDB/sw"
|
||||||
@@ -44,13 +44,24 @@ func get(c *gin.Context) {
|
|||||||
c.JSON(http.StatusOK, sw)
|
c.JSON(http.StatusOK, sw)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func count(c *gin.Context) {
|
||||||
|
count := sw.Count()
|
||||||
|
|
||||||
|
c.JSON(http.StatusOK, gin.H{"count": count})
|
||||||
|
}
|
||||||
|
|
||||||
func RunServer() error {
|
func RunServer() error {
|
||||||
|
// go func() {
|
||||||
|
// http.ListenAndServe("localhost:6060", nil)
|
||||||
|
// }()
|
||||||
|
|
||||||
gin.SetMode(ginMode)
|
gin.SetMode(ginMode)
|
||||||
router := gin.Default()
|
router := gin.Default()
|
||||||
|
|
||||||
authGroup := router.Group("/")
|
authGroup := router.Group("/")
|
||||||
// authGroup.Use(APIAuthMiddleWare())
|
// authGroup.Use(APIAuthMiddleWare())
|
||||||
authGroup.GET("/sw/:id", get)
|
authGroup.GET("/sw/:id", get)
|
||||||
|
authGroup.GET("/count", count)
|
||||||
|
|
||||||
// Star the SW service
|
// Star the SW service
|
||||||
err := sw.StartSWService(sw.FILEDB)
|
err := sw.StartSWService(sw.FILEDB)
|
||||||
|
|||||||
@@ -0,0 +1,61 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
// WE GOT MIGRATIONS AT HOME
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
func convertAction(cmd *cobra.Command, args []string) {
|
||||||
|
// source, err := os.ReadFile("./swdb.yaml")
|
||||||
|
// if err != nil {
|
||||||
|
// log.Fatalf("Unable to open configuration file [%s]: %s", "./swdb.yaml",
|
||||||
|
// err.Error())
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// var list model.SWList
|
||||||
|
// err = yaml.Unmarshal(source, &list)
|
||||||
|
// if err != nil {
|
||||||
|
// log.Fatalf("Error parsing JSON: %s", err.Error())
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// file, err := os.OpenFile("./new_swdb.yaml", os.O_CREATE|os.O_RDWR, 0744)
|
||||||
|
// if err != nil {
|
||||||
|
// log.Fatal("Failed to open DB file:", err)
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// newList := make(model.NewSWList, len(list))
|
||||||
|
// for index, value := range list {
|
||||||
|
// newList[index] = model.NewSW{
|
||||||
|
// Name: value.Name,
|
||||||
|
// Version: value.Version,
|
||||||
|
// Developer: model.Company{
|
||||||
|
// Name: value.Developer,
|
||||||
|
// NIF: "",
|
||||||
|
// },
|
||||||
|
// CertNo: value.CertNo,
|
||||||
|
// State: value.State,
|
||||||
|
// CertDate: value.CertDate,
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// n, err := file.Write(newList.ToYAML())
|
||||||
|
// if err != nil {
|
||||||
|
// log.Fatal("Error writing data to db file:", err)
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// log.Println("Succesfully wrote ", n, "to db file")
|
||||||
|
}
|
||||||
|
|
||||||
|
// shelf
|
||||||
|
var convertCMD = &cobra.Command{
|
||||||
|
Use: "convert",
|
||||||
|
Short: "",
|
||||||
|
Long: ``,
|
||||||
|
Args: nil,
|
||||||
|
Run: convertAction,
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
rootCmd.AddCommand(convertCMD)
|
||||||
|
}
|
||||||
+1
-1
@@ -58,7 +58,7 @@ func Scrape() models.SWList {
|
|||||||
|
|
||||||
sw.Name = el.ChildText("td:nth-child(1)")
|
sw.Name = el.ChildText("td:nth-child(1)")
|
||||||
sw.Version = el.ChildText("td:nth-child(2)")
|
sw.Version = el.ChildText("td:nth-child(2)")
|
||||||
sw.Developer = el.ChildText("td:nth-child(3)")
|
sw.Developer.Name = el.ChildText("td:nth-child(3)")
|
||||||
sw.CertNo = certNo
|
sw.CertNo = certNo
|
||||||
sw.State = el.ChildText("td:nth-child(5)")
|
sw.State = el.ChildText("td:nth-child(5)")
|
||||||
sw.CertDate = date
|
sw.CertDate = date
|
||||||
|
|||||||
+11
-7
@@ -8,15 +8,19 @@ import (
|
|||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type Company struct {
|
||||||
|
Name string `json:"name" yaml:"name"`
|
||||||
|
NIF string `json:"nif" yaml:"nif"`
|
||||||
|
}
|
||||||
|
|
||||||
// SW holds the data that describe an AT certified invoicing software
|
// SW holds the data that describe an AT certified invoicing software
|
||||||
type SW struct {
|
type SW struct {
|
||||||
Name string `json:"name" yaml:"name"`
|
Name string `json:"name" yaml:"name"`
|
||||||
Version string `json:"version" yaml:"version"`
|
Version string `json:"version" yaml:"version"`
|
||||||
Developer string `json:"developer" yaml:"developer"`
|
Developer Company `json:"developer" yaml:"developer"`
|
||||||
CertNo int `json:"certNo" yaml:"certNo"`
|
CertNo int `json:"certNo" yaml:"certNo"`
|
||||||
State string `json:"state" yaml:"state"`
|
State string `json:"state" yaml:"state"`
|
||||||
DeveloperNIF string `json:"string" yaml:"string"`
|
CertDate time.Time `json:"certDate" yaml:"certDate"`
|
||||||
CertDate time.Time `json:"certDate" yaml:"certDate"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SWList is just a list of SW
|
// SWList is just a list of SW
|
||||||
|
|||||||
@@ -60,3 +60,7 @@ func (yr YamlRepo) Get(id int) (models.SW, error) {
|
|||||||
|
|
||||||
return models.SW{}, errors.New("not found")
|
return models.SW{}, errors.New("not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (yr YamlRepo) Count() int {
|
||||||
|
return len(yr.Data)
|
||||||
|
}
|
||||||
|
|||||||
@@ -5,4 +5,5 @@ import models "github.com/ESilva15/PTInvCertSWDB/sw/models"
|
|||||||
|
|
||||||
type SWRepo interface {
|
type SWRepo interface {
|
||||||
Get(id int) (models.SW, error)
|
Get(id int) (models.SW, error)
|
||||||
|
Count() int
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,3 +45,7 @@ func StartSWService(rt RepoType) error {
|
|||||||
func Get(id int) (models.SW, error) {
|
func Get(id int) (models.SW, error) {
|
||||||
return service.SWRepo.Get(id)
|
return service.SWRepo.Get(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Count() int {
|
||||||
|
return service.SWRepo.Count()
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user