-
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.
- Loading branch information
Showing
10 changed files
with
146 additions
and
12 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
src/main/java/com/nexters/covid/letter/api/LetterController.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,8 +1,22 @@ | ||
package com.nexters.covid.letter.api; | ||
|
||
import com.nexters.covid.base.BaseResponse; | ||
import com.nexters.covid.letter.api.dto.OptionResponse; | ||
import com.nexters.covid.letter.service.LetterService; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RequiredArgsConstructor | ||
@RestController | ||
public class LetterController { | ||
|
||
private final LetterService letterService; | ||
|
||
@GetMapping("/letter/option") | ||
public BaseResponse<List<OptionResponse>> options() { | ||
List<OptionResponse> options = letterService.options(); | ||
return new BaseResponse<>(200, 0, "", options); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/com/nexters/covid/letter/api/dto/OptionResponse.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,23 @@ | ||
package com.nexters.covid.letter.api.dto; | ||
|
||
import static org.springframework.beans.BeanUtils.copyProperties; | ||
|
||
import com.nexters.covid.letter.domain.Question; | ||
import com.nexters.covid.letter.domain.SendOption; | ||
import java.util.List; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
public class OptionResponse { | ||
|
||
private String text; | ||
private Long covidStat; | ||
private List<Question> questions; | ||
|
||
public OptionResponse(SendOption source) { | ||
copyProperties(source, this); | ||
this.questions = source.questions(); | ||
} | ||
} |
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
28 changes: 28 additions & 0 deletions
28
src/main/java/com/nexters/covid/letter/domain/Question.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,28 @@ | ||
package com.nexters.covid.letter.domain; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnore; | ||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
import javax.persistence.JoinColumn; | ||
import javax.persistence.ManyToOne; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@Entity | ||
@NoArgsConstructor | ||
public class Question { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@ManyToOne | ||
@JsonIgnore | ||
@JoinColumn(name = "send_option_id") | ||
private SendOption sendOption; | ||
|
||
private String text; | ||
} |
36 changes: 33 additions & 3 deletions
36
src/main/java/com/nexters/covid/letter/domain/SendOption.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,6 +1,36 @@ | ||
package com.nexters.covid.letter.domain; | ||
|
||
public enum SendOption { | ||
// TODO: 회의 해서 정의 필요 | ||
A, B, C | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import javax.persistence.CascadeType; | ||
import javax.persistence.Entity; | ||
import javax.persistence.FetchType; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
import javax.persistence.OneToMany; | ||
import javax.persistence.Table; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@Entity | ||
@Table(name = "send_option") | ||
@NoArgsConstructor | ||
public class SendOption { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
private String text; | ||
|
||
private Long covidStat; | ||
|
||
@OneToMany(mappedBy = "sendOption", fetch = FetchType.LAZY, cascade = CascadeType.ALL) | ||
private final List<Question> questions = new ArrayList<>(); | ||
|
||
public List<Question> questions() { | ||
return questions; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/nexters/covid/letter/domain/SendOptionRepository.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,11 @@ | ||
package com.nexters.covid.letter.domain; | ||
|
||
import java.util.List; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
|
||
public interface SendOptionRepository extends JpaRepository<SendOption, Long> { | ||
|
||
@Query("select o from SendOption o join fetch o.questions") | ||
List<SendOption> findAllJoinFetch(); | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/com/nexters/covid/letter/service/LetterService.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,22 @@ | ||
package com.nexters.covid.letter.service; | ||
|
||
import com.nexters.covid.letter.api.dto.OptionResponse; | ||
import com.nexters.covid.letter.domain.SendOptionRepository; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@RequiredArgsConstructor | ||
@Service | ||
public class LetterService { | ||
|
||
private final SendOptionRepository sendOptionRepository; | ||
|
||
public List<OptionResponse> options() { | ||
return sendOptionRepository.findAllJoinFetch() | ||
.stream() | ||
.map(OptionResponse::new) | ||
.collect(Collectors.toList()); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -8,3 +8,4 @@ spring: | |
enabled: true | ||
jpa: | ||
defer-datasource-initialization: true | ||
show-sql: true |
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,6 +1,16 @@ | ||
insert into user (email, identifier, name) values ('email', 'identifier', 'name'); | ||
|
||
insert into letter (answer, contents, encrypted_id, letter_to, email, option, sticker, question_id, state, title, user_id) | ||
values ('ANSWER', 'CONTENTS', 'ENCRYPTED', 'LETTER_TO', 'email', 'A', 'B', 'HAPPY', 'PENDING', 'TITLE', 1); | ||
insert into letter (answer, contents, encrypted_id, letter_to, email, option, sticker, question_id, state, title, user_id) | ||
values ('ANSWER1', 'CONTENTS1', 'ENCRYPTED1', 'LETTER_TO1', 'email', 'A', 'B', 'BLUE', 'PENDING', 'TITLE1', 1); | ||
insert into letter (answer, contents, encrypted_id, letter_to, email, sticker, question_id, state, title, user_id) | ||
values ('ANSWER', 'CONTENTS', 'ENCRYPTED', 'LETTER_TO', 'email', 'A', 'HAPPY', 'PENDING', 'TITLE', 1); | ||
insert into letter (answer, contents, encrypted_id, letter_to, email, sticker, question_id, state, title, user_id) | ||
values ('ANSWER1', 'CONTENTS1', 'ENCRYPTED1', 'LETTER_TO1', 'email', 'A', 'BLUE', 'PENDING', 'TITLE1', 1); | ||
|
||
insert into send_option (text, covid_stat) values ('테스트', 1000); | ||
insert into send_option (text, covid_stat) values ('테스트2', 2000); | ||
|
||
insert into question (text, send_option_id) values ('테스트1에 1', 1); | ||
insert into question (text, send_option_id) values ('테스트1에 2', 1); | ||
insert into question (text, send_option_id) values ('테스트1에 3', 1); | ||
|
||
insert into question (text, send_option_id) values ('테스트2에 1', 2); | ||
insert into question (text, send_option_id) values ('테스트2에 2', 2); |