Skip to content

Commit

Permalink
Merge branch 'main' into 120-calculate-xirr
Browse files Browse the repository at this point in the history
  • Loading branch information
rajadilipkolli authored Jan 11, 2024
2 parents 447a51b + b1d7cdf commit b185b35
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Licensed under Apache-2.0 2021-2023. */
/* Licensed under Apache-2.0 2021-2024. */
package com.learning.mfscreener.entities;

import jakarta.persistence.Column;
Expand Down Expand Up @@ -33,7 +33,7 @@ public class MFSchemeNavEntity extends AuditableEntity<String> implements Serial
@Column(name = "id", nullable = false)
private Long id;

private double nav;
private Float nav;

@Column(name = "nav_date")
private LocalDate navDate;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Licensed under Apache-2.0 2021-2022. */
/* Licensed under Apache-2.0 2021-2024. */
package com.learning.mfscreener.mapper;

import com.learning.mfscreener.entities.MFSchemeEntity;
Expand Down Expand Up @@ -34,7 +34,7 @@ public interface MfSchemeDtoToEntityMapper extends Converter<MFSchemeDTO, MFSche
@AfterMapping
default void updateMFScheme(MFSchemeDTO scheme, @MappingTarget MFSchemeEntity mfSchemeEntity) {
MFSchemeNavEntity mfSchemenavEntity = new MFSchemeNavEntity();
mfSchemenavEntity.setNav("N.A.".equals(scheme.nav()) ? 0D : Double.parseDouble(scheme.nav()));
mfSchemenavEntity.setNav("N.A.".equals(scheme.nav()) ? 0F : Float.parseFloat(scheme.nav()));
mfSchemenavEntity.setNavDate(LocalDate.parse(scheme.date(), DATE_FORMATTER));
mfSchemeEntity.addSchemeNav(mfSchemenavEntity);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Licensed under Apache-2.0 2022-2023. */
/* Licensed under Apache-2.0 2022-2024. */
package com.learning.mfscreener.mapper;

import com.learning.mfscreener.entities.MFSchemeEntity;
Expand All @@ -23,7 +23,7 @@ public interface MfSchemeEntityToDtoMapper extends Converter<MFSchemeEntity, MFS
@AfterMapping
default MFSchemeDTO updateMFScheme(MFSchemeEntity mfSchemeEntity, @MappingTarget MFSchemeDTO mfSchemeDTO) {
if (!mfSchemeEntity.getMfSchemeNavEntities().isEmpty()) {
double navDouble = mfSchemeEntity.getMfSchemeNavEntities().get(0).getNav();
Float navDouble = mfSchemeEntity.getMfSchemeNavEntities().get(0).getNav();
LocalDate localDate = mfSchemeEntity.getMfSchemeNavEntities().get(0).getNavDate();
String nav = String.valueOf(navDouble);
String date = null;
Expand Down
13 changes: 6 additions & 7 deletions src/main/java/com/learning/mfscreener/models/NAVDataDTO.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
/* Licensed under Apache-2.0 2021-2022. */
/* Licensed under Apache-2.0 2021-2024. */
package com.learning.mfscreener.models;

import com.fasterxml.jackson.annotation.JsonFormat;
import java.io.Serializable;
import java.time.LocalDate;
import lombok.With;

public record NAVDataDTO(
@JsonFormat(pattern = "dd-MM-yyyy", shape = JsonFormat.Shape.STRING) LocalDate date, Double nav, Long schemeId)
implements Serializable {
public NAVDataDTO setSchemeId(Long schemeCode) {
return new NAVDataDTO(date(), nav(), schemeCode);
}
}
@JsonFormat(pattern = "dd-MM-yyyy", shape = JsonFormat.Shape.STRING) LocalDate date,
Float nav,
@With Long schemeId)
implements Serializable {}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void mergeList(NavResponse navResponse, MFSchemeEntity mfSchemeEntity, Long sche
if (navResponse.getData().size()
!= mfSchemeEntity.getMfSchemeNavEntities().size()) {
List<MFSchemeNavEntity> navList = navResponse.getData().stream()
.map(navDataDTO -> navDataDTO.setSchemeId(schemeCode))
.map(navDataDTO -> navDataDTO.withSchemeId(schemeCode))
.map(conversionServiceAdapter::mapNAVDataDTOToMFSchemeNavEntity)
.toList();
log.info("No of entries from Server :{}", navList.size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import com.learning.mfscreener.common.AbstractIntegrationTest;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;

class NavControllerIT extends AbstractIntegrationTest {
Expand All @@ -19,7 +19,7 @@ void shouldThrowExceptionWhenSchemeNotFound() throws Exception {
this.mockMvc
.perform(get("/api/nav/{schemeCode}", 1).accept(MediaType.APPLICATION_JSON))
.andExpect(status().isNotFound())
.andExpect(header().string("Content-Type", is("application/problem+json")))
.andExpect(header().string(HttpHeaders.CONTENT_TYPE, is(MediaType.APPLICATION_PROBLEM_JSON_VALUE)))
.andExpect(jsonPath("$.type", is("about:blank")))
.andExpect(jsonPath("$.title", is("Scheme NotFound")))
.andExpect(jsonPath("$.status", is(404)))
Expand All @@ -32,7 +32,7 @@ void shouldLoadDataWhenSchemeFound() throws Exception {
this.mockMvc
.perform(get("/api/nav/{schemeCode}", 120503L).accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(header().string("Content-Type", is("application/json")))
.andExpect(header().string(HttpHeaders.CONTENT_TYPE, is(MediaType.APPLICATION_JSON_VALUE)))
.andExpect(jsonPath("$.schemeCode", is(120503L), Long.class))
.andExpect(jsonPath("$.payout", is("INF846K01EW2")))
.andExpect(jsonPath("$.schemeName", is("Axis ELSS Tax Saver Fund - Direct Plan - Growth Option")))
Expand All @@ -46,7 +46,7 @@ void shouldLoadDataWhenSchemeFoundAndLoadHistoricalData() throws Exception {
.perform(get("/api/nav/{schemeCode}/{date}", 120503L, "2022-12-20")
.accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(header().string("Content-Type", is("application/json")))
.andExpect(header().string(HttpHeaders.CONTENT_TYPE, is(MediaType.APPLICATION_JSON_VALUE)))
.andExpect(jsonPath("$.schemeCode", is(120503L), Long.class))
.andExpect(jsonPath("$.payout", is("INF846K01EW2")))
.andExpect(jsonPath("$.schemeName", is("Axis ELSS Tax Saver Fund - Direct Plan - Growth Option")))
Expand All @@ -55,13 +55,12 @@ void shouldLoadDataWhenSchemeFoundAndLoadHistoricalData() throws Exception {
}

@Test
@Disabled
void shouldNotLoadDataWhenSchemeFoundAndLoadHistoricalDataNotFound() throws Exception {
this.mockMvc
.perform(get("/api/nav/{schemeCode}/{date}", 151113, "2022-10-20")
.accept(MediaType.APPLICATION_JSON))
.andExpect(status().isNotFound())
.andExpect(header().string("Content-Type", is("application/problem+json")))
.andExpect(header().string(HttpHeaders.CONTENT_TYPE, is(MediaType.APPLICATION_PROBLEM_JSON_VALUE)))
.andExpect(jsonPath("$.type", is("about:blank")))
.andExpect(jsonPath("$.title", is("Scheme NotFound")))
.andExpect(jsonPath("$.status", is(404)))
Expand Down

0 comments on commit b185b35

Please sign in to comment.