Skip to content

Commit 8d5f976

Browse files
authored
Merge pull request #220 from 9uttery/feat/joy-and-album-api-#219
[Feature] Phase 3.0 소확행/앨범 필드 추가 및 값 생성 로직 구현
2 parents 2bdb714 + 0766009 commit 8d5f976

File tree

4 files changed

+23
-18
lines changed

4 files changed

+23
-18
lines changed

src/main/java/com/guttery/madii/domain/albums/application/service/AlbumService.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public List<AlbumCreateResponse> createAlbum(AlbumCreateRequest albumCreateReque
5757
// 앨범 썸네일 아이콘 번호 1 ~ 24 중 랜덤 생성
5858
int albumIconNum = 1 + random.nextInt(24); // 1부터 24까지
5959
int albumColorNum;
60+
int boundNew = 8; // 소확행 썸네일 색상 번호 1 ~ 8 중 랜덤 생성 (phase 3.0)
6061

6162
// albumIconNum 범위에 따라 albumColorNum 결정
6263
if (albumIconNum >= 1 && albumIconNum <= 6) {
@@ -82,7 +83,7 @@ public List<AlbumCreateResponse> createAlbum(AlbumCreateRequest albumCreateReque
8283

8384
// 여기서 Album 객체 생성 및 나머지 로직 처리
8485
final Album album = Album.createAlbum(user, albumCreateRequest.name(), albumCreateRequest.description(),
85-
false, false, false, albumIconNum, albumColorNum);
86+
false, false, false, albumIconNum, albumColorNum, boundNew);
8687
albumRepository.save(album);
8788

8889
List<AlbumCreateResponse> albumCreateResponseList = albumQueryDslRepository.getMyAlbums(user.getUserId());
@@ -394,12 +395,13 @@ public void putAllAlbum(AlbumPutAllRequest albumPutAllRequest, Long albumId, Use
394395
// 3. 새로 추가된 소확행 처리
395396
Random random = new Random();
396397
int bound = 24; // 소확행 썸네일 아이콘 번호 1 ~ 24 중 랜덤 생성
398+
int boundNew = 7; // 소확행 썸네일 색상 번호 1 ~ 7 중 랜덤 생성 (phase 3.0)
397399

398400
Joy joy;
399401
if (album.getAlbumStatus().getIsOfficial()) {
400-
joy = Joy.createOfficialJoy(user, 1 + random.nextInt(bound), joyDto.contents());
402+
joy = Joy.createOfficialJoy(user, 1 + random.nextInt(bound), joyDto.contents(), 1 + random.nextInt(boundNew));
401403
} else {
402-
joy = Joy.createPersonalJoy(user, 1 + random.nextInt(bound), joyDto.contents());
404+
joy = Joy.createPersonalJoy(user, 1 + random.nextInt(bound), joyDto.contents(), 1 + random.nextInt(boundNew));
403405
}
404406

405407
joyRepository.save(joy);

src/main/java/com/guttery/madii/domain/albums/domain/model/Album.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,24 +44,26 @@ public class Album extends BaseTimeEntity {
4444
private AlbumStatus albumStatus; // 공개 여부, 신고 정지 여부, 삭제 여부
4545
@Embedded
4646
private AlbumInfo albumInfo; // 앨범 썸네일 아이콘 번호, 배경 번호
47+
private Integer albumCoverNum; // 앨범 썸네일 색상 번호 (phase 3.0)
4748
@OneToMany(mappedBy = "album", cascade = CascadeType.ALL, orphanRemoval = true)
4849
private List<SavingAlbum> savingAlbums;
4950
@OneToMany(mappedBy = "album", cascade = CascadeType.ALL, orphanRemoval = true)
5051
private List<SavingJoy> savingJoys;
5152
private LocalDateTime officialSetAt;
5253

53-
public Album(User user, String name, String description, AlbumStatus albumStatus, AlbumInfo albumInfo) {
54+
public Album(User user, String name, String description, AlbumStatus albumStatus, AlbumInfo albumInfo, Integer albumCoverNum) {
5455
this.user = user;
5556
this.name = name;
5657
this.description = description;
5758
this.albumStatus = albumStatus;
5859
this.albumInfo = albumInfo;
60+
this.albumCoverNum = albumCoverNum;
5961
}
6062

6163
public static Album createAlbum(User user, String name, String description,
6264
Boolean isOfficial, Boolean isBlocked, Boolean isDeleted,
63-
Integer albumIconNum, Integer albumColorNum) {
64-
return new Album(user, name, description, new AlbumStatus(isOfficial, isBlocked, isDeleted), new AlbumInfo(albumIconNum, albumColorNum));
65+
Integer albumIconNum, Integer albumColorNum, Integer albumCoverNum) {
66+
return new Album(user, name, description, new AlbumStatus(isOfficial, isBlocked, isDeleted), new AlbumInfo(albumIconNum, albumColorNum), albumCoverNum);
6567
}
6668

6769
public void modifyNameAndDes(String name, String description) {

src/main/java/com/guttery/madii/domain/joy/application/service/JoyService.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,11 @@ public class JoyService {
3939
public JoyCreateResponse createJoy(final JoyCreateRequest joyCreateRequest, UserPrincipal userPrincipal) {
4040
final User user = UserServiceHelper.findExistingUser(userRepository, userPrincipal);
4141

42-
// 소확행 썸네일 아이콘 번호 1 ~ 24 중 랜덤 생성
43-
Random random = new Random();
42+
Random random = new Random(); // 소확행 썸네일 아이콘 번호 1 ~ 24 중 랜덤 생성
4443
int bound = 24;
44+
int boundNew = 7; // 소확행 썸네일 색상 번호 1 ~ 7 중 랜덤 생성 (phase 3.0)
4545

46-
// 랜덤 값에 1을 더해 1부터 24까지의 값을 얻음
47-
final Joy joy = Joy.createPersonalJoy(user, 1 + random.nextInt(bound), joyCreateRequest.contents());
46+
final Joy joy = Joy.createPersonalJoy(user, 1 + random.nextInt(bound), joyCreateRequest.contents(), 1 + random.nextInt(boundNew));
4847
joyRepository.save(joy);
4948

5049
JoyCreateResponse joyCreateResponse = new JoyCreateResponse(joy.getJoyId(), joy.getJoyIconNum(), joy.getContents());
@@ -121,11 +120,11 @@ public JoyPutResponse putMyJoy(Long joyId, final JoyPutRequest joyPutRequest, Us
121120
deleteFromSavingJoy(joyId, joyPutRequest.beforeAlbumIds());
122121

123122
// 2. 내가 기록한 소확행으로 추가
124-
// 소확행 썸네일 아이콘 번호 0 ~ 17 중 랜덤 생성
125123
Random random = new Random();
126-
int bound = 18;
124+
int bound = 18; // 소확행 썸네일 아이콘 번호 0 ~ 17 중 랜덤 생성 // TODO: 왜 여기만 18개일까?
125+
int boundNew = 7; // 소확행 썸네일 색상 번호 1 ~ 7 중 랜덤 생성 (phase 3.0)
127126

128-
final Joy newJoy = Joy.createPersonalJoy(user, random.nextInt(bound), joyPutRequest.contents());
127+
final Joy newJoy = Joy.createPersonalJoy(user, random.nextInt(bound), joyPutRequest.contents(), 1 + random.nextInt(boundNew));
129128
joyRepository.save(newJoy);
130129
joyPutResponse = new JoyPutResponse(newJoy.getJoyIconNum(), newJoy.getContents());
131130

src/main/java/com/guttery/madii/domain/joy/domain/model/Joy.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,26 +40,28 @@ public class Joy extends BaseTimeEntity {
4040
@Enumerated(EnumType.STRING)
4141
private JoyType joyType; // 소확행 타입 (공식, 개인)
4242
private Integer joyIconNum; // 소확행 썸네일 아이콘 번호
43+
private Integer joyColorNum; // 소확행 썸네일 색상 번호 (phase 3.0)
4344
@Column(length = 30)
4445
private String contents; // 소확행 내용
4546
@OneToMany(mappedBy = "joy", cascade = CascadeType.ALL, orphanRemoval = true)
4647
private List<SavingJoy> savingJoys;
4748
@OneToMany(mappedBy = "joy", cascade = CascadeType.ALL, orphanRemoval = true)
4849
private List<Achievement> achievements;
4950

50-
public Joy(User user, JoyType joyType, Integer joyIconNum, String contents) {
51+
public Joy(User user, JoyType joyType, Integer joyIconNum, String contents, Integer joyColorNum) {
5152
this.user = user;
5253
this.joyType = joyType;
5354
this.joyIconNum = joyIconNum;
5455
this.contents = contents;
56+
this.joyColorNum = joyColorNum;
5557
}
5658

57-
public static Joy createPersonalJoy(User user, Integer joyIconNum, String contents) {
58-
return new Joy(user, JoyType.PERSONAL, joyIconNum, contents);
59+
public static Joy createPersonalJoy(User user, Integer joyIconNum, String contents, Integer joyColorNum) {
60+
return new Joy(user, JoyType.PERSONAL, joyIconNum, contents, joyColorNum);
5961
}
6062

61-
public static Joy createOfficialJoy(User user, Integer joyIconNum, String contents) {
62-
return new Joy(user, JoyType.OFFICIAL, joyIconNum, contents);
63+
public static Joy createOfficialJoy(User user, Integer joyIconNum, String contents, Integer joyColorNum) {
64+
return new Joy(user, JoyType.OFFICIAL, joyIconNum, contents, joyColorNum);
6365
}
6466

6567
public void modifyContents(String contents) {

0 commit comments

Comments
 (0)