Skip to content

Commit

Permalink
re
Browse files Browse the repository at this point in the history
  • Loading branch information
kjain110 committed Dec 16, 2023
1 parent e00c52d commit 00feb5d
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 15 deletions.
8 changes: 6 additions & 2 deletions src/main/java/org/folio/list/controller/ListController.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.time.OffsetDateTime;
Expand Down Expand Up @@ -91,9 +93,11 @@ public ResponseEntity<Void> cancelRefresh(UUID listId) {
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}

//@GetMapping("/lists/{listId}/versions")
@Override
public ResponseEntity<org.folio.list.domain.dto.ListVersionDTO> getListVersions (UUID listId) {
public ResponseEntity<List<org.folio.list.domain.dto.ListVersionDTO>> getListVersions (UUID listId) {
// List<org.folio.list.domain.dto.ListVersionDTO> dtoList = listService.getListVersions(listId);
var listVersionDto = listService.getListVersions(listId);
return new ResponseEntity<>(listVersionDto.get(), HttpStatus.CREATED);
return new ResponseEntity<>(listVersionDto, HttpStatus.CREATED);
}
}
10 changes: 5 additions & 5 deletions src/main/java/org/folio/list/domain/ListVersions.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import org.folio.list.rest.UsersClient.User;
import org.folio.spring.FolioExecutionContext;

import java.time.OffsetDateTime;
import java.util.List;
Expand Down Expand Up @@ -46,11 +47,11 @@ public class ListVersions {
private List<String> fields;

@Column(name = "updated_by")
@NotNull
//@NotNull
private UUID updatedBy;

@Column(name = "updated_by_username")
@NotNull
// @NotNull
@Size(min = 4, max = 1024)
private String updatedByUsername;

Expand All @@ -73,16 +74,15 @@ public class ListVersions {
@Column(name = "user_friendly_query")
private String userFriendlyQuery;

public static User user;
public void setDataFromListEntity(ListEntity listEntity) {
listId = listEntity.getId();
name = listEntity.getName();
fqlQuery = listEntity.getFqlQuery();
description = listEntity.getDescription();
userFriendlyQuery = listEntity.getUserFriendlyQuery();
fields = listEntity.getFields();
updatedBy = user.id();
updatedByUsername = user.getFullName().orElse(user.id().toString());;
// updatedBy = folioExecutionContext.getUserId();
//updatedByUsername = folioExecutionContext.getTenantId();
updatedDate = listEntity.getUpdatedDate();
version = listEntity.getVersion();
isActive = listEntity.getIsActive();
Expand Down
16 changes: 12 additions & 4 deletions src/main/java/org/folio/list/repository/ListVersionRepository.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
package org.folio.list.repository;

import org.folio.list.domain.ListEntity;
import org.folio.list.domain.ListVersions;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;
import java.util.UUID;

@Repository
public interface ListVersionRepository extends CrudRepository<ListVersions, UUID>{
Optional<ListVersions> findByListId(UUID listId);
public interface ListVersionRepository extends CrudRepository<ListVersions, UUID> {
// @Query(
// value = """
// SELECT lv FROM ListVersions lv WHERE lv.listId = :listId
// """,
// countQuery = """
// SELECT count(*) FROM ListVersions lv WHERE lv.listId = :listId
// """
// )
List<ListVersions> findByListId(UUID listId);

}
7 changes: 4 additions & 3 deletions src/main/java/org/folio/list/services/ListService.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@

import java.time.OffsetDateTime;
import java.util.*;
import java.util.stream.Collectors;

import static java.util.stream.Collectors.toMap;
import static java.util.Objects.nonNull;
Expand Down Expand Up @@ -304,8 +305,8 @@ private List<String> getFieldsFromEntityType(EntityType entityType) {
return fields;
}

public Optional<org.folio.list.domain.dto.ListVersionDTO> getListVersions(UUID listId) {
return listVersionRepository.findByListId(listId).map(listVersionMapper::toListVersionDTO);

public List<org.folio.list.domain.dto.ListVersionDTO> getListVersions(UUID listId) {
//return listVersionRepository.findByListId(listId).stream().map(list -> listVersionMapper.toListVersionDTO(list)).toList();
return listVersionRepository.findByListId(listId).stream().map(listVersionMapper::toListVersionDTO).collect(Collectors.toList());
}
}
5 changes: 4 additions & 1 deletion src/main/resources/swagger.api/list.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,10 @@ paths:
content:
application/json:
schema:
$ref: '#/components/schemas/ListVersionDTO'
type: array
items:
type:
$ref: "#/components/schemas/ListVersionDTO"
default:
description: unexpected error
content:
Expand Down

0 comments on commit 00feb5d

Please sign in to comment.