d4x1 commented on code in PR #8401:
URL: 
https://github.com/apache/incubator-devlake/pull/8401#discussion_r2057141533


##########
backend/plugins/customize/service/service.go:
##########
@@ -262,22 +263,53 @@ func (s *Service) importCSV(file io.ReadCloser, 
rawDataParams string, recordHand
        }
 }
 
+// createOrUpdateAccount creates or updates an account based on the provided 
name.
+// It returns the account ID and an error if any occurred.
+func (s *Service) createOrUpdateAccount(accountName string, rawDataParams 
string) (string, errors.Error) {
+       if accountName == "" {
+               return "", nil // Return empty ID if name is empty, no error 
needed here.
+       }
+       now := time.Now()
+       accountId := fmt.Sprintf("csv:CsvAccount:0:%s", accountName)

Review Comment:
   Is `0` in `csv:CsvAccount:0:%s` correct?



##########
backend/plugins/customize/service/service.go:
##########
@@ -262,22 +263,53 @@ func (s *Service) importCSV(file io.ReadCloser, 
rawDataParams string, recordHand
        }
 }
 
+// createOrUpdateAccount creates or updates an account based on the provided 
name.
+// It returns the account ID and an error if any occurred.
+func (s *Service) createOrUpdateAccount(accountName string, rawDataParams 
string) (string, errors.Error) {
+       if accountName == "" {
+               return "", nil // Return empty ID if name is empty, no error 
needed here.
+       }
+       now := time.Now()
+       accountId := fmt.Sprintf("csv:CsvAccount:0:%s", accountName)
+       account := &crossdomain.Account{
+               DomainEntity: domainlayer.DomainEntity{
+                       Id: accountId,
+                       NoPKModel: common.NoPKModel{
+                               RawDataOrigin: common.RawDataOrigin{
+                                       RawDataParams: rawDataParams,
+                               },
+                       },
+               },
+               FullName:    accountName,
+               UserName:    accountName,
+               CreatedDate: &now,
+       }
+       err := s.dal.CreateOrUpdate(account)
+       if err != nil {
+               return "", errors.Default.Wrap(err, fmt.Sprintf("failed to 
create or update account for %s", accountName))
+       }
+       return accountId, nil
+}
+
 // issueHandlerFactory returns a handler that save record into `issues`, 
`board_issues` and `issue_labels` table
 func (s *Service) issueHandlerFactory(boardId string, incremental bool) 
func(record map[string]interface{}) errors.Error {
        return func(record map[string]interface{}) errors.Error {
                var err errors.Error
                var id string
-               if record["id"] == nil {
+               idValue, ok := record["id"]

Review Comment:
   I've seen soem duplicated codes like:
   ```
   idValue, ok := record["id"]
   if !ok || idValue == nil {
        return errors.Default.New("record without id")
   }
   id, ok := idValue.(string)
   if !ok || id == "" {
        return errors.Default.New("invalid or empty id")
   }
   ```
   I think we can simplify a function.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to