Skip to content

Commit

Permalink
#31 core back-end api implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Siarhei_Kakichau committed Jul 8, 2024
1 parent 4efa967 commit fa3f004
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
package org.student.api;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.student.api.models.ArtifactCreateRequest;
import org.student.api.models.ArtifactCreateResponce;
import org.student.api.models.ArtifactResponse;
import reactor.core.publisher.Mono;

@RestController
@RequestMapping("api/v1/artifacts")
public class ArtifactsController {

private static final Logger logger = LogManager.getLogger(ArtifactsController.class);
import java.util.List;
import java.util.UUID;

public interface ArtifactsController {
@PostMapping("/upload")
public Mono<ArtifactCreateResponce> uploadFile(@RequestBody ArtifactCreateRequest request) {
logger.info("Received artifact: {}", request.toString());
return Mono.just(new ArtifactCreateResponce());
}
Mono<ArtifactResponse> uploadFile(@RequestBody ArtifactCreateRequest request);

@GetMapping("/getAll")
Mono<List<ArtifactResponse>> getAllFiles();

@GetMapping("/loadArtifact/{id}")
Mono<ArtifactResponse> loadArtifact(@PathVariable UUID id);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package org.student.api;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.web.bind.annotation.*;
import org.student.api.models.ArtifactCreateRequest;
import org.student.api.models.ArtifactResponse;
import reactor.core.publisher.Mono;

import java.util.Collections;
import java.util.List;
import java.util.UUID;

@RestController
@RequestMapping("api/v1/artifacts")
public class ArtifactsControllerImpl implements ArtifactsController {

private static final Logger logger = LogManager.getLogger(ArtifactsControllerImpl.class);

@Override
@PostMapping("/upload")
public Mono<ArtifactResponse> uploadFile(@RequestBody ArtifactCreateRequest request) {
logger.info("Received artifact: {}", request.toString());
return Mono.just(new ArtifactResponse());
}

@Override
@GetMapping("/getAll")
public Mono<List<ArtifactResponse>> getAllFiles() {

List<ArtifactResponse> res = Collections.emptyList();
logger.info("Received {} artifacts info from storage.", res.size());

return Mono.just(res);
}

@Override
@GetMapping("/loadArtifact/{id}")
public Mono<ArtifactResponse> loadArtifact(@PathVariable UUID id) {
logger.info("loading artifact with id {}", id);

return Mono.just(new ArtifactResponse());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.student.api.models;

import java.util.Arrays;
import java.util.UUID;

public class ArtifactLoadResponse extends ArtifactResponse{

private byte[] artifactBody;

public ArtifactLoadResponse(byte[] artifactBody) {
this.artifactBody = artifactBody;
}

public ArtifactLoadResponse(UUID id, ArtifactMateInfo metaInfo, byte[] artifactBody) {
super(id, metaInfo);
this.artifactBody = artifactBody;
}


public byte[] getArtifactBody() {
return artifactBody;
}

public void setArtifactBody(byte[] artifactBody) {
this.artifactBody = artifactBody;
}

@Override
public String toString() {
return "ArtifactLoadResponse{" +
"artifactBody=" + Arrays.toString(artifactBody) +
"} " + super.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

import java.util.UUID;

public class ArtifactCreateResponce {
public class ArtifactResponse {
private UUID id;

private ArtifactMateInfo metaInfo;

public ArtifactCreateResponce(UUID id, ArtifactMateInfo metaInfo) {
public ArtifactResponse(UUID id, ArtifactMateInfo metaInfo) {
this.id = id;
this.metaInfo = metaInfo;
}

public ArtifactCreateResponce() {
public ArtifactResponse() {
}

public UUID getId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import org.springframework.web.reactive.function.BodyInserters;

@ExtendWith(SpringExtension.class)
@WebFluxTest(ArtifactsController.class)
@WebFluxTest(ArtifactsControllerImpl.class)
public class FilesControllerTest {

@Autowired
Expand Down

0 comments on commit fa3f004

Please sign in to comment.