Skip to content

Commit

Permalink
[Fix] AnniversaryCategory 디자인 매칭, 친구 조회 userId 누락 #68
Browse files Browse the repository at this point in the history
  • Loading branch information
eunki96 committed Aug 11, 2023
1 parent 990ae5b commit d1d9fbb
Show file tree
Hide file tree
Showing 15 changed files with 152 additions and 58 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package com.favor.favor.anniversary;

import com.favor.favor.common.TimeStamped;
import com.favor.favor.common.enums.Category;
import com.favor.favor.common.enums.CategoryGift;
import com.favor.favor.user.User;
import lombok.*;

import javax.persistence.*;
import javax.transaction.Transactional;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;

@Entity
@Getter
Expand All @@ -30,8 +28,8 @@ public class Anniversary extends TimeStamped {
public void setAnniversaryDate(LocalDate anniversaryDate){ this.anniversaryDate = anniversaryDate; }

private Integer category;
public void setCategory(Category category){
this.category = category.getType();
public void setCategory(CategoryGift categoryGift){
this.category = categoryGift.getType();
}

private Boolean isPinned;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.favor.favor.anniversary;

import com.favor.favor.common.enums.Category;
import com.favor.favor.common.enums.CategoryGift;
import com.favor.favor.user.User;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
Expand All @@ -21,14 +21,14 @@ public class AnniversaryRequestDto {
private String anniversaryDate;

@ApiModelProperty(position = 3, required = true, value = "종류", example = "생일")
private Category category;
private CategoryGift categoryGift;

@Transactional
public Anniversary toEntity(User user, LocalDate localDate){
return Anniversary.builder()
.anniversaryTitle(anniversaryTitle)
.anniversaryDate(localDate)
.category(category.getType())
.category(categoryGift.getType())
.isPinned(false)
.user(user)
.build();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.favor.favor.anniversary;

import com.favor.favor.common.enums.CategoryAnniversary;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Getter
@AllArgsConstructor
Expand All @@ -18,6 +18,7 @@ public class AnniversaryResponseDto {
private Long userNo;
private LocalDateTime createdAt;
private LocalDateTime modifiedAt;
private CategoryAnniversary categoryAnniversary;

@Builder
public AnniversaryResponseDto(Anniversary anniversary){
Expand All @@ -28,5 +29,6 @@ public AnniversaryResponseDto(Anniversary anniversary){
this.userNo = anniversary.getUser().getUserNo();
this.createdAt = anniversary.getCreatedAt();
this.modifiedAt = anniversary.getModifiedAt();
this.categoryAnniversary = CategoryAnniversary.valueOf(anniversary.getCategory());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void updateAnniversary(AnniversaryUpdateRequestDto dto, Anniversary anniv
anniversary.setAnniversaryTitle(dto.getAnniversaryTitle());
LocalDate localDate = returnLocalDate(dto.getAnniversaryDate());
anniversary.setAnniversaryDate(localDate);
anniversary.setCategory(dto.getCategory());
anniversary.setCategory(dto.getCategoryGift());

anniversaryRepository.save(anniversary);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package com.favor.favor.anniversary;

import com.favor.favor.common.enums.Category;
import com.favor.favor.common.enums.CategoryGift;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.List;


@Getter
@NoArgsConstructor
Expand All @@ -21,7 +19,7 @@ public class AnniversaryUpdateRequestDto {
private String anniversaryDate;

@ApiModelProperty(position = 3, required = true, value = "종류", example = "생일")
private Category category;
private CategoryGift categoryGift;

@ApiModelProperty(position = 4, required = true, value = "핀 여부", example = "false")
private Boolean isPinned;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.favor.favor.common.enums;

import lombok.Getter;

public enum CategoryAnniversary {
연인(1),
축하_생일(2),
졸업(3),
합격(4),
입사_승진(5),
이사_집들이(6),
출산(7);

@Getter
Integer type;

CategoryAnniversary(Integer type){
this.type = type;
}

public static CategoryAnniversary validateType(String category){
try{
return CategoryAnniversary.valueOf(category);
}catch(IllegalStateException e){
throw new IllegalArgumentException();
}

}

public static CategoryAnniversary valueOf(Integer type){
CategoryAnniversary categoryAnniversary = null;
switch (type){
case 1:
categoryAnniversary = CategoryAnniversary.연인;
break;
case 2:
categoryAnniversary = CategoryAnniversary.축하_생일;
break;
case 3:
categoryAnniversary = CategoryAnniversary.졸업;
break;
case 4:
categoryAnniversary = CategoryAnniversary.합격;
break;
case 5:
categoryAnniversary = CategoryAnniversary.입사_승진;
break;
case 6:
categoryAnniversary = CategoryAnniversary.이사_집들이;
break;
case 7:
categoryAnniversary = CategoryAnniversary.출산;
break;
}
return categoryAnniversary;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import lombok.Getter;

public enum Category {
public enum CategoryGift {
// 가벼운선물, 생일, 집들이, 시험, 승진, 졸업, 기타
벼운선물(1),
생일(2),
Expand All @@ -14,46 +14,46 @@ public enum Category {

@Getter
Integer type;
Category (Integer type){
CategoryGift(Integer type){
this.type = type;
}

public static Category validateType(String category){
public static CategoryGift validateType(String category){
try{
return Category.valueOf(category);
return CategoryGift.valueOf(category);
}catch(IllegalStateException e){
//커스텀 전 임시
throw new IllegalArgumentException();
}
}

public static Category valueOf(Integer type){
Category category = null;
public static CategoryGift valueOf(Integer type){
CategoryGift categoryGift = null;
switch (type){
case 1:
category = Category.벼운선물;
categoryGift = CategoryGift.벼운선물;
break;
case 2:
category = Category.생일;
categoryGift = CategoryGift.생일;
break;
case 3:
category = Category.집들이;
categoryGift = CategoryGift.집들이;
break;
case 4:
category = Category.시험;
categoryGift = CategoryGift.시험;
break;
case 5:
category = Category.승진;
categoryGift = CategoryGift.승진;
break;
case 6:
category = Category.졸업;
categoryGift = CategoryGift.졸업;
break;
case 7:
category = Category.기타;
categoryGift = CategoryGift.기타;
break;
default:
break;
}
return category;
return categoryGift;
}
}
15 changes: 10 additions & 5 deletions favor/src/main/java/com/favor/favor/gift/Gift.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.favor.favor.gift;

import com.favor.favor.common.enums.Category;
import com.favor.favor.common.enums.CategoryGift;
import com.favor.favor.common.enums.Emotion;
import com.favor.favor.common.TimeStamped;
import com.favor.favor.photo.GiftPhoto;
Expand All @@ -11,7 +11,6 @@
import javax.transaction.Transactional;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

@Entity
Expand Down Expand Up @@ -43,8 +42,8 @@ public void setGiftMemo(String giftMemo){
}

private Integer category;
public void setCategory(Category category){
this.category = category.getType();
public void setCategory(CategoryGift categoryGift){
this.category = categoryGift.getType();
}

private Integer emotion;
Expand Down Expand Up @@ -78,7 +77,13 @@ public void setFriendNoList(List<Long> friendNoList){

@OneToMany(cascade = CascadeType.ALL)
private List<GiftPhoto> giftPhotoList = new ArrayList<>();
public void setGiftPhotoList(List<GiftPhoto> giftPhotoList){
public void setGiftPhotoList(List<GiftPhoto> giftPhotoList) {
this.giftPhotoList = giftPhotoList;
}

@ElementCollection
private List<String> tempFriendList;
public void setTempFriendList(List<String> tempFriendList){
this.tempFriendList = tempFriendList;
}
}
38 changes: 35 additions & 3 deletions favor/src/main/java/com/favor/favor/gift/GiftController.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package com.favor.favor.gift;

import com.favor.favor.common.DefaultResponseDto;
import com.favor.favor.friend.FriendResponseDto;
import com.favor.favor.user.User;
import com.favor.favor.user.UserResponseDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
Expand Down Expand Up @@ -129,6 +126,41 @@ public ResponseEntity<DefaultResponseDto<Object>> updateGift(
.build());
}

@ApiOperation("선물 임시친구목록 수정")
@ApiResponses(value={
@ApiResponse(code = 200,
message = "GIFT_TEMP_FRIEND_LIST_UPDATED",
response = GiftResponseDto.class),
@ApiResponse(code = 401,
message = "UNAUTHORIZED_USER"),
@ApiResponse(code = 404,
message = "GIFT_NOT_FOUND / FRIEND_NOT_FOUND"),
@ApiResponse(code = 500,
message = "SERVER_ERROR")
})
@ResponseStatus(HttpStatus.OK)
@Transactional
@PatchMapping("/temp-friend-list/{giftNo}")
public ResponseEntity<DefaultResponseDto<Object>> updateTempFriendListGift(
@PathVariable Long giftNo,
List<String> tempFriendList
){

giftService.isExistingGiftNo(giftNo);


Gift gift = giftService.findGiftByGiftNo(giftNo);
giftService.updateTempFriendList(gift, tempFriendList);
GiftResponseDto dto = giftService.returnDto(gift);

return ResponseEntity.status(200)
.body(DefaultResponseDto.builder()
.responseCode("GIFT_TEMP_FRIEND_LIST_UPDATED")
.responseMessage("선물 임시친구목록 수정 완료")
.data(dto)
.build());
}

@ApiOperation("선물 핀 여부 수정")
@ApiResponses(value={
@ApiResponse(code = 200,
Expand Down
6 changes: 3 additions & 3 deletions favor/src/main/java/com/favor/favor/gift/GiftRequestDto.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.favor.favor.gift;

import com.favor.favor.common.enums.Category;
import com.favor.favor.common.enums.CategoryGift;
import com.favor.favor.common.enums.Emotion;
import com.favor.favor.user.User;
import io.swagger.annotations.ApiModelProperty;
Expand All @@ -27,7 +27,7 @@ public class GiftRequestDto {
private String giftMemo;

@ApiModelProperty(position = 4, required = false, value = "카테고리", example = "생일")
private Category category;
private CategoryGift categoryGift;

@ApiModelProperty(position = 5, required = false, value = "감정", example = "기뻐요")
private Emotion emotion;
Expand All @@ -48,7 +48,7 @@ public Gift toEntity(User user, LocalDate giftDate){
.giftName(giftName)
.giftDate(giftDate)
.giftMemo(giftMemo)
.category(category.getType())
.category(categoryGift.getType())
.emotion(emotion.getType())
.isPinned(false)
.isGiven(isGiven)
Expand Down
Loading

0 comments on commit d1d9fbb

Please sign in to comment.