-
Notifications
You must be signed in to change notification settings - Fork 1
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 #20 from GlowTales/temp
[SETTING] 파일 구조 변경 [FEAT] #4~7 API 구현
- Loading branch information
Showing
15 changed files
with
346 additions
and
7 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
24 changes: 24 additions & 0 deletions
24
src/main/java/com/example/glowtales/config/SwaggerConfig.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.example.glowtales.config; | ||
|
||
import io.swagger.v3.oas.models.info.Info; | ||
import io.swagger.v3.oas.models.info.Contact; | ||
import io.swagger.v3.oas.models.OpenAPI; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class SwaggerConfig { | ||
|
||
@Bean | ||
public OpenAPI customOpenAPI() { | ||
return new OpenAPI() | ||
.info(new Info() | ||
.title("Member and Post API") | ||
.version("1.0") | ||
.description("API for managing members and their posts") | ||
.contact(new Contact() | ||
.name("Your Name") | ||
.email("[email protected]") | ||
.url("https://your-website.com"))); | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
src/main/java/com/example/glowtales/controller/TaleController.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,71 @@ | ||
package com.example.glowtales.controller; | ||
|
||
import com.example.glowtales.dto.response.TaleResponseDto; | ||
import com.example.glowtales.service.TaleService; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.List; | ||
|
||
|
||
@Slf4j | ||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/v1") | ||
@Tag(name = "Tale API", description = "API for managing tales") | ||
public class TaleController { | ||
|
||
//#001 전체 동화 상태창 불러오기 | ||
// | ||
//#002 단어장 미리보기 불러오기 | ||
//#003 단어장 모두 불러오기 | ||
// | ||
//#008 동화 만들기 | ||
//#009 동화의 학습 언어 선택하기 | ||
//#010 사진에서 키워드 추출하기 | ||
// | ||
//#011 동화의 퀴즈와 정답 불러오기 | ||
//#012 동화 퀴즈의 답 제출하기 | ||
|
||
|
||
|
||
private final TaleService tale_service; | ||
|
||
@Operation(summary = "#004 완료하지 않은 동화 미리보기 불러오기", description = "학습을 완료하지 않은 동화 중 최신 동화를 3개 불러오는 API입니다.") | ||
@GetMapping("/member/{memberId}/1") | ||
public ResponseEntity<List<TaleResponseDto>> getUnlearnedTalesTop3ByMemberId(@PathVariable Long memberId) { | ||
List<TaleResponseDto> posts = tale_service.getUnlearnedTaleTop3ByMemberId(memberId); | ||
return ResponseEntity.ok(posts); | ||
} | ||
|
||
@Operation(summary = "#005 완료하지 않은 동화 모두 불러오기", description = "학습을 완료하지 않은 동화를 최신순으로 불러오는 API입니다.") | ||
@GetMapping("/member/{memberId}/2") | ||
public ResponseEntity<List<TaleResponseDto>> getUnlearnedTalesByMemberId(@PathVariable Long memberId) { | ||
List<TaleResponseDto> posts = tale_service.getUnlearnedTaleByMemberId(memberId); | ||
return ResponseEntity.ok(posts); | ||
} | ||
|
||
@Operation(summary = "#006 최근 학습한 동화 미리보기 불러오기", description = "최근 학습한 동화 중 최신 동화를 3개 불러오는 API입니다.") | ||
@GetMapping("/member/{memberId}/3") | ||
public ResponseEntity<List<TaleResponseDto>> getStudiedTalesTop3ByMemberId(@PathVariable Long memberId) { | ||
List<TaleResponseDto> posts = tale_service.getStudiedTaleTop3ByMemberId(memberId); | ||
return ResponseEntity.ok(posts); | ||
} | ||
|
||
@Operation(summary = "#007 최근 학습한 동화 모두 불러오기", description = "최근 학습한 동화를 최신순으로 불러오는 API입니다.") | ||
@GetMapping("/member/{memberId}/4") | ||
public ResponseEntity<List<TaleResponseDto>> getStudiedTalesByMemberId(@PathVariable Long memberId) { | ||
List<TaleResponseDto> posts = tale_service.getStudiedTaleByMemberId(memberId); | ||
return ResponseEntity.ok(posts); | ||
} | ||
|
||
|
||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/com/example/glowtales/converter/YesOrNoConverter.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,20 @@ | ||
package com.example.glowtales.converter; | ||
|
||
|
||
import com.example.glowtales.domain.YesOrNo; | ||
import jakarta.persistence.AttributeConverter; | ||
import jakarta.persistence.Converter; | ||
|
||
@Converter(autoApply = true) | ||
public class YesOrNoConverter implements AttributeConverter<YesOrNo, Integer> { | ||
|
||
@Override | ||
public Integer convertToDatabaseColumn(YesOrNo attribute) { | ||
return attribute != null ? attribute.getValue() : null; | ||
} | ||
|
||
@Override | ||
public YesOrNo convertToEntityAttribute(Integer dbData) { | ||
return dbData != null ? YesOrNo.fromValue(dbData) : null; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,25 @@ | ||
package com.example.glowtales.domain; | ||
|
||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public enum YesOrNo { | ||
YES, NO | ||
YES(0), | ||
NO(1); | ||
|
||
private final int value; | ||
|
||
YesOrNo(int value) { | ||
this.value = value; | ||
} | ||
|
||
public static YesOrNo fromValue(int value) { | ||
for (YesOrNo yesOrNo : YesOrNo.values()) { | ||
if (yesOrNo.getValue() == value) { | ||
return yesOrNo; | ||
} | ||
} | ||
throw new IllegalArgumentException("Unknown value: " + value); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/com/example/glowtales/dto/response/LanguageTaleTitleResponseDto.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,17 @@ | ||
package com.example.glowtales.dto.response; | ||
|
||
import com.example.glowtales.domain.LanguageTale; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
public class LanguageTaleTitleResponseDto { | ||
private String title; | ||
|
||
@Builder | ||
public LanguageTaleTitleResponseDto(LanguageTale languageTale) { | ||
this.title = languageTale.getTitle(); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/com/example/glowtales/dto/response/TaleResponseDto.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,35 @@ | ||
package com.example.glowtales.dto.response; | ||
|
||
import com.example.glowtales.domain.Tale; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.stream.Collectors; | ||
|
||
@Getter | ||
@Setter | ||
public class TaleResponseDto { | ||
private Long tale_id; | ||
private LocalDateTime created_at; | ||
private Long member_id; | ||
private LanguageTaleTitleResponseDto title; | ||
|
||
@Builder | ||
public TaleResponseDto(Tale tale) { | ||
this.tale_id = tale.getId(); | ||
this.created_at = tale.getCreated_at(); | ||
this.member_id = tale.getMember().getId(); | ||
this.title = tale.getLanguage_tale_list().stream() | ||
// .filter(languageTale -> isKorean(languageTale.getLanguage().getId())) | ||
.findFirst() | ||
.map(LanguageTaleTitleResponseDto::new) | ||
.orElse(null); | ||
|
||
} | ||
|
||
// private boolean isKorean(Long language_id) { | ||
// return language_id == 1; | ||
// } | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/example/glowtales/repository/LanguageTaleRepository.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,8 @@ | ||
package com.example.glowtales.repository; | ||
|
||
import com.example.glowtales.domain.LanguageTale; | ||
import com.example.glowtales.domain.Member; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface LanguageTaleRepository extends JpaRepository<LanguageTale, Long> { | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/example/glowtales/repository/MemberRepository.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,8 @@ | ||
package com.example.glowtales.repository; | ||
|
||
import com.example.glowtales.domain.Member; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface MemberRepository extends JpaRepository<Member, Long> { | ||
} | ||
|
10 changes: 10 additions & 0 deletions
10
src/main/java/com/example/glowtales/repository/TaleRepository.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,10 @@ | ||
package com.example.glowtales.repository; | ||
|
||
import com.example.glowtales.domain.Tale; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.List; | ||
|
||
public interface TaleRepository extends JpaRepository<Tale, Long> { | ||
List<Tale> findByMemberId(Long memberId); | ||
} |
73 changes: 73 additions & 0 deletions
73
src/main/java/com/example/glowtales/service/TaleService.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,73 @@ | ||
package com.example.glowtales.service; | ||
|
||
import com.example.glowtales.domain.Tale; | ||
import com.example.glowtales.dto.response.TaleResponseDto; | ||
import com.example.glowtales.repository.TaleRepository; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.Comparator; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Service | ||
public class TaleService { | ||
|
||
private final TaleRepository tale_repository; | ||
|
||
@Autowired | ||
public TaleService(TaleRepository tale_repository) { | ||
this.tale_repository = tale_repository; | ||
} | ||
|
||
//#004 완료하지 않은 동화 미리보기 불러오기 | ||
public List<TaleResponseDto> getUnlearnedTaleTop3ByMemberId(Long memberId) { | ||
List<Tale> tales = tale_repository.findByMemberId(memberId); | ||
return tales.stream() | ||
.filter(tale -> tale.getLanguage_tale_list().stream() | ||
.anyMatch(languageTale -> languageTale.getLanguage().getId() == 1 && languageTale.getIs_learned().getValue() == 2)) | ||
|
||
.sorted(Comparator.comparing(Tale::getStudied_at).reversed()) | ||
.limit(3) | ||
.map(TaleResponseDto::new) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
//#005 완료하지 않은 동화 모두 불러오기 | ||
public List<TaleResponseDto> getUnlearnedTaleByMemberId(Long memberId) { | ||
List<Tale> tales = tale_repository.findByMemberId(memberId); | ||
return tales.stream() | ||
.filter(tale -> tale.getLanguage_tale_list().stream() | ||
.anyMatch(languageTale -> languageTale.getLanguage().getId() == 1 && languageTale.getIs_learned().getValue() == 2)) | ||
|
||
.sorted(Comparator.comparing(Tale::getStudied_at).reversed()) | ||
.map(TaleResponseDto::new) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
//#006 최근 학습한 동화 미리보기 불러오기 | ||
public List<TaleResponseDto> getStudiedTaleTop3ByMemberId(Long memberId) { | ||
List<Tale> tales = tale_repository.findByMemberId(memberId); | ||
return tales.stream() | ||
.filter(tale -> tale.getLanguage_tale_list().stream() | ||
.anyMatch(languageTale -> languageTale.getLanguage().getId() == 1 && languageTale.getIs_learned().getValue() == 1)) | ||
.sorted(Comparator.comparing(Tale::getStudied_at).reversed()) | ||
.limit(3) | ||
.map(TaleResponseDto::new) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
//#007 최근 학습한 동화 모두 불러오기 | ||
public List<TaleResponseDto> getStudiedTaleByMemberId(Long memberId) { | ||
List<Tale> tales = tale_repository.findByMemberId(memberId); | ||
return tales.stream() | ||
.filter(tale -> tale.getLanguage_tale_list().stream() | ||
.anyMatch(languageTale -> languageTale.getLanguage().getId() == 1 && languageTale.getIs_learned().getValue() == 1)) | ||
|
||
.sorted(Comparator.comparing(Tale::getStudied_at).reversed()) | ||
.map(TaleResponseDto::new) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.