-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
123 additions
and
34 deletions.
There are no files selected for viewing
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,35 @@ | ||
package com.flowci.build; | ||
|
||
import com.flowci.build.business.ListBuilds; | ||
import com.flowci.build.model.Build; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import jakarta.validation.Valid; | ||
import jakarta.validation.constraints.Min; | ||
import lombok.AllArgsConstructor; | ||
import org.springframework.data.domain.PageRequest; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequestMapping("/v2/builds") | ||
@Tag(name = "build") | ||
@AllArgsConstructor | ||
public class BuildController { | ||
|
||
private final ListBuilds listBuilds; | ||
|
||
@Operation(description = "list builds") | ||
@GetMapping | ||
public List<Build> getBuildsByStatus(@RequestParam("status") Build.Status status, | ||
@RequestParam(required = false, name = "page", defaultValue = "0") | ||
@Valid @Min(0) | ||
Integer page, | ||
@RequestParam(required = false, name = "size", defaultValue = "20") | ||
@Valid @Min(20) | ||
Integer size) { | ||
return listBuilds.invoke(status, PageRequest.of(page, size)); | ||
} | ||
} |
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
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,7 @@ | ||
package com.flowci.build.business; | ||
|
||
import com.flowci.build.model.Build; | ||
|
||
public interface FetchBuild { | ||
Build invoke(Long buildId); | ||
} |
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,11 @@ | ||
package com.flowci.build.business; | ||
|
||
import com.flowci.build.model.Build; | ||
import org.springframework.data.domain.PageRequest; | ||
|
||
import java.util.List; | ||
|
||
public interface ListBuilds { | ||
List<Build> invoke(PageRequest pageRequest); | ||
List<Build> invoke(Build.Status status, PageRequest pageRequest); | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/com/flowci/build/business/impl/FetchBuildImpl.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,24 @@ | ||
package com.flowci.build.business.impl; | ||
|
||
import com.flowci.build.business.FetchBuild; | ||
import com.flowci.build.model.Build; | ||
import com.flowci.build.repo.BuildRepo; | ||
import com.flowci.common.exception.NotAvailableException; | ||
import lombok.AllArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@AllArgsConstructor | ||
public class FetchBuildImpl implements FetchBuild { | ||
|
||
private final BuildRepo buildRepo; | ||
|
||
@Override | ||
public Build invoke(Long buildId) { | ||
var optional = buildRepo.findById(buildId); | ||
if (optional.isEmpty()) { | ||
throw new NotAvailableException("Build not found"); | ||
} | ||
return optional.get(); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/com/flowci/build/business/impl/ListBuildsImpl.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 com.flowci.build.business.impl; | ||
|
||
import com.flowci.build.business.ListBuilds; | ||
import com.flowci.build.model.Build; | ||
import com.flowci.build.repo.BuildRepo; | ||
import lombok.AllArgsConstructor; | ||
import org.springframework.data.domain.PageRequest; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.List; | ||
|
||
@Component | ||
@AllArgsConstructor | ||
public class ListBuildsImpl implements ListBuilds { | ||
|
||
private final BuildRepo buildRepo; | ||
|
||
@Override | ||
public List<Build> invoke(PageRequest pageRequest) { | ||
return buildRepo.findAll(pageRequest).getContent(); | ||
} | ||
|
||
@Override | ||
public List<Build> invoke(Build.Status status, PageRequest pageRequest) { | ||
return buildRepo.findAllByStatusOrderByCreatedAtDesc(status, pageRequest); | ||
} | ||
} |
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
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
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
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
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
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
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
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