Skip to content

Commit 111366a

Browse files
authored
Feat/reward table (#86)
* 보상관련 엔티티 및 내부적으로 사용할 service만 간단하게 추가 * 보상관련 엔티티 및 내부적으로 사용할 service만 간단하게 추가
1 parent 122f5d6 commit 111366a

File tree

9 files changed

+135
-16
lines changed

9 files changed

+135
-16
lines changed

backend/src/main/java/com/back/domain/item/controller/ApiV1ItemController.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public ApiResponse<List<ItemDto>> findAllItems()
4545
{
4646
try {
4747
List<ItemDto> data =itemService.ReadAllItem();
48-
return new ApiResponse<>("200", "아이템 단건 조회 성공", data);
48+
return new ApiResponse<>("200", "아이템 전체 조회 성공", data);
4949
} catch (IllegalArgumentException e) {
5050
return new ApiResponse<>("404", "아이템이 존재하지 않습니다.", null);
5151
}
@@ -99,8 +99,12 @@ public ApiResponse<ItemDto> UpdateItem(@PathVariable int id, @RequestBody ItemDt
9999
@Operation(summary = "아이템 삭제")
100100
public ApiResponse<ItemDto> DeleteItem(@PathVariable int id)
101101
{
102-
itemService.DeleteItem(id);
103-
return new ApiResponse<>("200", "아이템 삭제 성공", null);
102+
try {
103+
itemService.DeleteItem(id);
104+
return new ApiResponse<>("200", "아이템 삭제 성공", null);
105+
} catch (IllegalArgumentException e) {
106+
return new ApiResponse<>("404", "아이템이 존재하지 않습니다.", null);
107+
}
104108
}
105109

106110
// @PostMapping()

backend/src/main/java/com/back/domain/notification/Controller/ApiV1NotificationController.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package com.back.domain.notification.Controller;
22

33

4+
import com.back.domain.member.entity.Member;
45
import com.back.domain.member.service.MemberService;
56
import com.back.domain.notification.dto.CreateNotificationDto;
67
import com.back.domain.notification.dto.ModifyNotificationDto;
78
import com.back.domain.notification.dto.NotificationDto;
89
import com.back.domain.notification.service.NotificationService;
910
import com.back.global.common.ApiResponse;
11+
import com.back.global.rq.Rq;
1012
import io.swagger.v3.oas.annotations.Operation;
1113
import io.swagger.v3.oas.annotations.tags.Tag;
1214
import jakarta.validation.Valid;
@@ -23,7 +25,7 @@
2325
public class ApiV1NotificationController {
2426
private final NotificationService notificationService;
2527
private final MemberService memberService;
26-
28+
private final Rq rq;
2729

2830
@PostMapping
2931
@Transactional
@@ -55,18 +57,7 @@ public ApiResponse<NotificationDto> findNotifications(@PathVariable int id )
5557
return new ApiResponse<>("200", "알림 전체 조회 성공", notificationService.findById(id));
5658
}
5759

58-
//
59-
// @GetMapping("/me")
60-
// @Transactional
61-
// @Operation(summary = "알림 회원 전체 조회")
62-
// public ApiResponse<> findAllNotificationsByAuth(Authenticator authentication)
63-
// {
64-
// if (authentication == null || !authentication.isAuthenticated()) {
65-
// return new ApiResponse<>("401", "인증되지 않은 사용자입니다.");
66-
// }
67-
// int userId = memberService.getMemberIdByAuthentication(authentication);
68-
// return new ApiResponse<>("200", "알림 전체 조회 성공", notificationService.findByUserId());
69-
// }
60+
7061

7162

7263

@@ -94,4 +85,14 @@ public ApiResponse<?> deleteNotification(@PathVariable int id)
9485
notificationService.deleteNotification(id);
9586
return new ApiResponse<>("200", "알림 삭제 성공", null);
9687
}
88+
89+
@GetMapping("/me")
90+
@Transactional
91+
@Operation
92+
public ApiResponse<List<NotificationDto>> findNotificationsByUserId(
93+
) {
94+
Member member = rq.getActorFromDb();
95+
96+
return new ApiResponse<>("200", "사용자 알림 조회 성공", notificationService.findByUserId(member.getId()));
97+
}
9798
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.back.domain.reward.entity;
2+
3+
public enum ContentType {
4+
XP,
5+
MONEY,
6+
ITEM,
7+
TITLE
8+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.back.domain.reward.entity;
2+
3+
import com.back.global.jpa.entity.BaseEntity;
4+
import jakarta.persistence.*;
5+
import lombok.Getter;
6+
import lombok.NoArgsConstructor;
7+
import lombok.Setter;
8+
9+
import java.util.ArrayList;
10+
import java.util.List;
11+
12+
@Entity
13+
@Getter
14+
@Setter
15+
@NoArgsConstructor
16+
public class Reward extends BaseEntity {
17+
@Enumerated(EnumType.STRING)
18+
private RewardType rewardType;
19+
20+
@ElementCollection
21+
@CollectionTable(name = "reward_contents", joinColumns = @JoinColumn(name = "reward_id"))
22+
private List<RewardContent> rewards = new ArrayList<>();
23+
24+
private int requireValue;
25+
26+
public Reward(RewardType rewardType, List<RewardContent> rewards, int requireValue) {
27+
28+
this.rewardType = rewardType;
29+
this.rewards = rewards;
30+
this.requireValue = requireValue;
31+
}
32+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.back.domain.reward.entity;
2+
3+
import jakarta.persistence.Embeddable;
4+
5+
@Embeddable
6+
public class RewardContent {
7+
ContentType contentType;
8+
int value;
9+
10+
public RewardContent(ContentType contentType, int value) {
11+
this.contentType = contentType;
12+
this.value = value;
13+
}
14+
15+
public RewardContent() {
16+
17+
}
18+
19+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.back.domain.reward.entity;
2+
3+
public enum RewardType {
4+
DAILY,
5+
WEEKLY,
6+
CHALLENGE,
7+
LEVELUP,
8+
CLEARCOUNT
9+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.back.domain.reward.repository;
2+
3+
import com.back.domain.reward.entity.Reward;
4+
import org.springframework.data.jpa.repository.JpaRepository;
5+
6+
public interface RewardRepository extends JpaRepository<Reward,Integer> {
7+
8+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.back.domain.reward.service;
2+
3+
import com.back.domain.reward.entity.Reward;
4+
import com.back.domain.reward.entity.RewardContent;
5+
import com.back.domain.reward.entity.RewardType;
6+
import com.back.domain.reward.repository.RewardRepository;
7+
import lombok.RequiredArgsConstructor;
8+
import org.springframework.stereotype.Service;
9+
10+
import java.util.List;
11+
12+
@Service
13+
@RequiredArgsConstructor
14+
public class RewardService {
15+
private final RewardRepository rewardRepository;
16+
17+
public void crearteReward (RewardType rewardType, List<RewardContent> rewardContents, int requiredValue )
18+
{
19+
rewardRepository.save(new Reward(rewardType,rewardContents,requiredValue));
20+
}
21+
public void findReward()
22+
{
23+
rewardRepository.findAll();
24+
}
25+
public void updateReward(int id, RewardType rewardType, List<RewardContent> rewardContents, int requiredValue)
26+
{
27+
Reward reward = rewardRepository.findById(id).get();
28+
reward.setRewardType(rewardType);
29+
reward.setRewards(rewardContents);
30+
reward.setRequireValue(requiredValue);
31+
rewardRepository.save(reward);
32+
}
33+
public void deleteReward(int id)
34+
{
35+
rewardRepository.deleteById(id);
36+
}
37+
}

backend/src/main/java/com/back/domain/title/entity/Title.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
@NoArgsConstructor
1313
public class Title extends BaseEntity {
1414
String content;
15+
int level;
1516

1617

1718
public Title(String content) {

0 commit comments

Comments
 (0)