Skip to content

Commit e846d04

Browse files
committed
feat: update goal with list instead of int
Signed-off-by: Otavio Santana <[email protected]>
1 parent 13361f6 commit e846d04

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
package os.expert.sample;
22

3+
import jakarta.json.bind.annotation.JsonbProperty;
4+
import jakarta.json.bind.annotation.JsonbPropertyOrder;
35
import jakarta.nosql.Column;
46
import jakarta.nosql.Entity;
57
import jakarta.nosql.Id;
68

79
import java.util.List;
810

11+
@JsonbPropertyOrder({"id", "title", "description", "priority", "tasks"})
912
@Entity
10-
public record Goal(@Id String title, @Column String description, @Column int priority, @Column List<Task> tasks) {
13+
public record Goal(
14+
@Id @JsonbProperty("id") String id,
15+
@JsonbProperty("title") @Column String title,
16+
@JsonbProperty("description") @Column String description,
17+
@JsonbProperty("priority") @Column int priority,
18+
@JsonbProperty("tasks") @Column List<String> tasks) {
19+
1120
}

src/main/java/os/expert/sample/GoalResource.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,22 @@
22

33

44
import jakarta.inject.Inject;
5+
import jakarta.ws.rs.Consumes;
56
import jakarta.ws.rs.DefaultValue;
67
import jakarta.ws.rs.GET;
8+
import jakarta.ws.rs.POST;
79
import jakarta.ws.rs.PUT;
810
import jakarta.ws.rs.Path;
11+
import jakarta.ws.rs.Produces;
912
import jakarta.ws.rs.QueryParam;
13+
import jakarta.ws.rs.core.MediaType;
1014

1115
import java.util.List;
1216
import java.util.logging.Logger;
1317

1418
@Path("/goals")
19+
@Consumes(MediaType.APPLICATION_JSON)
20+
@Produces(MediaType.APPLICATION_JSON)
1521
public class GoalResource {
1622

1723
private static final Logger LOGGER = Logger.getLogger(GoalResource.class.getName());
@@ -35,7 +41,7 @@ public List<Goal> goals(@QueryParam("page") @DefaultValue("1") int page,
3541
return goalService.findGoals(page, size);
3642
}
3743

38-
@PUT
44+
@POST
3945
public Goal create(Goal goal) {
4046
LOGGER.info("Creating a goal: " + goal);
4147
return goalService.save(goal);

0 commit comments

Comments
 (0)