diff --git a/application/external-api-v2/src/main/java/com/namo/spring/application/external/api/guest/service/GuestManageService.java b/application/external-api-v2/src/main/java/com/namo/spring/application/external/api/guest/service/GuestManageService.java index dfdc4ebe..e9c3d927 100644 --- a/application/external-api-v2/src/main/java/com/namo/spring/application/external/api/guest/service/GuestManageService.java +++ b/application/external-api-v2/src/main/java/com/namo/spring/application/external/api/guest/service/GuestManageService.java @@ -8,6 +8,8 @@ import java.util.stream.Collectors; import com.namo.spring.application.external.global.config.properties.WebUrlConfig; +import com.namo.spring.db.mysql.domains.category.service.PaletteService; +import com.namo.spring.db.mysql.domains.user.entity.Member; import org.springframework.stereotype.Service; import com.namo.spring.application.external.api.guest.dto.GuestParticipantRequest; @@ -38,21 +40,22 @@ public class GuestManageService { private final AnonymousService anonymousService; private final ParticipantService participantService; private final ParticipantMaker participantMaker; + private final PaletteService paletteService; private final TagGenerator tagGenerator; private final WebUrlConfig webUrlConfig; - public Anonymous createAnonymous(GuestParticipantRequest.PostGuestParticipantDto dto, Schedule schedule, - String code, String tag) { - Anonymous anonymous = Anonymous.of(null, null, tag, dto.getNickname(), dto.getPassword(), code); + public Anonymous createAnonymous(GuestParticipantRequest.PostGuestParticipantDto dto, String code, String tag, Palette palette) { + Anonymous anonymous = Anonymous.of(null, null, tag, dto.getNickname(), dto.getPassword(), code, palette); return anonymousService.createAnonymous(anonymous); } private Participant createGuest(GuestParticipantRequest.PostGuestParticipantDto dto, Schedule schedule, String code) { String tag = tagGenerator.generateTag(dto.getNickname()); - Anonymous anonymous = createAnonymous(dto, schedule, code, tag); Long paletteId = selectPaletteColorId(schedule.getId()); - return participantMaker.makeGuestParticipant(schedule, anonymous, paletteId); + Palette palette = paletteService.readPalette(paletteId).orElseThrow(()-> new PaletteException(ErrorStatus.NOT_FOUND_COLOR)); + Anonymous anonymous = createAnonymous(dto, code, tag, palette); + return participantMaker.makeGuestParticipant(schedule, anonymous); } public Participant getAnonymousParticipant(Long anonymousId, Long scheduleId) { @@ -71,7 +74,7 @@ public Anonymous getAnonymousByTagAndNickname(String tag, String nickname) { private Long selectPaletteColorId(Long scheduleId) { List participantsColors = participantService.readParticipantsByScheduleIdAndScheduleType(scheduleId, ScheduleType.MEETING) - .stream().map(Participant::getPalette).map(Palette::getId).collect(Collectors.toList()); + .stream().map(Participant::getMember).map(Member::getPalette).map(Palette::getId).collect(Collectors.toList()); return Arrays.stream(PALETTE_IDS) .filter((color) -> !participantsColors.contains(color)) .findFirst() diff --git a/application/external-api-v2/src/main/java/com/namo/spring/application/external/api/point/controller/AdminPointController.java b/application/external-api-v2/src/main/java/com/namo/spring/application/external/api/point/controller/AdminPointController.java index d7f20c75..bbce1850 100644 --- a/application/external-api-v2/src/main/java/com/namo/spring/application/external/api/point/controller/AdminPointController.java +++ b/application/external-api-v2/src/main/java/com/namo/spring/application/external/api/point/controller/AdminPointController.java @@ -23,7 +23,7 @@ import lombok.RequiredArgsConstructor; -@Tag(name = "11. 포인트 - 관리자", description = "포인트 관련 관리자 API") +@Tag(name = "12. 포인트 - 관리자", description = "포인트 관련 관리자 API") @RestController @RequiredArgsConstructor @RequestMapping("/api/v2/admin/points/transactions") diff --git a/application/external-api-v2/src/main/java/com/namo/spring/application/external/api/point/controller/MemberPointController.java b/application/external-api-v2/src/main/java/com/namo/spring/application/external/api/point/controller/MemberPointController.java index 1433643a..18e02370 100644 --- a/application/external-api-v2/src/main/java/com/namo/spring/application/external/api/point/controller/MemberPointController.java +++ b/application/external-api-v2/src/main/java/com/namo/spring/application/external/api/point/controller/MemberPointController.java @@ -19,7 +19,7 @@ import lombok.RequiredArgsConstructor; -@Tag(name = "11. 포인트 - 유저", description = "포인트 관련 API") +@Tag(name = "12. 포인트 - 유저", description = "포인트 관련 API") @RestController @RequiredArgsConstructor @RequestMapping("/api/v2/users/points") diff --git a/application/external-api-v2/src/main/java/com/namo/spring/application/external/api/schedule/converter/MeetingScheduleResponseConverter.java b/application/external-api-v2/src/main/java/com/namo/spring/application/external/api/schedule/converter/MeetingScheduleResponseConverter.java index 0ba278e6..ad711721 100644 --- a/application/external-api-v2/src/main/java/com/namo/spring/application/external/api/schedule/converter/MeetingScheduleResponseConverter.java +++ b/application/external-api-v2/src/main/java/com/namo/spring/application/external/api/schedule/converter/MeetingScheduleResponseConverter.java @@ -172,7 +172,7 @@ private static MeetingScheduleResponse.UserParticipantDetailDto toUserParticipan .isGuest(participant.getUser() instanceof Anonymous) .tag(participant.getUser().getTag()) .nickname(participant.getUser().getNickname()) - .colorId(participant.getPalette() != null ? participant.getPalette().getId() : null) + .colorId(participant.getPalette().getId()) .isOwner(getParticipantIsOwner(participant.getIsOwner())) .build(); } diff --git a/application/external-api-v2/src/main/java/com/namo/spring/application/external/api/schedule/service/ParticipantMaker.java b/application/external-api-v2/src/main/java/com/namo/spring/application/external/api/schedule/service/ParticipantMaker.java index aabe6ff7..205d600f 100644 --- a/application/external-api-v2/src/main/java/com/namo/spring/application/external/api/schedule/service/ParticipantMaker.java +++ b/application/external-api-v2/src/main/java/com/namo/spring/application/external/api/schedule/service/ParticipantMaker.java @@ -27,18 +27,17 @@ public class ParticipantMaker { private final CategoryService categoryService; private final ParticipantService participantService; - public void makeScheduleOwner(Schedule schedule, Member member, Long categoryId, Long paletteId) { + public void makeScheduleOwner(Schedule schedule, Member member, Long categoryId) { Category category; if (categoryId != null) { category = categoryService.readCategoryByMemberAndId(categoryId, member); } else category = categoryService.readMeetingCategoryByMember(member); - Palette palette = paletteId != null ? paletteService.getPalette(paletteId) : null; Participant participant; if(schedule.getIsMeetingSchedule()){ - participant = Participant.of(ParticipantRole.OWNER.getValue(), member, schedule, category, palette, schedule.getTitle(), schedule.getImageUrl()); - } else participant = Participant.of(ParticipantRole.OWNER.getValue(), member, schedule, category, palette, null, null); + participant = Participant.of(ParticipantRole.OWNER.getValue(), member, schedule, category, schedule.getTitle(), schedule.getImageUrl()); + } else participant = Participant.of(ParticipantRole.OWNER.getValue(), member, schedule, category,null, null); participantService.createParticipant(participant); } @@ -47,16 +46,15 @@ public void makeMeetingScheduleParticipants(Schedule schedule, List memb .map(member -> { Category category = categoryService.readMeetingCategoryByMember(member); return Participant.of(ParticipantRole.NON_OWNER.getValue(), member, schedule, - category, member.getPalette(), schedule.getTitle(), schedule.getImageUrl()); + category, schedule.getTitle(), schedule.getImageUrl()); }) .collect(Collectors.toList()); participantService.createParticipants(participants); } - public Participant makeGuestParticipant(Schedule schedule, Anonymous anonymous, Long paletteId) { - Palette palette = paletteService.getPalette(paletteId); + public Participant makeGuestParticipant(Schedule schedule, Anonymous anonymous) { Participant participant = Participant.of(ParticipantRole.NON_OWNER.getValue(), anonymous, schedule, - null, palette, schedule.getTitle(), schedule.getImageUrl()); + null, schedule.getTitle(), schedule.getImageUrl()); Participant savedParticipant = participantService.createParticipant(participant); schedule.setGuestParticipantsInfo(anonymous.getNickname()); return savedParticipant; diff --git a/application/external-api-v2/src/main/java/com/namo/spring/application/external/api/schedule/service/ParticipantManageService.java b/application/external-api-v2/src/main/java/com/namo/spring/application/external/api/schedule/service/ParticipantManageService.java index 42a3aedc..e8bad108 100644 --- a/application/external-api-v2/src/main/java/com/namo/spring/application/external/api/schedule/service/ParticipantManageService.java +++ b/application/external-api-v2/src/main/java/com/namo/spring/application/external/api/schedule/service/ParticipantManageService.java @@ -35,8 +35,8 @@ public class ParticipantManageService { private final FriendshipService friendshipService; private final ParticipantService participantService; - public void createScheduleOwner(Member member, Schedule schedule, Long categoryId, Long paletteId) { - participantMaker.makeScheduleOwner(schedule, member, categoryId, paletteId); + public void createScheduleOwner(Member member, Schedule schedule, Long categoryId) { + participantMaker.makeScheduleOwner(schedule, member, categoryId); } public void createMeetingParticipants(Member owner, Schedule schedule, List memberIds){ diff --git a/application/external-api-v2/src/main/java/com/namo/spring/application/external/api/schedule/service/ScheduleManageService.java b/application/external-api-v2/src/main/java/com/namo/spring/application/external/api/schedule/service/ScheduleManageService.java index 969cabdd..1cdf6184 100644 --- a/application/external-api-v2/src/main/java/com/namo/spring/application/external/api/schedule/service/ScheduleManageService.java +++ b/application/external-api-v2/src/main/java/com/namo/spring/application/external/api/schedule/service/ScheduleManageService.java @@ -73,14 +73,14 @@ public Schedule getMeetingSchedule(Long scheduleId) { public Schedule createPersonalSchedule(PersonalScheduleRequest.PostPersonalScheduleDto request, Member member) { Period period = getValidatedPeriod(request.getPeriod().getStartDate(), request.getPeriod().getEndDate()); Schedule schedule = scheduleMaker.createPersonalSchedule(request, period, member.getNickname()); - participantManageService.createScheduleOwner(member, schedule, request.getCategoryId(), null); + participantManageService.createScheduleOwner(member, schedule, request.getCategoryId()); return schedule; } public Schedule createMeetingSchedule(MeetingScheduleRequest.PostMeetingScheduleDto request, Member owner) { Period period = getValidatedPeriod(request.getPeriod().getStartDate(), request.getPeriod().getEndDate()); Schedule schedule = scheduleMaker.createMeetingSchedule(request, period, owner.getNickname()); - participantManageService.createScheduleOwner(owner, schedule, null, owner.getPalette().getId()); + participantManageService.createScheduleOwner(owner, schedule, null); return schedule; } diff --git a/application/external-api-v2/src/main/java/com/namo/spring/application/external/api/user/controller/MemberProfileController.java b/application/external-api-v2/src/main/java/com/namo/spring/application/external/api/user/controller/MemberProfileController.java index d907282f..ade6c109 100644 --- a/application/external-api-v2/src/main/java/com/namo/spring/application/external/api/user/controller/MemberProfileController.java +++ b/application/external-api-v2/src/main/java/com/namo/spring/application/external/api/user/controller/MemberProfileController.java @@ -15,7 +15,7 @@ @RestController @RequiredArgsConstructor -@Tag(name = "11. Profile", description = "유저 프로필 API") +@Tag(name = "11. Member Profile", description = "유저 프로필 API") @RequestMapping("/api/v2/members") public class MemberProfileController { private final MemberProfileUsecase memberProfileUsecase; diff --git a/storage/db-mysql-v2/src/main/java/com/namo/spring/db/mysql/domains/schedule/entity/Participant.java b/storage/db-mysql-v2/src/main/java/com/namo/spring/db/mysql/domains/schedule/entity/Participant.java index 99efadd8..07ccfbc9 100644 --- a/storage/db-mysql-v2/src/main/java/com/namo/spring/db/mysql/domains/schedule/entity/Participant.java +++ b/storage/db-mysql-v2/src/main/java/com/namo/spring/db/mysql/domains/schedule/entity/Participant.java @@ -61,10 +61,6 @@ public class Participant extends BaseTimeEntity { @JoinColumn(name = "category_id", nullable = true) private Category category; - @ManyToOne(fetch = FetchType.LAZY, optional = true) - @JoinColumn(name = "palette_id", nullable = true) - private Palette palette; - @JdbcTypeCode(SqlTypes.VARCHAR) @Column(length = 50) private String customTitle; @@ -78,27 +74,23 @@ public class Participant extends BaseTimeEntity { private Diary diary; @Builder - public Participant(int isOwner, User user, Schedule schedule, Category category, - Palette palette, String customTitle, String customImage) { + public Participant(int isOwner, User user, Schedule schedule, Category category, String customTitle, String customImage) { this.isOwner = Objects.requireNonNull(isOwner, "isOwner은 null일 수 없습니다."); this.member = user instanceof Member ? (Member)user : null; this.anonymous = user instanceof Anonymous ? (Anonymous)user : null; this.schedule = Objects.requireNonNull(schedule, "schedule은 null일 수 없습니다."); this.category = category; - this.palette = palette; this.hasDiary = false; this.customTitle = customTitle; this.customImage =customImage; } - public static Participant of(int isOwner, User user, Schedule schedule, Category category, - Palette palette, String customTitle, String customImage) { + public static Participant of(int isOwner, User user, Schedule schedule, Category category, String customTitle, String customImage) { return Participant.builder() .isOwner(isOwner) .user(user) .schedule(schedule) .category(category) - .palette(palette) .customTitle(customTitle) .customImage(customImage) .build(); @@ -113,6 +105,15 @@ public User getUser() { return null; } + public Palette getPalette() { + if(this.getUser() instanceof Member){ + return this.member.getPalette(); + } + else { + return this.anonymous.getPalette(); + } + } + public void setIsOwner(ParticipantRole role) { this.isOwner = role.getValue(); } diff --git a/storage/db-mysql-v2/src/main/java/com/namo/spring/db/mysql/domains/schedule/repository/ParticipantRepository.java b/storage/db-mysql-v2/src/main/java/com/namo/spring/db/mysql/domains/schedule/repository/ParticipantRepository.java index dc037cd9..2e32089d 100644 --- a/storage/db-mysql-v2/src/main/java/com/namo/spring/db/mysql/domains/schedule/repository/ParticipantRepository.java +++ b/storage/db-mysql-v2/src/main/java/com/namo/spring/db/mysql/domains/schedule/repository/ParticipantRepository.java @@ -39,7 +39,7 @@ public interface ParticipantRepository extends JpaRepository boolean existsByScheduleIdAndAnonymousId(Long scheduleId, Long anonymousId); - @Query("SELECT p FROM Participant p JOIN FETCH p.schedule s LEFT JOIN FETCH p.palette " + + @Query("SELECT p FROM Participant p JOIN FETCH p.schedule s " + "WHERE s.id = :scheduleId AND s.scheduleType = :scheduleType ") List findParticipantsByScheduleIdAndStatusAndType(Long scheduleId, int scheduleType); diff --git a/storage/db-mysql-v2/src/main/java/com/namo/spring/db/mysql/domains/user/entity/Anonymous.java b/storage/db-mysql-v2/src/main/java/com/namo/spring/db/mysql/domains/user/entity/Anonymous.java index e05636c1..eaab166d 100644 --- a/storage/db-mysql-v2/src/main/java/com/namo/spring/db/mysql/domains/user/entity/Anonymous.java +++ b/storage/db-mysql-v2/src/main/java/com/namo/spring/db/mysql/domains/user/entity/Anonymous.java @@ -2,12 +2,8 @@ import static com.namo.spring.db.mysql.domains.user.utils.UserValidationUtils.*; -import jakarta.persistence.Column; -import jakarta.persistence.Embedded; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; +import com.namo.spring.db.mysql.domains.category.entity.Palette; +import jakarta.persistence.*; import org.hibernate.annotations.DynamicInsert; import org.hibernate.annotations.JdbcTypeCode; @@ -50,27 +46,33 @@ public class Anonymous extends BaseTimeEntity implements User { @Embedded private Password password; + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "palette_id") + private Palette palette; + private String inviteCode; @Builder public Anonymous(String name, Boolean nameVisible, String tag, - String nickname, String password, String inviteCode) { + String nickname, String password, String inviteCode, Palette palette) { this.name = name; this.nameVisible = nameVisible; this.tag = validateTag(tag); this.nickname = validateNickname(nickname); this.password = Password.encrypt(password); + this.palette = palette; this.inviteCode = inviteCode; } public static Anonymous of(String name, Boolean nameVisible, String tag, - String nickname, String password, String inviteCode) { + String nickname, String password, String inviteCode, Palette palette) { return Anonymous.builder() .nickname(nickname) .name(name) .nameVisible(nameVisible) .tag(tag) .password(password) + .palette(palette) .inviteCode(inviteCode) .build(); } diff --git a/storage/db-mysql-v2/src/main/resources/db/migration/dev/V1.1.8__Add_palette_column_to_anonymous_table.sql b/storage/db-mysql-v2/src/main/resources/db/migration/dev/V1.1.8__Add_palette_column_to_anonymous_table.sql new file mode 100644 index 00000000..95bc691e --- /dev/null +++ b/storage/db-mysql-v2/src/main/resources/db/migration/dev/V1.1.8__Add_palette_column_to_anonymous_table.sql @@ -0,0 +1,15 @@ +-- V1.1.8__Add_palette_column_to_anonymous_table + +-- 1. anonymous에 palette_id 추가 +ALTER TABLE anonymous + ADD COLUMN palette_id BIGINT, + ADD CONSTRAINT fk_anonymous_palette FOREIGN KEY (palette_id) REFERENCES palette (id); + +-- 2. participant의 palette_id를 anonymous의 palette_id로 복사 +UPDATE anonymous a + JOIN participant p ON a.id = p.anonymous_id + SET a.palette_id = p.palette_id +WHERE p.palette_id IS NOT NULL; + +ALTER TABLE anonymous + MODIFY COLUMN palette_id BIGINT NOT NULL; diff --git a/storage/db-mysql-v2/src/main/resources/db/migration/dev/V1.1.9__Drop_palette_column_from_particiapnt.sql b/storage/db-mysql-v2/src/main/resources/db/migration/dev/V1.1.9__Drop_palette_column_from_particiapnt.sql new file mode 100644 index 00000000..b44ee22b --- /dev/null +++ b/storage/db-mysql-v2/src/main/resources/db/migration/dev/V1.1.9__Drop_palette_column_from_particiapnt.sql @@ -0,0 +1,7 @@ +-- V1.1.9__Drop_palette_column_from_participant_table + +SET foreign_key_checks = 0; +ALTER TABLE participant DROP FOREIGN KEY FK7q1eb1aao98hr1nsa85agu6x5; +ALTER TABLE participant DROP COLUMN palette_id; +SET foreign_key_checks = 1; +