Skip to content

Commit

Permalink
Fixed issue with null object for delete request
Browse files Browse the repository at this point in the history
  • Loading branch information
maallen committed Nov 7, 2024
1 parent 524ea6b commit 8a59d89
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
import com.beust.jcommander.Parameters;
import com.box.l10n.mojito.rest.client.AIServiceClient;
import com.box.l10n.mojito.rest.entity.AITranslationLocalePromptOverridesRequest;
import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

@Component
@Scope("prototype")
Expand Down Expand Up @@ -38,8 +38,8 @@ public class AIRepositoryLocaleOverrideCommand extends Command {
@Parameter(
names = {"--locales", "-l"},
required = true,
description = "Locale BCP-47 tags")
Set<String> locales;
description = "Locale BCP-47 tags provided in a comma separated list")
String locales;

@Parameter(
names = {"--disabled"},
Expand All @@ -57,7 +57,8 @@ public class AIRepositoryLocaleOverrideCommand extends Command {
@Override
protected void execute() throws CommandException {
AITranslationLocalePromptOverridesRequest aiTranslationLocalePromptOverridesRequest =
new AITranslationLocalePromptOverridesRequest(repository, locales, aiPromptId, disabled);
new AITranslationLocalePromptOverridesRequest(
repository, StringUtils.commaDelimitedListToSet(locales), aiPromptId, disabled);

if (isDelete) {
aiServiceClient.deleteRepositoryLocalePromptOverrides(
Expand Down
10 changes: 7 additions & 3 deletions webapp/src/main/java/com/box/l10n/mojito/rest/ai/AIPromptWS.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
Expand Down Expand Up @@ -95,25 +97,27 @@ public void deletePromptMessage(@PathVariable("context_message_id") Long context
value = "/api/ai/prompts/translation/locale/overrides",
method = RequestMethod.POST)
@Timed("AIWS.createOrUpdateRepositoryLocalePromptOverrides")
public void createOrUpdateRepositoryLocalePromptOverrides(
public ResponseEntity<String> createOrUpdateRepositoryLocalePromptOverrides(
@RequestBody AITranslationLocalePromptOverridesRequest request) {
logger.debug("Received request to create or update repository locale prompt overrides");
promptService.createOrUpdateRepositoryLocaleTranslationPromptOverrides(
request.getRepositoryName(),
request.getLocales(),
request.getAiPromptId(),
request.isDisabled());
return new ResponseEntity<>("Success", HttpStatus.CREATED);
}

@RequestMapping(
value = "/api/ai/prompts/translation/locale/overrides",
method = RequestMethod.DELETE)
@Timed("AIWS.deleteRepositoryLocalePromptOverrides")
public void deleteRepositoryLocalePromptOverrides(
AITranslationLocalePromptOverridesRequest request) {
public ResponseEntity<String> deleteRepositoryLocalePromptOverrides(
@RequestBody AITranslationLocalePromptOverridesRequest request) {
logger.debug("Received request to delete repository locale prompt overrides");
promptService.deleteRepositoryLocaleTranslationPromptOverride(
request.getRepositoryName(), request.getLocales());
return new ResponseEntity<>("Delete success", HttpStatus.OK);
}

private static AIPrompt buildOpenAIPromptDTO(com.box.l10n.mojito.entity.AIPrompt prompt) {
Expand Down

0 comments on commit 8a59d89

Please sign in to comment.