Skip to content

Commit

Permalink
fix: noskin image 변경 (#162)
Browse files Browse the repository at this point in the history
* fix: 회원 로그인 시 기본 부엉이, 오목눈이 생성 기능 추가 및 테스트 코드 변경

* fix: 테스트 코드 변경

* refacotr: config 수정
  • Loading branch information
parksey authored Nov 27, 2023
1 parent c1e925e commit a8a32bc
Show file tree
Hide file tree
Showing 16 changed files with 169 additions and 106 deletions.
8 changes: 8 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ ext {
snippetsDir = file('build/generated-snippets')
}

def querydslSrcDir = 'src/main/generated'
clean {
delete file(querydslSrcDir)
}
tasks.withType(JavaCompile) {
options.generatedSourceOutputDirectory = file(querydslSrcDir)
}

configurations {
asciidoctorExtensions

Expand Down
31 changes: 21 additions & 10 deletions src/main/java/com/moabam/api/application/member/MemberMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@

import static com.moabam.global.common.util.GlobalConstant.*;

import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;

import com.moabam.api.domain.bug.Bug;
import com.moabam.api.domain.item.Inventory;
import com.moabam.api.domain.item.Item;
import com.moabam.api.domain.item.ItemType;
import com.moabam.api.domain.member.BadgeType;
import com.moabam.api.domain.member.Member;
import com.moabam.api.dto.member.BadgeResponse;
Expand Down Expand Up @@ -41,6 +43,8 @@ public static MemberInfoSearchResponse toMemberInfoSearchResponse(List<MemberInf
return MemberInfoSearchResponse.builder()
.nickname(infos.nickname())
.profileImage(infos.profileImage())
.morningImage(infos.morningImage())
.nightImage(infos.nightImage())
.intro(infos.intro())
.totalCertifyCount(infos.totalCertifyCount())
.badges(new HashSet<>(badgeTypes))
Expand All @@ -50,8 +54,7 @@ public static MemberInfoSearchResponse toMemberInfoSearchResponse(List<MemberInf
.build();
}

public static MemberInfoResponse toMemberInfoResponse(MemberInfoSearchResponse memberInfoSearchResponse,
List<Inventory> inventories) {
public static MemberInfoResponse toMemberInfoResponse(MemberInfoSearchResponse memberInfoSearchResponse) {
long certifyCount = memberInfoSearchResponse.totalCertifyCount();

return MemberInfoResponse.builder()
Expand All @@ -60,23 +63,31 @@ public static MemberInfoResponse toMemberInfoResponse(MemberInfoSearchResponse m
.intro(memberInfoSearchResponse.intro())
.level(certifyCount / LEVEL_DIVISOR)
.exp(certifyCount % LEVEL_DIVISOR)
.birds(defaultSkins(inventories))
.birds(defaultSkins(memberInfoSearchResponse.morningImage(), memberInfoSearchResponse.nightImage()))
.badges(badgedNames(memberInfoSearchResponse.badges()))
.goldenBug(memberInfoSearchResponse.goldenBug())
.morningBug(memberInfoSearchResponse.morningBug())
.nightBug(memberInfoSearchResponse.nightBug())
.build();
}

public static Inventory toInventory(Long memberId, Item item) {
return Inventory.builder()
.memberId(memberId)
.item(item)
.isDefault(true)
.build();
}

private static List<BadgeResponse> badgedNames(Set<BadgeType> badgeTypes) {
return BadgeType.memberBadgeMap(badgeTypes);
}

private static Map<String, String> defaultSkins(List<Inventory> inventories) {
return inventories.stream()
.collect(Collectors.toMap(
inventory -> inventory.getItem().getType().name(),
inventory -> inventory.getItem().getImage()
));
private static Map<String, String> defaultSkins(String morningImage, String nightImage) {
Map<String, String> birdsSkin = new HashMap<>();
birdsSkin.put(ItemType.MORNING.name(), morningImage);
birdsSkin.put(ItemType.NIGHT.name(), nightImage);

return birdsSkin;
}
}
40 changes: 24 additions & 16 deletions src/main/java/com/moabam/api/application/member/MemberService.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@

import com.moabam.api.application.auth.mapper.AuthMapper;
import com.moabam.api.domain.item.Inventory;
import com.moabam.api.domain.item.repository.InventorySearchRepository;
import com.moabam.api.domain.item.Item;
import com.moabam.api.domain.item.repository.InventoryRepository;
import com.moabam.api.domain.item.repository.ItemRepository;
import com.moabam.api.domain.member.Member;
import com.moabam.api.domain.member.repository.MemberRepository;
import com.moabam.api.domain.member.repository.MemberSearchRepository;
Expand All @@ -22,8 +24,8 @@
import com.moabam.api.dto.member.MemberInfoSearchResponse;
import com.moabam.api.dto.member.ModifyMemberRequest;
import com.moabam.global.auth.model.AuthMember;
import com.moabam.global.common.util.BaseDataCode;
import com.moabam.global.common.util.ClockHolder;
import com.moabam.global.common.util.GlobalConstant;
import com.moabam.global.error.exception.BadRequestException;
import com.moabam.global.error.exception.ConflictException;
import com.moabam.global.error.exception.NotFoundException;
Expand All @@ -37,7 +39,8 @@
public class MemberService {

private final MemberRepository memberRepository;
private final InventorySearchRepository inventorySearchRepository;
private final InventoryRepository inventoryRepository;
private final ItemRepository itemRepository;
private final MemberSearchRepository memberSearchRepository;
private final ClockHolder clockHolder;

Expand Down Expand Up @@ -78,11 +81,8 @@ public MemberInfoResponse searchInfo(AuthMember authMember, Long memberId) {
if (!isMe) {
searchId = memberId;
}

MemberInfoSearchResponse memberInfoSearchResponse = findMemberInfo(searchId, isMe);
List<Inventory> inventories = getDefaultSkin(searchId);

return MemberMapper.toMemberInfoResponse(memberInfoSearchResponse, inventories);
return MemberMapper.toMemberInfoResponse(memberInfoSearchResponse);
}

@Transactional
Expand All @@ -105,19 +105,27 @@ private void validateNickname(String nickname) {
}
}

private List<Inventory> getDefaultSkin(Long searchId) {
List<Inventory> inventories = inventorySearchRepository.findDefaultSkin(searchId);
if (inventories.size() != GlobalConstant.DEFAULT_SKIN_SIZE) {
throw new BadRequestException(INVALID_DEFAULT_SKIN_SIZE);
}
private Member signUp(Long socialId) {
Member member = MemberMapper.toMember(socialId);
return memberRepository.save(member);
}

return inventories;
private void saveMyEgg(Member member) {
List<Item> items = getBasicEggs();
List<Inventory> inventories = items.stream()
.map(item -> MemberMapper.toInventory(member.getId(), item))
.toList();
inventoryRepository.saveAll(inventories);
}

private Member signUp(Long socialId) {
Member member = MemberMapper.toMember(socialId);
private List<Item> getBasicEggs() {
List<Item> items = itemRepository.findAllById(List.of(BaseDataCode.MORNING_EGG, BaseDataCode.NIGHT_EGG));

return memberRepository.save(member);
if (items.isEmpty()) {
throw new BadRequestException(BASIC_SKIN_NOT_FOUND);
}

return items;
}

private MemberInfoSearchResponse findMemberInfo(Long searchId, boolean isMe) {
Expand Down
31 changes: 29 additions & 2 deletions src/main/java/com/moabam/api/domain/member/Member.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.moabam.api.domain.member;

import static com.moabam.global.common.util.BaseImageUrl.*;
import static com.moabam.global.common.util.GlobalConstant.*;
import static com.moabam.global.common.util.RandomUtils.*;
import static com.moabam.global.error.model.ErrorMessage.*;
import static java.util.Objects.*;

import java.time.LocalDateTime;
Expand All @@ -10,9 +12,11 @@
import org.hibernate.annotations.SQLDelete;

import com.moabam.api.domain.bug.Bug;
import com.moabam.api.domain.item.Item;
import com.moabam.api.domain.item.ItemType;
import com.moabam.api.domain.room.RoomType;
import com.moabam.global.common.entity.BaseTimeEntity;
import com.moabam.global.common.util.BaseImageUrl;
import com.moabam.global.error.exception.NotFoundException;

import jakarta.persistence.Column;
import jakarta.persistence.Embedded;
Expand Down Expand Up @@ -52,6 +56,12 @@ public class Member extends BaseTimeEntity {
@Column(name = "profile_image", nullable = false)
private String profileImage;

@Column(name = "morning_image", nullable = false)
private String morningImage;

@Column(name = "night_image", nullable = false)
private String nightImage;

@Column(name = "total_certify_count", nullable = false)
@ColumnDefault("0")
private long totalCertifyCount;
Expand Down Expand Up @@ -85,7 +95,9 @@ private Member(Long id, String socialId, Bug bug) {
this.socialId = requireNonNull(socialId);
this.nickname = createNickName();
this.intro = "";
this.profileImage = BaseImageUrl.MEMBER_PROFILE_URL;
this.profileImage = IMAGE_DOMAIN + MEMBER_PROFILE_URL;
this.morningImage = IMAGE_DOMAIN + DEFAULT_MORNING_EGG_URL;
this.nightImage = IMAGE_DOMAIN + DEFAULT_NIGHT_EGG_URL;
this.bug = requireNonNull(bug);
this.role = Role.USER;
}
Expand Down Expand Up @@ -134,6 +146,21 @@ public void changeIntro(String intro) {

public void changeProfileUri(String newProfileUri) {
this.profileImage = requireNonNullElse(newProfileUri, profileImage);
this.profileImage = requireNonNullElse(newProfileUri, profileImage);
}

public void changeDefaultSkintUrl(Item item) throws NotFoundException {
if (ItemType.MORNING.equals(item.getType())) {
this.morningImage = item.getImage();
return;
}

if (ItemType.NIGHT.equals(item.getType())) {
this.nightImage = item.getImage();
return;
}

throw new NotFoundException(SKIN_TYPE_NOT_FOUND);
}

private String createNickName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public List<MemberInfo> findMemberAndBadges(Long searchId, boolean isMe) {
List<Expression<?>> selectExpression = new ArrayList<>(List.of(
member.nickname,
member.profileImage,
member.morningImage,
member.nightImage,
member.intro,
member.totalCertifyCount,
badge.type));
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/com/moabam/api/dto/member/MemberInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
public record MemberInfo(
String nickname,
String profileImage,
String morningImage,
String nightImage,
String intro,
long totalCertifyCount,
BadgeType badges,
Expand All @@ -13,8 +15,9 @@ public record MemberInfo(
Integer nightBug
) {

public MemberInfo(String nickname, String profileImage, String intro,
long totalCertifyCount, BadgeType badges) {
this(nickname, profileImage, intro, totalCertifyCount, badges, null, null, null);
public MemberInfo(String nickname, String profileImage, String morningImage, String nightImage,
String intro, long totalCertifyCount, BadgeType badges) {
this(nickname, profileImage, morningImage, nightImage, intro,
totalCertifyCount, badges, null, null, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
public record MemberInfoSearchResponse(
String nickname,
String profileImage,
String morningImage,
String nightImage,
String intro,
long totalCertifyCount,
Set<BadgeType> badges,
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/moabam/global/common/util/BaseDataCode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.moabam.global.common.util;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;

@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class BaseDataCode {

public static final Long MORNING_EGG = 1L;
public static final Long NIGHT_EGG = 2L;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class BaseImageUrl {

public static final String IMAGE_DOMAIN = "https://image.moabam.com/";

public static final String DEFAULT_SKIN_URL = "";
public static final String DEFAULT_MORNING_AWAKE_SKIN_URL = "";
public static final String DEFAULT_MORNING_SLEEP_SKIN_URL = "";
public static final String DEFAULT_NIGHT_AWAKE_SKIN_URL = "";
public static final String DEFAULT_NIGHT_SLEEP_SKIN_URL = "";

public static final String MEMBER_PROFILE_URL = "/profile/baseUrl";
public static final String DEFAULT_MORNING_EGG_URL = "moabam/skins/오목눈이/기본/오목눈이알.png";
public static final String DEFAULT_NIGHT_EGG_URL = "moabam/skins/부엉이/기본/부엉이알.png";
public static final String MEMBER_PROFILE_URL = "moabam/default/기본회원프로필.png";
}
2 changes: 2 additions & 0 deletions src/main/java/com/moabam/global/error/model/ErrorMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ public enum ErrorMessage {
UNLINK_REQUEST_FAIL_ROLLBACK_SUCCESS("카카오 연결 요청 실패로 Rollback하였습니다."),
NICKNAME_CONFLICT("이미 존재하는 닉네임입니다."),

BASIC_SKIN_NOT_FOUND("기본 스킨 오류 발생, 관리자에게 문의하세요"),
INVALID_DEFAULT_SKIN_SIZE("기본 스킨은 2개여야 합니다. 관리자에게 문의하세요"),
SKIN_TYPE_NOT_FOUND("스킨 타입이 없습니다. 관리자에게 문의하세요"),

BUG_NOT_ENOUGH("보유한 벌레가 부족합니다."),

Expand Down
Loading

0 comments on commit a8a32bc

Please sign in to comment.