Skip to content

Commit

Permalink
various docstring changes, remove gql java version lock
Browse files Browse the repository at this point in the history
  • Loading branch information
bthreader committed Dec 9, 2023
1 parent 6102d66 commit 1296890
Show file tree
Hide file tree
Showing 15 changed files with 36 additions and 108 deletions.
1 change: 0 additions & 1 deletion service-course-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'com.netflix.graphql.dgs:graphql-dgs-extended-scalars'
testImplementation "org.mockito:mockito-core:3.+"
implementation 'com.graphql-java:graphql-java:21.2' // Locked version to avoid problems
implementation 'org.springframework.boot:spring-boot-starter-cache'
implementation 'com.github.ben-manes.caffeine:caffeine:3.1.8'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public class BikeBrandsDataFetcher {
private final BikeBrandsService bikeBrandsService;

/**
* This is an enhanced attribute. Services will not generate it ahead of time (unlike brand
* name). Therefore, if specified by the user, it must be computed here.
* This is an enhanced attribute. Services will not generate it ahead of time. Therefore, if
* requested by the user, it must be computed here.
* <p>
* A data loader is used to avoid sending multiple separate requests to the models service when
* handling a request that involves multiple bike brands (see {@link #bikeBrands()}).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import servicecourse.generated.types.Bike;
import servicecourse.repo.common.URLConverter;
import servicecourse.services.bikes.BikeId;
import servicecourse.services.bikes.CrudBikeInput;
import servicecourse.services.bikes.UpdateBikeParams;

import java.net.URL;

Expand Down Expand Up @@ -46,10 +46,13 @@ public Bike asBike() {
.build();
}

public void apply(CrudBikeInput input) {
input.model().ifPresent(this::setModel);
/**
* Apply the updates ready for persisting
*
* @param input the details of an update to a bike entity
*/
public void apply(UpdateBikeParams input) {
input.groupset().ifPresent(this::setGroupset);
input.heroImageUrl().ifPresent(this::setHeroImageUrl);
input.size().ifPresent(this::setSize);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@

public class BikeEntitySpecification {
/**
* @param input the filters to help select specific bikes
* @return a specification based on the input, if no fields were provided in the input the
* specification will be equivalent to "match all"
* @param input the details of the filter to apply to the entities
* @return a specification based on the input, if the input is empty the specification will be
* equivalent to "match all"
* @throws NullPointerException if input is null
*/
public static Specification<BikeEntity> from(@NonNull BikesFilterInput input) {
return (root, query, cb) -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package servicecourse.repo;

import lombok.NonNull;
import org.springframework.data.jpa.domain.Specification;
import servicecourse.generated.types.GroupsetBrand;
import servicecourse.generated.types.GroupsetFilterInput;
Expand All @@ -15,11 +14,11 @@

public class GroupsetEntitySpecification {
/**
* @param input the filters to help select specific groupsets
* @return a specification based on the input, if no fields were provided in the input the
* specification will be equivalent to "match all"
* @param input the details of the filter to apply to the entities
* @return a specification based on the input, if the input is empty the specification will be
* equivalent to "match all"
*/
public static Specification<GroupsetEntity> from(@NonNull GroupsetFilterInput input) {
public static Specification<GroupsetEntity> from(GroupsetFilterInput input) {
List<Specification<GroupsetEntity>> specifications = Stream.of(
Optional.ofNullable(input.getBrand())
.map(GroupsetEntitySpecification::brand),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ public class ModelEntity {
private int modelYear;
private String brandName;

/**
* Importantly, sets the {@code brandName} attribute on the {@code brand} field (of type
* {@code BikeBrand}), but not the {@code models} attribute. This will need to be resolved
* later.
*/
public Model asModel() {
return Model.newBuilder()
.id(ModelId.serialize(id))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package servicecourse.repo;

import lombok.NonNull;
import org.springframework.data.jpa.domain.Specification;
import servicecourse.generated.types.ModelFilterInput;
import servicecourse.generated.types.StringFilterInput;
Expand All @@ -14,11 +13,11 @@

public class ModelEntitySpecification {
/**
* @param input the filters to help select specific models
* @return a specification based on the input, if no fields were provided in the input the
* specification will be equivalent to "match all"
* @param input the details of the filter to apply to the entities
* @return a specification based on the input, if the input is empty the specification will be
* equivalent to "match all"
*/
public static Specification<ModelEntity> from(@NonNull ModelFilterInput input) {
public static Specification<ModelEntity> from(ModelFilterInput input) {
List<Specification<ModelEntity>> specifications = Stream.of(
Optional.ofNullable(input.getName())
.map(ModelEntitySpecification::name))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class StringFilterSpecification {
* @param <T> the entity for which {@code fieldPath} is an attribute
* @return a specification ready to apply to entities of type {@code T}, if the input is empty
* the specification will be equivalent to "match all"
* @throws NullPointerException if {@code input} is null
*/
public static <T> Specification<T> from(@NonNull StringFilterInput input,
SingularAttribute<T, String> fieldPath) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ public interface BikeBrandsService {
* @throws BikeBrandAlreadyExistsException if the bike brand name specified in {@code input}
* already exists
*/
BikeBrand createBikeBrand(CreateBikeBrandInput input) throws BikeBrandAlreadyExistsException;
BikeBrand createBikeBrand(CreateBikeBrandInput input);

/**
* @param name the name of the bike brand to delete
* @return the name of the deleted bike brand if it existed, throws otherwise
* @throws BikeBrandNotFoundException if a bike brand with the provided {@code name} doesn't
* exist
*/
String deleteBikeBrand(String name) throws BikeBrandNotFoundException;
String deleteBikeBrand(String name);

/** @return all bike brands */
List<BikeBrand> bikeBrands();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public interface BikesService {
* @throws ModelNotFoundException if the model specified in {@code input} doesn't exist
* @throws GroupsetNotFoundException if the groupset specified in {@code input} doesn't exist
*/
Bike createBike(CreateBikeInput input) throws ModelNotFoundException, GroupsetNotFoundException;
Bike createBike(CreateBikeInput input);

/**
* @param input the details of an update to a bike
Expand All @@ -28,12 +28,12 @@ public interface BikesService {
* @throws GroupsetNotFoundException if a groupset is specified in {@code input} but it doesn't
* exist
*/
Bike updateBike(UpdateBikeInput input) throws BikeNotFoundException, GroupsetNotFoundException;
Bike updateBike(UpdateBikeInput input);

/**
* @param id the ID of the bike to delete
* @return the ID of the deleted bike if it existed, throws otherwise
* @throws BikeNotFoundException if a bike with the provided {@code id} doesn't exist
*/
Long deleteBike(String id) throws BikeNotFoundException;
Long deleteBike(String id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,12 @@ public Bike createBike(CreateBikeInput input) {
GroupsetEntity groupsetEntity = groupsetRespository.findById(input.getGroupsetName())
.orElseThrow(() -> new GroupsetNotFoundException(input.getGroupsetName()));

BikeEntity newBike = new BikeEntity();
newBike.apply(CreateBikeParams.builder()
.modelEntity(modelEntity)
.groupsetEntity(groupsetEntity)
.size(input.getSize())
.heroImageUrl(input.getHeroImageUrl())
.build());
BikeEntity newBike = BikeEntity.builder()
.model(modelEntity)
.groupset(groupsetEntity)
.size(input.getSize())
.heroImageUrl(input.getHeroImageUrl())
.build();

return bikeRepository.save(newBike).asBike();
}
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,20 @@

import lombok.Builder;
import servicecourse.repo.GroupsetEntity;
import servicecourse.repo.ModelEntity;

import java.net.URL;
import java.util.Optional;

@Builder
public class UpdateBikeParams implements CrudBikeInput {
public class UpdateBikeParams {
private Optional<GroupsetEntity> groupset;
private URL heroImageUrl;

@Override
public Optional<GroupsetEntity> groupset() {
return groupset;
}

@Override
public Optional<URL> heroImageUrl() {
return Optional.ofNullable(heroImageUrl);
}

// Model and size cannot be updated, so always return empty

@Override
public Optional<ModelEntity> model() {
return Optional.empty();
}

@Override
public Optional<String> size() { return Optional.empty(); }
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ public interface ModelsService {
* @throws BikeBrandNotFoundException if the bike brand specified in {@code input} doesn't
* exist
*/
Model createModel(CreateModelInput input) throws BikeBrandNotFoundException;
Model createModel(CreateModelInput input);

/**
* @param id the ID of the model to delete
* @return the ID of the deleted model if it existed, throws otherwise
* @throws ModelNotFoundException if a model with the provided {@code id} doesn't exist
*/
String deleteModel(String id) throws ModelNotFoundException;
String deleteModel(String id);

/**
* @return a map; bike brand name -> models for that brand
Expand Down

0 comments on commit 1296890

Please sign in to comment.