-
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.
#31 core back-end api implementation
- Loading branch information
Siarhei_Kakichau
committed
Jul 8, 2024
1 parent
4efa967
commit fa3f004
Showing
5 changed files
with
97 additions
and
17 deletions.
There are no files selected for viewing
27 changes: 14 additions & 13 deletions
27
core-back-end/src/main/java/org/student/api/ArtifactsController.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 |
---|---|---|
@@ -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); | ||
} |
45 changes: 45 additions & 0 deletions
45
core-back-end/src/main/java/org/student/api/ArtifactsControllerImpl.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,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()); | ||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
core-back-end/src/main/java/org/student/api/models/ArtifactLoadResponse.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,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(); | ||
} | ||
} |
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