Changed the data types to be able to hold a companys NIF

This commit is contained in:
2025-09-20 23:47:44 +01:00
parent b578976dad
commit 3821c3fffc
8 changed files with 24672 additions and 9 deletions
+12 -1
View File
@@ -2,9 +2,9 @@
package api
// TODO: configure the logging
import (
"net/http"
// _ "net/http/pprof"
"strconv"
sw "github.com/ESilva15/PTInvCertSWDB/sw"
@@ -44,13 +44,24 @@ func get(c *gin.Context) {
c.JSON(http.StatusOK, sw)
}
func count(c *gin.Context) {
count := sw.Count()
c.JSON(http.StatusOK, gin.H{"count": count})
}
func RunServer() error {
// go func() {
// http.ListenAndServe("localhost:6060", nil)
// }()
gin.SetMode(ginMode)
router := gin.Default()
authGroup := router.Group("/")
// authGroup.Use(APIAuthMiddleWare())
authGroup.GET("/sw/:id", get)
authGroup.GET("/count", count)
// Star the SW service
err := sw.StartSWService(sw.FILEDB)
+61
View File
@@ -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
View File
@@ -58,7 +58,7 @@ func Scrape() models.SWList {
sw.Name = el.ChildText("td:nth-child(1)")
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.State = el.ChildText("td:nth-child(5)")
sw.CertDate = date
+11 -7
View File
@@ -8,15 +8,19 @@ import (
"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
type SW struct {
Name string `json:"name" yaml:"name"`
Version string `json:"version" yaml:"version"`
Developer string `json:"developer" yaml:"developer"`
CertNo int `json:"certNo" yaml:"certNo"`
State string `json:"state" yaml:"state"`
DeveloperNIF string `json:"string" yaml:"string"`
CertDate time.Time `json:"certDate" yaml:"certDate"`
Name string `json:"name" yaml:"name"`
Version string `json:"version" yaml:"version"`
Developer Company `json:"developer" yaml:"developer"`
CertNo int `json:"certNo" yaml:"certNo"`
State string `json:"state" yaml:"state"`
CertDate time.Time `json:"certDate" yaml:"certDate"`
}
// SWList is just a list of SW
+4
View File
@@ -60,3 +60,7 @@ func (yr YamlRepo) Get(id int) (models.SW, error) {
return models.SW{}, errors.New("not found")
}
func (yr YamlRepo) Count() int {
return len(yr.Data)
}
+1
View File
@@ -5,4 +5,5 @@ import models "github.com/ESilva15/PTInvCertSWDB/sw/models"
type SWRepo interface {
Get(id int) (models.SW, error)
Count() int
}
+4
View File
@@ -45,3 +45,7 @@ func StartSWService(rt RepoType) error {
func Get(id int) (models.SW, error) {
return service.SWRepo.Get(id)
}
func Count() int {
return service.SWRepo.Count()
}
Executable
+24578
View File
File diff suppressed because it is too large Load Diff