Skip to content

Commit 425bb9e

Browse files
authored
Merge pull request #4 from TeamProject-Daewoo/dev
Dev
2 parents aa3d3d2 + ec4c88c commit 425bb9e

File tree

17 files changed

+317
-45
lines changed

17 files changed

+317
-45
lines changed

pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@
7575
<artifactId>lombok</artifactId>
7676
<optional>true</optional>
7777
</dependency>
78+
<dependency>
79+
<groupId>org.springframework.boot</groupId>
80+
<artifactId>spring-boot-starter-mail</artifactId>
81+
</dependency>
7882

7983
<dependency>
8084
<groupId>io.jsonwebtoken</groupId>

src/main/java/com/example/backend/CustomerService/Inquiry.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.time.LocalDateTime;
66
import java.util.ArrayList;
77
import java.util.List;
8+
import com.example.backend.authentication.*;
89

910
@Entity
1011
@Getter
@@ -32,23 +33,24 @@ public class Inquiry {
3233
private LocalDateTime createdAt;
3334

3435
@ManyToOne(fetch = FetchType.LAZY)
35-
@JoinColumn(name = "username", referencedColumnName = "user_name", nullable = false)
36-
private UserInquiryDto user;
36+
@JoinColumn(name = "username", referencedColumnName = "user_name", nullable = false)
37+
private User user;
38+
3739

3840
@OneToMany(mappedBy = "inquiry", cascade = CascadeType.ALL, orphanRemoval = true)
3941
private List<InquiryFile> inquiryFiles = new ArrayList<>();
4042

4143
// 생성자 헬퍼 (첨부파일 관련 파라미터는 따로 처리)
42-
public static Inquiry create(String category, String title, String content, UserInquiryDto user) {
43-
return Inquiry.builder()
44-
.category(category)
45-
.title(title)
46-
.content(content)
47-
.status(InquiryStatus.PENDING)
48-
.createdAt(LocalDateTime.now())
49-
.user(user)
50-
.build();
51-
}
44+
public static Inquiry create(String category, String title, String content, User user) {
45+
return Inquiry.builder()
46+
.category(category)
47+
.title(title)
48+
.content(content)
49+
.status(InquiryStatus.PENDING)
50+
.createdAt(LocalDateTime.now())
51+
.user(user)
52+
.build();
53+
}
5254

5355
public void markAsAnswered() {
5456
this.status = InquiryStatus.ANSWERED;

src/main/java/com/example/backend/CustomerService/InquiryAnswer.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import jakarta.persistence.*;
44
import lombok.*;
55
import java.time.LocalDateTime;
6-
6+
import com.example.backend.authentication.User;
77

88
@Entity
99
@Getter
@@ -25,7 +25,7 @@ public class InquiryAnswer {
2525

2626
@ManyToOne(fetch = FetchType.LAZY)
2727
@JoinColumn(name = "admin_username", referencedColumnName = "user_name", nullable = false)
28-
private UserInquiryDto adminUser;
28+
private User adminUser;
2929

3030
@OneToOne(fetch = FetchType.LAZY)
3131
@JoinColumn(name = "inquiry_id", unique = true)
@@ -40,11 +40,11 @@ public void setAnsweredAt(LocalDateTime answeredAt) {
4040
this.answeredAt = answeredAt;
4141
}
4242

43-
public void setAdminUser(UserInquiryDto adminUser) {
43+
public void setAdminUser(User adminUser) {
4444
this.adminUser = adminUser;
4545
}
4646

47-
public static InquiryAnswer create(Inquiry inquiry, String answerContent, UserInquiryDto adminUser) {
47+
public static InquiryAnswer create(Inquiry inquiry, String answerContent, User adminUser) {
4848
return InquiryAnswer.builder()
4949
.inquiry(inquiry)
5050
.answerContent(answerContent)

src/main/java/com/example/backend/CustomerService/InquiryAnswerService.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
import lombok.RequiredArgsConstructor;
55
import org.springframework.stereotype.Service;
66
import org.springframework.transaction.annotation.Transactional;
7+
import com.example.backend.authentication.UserRepository;
8+
import com.example.backend.authentication.*;
9+
10+
11+
712
import java.time.LocalDateTime;
813

914
@Service
@@ -12,15 +17,19 @@ public class InquiryAnswerService {
1217

1318
private final InquiryRepository inquiryRepository;
1419
private final InquiryAnswerRepository inquiryAnswerRepository;
15-
private final UserInquiryRepository userRepository;
20+
private final UserRepository userRepository;
1621

1722
@Transactional
1823
public void saveAnswer(Long inquiryId, String answerContent, String adminUsername) {
1924
Inquiry inquiry = inquiryRepository.findById(inquiryId)
2025
.orElseThrow(() -> new IllegalArgumentException("문의가 존재하지 않습니다."));
2126

22-
UserInquiryDto adminUser = userRepository.findByUsername(adminUsername)
23-
.orElseThrow(() -> new IllegalArgumentException("관리자 사용자를 찾을 수 없습니다."));
27+
// 진짜 User 엔티티 조회
28+
User adminUser = userRepository.findById(adminUsername)
29+
.orElseThrow(() -> new IllegalArgumentException("관리자 사용자를 찾을 수 없습니다."));
30+
31+
// DTO로 변환
32+
UserInquiryDto adminDto = UserInquiryDto.from(adminUser);
2433

2534
InquiryAnswer answer = inquiryAnswerRepository.findByInquiryId(inquiryId)
2635
.orElseGet(() -> InquiryAnswer.create(inquiry, answerContent, adminUser));
Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,27 @@
11
package com.example.backend.CustomerService;
22

33
import com.example.backend.authentication.Role;
4-
5-
import jakarta.persistence.*;
64
import lombok.*;
75

8-
@Entity
9-
@Table(name = "users") // DB 테이블 이름은 그대로 유지해야 함
106
@Getter
11-
@NoArgsConstructor(access = AccessLevel.PROTECTED)
7+
@NoArgsConstructor
128
@AllArgsConstructor
139
@Builder
1410
public class UserInquiryDto {
15-
16-
@Id
17-
@Column(name = "user_name")
1811
private String username;
19-
20-
@Column(name = "name")
2112
private String name;
22-
23-
@Enumerated(EnumType.STRING)
24-
@Column(name = "role")
2513
private Role role;
2614

27-
// 필요시: admin 여부 확인용 헬퍼 메서드
2815
public boolean isAdmin() {
29-
return this.role.name().startsWith("ADMIN_");
16+
return this.role != null && this.role.name().startsWith("ADMIN_");
17+
}
18+
19+
// 정적 팩토리 메서드로 Entity → DTO 변환
20+
public static UserInquiryDto from(com.example.backend.authentication.User user) {
21+
return UserInquiryDto.builder()
22+
.username(user.getUsername())
23+
.name(user.getName())
24+
.role(user.getRole())
25+
.build();
3026
}
3127
}

src/main/java/com/example/backend/CustomerService/UserInquiryRepository.java

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/main/java/com/example/backend/announcement/NoticeController.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@ public class NoticeController {
1717

1818
private final NoticeService noticeService;
1919

20+
21+
@GetMapping
22+
public List<NoticeDTO> getAllNotices() {
23+
return noticeService.getAllNotices();
24+
}
2025

26+
2127
@GetMapping("/paged")
2228
public ResponseEntity<Page<NoticeDTO>> getNoticesPaged(
2329
@RequestParam int page,

src/main/java/com/example/backend/announcement/NoticeService.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,20 @@ private NoticeDTO entityToDto(Notice notice) {
6767
.createdAt(notice.getCreatedAt())
6868
.build();
6969
}
70+
71+
public List<NoticeDTO> getAllNotices() {
72+
return noticeRepository.findAll().stream()
73+
.map(this::convertToDTO)
74+
.collect(Collectors.toList());
75+
}
76+
77+
private NoticeDTO convertToDTO(Notice notice) {
78+
return NoticeDTO.builder()
79+
.id(notice.getId())
80+
.category(notice.getCategory())
81+
.title(notice.getTitle())
82+
.content(notice.getContent())
83+
.createdAt(notice.getCreatedAt())
84+
.build();
85+
}
7086
}

src/main/java/com/example/backend/authentication/User.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public class User implements UserDetails {
6161
private String business_registration_number;
6262

6363
@Column(name = "points")
64-
private Integer points = 0;
64+
private Integer point = 0;
6565

6666
@Builder
6767
public User(String username, String password, String name, String phoneNumber, Role role, String uuid, String business_registration_number, String loginType, Integer points) {
@@ -74,7 +74,7 @@ public User(String username, String password, String name, String phoneNumber, R
7474
this.uuid = uuid;
7575
this.business_registration_number = business_registration_number;
7676
this.loginType = loginType;
77-
this.points = points;
77+
this.point = points;
7878

7979
if (role == Role.BUSINESS) {
8080
this.approvalStatus = ApprovalStatus.PENDING;
@@ -118,4 +118,11 @@ public boolean isCredentialsNonExpired() {
118118
public boolean isEnabled() {
119119
return true;
120120
}
121+
122+
public void addPoints(int pointsToAdd) {
123+
if (pointsToAdd < 0) {
124+
throw new IllegalArgumentException("포인트는 음수일 수 없습니다.");
125+
}
126+
this.point += pointsToAdd;
127+
}
121128
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.example.backend.config;
2+
3+
// AppConfig.java 등 설정 파일
4+
import org.springframework.context.annotation.Bean;
5+
import org.springframework.context.annotation.Configuration;
6+
import org.springframework.web.client.RestTemplate;
7+
8+
@Configuration
9+
public class AppConfig {
10+
11+
@Bean
12+
public RestTemplate restTemplate() {
13+
return new RestTemplate();
14+
}
15+
}

0 commit comments

Comments
 (0)