Today Eats
A delivery backend where I focused on menu visibility, ownership, and handling uncertain AI responses.

I built menu management and AI-assisted descriptions for a team delivery backend. I paid most attention to two edges: what a customer can order versus what a store owner can manage, and what the menu editor should receive when an external AI call fails.

Separating the shop window from the management view
In Spring Boot, the owner read path loads the store and checks ownership before querying management results. Public reads use their own repository method for orderable menus. Writes recheck ownership against the menu’s store. Soft deletion retains the record and takes it out of the customer’s ordering flow.
public Page<Menu> getOwnerMenusByStore(
UUID storeId,
UUID userId,
String keyword,
Pageable pageable
) {
Store store = storeRepository.findById(storeId)
.orElseThrow(() -> new IllegalArgumentException("가게 없음"));
validateStoreOwner(store, userId);
return menuRepository.findOwnerMenusByStoreId(storeId, keyword, pageable);
}
// 고객용 가게 메뉴 조회
public Page<Menu> getMenusByStore(
UUID storeId,
String keyword,
Pageable pageable
) {
return menuRepository.findOrderableMenusByStoreId(storeId, keyword, pageable);
}
Turning Gemini responses into application outcomes
The vendor client distinguishes a transport failure from other API errors. It also checks that the first candidate contains non-blank text, even when the HTTP response is successful. This gives the menu workflow a clear error when generation returns an empty response.
ResponseEntity<GeminiResponseDto> response;
try {
response = restTemplate.postForEntity(url, body, GeminiResponseDto.class);
} catch (ResourceAccessException e) {
throw new BaseException(AiRequestLogErrorCode.AI_TIMEOUT); // AI_TIMEOUT
} catch (Exception e) {
throw new BaseException(AiRequestLogErrorCode.AI_API_ERROR); // 네트워크 오류, 키 오류, 서버 오류
}
if (!response.getStatusCode().is2xxSuccessful()) {
throw new BaseException(AiRequestLogErrorCode.AI_API_ERROR); // 400, 500
}
GeminiResponseDto bodyResponse = response.getBody();
if (bodyResponse == null
|| bodyResponse.candidates() == null
|| bodyResponse.candidates().isEmpty()
|| bodyResponse.candidates().get(0).content() == null
|| bodyResponse.candidates().get(0).content().parts() == null
|| bodyResponse.candidates().get(0).content().parts().isEmpty()
|| bodyResponse.candidates().get(0).content().parts().get(0).text() == null
|| bodyResponse.candidates().get(0).content().parts().get(0).text().isBlank()) {
throw new BaseException(AiRequestLogErrorCode.AI_RESPONSE_EMPTY); // AI_RESPONSE_EMPTY
}Keeping generated copy short and traceable
The service trims the output and caps it at 50 characters for the menu description. It also logs the original prompt separately from the prompt sent to Gemini, so the request can be reviewed in context.
// 2. 공백 제거
response = response.trim();
// 3. 길이 제한
if (response.length() > MAX_DESCRIPTION_LENGTH) {
response = response.substring(0, MAX_DESCRIPTION_LENGTH);
}
aiRequestLogRepository.save(
new AiRequestLogEntity(prompt, requestPrompt, response, userId)
);
return new AiProductDescriptionResponse(prompt, response);What I learned
Both features benefited from enforcing their rules in the backend. The UI can present permissions and suggested text, while the service decides which records are visible and what result is safe to return.