Setup domain method to get ID by Project Name

This commit is contained in:
naudachu 2023-07-08 14:13:45 +05:00
parent 2cba8c5c26
commit 0d48ccedb9
1 changed files with 23 additions and 0 deletions

View File

@ -1,5 +1,7 @@
package domain
import "fmt"
type Project struct {
ID string `json:"id"`
ShortName string `json:"shortName"`
@ -10,6 +12,23 @@ type ProjectID struct {
ID string `json:"id"`
}
// Find needed project.ID in the project's list
func (plist *ProjectsList) FindProjectByName(searchName string) (string, error) {
projectID := ""
for _, elem := range plist.Projects {
if elem.ShortName == searchName {
projectID = elem.ID
}
}
if projectID == "" {
return "", fmt.Errorf("project %s doesn't exist", searchName)
}
return projectID, nil
}
type IssueCreateRequest struct {
ProjectID ProjectID `json:"project"`
Key string `json:"idReadable"`
@ -30,3 +49,7 @@ type CustomField struct {
Type string `json:"$type"`
Value string `json:"value"`
}
type ProjectsList struct {
Projects []Project
}