Skip to content

Commit

Permalink
adds junit and fixes parsing endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
rajadilipkolli committed Jun 25, 2023
1 parent 7025dd2 commit 1bc5079
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 10 deletions.
8 changes: 5 additions & 3 deletions src/main/java/com/learning/mfscreener/service/NavService.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
@Service
@RequiredArgsConstructor
@Slf4j
@Transactional(readOnly = true)
@Transactional
public class NavService {

private final MFSchemeRepository mfSchemesRepository;
private final ConversionServiceAdapter conversionServiceAdapter;
private final SchemeService schemeService;

@Loggable
@Transactional(readOnly = true)
public MFSchemeDTO getNav(Long schemeCode) {
return mfSchemesRepository
.findBySchemeIdAndMfSchemeNavEntities_NavDate(
Expand All @@ -32,8 +33,9 @@ public MFSchemeDTO getNav(Long schemeCode) {
.orElseThrow(() -> new SchemeNotFoundException(String.format("Scheme %s Not Found", schemeCode)));
}

public MFSchemeDTO getNavOnDate(Long schemeCode, String inputDate) {
LocalDate adjustedDate = LocalDateUtility.getAdjustedDateForNAV(inputDate);
@Loggable
public MFSchemeDTO getNavOnDate(Long schemeCode, LocalDate inputDate) {
LocalDate adjustedDate = LocalDateUtility.getAdjustedDate(inputDate);
return getNavByDate(schemeCode, adjustedDate);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.learning.mfscreener.service;

import com.learning.mfscreener.adapter.ConversionServiceAdapter;
import com.learning.mfscreener.config.logging.Loggable;
import com.learning.mfscreener.entities.MFSchemeEntity;
import com.learning.mfscreener.entities.MFSchemeNavEntity;
import com.learning.mfscreener.entities.MFSchemeTypeEntity;
Expand Down Expand Up @@ -32,6 +33,7 @@ public class SchemeService {
private final MFSchemeTypeRepository mfSchemeTypeRepository;
private final ConversionServiceAdapter conversionServiceAdapter;

@Loggable
void fetchSchemeDetails(Long schemeCode) {
log.info("Fetching SchemeDetails for AMFISchemeCode :{} ", schemeCode);
URI uri = UriComponentsBuilder.fromHttpUrl(AppConstants.MFAPI_WEBSITE_BASE_URL + schemeCode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,4 @@ public LocalDate getAdjustedDate(LocalDate adjustedDate) {
}
return adjustedDate;
}

public LocalDate getAdjustedDateForNAV(String inputDate) {
LocalDate adjustedDate = LocalDate.parse(inputDate, AppConstants.FORMATTER);
return getAdjustedDate(adjustedDate);
}
}
3 changes: 2 additions & 1 deletion src/main/java/com/learning/mfscreener/web/api/NAVApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import java.time.LocalDate;
import org.springframework.http.ResponseEntity;

public interface NAVApi {
Expand All @@ -21,5 +22,5 @@ ResponseEntity<MFSchemeDTO> getScheme(
public ResponseEntity<MFSchemeDTO> getSchemeNavOnDate(
@Parameter(description = "scheme Code for mutual fund", in = ParameterIn.PATH, example = "120503")
Long schemeCode,
@Parameter(description = "date", in = ParameterIn.PATH, example = "20-01-2020") String date);
@Parameter(description = "date", in = ParameterIn.PATH, example = "2020-20-01") LocalDate date);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import com.learning.mfscreener.models.MFSchemeDTO;
import com.learning.mfscreener.service.NavService;
import com.learning.mfscreener.web.api.NAVApi;
import java.time.LocalDate;
import lombok.RequiredArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
Expand All @@ -24,7 +26,9 @@ public ResponseEntity<MFSchemeDTO> getScheme(@PathVariable(value = "schemeCode")

@Override
@GetMapping(path = "/{schemeCode}/{date}")
public ResponseEntity<MFSchemeDTO> getSchemeNavOnDate(Long schemeCode, String date) {
public ResponseEntity<MFSchemeDTO> getSchemeNavOnDate(
@PathVariable Long schemeCode,
@PathVariable @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate date) {
return ResponseEntity.ok(navService.getNavOnDate(schemeCode, date));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,17 @@ void shouldLoadDataWhenSchemeFound() throws Exception {
.andExpect(jsonPath("$.nav", notNullValue(String.class)))
.andExpect(jsonPath("$.date", notNullValue(String.class)));
}

@Test
void shouldLoadDataWhenSchemeFoundAndLoadHistoricalData() throws Exception {
this.mockMvc
.perform(get("/api/nav/{schemeCode}/{date}", 120503L, "2022-12-20"))
.andExpect(status().isOk())
.andExpect(header().string("Content-Type", is("application/json")))
.andExpect(jsonPath("$.schemeCode", is(120503L), Long.class))
.andExpect(jsonPath("$.payout", is("INF846K01EW2")))
.andExpect(jsonPath("$.schemeName", is("Axis Long Term Equity Fund - Direct Plan - Growth Option")))
.andExpect(jsonPath("$.nav", is("77.6483")))
.andExpect(jsonPath("$.date", is("2023-06-23")));
}
}

0 comments on commit 1bc5079

Please sign in to comment.