-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
task: add endpoint to request single field definitions
- Loading branch information
Dominick Leppich
committed
Nov 12, 2024
1 parent
b875428
commit 10ea3bf
Showing
3 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
module-core/src/main/java/io/goobi/vocabulary/api/FieldDefinitionController.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,27 @@ | ||
package io.goobi.vocabulary.api; | ||
|
||
import io.goobi.vocabulary.api.assemblers.FieldDefinitionAssembler; | ||
import io.goobi.vocabulary.exchange.FieldDefinition; | ||
import io.goobi.vocabulary.service.manager.FieldDefinitionDTOManager; | ||
import org.springframework.hateoas.EntityModel; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/api/v1") | ||
public class FieldDefinitionController { | ||
private final FieldDefinitionDTOManager manager; | ||
private final FieldDefinitionAssembler assembler; | ||
|
||
public FieldDefinitionController(FieldDefinitionDTOManager manager, FieldDefinitionAssembler assembler) { | ||
this.manager = manager; | ||
this.assembler = assembler; | ||
} | ||
|
||
@GetMapping("/fieldDefinitions/{id}") | ||
public EntityModel<FieldDefinition> one(@PathVariable long id) { | ||
return assembler.toModel(manager.get(id)); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
module-core/src/main/java/io/goobi/vocabulary/api/assemblers/FieldDefinitionAssembler.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,22 @@ | ||
package io.goobi.vocabulary.api.assemblers; | ||
|
||
import io.goobi.vocabulary.api.FieldTypeController; | ||
import io.goobi.vocabulary.api.VocabularySchemaController; | ||
import io.goobi.vocabulary.exchange.FieldDefinition; | ||
import org.springframework.hateoas.EntityModel; | ||
import org.springframework.hateoas.server.RepresentationModelAssembler; | ||
import org.springframework.stereotype.Component; | ||
|
||
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo; | ||
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn; | ||
|
||
@Component | ||
public class FieldDefinitionAssembler implements RepresentationModelAssembler<FieldDefinition, EntityModel<FieldDefinition>> { | ||
@Override | ||
public EntityModel<FieldDefinition> toModel(FieldDefinition entity) { | ||
return EntityModel.of(entity, | ||
linkTo(methodOn(FieldTypeController.class).one(entity.getId())).withSelfRel(), | ||
linkTo(methodOn(VocabularySchemaController.class).one(entity.getSchemaId())).withRel("schema") | ||
); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
module-core/src/main/java/io/goobi/vocabulary/service/manager/FieldDefinitionDTOManager.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,25 @@ | ||
package io.goobi.vocabulary.service.manager; | ||
|
||
import io.goobi.vocabulary.exception.EntityNotFoundException; | ||
import io.goobi.vocabulary.exchange.FieldDefinition; | ||
import io.goobi.vocabulary.repositories.FieldDefinitionRepository; | ||
import io.goobi.vocabulary.service.exchange.DTOMapper; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class FieldDefinitionDTOManager { | ||
private final FieldDefinitionRepository fieldDefinitionRepository; | ||
private final DTOMapper modelMapper; | ||
|
||
public FieldDefinitionDTOManager(FieldDefinitionRepository fieldDefinitionRepository, DTOMapper modelMapper) { | ||
this.fieldDefinitionRepository = fieldDefinitionRepository; | ||
this.modelMapper = modelMapper; | ||
} | ||
|
||
public FieldDefinition get(long id) { | ||
return modelMapper.toDTO( | ||
fieldDefinitionRepository.findById(id) | ||
.orElseThrow(() -> new EntityNotFoundException(FieldDefinition.class, id)) | ||
); | ||
} | ||
} |