From d505d6d6913908e3d878137c4978004f125893aa Mon Sep 17 00:00:00 2001 From: laura Date: Tue, 17 Aug 2021 14:30:37 -0400 Subject: [PATCH 1/3] first --- README.md | 24 ++++----- .../domain/Option.java | 40 ++++++++++++++ .../domain/Poll.java | 53 +++++++++++++++++++ .../domain/Vote.java | 41 ++++++++++++++ .../repositories/OptionRepositiry.java | 7 +++ .../repositories/PollRepository.java | 7 +++ .../repositories/VoteRepository.java | 8 +++ 7 files changed, 168 insertions(+), 12 deletions(-) create mode 100644 src/main/java/io/zipcoder/tc_spring_poll_application/domain/Option.java create mode 100644 src/main/java/io/zipcoder/tc_spring_poll_application/domain/Poll.java create mode 100644 src/main/java/io/zipcoder/tc_spring_poll_application/domain/Vote.java create mode 100644 src/main/java/io/zipcoder/tc_spring_poll_application/repositories/OptionRepositiry.java create mode 100644 src/main/java/io/zipcoder/tc_spring_poll_application/repositories/PollRepository.java create mode 100644 src/main/java/io/zipcoder/tc_spring_poll_application/repositories/VoteRepository.java diff --git a/README.md b/README.md index 2c6950e..7c9e121 100644 --- a/README.md +++ b/README.md @@ -6,12 +6,12 @@ # Part 1 - Domain Implementation * _Domain objects_ are the backbone for an application and contain the [business logic](https://en.wikipedia.org/wiki/Business_logic). -* Create a sub package of `io.zipcoder.tc_spring_poll_application` named `domain`. +* Create a sub package of `io.zipcoder.tc_spring_poll_application` named `io.zipcoder.tc_spring_poll_application.domain`. ## Part 1.1 - Create class `Option` -* Create an `Option` class in the `domain` sub-package. +* Create an `Option` class in the `io.zipcoder.tc_spring_poll_application.domain` sub-package. * `Option` class signature is annotated with `@Entity` * `Option` has an `id` instance variable of type `Long` * `id` should be `annotated` with @@ -32,7 +32,7 @@ ## Part 1.2 - Create class `Poll` -* Create a `Poll` class in the `domain` sub-package. +* Create a `Poll` class in the `io.zipcoder.tc_spring_poll_application.domain` sub-package. * `Poll` class signature is annotated with `@Entity` * `Poll` has an `id` instance variable of type `Long` * `id` should be `annotated` with @@ -55,7 +55,7 @@ ## Part 1.3 - Create class `Vote` -* Create a `Vote` class in the `domain` sub-package. +* Create a `Vote` class in the `io.zipcoder.tc_spring_poll_application.domain` sub-package. * `Vote` class signature is annotated with `@Entity` * `Vote` has an `id` instance variable of type `Long` * `id` should be `annotated` with @@ -75,30 +75,30 @@ * _Repositories_ or [Data Access Objects (DAO)](https://en.wikipedia.org/wiki/Data_access_object), provide an abstraction for interacting with _datastores_. * Typically DAOs include an interface that provides a set of finder methods such as `findById`, `findAll`, for retrieving data, and methods to persist and delete data. -* It is customary to have one `Repository` per `domain` object. -* Create a sub-package of `io.zipcoder.tc_spring_poll_application` named `repositories`. +* It is customary to have one `Repository` per `io.zipcoder.tc_spring_poll_application.domain` object. +* Create a sub-package of `io.zipcoder.tc_spring_poll_application` named `io.zipcoder.tc_spring_poll_application.repositories`. ## Part 2.1 - Create interface `OptionRepository` -* Create an `OptionRepository` interface in the `repositories` subpackage. +* Create an `OptionRepository` interface in the `io.zipcoder.tc_spring_poll_application.repositories` subpackage. * `OptionRepository` is a subclass of `CrudRepository` ## Part 2.2 - Create interface `PollRepository` -* Create a `PollRepository` interface in the `repositories` subpackage. +* Create a `PollRepository` interface in the `io.zipcoder.tc_spring_poll_application.repositories` subpackage. * `PollRepository` is a subclass of `CrudRepository` ## Part 2.3 - Create interface `VoteRepository` -* Create a `VoteRepository` interface in the `repositories` subpackage. +* Create a `VoteRepository` interface in the `io.zipcoder.tc_spring_poll_application.repositories` subpackage. * `VoteRepository` is a subclass of `CrudRepository` # Part 3 - Controller Implementation -* _Controllers_ provides all of the necessary [endpoints](https://en.wikipedia.org/wiki/Web_API#Endpoints) to access and manipulate respective domain objects. +* _Controllers_ provides all of the necessary [endpoints](https://en.wikipedia.org/wiki/Web_API#Endpoints) to access and manipulate respective io.zipcoder.tc_spring_poll_application.domain objects. * REST resources are identified using URI endpoints. * Create a sub package of `io.zipcoder.tc_spring_poll_application` named `controller`. @@ -357,7 +357,7 @@ public Iterable getVote(@PathVariable Long pollId) { # Part 4 - Data Transfer Object (DTO) Implementation * The final piece remaining for us is the implementation of the ComputeResult resource. -* Because we don’t have any domain objects that can directly help generate this resource representation, we implement two Data Transfer Objects or DTOs—OptionCount and VoteResult +* Because we don’t have any io.zipcoder.tc_spring_poll_application.domain objects that can directly help generate this resource representation, we implement two Data Transfer Objects or DTOs—OptionCount and VoteResult * Create a sub package of `java` named `dtos` @@ -506,7 +506,7 @@ public ResponseEntity handleResourceNotFoundException(ResourceNotFoundExcepti -## Part 5.4 - Validating domain entities +## Part 5.4 - Validating io.zipcoder.tc_spring_poll_application.domain entities Now it's time to make sure that all objects persisted to the database actually contain valid values. Use the `org.hibernate.validator.constraints.NotEmpty` and `javax.validation.constraints.Size` and `javax.validation.Valid` annotations for validation. diff --git a/src/main/java/io/zipcoder/tc_spring_poll_application/domain/Option.java b/src/main/java/io/zipcoder/tc_spring_poll_application/domain/Option.java new file mode 100644 index 0000000..a7fcaac --- /dev/null +++ b/src/main/java/io/zipcoder/tc_spring_poll_application/domain/Option.java @@ -0,0 +1,40 @@ +package io.zipcoder.tc_spring_poll_application.domain; + +import javax.persistence.*; + +@Entity +public class Option { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "OPTION_ID") + Long id; + + @Column(name = "OPTION_VALUE") + String value; + + + public Option() { + } + + public Option(Long id, String value) { + this.id = id; + this.value = value; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } +} diff --git a/src/main/java/io/zipcoder/tc_spring_poll_application/domain/Poll.java b/src/main/java/io/zipcoder/tc_spring_poll_application/domain/Poll.java new file mode 100644 index 0000000..3f255b0 --- /dev/null +++ b/src/main/java/io/zipcoder/tc_spring_poll_application/domain/Poll.java @@ -0,0 +1,53 @@ +package io.zipcoder.tc_spring_poll_application.domain; + +import javax.persistence.*; +import java.util.Set; + +@Entity +public class Poll { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "POLL_ID") + Long id; + @Column(name = "QUESTION") + String question; + + @OneToMany(cascade = CascadeType.ALL) + @JoinColumn(name = "POLL_ID") + @OrderBy + Set