Skip to content

Commit

Permalink
Merge pull request #91 from studio-recoding/dev
Browse files Browse the repository at this point in the history
[🚀feat] 6차 배포
  • Loading branch information
JeonHaeseung authored May 25, 2024
2 parents 99b4016 + 5ab394d commit 48a93c1
Show file tree
Hide file tree
Showing 28 changed files with 405 additions and 67 deletions.
26 changes: 19 additions & 7 deletions src/main/java/Ness/Backend/domain/category/CategoryController.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
package Ness.Backend.domain.category;

import Ness.Backend.domain.category.dto.reponse.GetCategoryListDto;
import Ness.Backend.domain.category.dto.request.PostCategoryDto;
import Ness.Backend.domain.category.dto.request.PutCategoryDto;
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;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
Expand All @@ -22,8 +20,22 @@ public class CategoryController {
private final CategoryService categoryService;
@GetMapping("")
@Operation(summary = "특정 사용자의 모든 카테고리", description = "모든 카테고리가 리스트로 반환됩니다.")
public ResponseEntity<GetCategoryListDto> getUserSchedule(@AuthUser Member member){
GetCategoryListDto getCategoryListDto = categoryService.getOneUserCategory(member.getId());
public ResponseEntity<GetCategoryListDto> getUserCategory(@AuthUser Member member){
GetCategoryListDto getCategoryListDto = categoryService.getUserCategory(member.getId());
return new ResponseEntity<>(getCategoryListDto, HttpStatusCode.valueOf(200));
}

@PostMapping("")
@Operation(summary = "사용자가 만든 카테고리 저장", description = "사용자가 만든 카테고리를 저장합니다.")
public ResponseEntity<?> postUserCategory(@AuthUser Member member, @RequestBody PostCategoryDto postCategoryDto){
categoryService.postUserCategory(member.getId(), postCategoryDto);
return new ResponseEntity<>(HttpStatusCode.valueOf(200));
}

@PutMapping("")
@Operation(summary = "사용자가 만든 카테고리 수정", description = "사용자가 만든 카테고리를 수정합니다.")
public ResponseEntity<?> putUserCategory(@AuthUser Member member, @RequestBody PutCategoryDto putCategoryDto){
categoryService.putUserCategory(member.getId(), putCategoryDto);
return new ResponseEntity<>(HttpStatusCode.valueOf(200));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import Ness.Backend.domain.category.entity.Category;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;
Expand All @@ -10,5 +11,14 @@
public interface CategoryRepository extends JpaRepository<Category, Long> {
Category findCategoryById(Long id);

List<Category> findCategoryByMember_id(Long memberId);
List<Category> findCategoriesByMember_id(Long memberId);

@Query(value = "SELECT * FROM category " +
"WHERE member_id = :memberId " +
"AND name = :name " +
"AND category_id != :categoryId",
nativeQuery = true)
List<Category> findCategoriesByMember_idAndNameExcludeId(Long memberId, String name, Long categoryId);

List<Category> findCategoriesByMember_idAndName(Long memberId, String name);
}
50 changes: 46 additions & 4 deletions src/main/java/Ness/Backend/domain/category/CategoryService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,29 @@

import Ness.Backend.domain.category.dto.reponse.GetCategoryDto;
import Ness.Backend.domain.category.dto.reponse.GetCategoryListDto;
import Ness.Backend.domain.category.dto.request.PostCategoryDto;
import Ness.Backend.domain.category.dto.request.PutCategoryDto;
import Ness.Backend.domain.category.entity.Category;
import Ness.Backend.domain.chat.dto.response.GetChatDto;
import Ness.Backend.domain.chat.dto.response.GetChatListDto;
import Ness.Backend.domain.member.MemberRepository;
import Ness.Backend.domain.member.entity.Member;
import Ness.Backend.global.error.exception.DuplicateCategoryException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

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

List<GetCategoryDto> getCategoryDtos = categoryList.stream()
.map(category -> GetCategoryDto.builder()
Expand All @@ -29,4 +35,40 @@ public GetCategoryListDto getOneUserCategory(Long memberId) {
.toList();
return new GetCategoryListDto(getCategoryDtos);
}

/* 카테고리 새롭게 만들기(유저에 의해서만 직접 생성) */
@Transactional
public void postUserCategory(Long memberId, PostCategoryDto postCategoryDto){
List<Category> categoryList = categoryRepository.findCategoriesByMember_idAndName(memberId, postCategoryDto.getName());
if(categoryList.isEmpty()){
//중복되지 않은 카테고리일 경우는 그대로 저장해주기
Member member = memberRepository.findMemberById(memberId);

Category category = Category.builder()
.member(member)
.color(postCategoryDto.getColor())
.name(postCategoryDto.getName())
.build();

categoryRepository.save(category);
}
else {
throw new DuplicateCategoryException();
}
}

/* 카테고리 수정하기 */
@Transactional
public void putUserCategory(Long memberId, PutCategoryDto putCategoryDto){
List<Category> categoryList = categoryRepository.findCategoriesByMember_idAndNameExcludeId(memberId, putCategoryDto.getName(), putCategoryDto.getId());

if(categoryList.isEmpty()){
//중복되지 않은 카테고리일 경우는 변경사항 저장 가능
Category category = categoryRepository.findCategoryById(putCategoryDto.getId());
category.changeCategory(putCategoryDto.getName(), putCategoryDto.getColor());
}
else {
throw new DuplicateCategoryException();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package Ness.Backend.domain.category.dto.reponse;

import Ness.Backend.domain.chat.dto.response.GetChatDto;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package Ness.Backend.domain.category.dto.request;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class PostCategoryDto {
@JsonProperty("category")
private String name;

@JsonProperty("categoryColor")
private String color;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package Ness.Backend.domain.category.dto.request;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class PutCategoryDto {
@JsonProperty("id")
private Long id;

@JsonProperty("category")
private String name;

@JsonProperty("categoryColor")
private String color;
}
15 changes: 15 additions & 0 deletions src/main/java/Ness/Backend/domain/category/entity/Category.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
import Ness.Backend.domain.member.entity.Member;
import Ness.Backend.domain.schedule.entity.Schedule;
import jakarta.persistence.*;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;

@Entity
@Getter
@NoArgsConstructor
public class Category {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand All @@ -27,4 +30,16 @@ public class Category {

@OneToMany(mappedBy = "category")
private List<Schedule> schedules = new ArrayList<>();

public void changeCategory(String name, String color){
this.name = name;
this.color = color;
}

@Builder
public Category(Member member, String name, String color){
this.member = member;
this.name = name;
this.color = color;
}
}
2 changes: 1 addition & 1 deletion src/main/java/Ness/Backend/domain/chat/ChatRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public interface ChatRepository extends JpaRepository<Chat, Long>{
// 특정 맴버의 일주일치 데이터만 반환
@Query( value = "SELECT * FROM chat " +
"WHERE member_id = :memberId " +
"AND created_date >= DATE_SUB(NOW(), INTERVAL 1 WEEK) " +
"AND CONVERT_TZ(created_date, '+00:00', '+09:00') >= DATE_SUB(CONVERT_TZ(NOW(), '+00:00', '+09:00'), INTERVAL 1 WEEK) " +
//"AND created_date BETWEEN DATE_ADD(NOW(), INTERVAL -1 WEEK) AND NOW() " +
"ORDER BY created_date ASC",
nativeQuery = true)
Expand Down
1 change: 0 additions & 1 deletion src/main/java/Ness/Backend/domain/chat/ChatService.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ public PostFastApiAiChatDto postNewAiChat(Long memberId, String text, ChatType c
persona = "easy";
}

//TODO: member_id 전달하는 로직 만들어야 하지 않을까?(RAG를 위해)
PostFastApiUserChatDto userDto = PostFastApiUserChatDto.builder()
.persona(persona)
.chatType(chatType) // 유저가 키보드로 친 채팅인지, 아니면 STT를 썼는지 구분
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/Ness/Backend/domain/member/MemberService.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package Ness.Backend.domain.member;

import Ness.Backend.domain.category.CategoryRepository;
import Ness.Backend.domain.category.entity.Category;
import Ness.Backend.domain.member.entity.Member;
import Ness.Backend.domain.profile.ProfileRepository;
import Ness.Backend.domain.profile.entity.PersonaType;
Expand All @@ -16,6 +18,7 @@ public class MemberService {
private final MemberRepository memberRepository;
private final ProfileRepository profileRepository;
private final BCryptPasswordEncoder bCryptPasswordEncoder;
private final CategoryRepository categoryRepository;
public void deleteMember(Member member) {
profileRepository.delete(member.getProfile());
/* 소프트 삭제 */
Expand All @@ -38,7 +41,15 @@ public Member createMember(String email, String password, String picture, String
.personaType(PersonaType.NESS) //디폴트로 NESS를 저장해줌, 나중에 개인 페이지에서 변경 가능
.build();

//디폴트 미분류 카테고리가 있어야 함, 맴버 생성시 자동 만들어주기
Category category = Category.builder()
.member(member)
.name("\uD83C\uDF40미분류")
.color("#D9D9D9")
.build();

profileRepository.save(profile);
categoryRepository.save(category);
return memberRepository.save(member);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package Ness.Backend.domain.profile.dto.request;

import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.NoArgsConstructor;
Expand All @@ -11,5 +12,6 @@ public class PutProfileDto {
private String nickname;

@Schema(description = "업데이트할 사용자 프로필 키 경로", example = "untitle.png")
@JsonProperty("imageUrl")
private String key;
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ public ResponseEntity<GetScheduleListDto> postOneSchedule(@AuthUser Member membe
description =
"하나의 스케쥴의 정보를 변경하는 API로 스케쥴, 위치, 사람, 시간 모두 PUT으로 처리합니다." +
"&day=2024-01-01과 같은 형식으로 데이터가 전달됩니다.")
public ResponseEntity<GetScheduleListDto> putOneSchedule(@AuthUser Member member, @RequestParam String day, @RequestBody PutScheduleDto putScheduleDto){
GetScheduleListDto oneUserOneDaySchedules = scheduleService.changeSchedule(member.getId(), putScheduleDto, day);
public ResponseEntity<GetScheduleListDto> putOneSchedule(@AuthUser Member member, @RequestBody PutScheduleDto putScheduleDto){
GetScheduleListDto oneUserOneDaySchedules = scheduleService.changeSchedule(member.getId(), putScheduleDto);
return new ResponseEntity<>(oneUserOneDaySchedules, HttpStatusCode.valueOf(200));
}

@DeleteMapping("")
@Operation(summary = "하나의 스케쥴 삭제", description = "하나의 스케쥴을 삭제하는 API 입니다.")
public ResponseEntity<GetScheduleListDto> deleteOneSchedule(@AuthUser Member member, @RequestParam Long id){
GetScheduleListDto oneUserOneDaySchedules = scheduleService.deleteSchedule(id);
GetScheduleListDto oneUserOneDaySchedules = scheduleService.deleteSchedule(member.getId(), id);
return new ResponseEntity<>(oneUserOneDaySchedules, HttpStatusCode.valueOf(200));
}

Expand Down
Loading

0 comments on commit 48a93c1

Please sign in to comment.