-
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.
Merge pull request #33 from Kasean/milestone/first-api-impl
Milestone/first api impl
- Loading branch information
Showing
9 changed files
with
398 additions
and
39 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.student.api; | ||
|
||
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.ArtifactLoadResponse; | ||
import org.student.api.models.ArtifactResponse; | ||
import reactor.core.publisher.Flux; | ||
import reactor.core.publisher.Mono; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
public interface ArtifactsController { | ||
@PostMapping("/upload") | ||
Mono<ArtifactResponse> uploadArtifact(@RequestBody ArtifactCreateRequest request); | ||
|
||
@GetMapping("/getAll") | ||
Flux<ArtifactResponse> getAllArtifacts(); | ||
|
||
@GetMapping("/loadArtifact/{id}") | ||
Mono<ArtifactLoadResponse> loadArtifact(@PathVariable UUID id); | ||
} |
52 changes: 52 additions & 0 deletions
52
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,52 @@ | ||
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.ArtifactLoadResponse; | ||
import org.student.api.models.ArtifactResponse; | ||
import org.student.services.ArtifactsService; | ||
import reactor.core.publisher.Flux; | ||
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); | ||
|
||
private final ArtifactsService artifactsService; | ||
|
||
public ArtifactsControllerImpl(ArtifactsService artifactsService) { | ||
this.artifactsService = artifactsService; | ||
} | ||
|
||
@Override | ||
@PostMapping("/upload") | ||
public Mono<ArtifactResponse> uploadArtifact(@RequestBody ArtifactCreateRequest request) { | ||
|
||
logger.info("Creating artifact from request: {}", request); | ||
|
||
return artifactsService.upload(request).doOnNext(artifactResponse -> logger.info("Created artifact: {}", artifactResponse)); | ||
} | ||
|
||
@Override | ||
@GetMapping("/getAll") | ||
public Flux<ArtifactResponse> getAllArtifacts() { | ||
return artifactsService.getAllArtifacts() | ||
.doOnNext(artifact -> logger.info("Received artifact info from storage: {}", artifact)); | ||
} | ||
|
||
@Override | ||
@GetMapping("/loadArtifact/{id}") | ||
public Mono<ArtifactLoadResponse> loadArtifact(@PathVariable UUID id) { | ||
return artifactsService.getArtifactById(id) | ||
.doOnNext(artifact -> logger.info("Loading artifact with id {}", id)); | ||
} | ||
|
||
} |
26 changes: 0 additions & 26 deletions
26
core-back-end/src/main/java/org/student/api/FilesController.java
This file was deleted.
Oops, something went wrong.
58 changes: 58 additions & 0 deletions
58
core-back-end/src/main/java/org/student/api/models/ArtifactCreateRequest.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,58 @@ | ||
package org.student.api.models; | ||
|
||
import java.util.Arrays; | ||
import java.util.Objects; | ||
|
||
public class ArtifactCreateRequest { | ||
|
||
private String name; | ||
|
||
private byte[] artifactBody; | ||
|
||
public ArtifactCreateRequest(String name, byte[] artifactBody) { | ||
this.name = name; | ||
this.artifactBody = artifactBody; | ||
} | ||
|
||
public ArtifactCreateRequest() { | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public byte[] getArtifactBody() { | ||
return artifactBody; | ||
} | ||
|
||
public void setArtifactBody(byte[] artifactBody) { | ||
this.artifactBody = artifactBody; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "ArtifactCreateRequest{" + | ||
"name='" + name + '\'' + | ||
", artifactBody=" + Arrays.toString(artifactBody) + | ||
'}'; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
ArtifactCreateRequest that = (ArtifactCreateRequest) o; | ||
return Objects.equals(name, that.name) && Arrays.equals(artifactBody, that.artifactBody); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = Objects.hash(name); | ||
result = 31 * result + Arrays.hashCode(artifactBody); | ||
return result; | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
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,47 @@ | ||
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(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
ArtifactLoadResponse that = (ArtifactLoadResponse) o; | ||
return Arrays.equals(artifactBody, that.artifactBody); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Arrays.hashCode(artifactBody); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
core-back-end/src/main/java/org/student/api/models/ArtifactMateInfo.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,53 @@ | ||
package org.student.api.models; | ||
|
||
import java.util.Objects; | ||
|
||
public class ArtifactMateInfo { | ||
private String artifactName; | ||
private long artifactSize; | ||
|
||
public ArtifactMateInfo(String artifactName, long artifactSize) { | ||
this.artifactName = artifactName; | ||
this.artifactSize = artifactSize; | ||
} | ||
|
||
public ArtifactMateInfo() { | ||
} | ||
|
||
public String getArtifactName() { | ||
return artifactName; | ||
} | ||
|
||
public void setArtifactName(String artifactName) { | ||
this.artifactName = artifactName; | ||
} | ||
|
||
public long getArtifactSize() { | ||
return artifactSize; | ||
} | ||
|
||
public void setArtifactSize(long artifactSize) { | ||
this.artifactSize = artifactSize; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "ArtifactMateInfo{" + | ||
"artifactName='" + artifactName + '\'' + | ||
", artifactSize=" + artifactSize + | ||
'}'; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
ArtifactMateInfo that = (ArtifactMateInfo) o; | ||
return artifactSize == that.artifactSize && Objects.equals(artifactName, that.artifactName); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(artifactName, artifactSize); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
core-back-end/src/main/java/org/student/api/models/ArtifactResponse.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,55 @@ | ||
package org.student.api.models; | ||
|
||
import java.util.Objects; | ||
import java.util.UUID; | ||
|
||
public class ArtifactResponse { | ||
private UUID id; | ||
|
||
private ArtifactMateInfo metaInfo; | ||
|
||
public ArtifactResponse(UUID id, ArtifactMateInfo metaInfo) { | ||
this.id = id; | ||
this.metaInfo = metaInfo; | ||
} | ||
|
||
public ArtifactResponse() { | ||
} | ||
|
||
public UUID getId() { | ||
return id; | ||
} | ||
|
||
public void setId(UUID id) { | ||
this.id = id; | ||
} | ||
|
||
public ArtifactMateInfo getMetaInfo() { | ||
return metaInfo; | ||
} | ||
|
||
public void setMetaInfo(ArtifactMateInfo metaInfo) { | ||
this.metaInfo = metaInfo; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "ArtifactCreateResponce{" + | ||
"id=" + id + | ||
", metaInfo=" + metaInfo + | ||
'}'; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
ArtifactResponse response = (ArtifactResponse) o; | ||
return Objects.equals(id, response.id) && Objects.equals(metaInfo, response.metaInfo); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(id, metaInfo); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
core-back-end/src/main/java/org/student/services/ArtifactsService.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,21 @@ | ||
package org.student.services; | ||
|
||
import org.springframework.stereotype.Service; | ||
import org.student.api.models.ArtifactCreateRequest; | ||
import org.student.api.models.ArtifactLoadResponse; | ||
import org.student.api.models.ArtifactResponse; | ||
import reactor.core.publisher.Flux; | ||
import reactor.core.publisher.Mono; | ||
|
||
import java.util.UUID; | ||
|
||
@Service | ||
public interface ArtifactsService { | ||
|
||
|
||
Mono<ArtifactResponse> upload(ArtifactCreateRequest request); | ||
|
||
Flux<ArtifactResponse> getAllArtifacts(); | ||
|
||
Mono<ArtifactLoadResponse> getArtifactById(UUID id); | ||
} |
Oops, something went wrong.