Skip to content

Commit

Permalink
Feat: 오늘의 회화 생성 및 조회
Browse files Browse the repository at this point in the history
* Refactor: 스케줄링 허용

* Feat: Language 클래스 생성

* Feat: Conversation 생성

- 오늘의 회화
- 영어, 일본어, 스페인어, 프랑스어

* Feat: 오늘의 회화 업데이트

* Delete: 테스트용 Controller 코드 삭제

* Refactor: language 반환 제거

* Refactor: ManyToOne으로 수정
  • Loading branch information
tjdgns8439 authored Mar 5, 2024
1 parent 6fce5d0 commit 1c56f21
Show file tree
Hide file tree
Showing 15 changed files with 281 additions and 16 deletions.
2 changes: 2 additions & 0 deletions src/main/java/com/example/tripy/TripyApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;

@EnableScheduling
@SpringBootApplication
public class TripyApplication {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.tripy.domain.conversation;

import com.example.tripy.domain.conversation.dto.ConversationRequestDto.ConversationCreateRequest;
import com.example.tripy.domain.country.Country;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
Expand All @@ -8,16 +9,17 @@
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Builder
public class Conversation {


Expand All @@ -28,13 +30,23 @@ public class Conversation {
@NotNull
private String korean;

@NotNull
private String translation;

@NotNull
private String pronunciation;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "country_id")
private Country country;



public static Conversation toEntity(ConversationCreateRequest requestDto) {
return Conversation.builder()
.korean(requestDto.getKorean())
.translation(requestDto.getTranslation())
.pronunciation(requestDto.getPronunciation())
.country(requestDto.getCountry())
.build();
}

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
package com.example.tripy.domain.conversation;

import com.example.tripy.domain.conversation.dto.ConversationResponseDto.ConversationDetailResponse;
import com.example.tripy.global.s3.S3Service;
import java.util.List;
import lombok.RequiredArgsConstructor;
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.RestController;

@RequiredArgsConstructor
@RestController
public class ConversationController {

private final ConversationService conversationService;
private final S3Service s3Service;

@GetMapping("/api/conversation/country/{country-id}")
public ResponseEntity<List<ConversationDetailResponse>> findConversationListByCountry(
@PathVariable("country-id") Long countryId) {
return ResponseEntity.ok(conversationService.findConversationListByCountry(countryId));
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.example.tripy.domain.conversation;

import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;

public interface ConversationRepository extends JpaRepository<Conversation, Long> {
List<Conversation> findAllByCountryId(Long countryId);
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
package com.example.tripy.domain.conversation;

import com.example.tripy.domain.conversation.dto.ConversationResponseDto.ConversationDetailResponse;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@RequiredArgsConstructor
@Service
public class ConversationService {
private final ConversationRepository conversationRepository;

public List<ConversationDetailResponse> findConversationListByCountry(Long countryId) {
return conversationRepository.findAllByCountryId(countryId)
.stream()
.map(ConversationDetailResponse::toDTO)
.toList();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.example.tripy.domain.conversation.dto;

import com.example.tripy.domain.country.Country;
import lombok.AllArgsConstructor;
import lombok.Getter;

public class ConversationRequestDto {
@Getter
@AllArgsConstructor
public static class ConversationCreateRequest {
private String korean;

private String translation;

private String pronunciation;

private Country country;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.example.tripy.domain.conversation.dto;

import com.example.tripy.domain.conversation.Conversation;
import com.example.tripy.domain.language.Language;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

public class ConversationResponseDto {

@Builder
@Getter
@NoArgsConstructor
@AllArgsConstructor
public static class ConversationDetailResponse {

private String koreanSentences;
private String translatedSentences;
private Long countryId;
private String pronunciation;

public static ConversationDetailResponse toDTO(Conversation conversation) {
return ConversationDetailResponse.builder()
.koreanSentences(conversation.getKorean())
.translatedSentences(conversation.getTranslation())
.countryId(conversation.getCountry().getId())
.pronunciation(conversation.getPronunciation())
.build();
}
}
}
11 changes: 4 additions & 7 deletions src/main/java/com/example/tripy/domain/country/Country.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
package com.example.tripy.domain.country;

import com.example.tripy.domain.city.City;
import com.example.tripy.domain.continent.Continent;
import com.example.tripy.domain.conversation.Conversation;
import com.example.tripy.domain.countrymaterial.CountryMaterial;
import com.example.tripy.domain.currency.Currency;
import com.example.tripy.global.utils.BaseTimeEntity;
import com.example.tripy.domain.language.Language;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import jakarta.persistence.OneToOne;
import jakarta.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand Down Expand Up @@ -45,5 +39,8 @@ public class Country {
@JoinColumn(name = "continent_id")
private Continent continent;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "language_id")
private Language language;

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@
public interface CountryRepository extends JpaRepository<Country, Long> {

Optional<Country> findCountryByName(String name);


public interface CountryRepository extends JpaRepository<Country, Long> {
Country findByLanguage(Language language);
}
24 changes: 24 additions & 0 deletions src/main/java/com/example/tripy/domain/language/Language.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.example.tripy.domain.language;

import com.example.tripy.global.utils.BaseTimeEntity;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@AllArgsConstructor
@NoArgsConstructor
@Entity
public class Language extends BaseTimeEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@NotNull
private String languageName;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.example.tripy.domain.language;

import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RestController;

@RequiredArgsConstructor
@RestController
public class LanguageController {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.example.tripy.domain.language;

import org.springframework.data.jpa.repository.JpaRepository;

public interface LanguageRepository extends JpaRepository<Language, Long> {
Language findByLanguageName(String languageName);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.example.tripy.domain.language;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@RequiredArgsConstructor
@Service
public class LanguageService {

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public enum ErrorStatus implements BaseErrorCode {
_ALREADY_TRAVEL_PLAN_BAG_EXISTS(HttpStatus.BAD_REQUEST, "TRAVEL_PLAN_002",
"이미 가방이 존재하는 여행 계획입니다."),

//S3 관련
_FAULT_S3_KEY(HttpStatus.NOT_FOUND, "S3_001", "잘못된 S3 정보입니다."),

//파일 업로드 관련
_FILE_UPLOAD_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "FILE_001", "파일 업로드에 실패했습니다."),

Expand Down
Loading

0 comments on commit 1c56f21

Please sign in to comment.