-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
42 changed files
with
847 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package greencity.controller; | ||
|
||
import greencity.annotations.ApiLocale; | ||
import greencity.annotations.CurrentUser; | ||
import greencity.constant.HttpStatuses; | ||
import greencity.dto.user.UserVO; | ||
import greencity.service.AIService; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
import io.swagger.v3.oas.annotations.media.Content; | ||
import io.swagger.v3.oas.annotations.media.ExampleObject; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
import lombok.AllArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import java.util.Locale; | ||
|
||
@RestController | ||
@RequestMapping("/ai") | ||
@AllArgsConstructor | ||
public class AIController { | ||
private final AIService aiService; | ||
|
||
@Operation(summary = "Makes predictions about the environmental impact of the current user " | ||
+ "based on the analysis of their habits and habit duration.") | ||
@ApiResponses(value = { | ||
@ApiResponse(responseCode = "200", description = HttpStatuses.OK), | ||
@ApiResponse(responseCode = "400", description = HttpStatuses.BAD_REQUEST, | ||
content = @Content(examples = @ExampleObject(HttpStatuses.BAD_REQUEST))), | ||
@ApiResponse(responseCode = "401", description = HttpStatuses.UNAUTHORIZED, | ||
content = @Content(examples = @ExampleObject(HttpStatuses.UNAUTHORIZED))), | ||
@ApiResponse(responseCode = "404", description = HttpStatuses.NOT_FOUND, | ||
content = @Content(examples = @ExampleObject(HttpStatuses.NOT_FOUND))) | ||
}) | ||
@ApiLocale | ||
@GetMapping("/forecast") | ||
public ResponseEntity<String> forecast(@Parameter(hidden = true) @CurrentUser UserVO userVO, | ||
@Parameter(hidden = true) Locale locale) { | ||
return ResponseEntity.status(HttpStatus.OK) | ||
.body(aiService.getForecast(userVO.getId(), locale.getDisplayLanguage())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
55 changes: 55 additions & 0 deletions
55
core/src/test/java/greencity/controller/AIControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package greencity.controller; | ||
|
||
import greencity.service.AIService; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import org.mockito.junit.jupiter.MockitoSettings; | ||
import org.mockito.quality.Strictness; | ||
import org.springframework.context.annotation.Import; | ||
import org.springframework.data.web.PageableHandlerMethodArgumentResolver; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import org.springframework.test.web.servlet.setup.MockMvcBuilders; | ||
import java.security.Principal; | ||
import java.util.Locale; | ||
import static greencity.ModelUtils.getPrincipal; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | ||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.any; | ||
import static org.mockito.Mockito.eq; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
@MockitoSettings(strictness = Strictness.LENIENT) | ||
@Import(AIController.class) | ||
class AIControllerTest { | ||
@Mock | ||
private AIService aiService; | ||
@InjectMocks | ||
private AIController aiController; | ||
private MockMvc mockMvc; | ||
private Principal principal = getPrincipal(); | ||
|
||
@BeforeEach | ||
void setup() { | ||
this.mockMvc = MockMvcBuilders.standaloneSetup(aiController) | ||
.setCustomArgumentResolvers(new PageableHandlerMethodArgumentResolver()) | ||
.build(); | ||
} | ||
|
||
@Test | ||
void forecast_ReturnsForecast_FromAIService() throws Exception { | ||
Locale testLocale = Locale.forLanguageTag("en"); | ||
|
||
mockMvc.perform(get("/ai/forecast") | ||
.principal(principal) | ||
.locale(testLocale)) | ||
.andExpect(status().isOk()); | ||
|
||
verify(aiService, times(1)).getForecast(any(), eq(testLocale.getDisplayLanguage())); | ||
} | ||
} |
35 changes: 0 additions & 35 deletions
35
core/src/test/java/greencity/repository/LanguageRepoTest.java
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
service-api/src/main/java/greencity/constant/OpenAIRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package greencity.constant; | ||
|
||
import lombok.experimental.UtilityClass; | ||
|
||
@UtilityClass | ||
public class OpenAIRequest { | ||
public static final String FORECAST = | ||
"respond in a personalized manner, concisely, and accurately. Use numbers to present approximate data. " | ||
+ "Provide a forecast of this person's impact on the global environment, considering their habits " | ||
+ "over the specified number of days:"; | ||
} |
Oops, something went wrong.