Files
tm_back/ted/calendar.go
T
n.nakhostin 44f266189c Refactor TED Calendar and EForm Structure for Enhanced Functionality
- Updated the GetOJS function to accept a base URL parameter, improving flexibility in constructing the calendar URL.
- Removed the deprecated eform.go file, streamlining the codebase by eliminating unused components.
- Introduced new eform structures for BusinessRegistrationInformationNotice, ContractNotice, ContractAwardNotice, and PriorInformationNotice, enhancing the handling of TED XML data.
- Implemented mapping functions to convert eform notices to the Tender entity, improving integration with the tender management system.
- Added a service layer to encapsulate business logic related to eform processing, adhering to Clean Architecture principles.
2025-09-30 16:51:40 +03:30

47 lines
838 B
Go

package ted
import (
"bytes"
"encoding/csv"
"fmt"
"io"
"net/http"
"strings"
)
const (
calendarUrl = "%s/en/release-calendar/-/download/file/CSV/%d"
)
// Get OJS Number
func GetOJS(baseURL string, year int, date string) (string, error) {
var (
ojs string
)
url := fmt.Sprintf(calendarUrl, baseURL, year)
resp, err := http.Get(url)
if err != nil {
return ojs, err
}
defer resp.Body.Close()
// read CSV
body, _ := io.ReadAll(resp.Body)
reader := csv.NewReader(bytes.NewReader(body))
records, _ := reader.ReadAll()
for _, row := range records[1:] {
rowDate := strings.TrimSpace(row[1])
if rowDate == strings.TrimSpace(date) {
ojs = fmt.Sprintf("%v00%v", year, strings.TrimSpace(fmt.Sprint(row[0])))
break
}
}
if ojs == "" {
return ojs, fmt.Errorf("can not find ojs number")
}
return ojs, nil
}