-
Notifications
You must be signed in to change notification settings - Fork 34
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 #288 from JasonHHouse/improvement/Gaps_currently_r…
…eports_future_releases_as_missing#257 Initial work to implement and remove unreleased movies or show all
- Loading branch information
Showing
34 changed files
with
396 additions
and
29 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
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 com.jasonhhouse.gaps; | ||
|
||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
import com.fasterxml.jackson.databind.annotation.JsonSerialize; | ||
import com.jasonhhouse.gaps.json.MovieStatusDeserializer; | ||
import com.jasonhhouse.gaps.json.MovieStatusSerializer; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
@JsonSerialize(using = MovieStatusSerializer.class) | ||
@JsonDeserialize(using = MovieStatusDeserializer.class) | ||
public enum MovieStatus { | ||
ALL("All", 0), | ||
RELEASED("Released", 1); | ||
|
||
public static final String ID_LABEL = "id"; | ||
public static final String MESSAGE_LABEL = "message"; | ||
|
||
@NotNull | ||
private final String message; | ||
|
||
@NotNull | ||
private final Integer id; | ||
|
||
MovieStatus(@NotNull String message, @NotNull Integer id) { | ||
this.message = message; | ||
this.id = id; | ||
} | ||
|
||
public static MovieStatus getMovieStatus(@NotNull Integer id) { | ||
if (RELEASED.getId().equals(id)) { | ||
return RELEASED; | ||
} else { | ||
return ALL; | ||
} | ||
} | ||
|
||
public static @NotNull List<MovieStatus> getAllMovieStatuses() { | ||
return Arrays.asList(ALL, RELEASED); | ||
} | ||
|
||
public @NotNull String getMessage() { | ||
return message; | ||
} | ||
|
||
public @NotNull Integer getId() { | ||
return id; | ||
} | ||
|
||
@Override | ||
public @NotNull String toString() { | ||
return "MovieStatus{" + | ||
"message='" + message + '\'' + | ||
", id=" + id + | ||
'}'; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
Core/src/main/java/com/jasonhhouse/gaps/MovieStatusPayload.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.jasonhhouse.gaps; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
public final class MovieStatusPayload { | ||
private final Integer status; | ||
|
||
@JsonCreator | ||
public MovieStatusPayload(@JsonProperty("status") Integer status) { | ||
this.status = status; | ||
} | ||
|
||
public Integer getStatus() { | ||
return status; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "MovieStatusPayload{" + | ||
"status=" + status + | ||
'}'; | ||
} | ||
} |
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
25 changes: 25 additions & 0 deletions
25
Core/src/main/java/com/jasonhhouse/gaps/json/MovieStatusDeserializer.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 com.jasonhhouse.gaps.json; | ||
|
||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.databind.DeserializationContext; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.deser.std.StdDeserializer; | ||
import com.jasonhhouse.gaps.MovieStatus; | ||
import java.io.IOException; | ||
|
||
public class MovieStatusDeserializer extends StdDeserializer<MovieStatus> { | ||
public MovieStatusDeserializer() { | ||
this(null); | ||
} | ||
|
||
protected MovieStatusDeserializer(Class<?> vc) { | ||
super(vc); | ||
} | ||
|
||
@Override | ||
public MovieStatus deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException { | ||
JsonNode node = jsonParser.getCodec().readTree(jsonParser); | ||
int id = node.get(MovieStatus.ID_LABEL).numberValue().intValue(); | ||
return MovieStatus.getMovieStatus(id); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
Core/src/main/java/com/jasonhhouse/gaps/json/MovieStatusSerializer.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,36 @@ | ||
/* | ||
* Copyright 2020 Jason H House | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
package com.jasonhhouse.gaps.json; | ||
|
||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.databind.SerializerProvider; | ||
import com.fasterxml.jackson.databind.ser.std.StdSerializer; | ||
import com.jasonhhouse.gaps.MovieStatus; | ||
import java.io.IOException; | ||
|
||
public class MovieStatusSerializer extends StdSerializer<MovieStatus> { | ||
|
||
public MovieStatusSerializer() { | ||
this(null); | ||
} | ||
|
||
protected MovieStatusSerializer(Class<MovieStatus> t) { | ||
super(t); | ||
} | ||
|
||
@Override | ||
public void serialize(MovieStatus value, JsonGenerator jsonGenerator, SerializerProvider provider) throws IOException { | ||
jsonGenerator.writeStartObject(); | ||
jsonGenerator.writeNumberField(MovieStatus.ID_LABEL, value.getId()); | ||
jsonGenerator.writeStringField(MovieStatus.MESSAGE_LABEL, value.getMessage()); | ||
jsonGenerator.writeEndObject(); | ||
} | ||
} |
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
58 changes: 58 additions & 0 deletions
58
GapsWeb/src/main/java/com/jasonhhouse/gaps/controller/MovieStatusController.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 com.jasonhhouse.gaps.controller; | ||
|
||
import com.jasonhhouse.gaps.MovieStatusPayload; | ||
import com.jasonhhouse.gaps.Payload; | ||
import com.jasonhhouse.gaps.service.MovieStatusService; | ||
import java.io.IOException; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PutMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.ResponseBody; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping(value = "/movieStatus") | ||
public class MovieStatusController { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(MovieStatusController.class); | ||
|
||
private final MovieStatusService movieStatusService; | ||
|
||
@Autowired | ||
public MovieStatusController(MovieStatusService movieStatusService) { | ||
this.movieStatusService = movieStatusService; | ||
} | ||
|
||
@PutMapping(consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) | ||
@ResponseBody | ||
public ResponseEntity<Payload> putMovieStatus(@RequestBody final MovieStatusPayload movieStatusPayload) { | ||
LOGGER.info("putMovieStatus( {} )", movieStatusPayload); | ||
|
||
try { | ||
movieStatusService.setMovieStatus(movieStatusPayload); | ||
} catch (Exception e) { | ||
LOGGER.error("Failed to update Movie Status", e); | ||
ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(Payload.MOVIE_STATUS_NOT_UPDATED); | ||
} | ||
|
||
return ResponseEntity.ok().body(Payload.MOVIE_STATUS_UPDATED); | ||
} | ||
|
||
@GetMapping(produces = MediaType.APPLICATION_JSON_VALUE) | ||
public ResponseEntity<String> getSchedule() { | ||
LOGGER.info("getSchedule()"); | ||
try { | ||
return ResponseEntity.ok().body(movieStatusService.getJsonMovieStatus()); | ||
} catch (IOException e) { | ||
LOGGER.error("Failed to parse schedule into JSON", e); | ||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Failed to parse schedule into JSON"); | ||
} | ||
} | ||
} |
Oops, something went wrong.