Skip to content

Commit

Permalink
Merge pull request #86 from studio-recoding/dev
Browse files Browse the repository at this point in the history
[🚀feat] 5차 배포
  • Loading branch information
JeonHaeseung authored May 24, 2024
2 parents 7165add + 7540e68 commit 99b4016
Show file tree
Hide file tree
Showing 15 changed files with 136 additions and 13 deletions.
29 changes: 29 additions & 0 deletions src/main/java/Ness/Backend/domain/category/CategoryController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package Ness.Backend.domain.category;

import Ness.Backend.domain.category.dto.reponse.GetCategoryListDto;
import Ness.Backend.domain.member.entity.Member;
import Ness.Backend.domain.schedule.dto.response.GetScheduleListDto;
import Ness.Backend.global.auth.AuthUser;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatusCode;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
@Tag(name = "카테고리 API", description = "사용자의 카테고리 관련 API")
@RequestMapping("/category")
public class CategoryController {
private final CategoryService categoryService;
@GetMapping("")
@Operation(summary = "특정 사용자의 모든 카테고리", description = "모든 카테고리가 리스트로 반환됩니다.")
public ResponseEntity<GetCategoryListDto> getUserSchedule(@AuthUser Member member){
GetCategoryListDto getCategoryListDto = categoryService.getOneUserCategory(member.getId());
return new ResponseEntity<>(getCategoryListDto, HttpStatusCode.valueOf(200));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface CategoryRepository extends JpaRepository<Category, Long> {
Category findCategoryById(Long id);

List<Category> findCategoryByMember_id(Long memberId);
}
32 changes: 32 additions & 0 deletions src/main/java/Ness/Backend/domain/category/CategoryService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package Ness.Backend.domain.category;

import Ness.Backend.domain.category.dto.reponse.GetCategoryDto;
import Ness.Backend.domain.category.dto.reponse.GetCategoryListDto;
import Ness.Backend.domain.category.entity.Category;
import Ness.Backend.domain.chat.dto.response.GetChatDto;
import Ness.Backend.domain.chat.dto.response.GetChatListDto;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class CategoryService {
private final CategoryRepository categoryRepository;
/* 특정 유저의 카테고리 전부 가져오기 */
public GetCategoryListDto getOneUserCategory(Long memberId) {
List<Category> categoryList = categoryRepository.findCategoryByMember_id(memberId);

List<GetCategoryDto> getCategoryDtos = categoryList.stream()
.map(category -> GetCategoryDto.builder()
.id(category.getId())
.name(category.getName())
.color(category.getColor())
.build())
.toList();
return new GetCategoryListDto(getCategoryDtos);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package Ness.Backend.domain.category.dto.reponse;

import Ness.Backend.domain.category.entity.Category;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
public class GetCategoryDto {
@JsonProperty("categoryNum")
private Long id;

@JsonProperty("category")
private String name;

@JsonProperty("categoryColor")
private String color;

@Builder
public GetCategoryDto(Long id, String name, String color){
this.id = id;
this.name = name;
this.color = color;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package Ness.Backend.domain.category.dto.reponse;

import Ness.Backend.domain.chat.dto.response.GetChatDto;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class GetCategoryListDto {
private List<GetCategoryDto> categoryList;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package Ness.Backend.domain.category.entity;

import Ness.Backend.domain.member.entity.Member;
import Ness.Backend.domain.schedule.entity.Schedule;
import jakarta.persistence.*;
import lombok.Getter;
Expand All @@ -17,6 +18,13 @@ public class Category {

private String name;

//카테고리별 색상
private String color;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member_id", nullable = false)
private Member member;

@OneToMany(mappedBy = "category")
private List<Schedule> schedules = new ArrayList<>();
}
3 changes: 2 additions & 1 deletion src/main/java/Ness/Backend/domain/chat/ChatService.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public GetChatListDto postNewUserChat(Long memberId, PostUserChatDto postUserCha
}

/* AI에 채팅 전송하는 로직 */
public PostFastApiAiChatDto postNewAiChat(Long id, String text, ChatType chatType, PersonaType personaType){
public PostFastApiAiChatDto postNewAiChat(Long memberId, String text, ChatType chatType, PersonaType personaType){
String persona = "default";
if (personaType == PersonaType.HARDNESS){
persona = "hard";
Expand All @@ -109,6 +109,7 @@ public PostFastApiAiChatDto postNewAiChat(Long id, String text, ChatType chatTyp
.persona(persona)
.chatType(chatType) // 유저가 키보드로 친 채팅인지, 아니면 STT를 썼는지 구분
.message(text)
.member_id(memberId)
.build();

//Fast API에 전송하기
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
@Builder
/* AI에게 보내는 유저 채팅 */
public class PostFastApiUserChatDto {
@JsonProperty("member_id")
private Long member_id;

@JsonProperty("prompt")
private String message;

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/Ness/Backend/domain/chat/entity/Chat.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ public class Chat {
@Enumerated(EnumType.STRING)
private ChatType chatType;

@OneToOne(mappedBy = "chat")
@OneToOne(mappedBy = "chat", fetch = FetchType.LAZY)
private Schedule schedule;

@ManyToOne
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member_id")
private Member member;

Expand Down
6 changes: 5 additions & 1 deletion src/main/java/Ness/Backend/domain/member/entity/Member.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package Ness.Backend.domain.member.entity;


import Ness.Backend.domain.category.entity.Category;
import Ness.Backend.domain.chat.entity.Chat;
import Ness.Backend.domain.profile.entity.Profile;
import Ness.Backend.domain.report.entity.ReportMemory;
Expand Down Expand Up @@ -43,14 +44,17 @@ public class Member {
private List<Chat> chats = new ArrayList<>();

@OneToMany(mappedBy = "member")
private List<ReportTag> re = new ArrayList<>();
private List<ReportTag> reportTags = new ArrayList<>();

@OneToMany(mappedBy = "member")
private List<ReportMemory> reportMemories = new ArrayList<>();

@OneToMany(mappedBy = "member")
private List<ReportRecommend> reportRecommends = new ArrayList<>();

@OneToMany(mappedBy = "member")
private List<Category> categories = new ArrayList<>();

@Column(columnDefinition = "boolean default false")
private boolean isDeleted;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package Ness.Backend.domain.profile;

import Ness.Backend.domain.member.entity.Member;
import Ness.Backend.domain.profile.dto.request.PutProfileDto;
import Ness.Backend.domain.profile.dto.response.GetProfileDto;
import Ness.Backend.domain.profile.entity.PersonaType;
Expand Down Expand Up @@ -59,6 +58,6 @@ private String createPictureUrl(Long memberId, Profile profile){
return profile.getPictureUrl();
}
return s3Service.getGetS3Url(memberId,
profile.getPictureKey()).getPreSignedUrl();
profile.getPictureKey()).getPreSignedUrl();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public interface ScheduleRepository extends JpaRepository<Schedule, Long> {
// 특정 맴버의 한달 치 스케쥴 반환
@Query( value = "SELECT * FROM schedule " +
"WHERE member_id = :memberId " +
"AND YEAR(start_time) = :year " +
"AND MONTH(start_time) = :month " +
"AND YEAR(CONVERT_TZ(start_time, '+00:00', '+09:00')) = CONVERT_TZ(:year, '+00:00', '+09:00')" +
"AND MONTH(CONVERT_TZ(start_time, '+00:00', '+09:00')) = CONVERT_TZ(:month, '+00:00', '+09:00')" +
"ORDER BY start_time ASC",
nativeQuery = true)
List<Schedule> findOneMonthSchedulesByMember_Id(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ public class Schedule {

private ZonedDateTime endTime;

@ManyToOne
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member_id")
private Member member;

@ManyToOne
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "category_id")
private Category category;

@OneToOne
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "chat_id")
private Chat chat;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/Ness/Backend/infra/s3/S3Service.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class S3Service {
// 버킷 이름
@Value("${cloud.aws.s3.bucket}")
private String bucket;

@Transactional(readOnly = true)
public GetS3UrlDto getPostS3Url(Long memberId, String filename) {
// filename 설정하기(profile 경로 + 멤버ID + 랜덤 값)
Expand Down
1 change: 0 additions & 1 deletion src/main/java/Ness/Backend/infra/s3/dto/GetS3UrlDto.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package Ness.Backend.infra.s3.dto;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.*;


Expand Down

0 comments on commit 99b4016

Please sign in to comment.