-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[FEAT] 신고하기 기능 추가
- Loading branch information
Showing
8 changed files
with
177 additions
and
0 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
src/main/java/com/soongsil/CoffeeChat/controller/ReportController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.soongsil.CoffeeChat.controller; | ||
|
||
import com.soongsil.CoffeeChat.dto.Oauth.CustomOAuth2User; | ||
import com.soongsil.CoffeeChat.dto.ReportDto; | ||
import com.soongsil.CoffeeChat.service.ReportService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.security.core.Authentication; | ||
import org.springframework.web.ErrorResponse; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import static com.soongsil.CoffeeChat.enums.RequestUri.REPORT_URI; | ||
|
||
|
||
@RestController | ||
@RequestMapping(REPORT_URI) | ||
@RequiredArgsConstructor | ||
public class ReportController { | ||
private final ReportService reportService; | ||
|
||
private String getUserNameByAuthentication(Authentication authentication) throws Exception { | ||
CustomOAuth2User principal = (CustomOAuth2User)authentication.getPrincipal(); | ||
if (principal == null) | ||
throw new Exception(); //TODO : Exception 만들기 | ||
return principal.getUsername(); | ||
} | ||
|
||
@PostMapping("/mentor") | ||
public ResponseEntity<?> createReportMentor(Authentication authentication, | ||
@RequestBody ReportDto request) throws Exception { | ||
ReportDto response = reportService.createReportMentor(request, getUserNameByAuthentication(authentication)); | ||
return ResponseEntity.status(HttpStatus.CREATED).body(response); | ||
|
||
} | ||
|
||
@PostMapping("/mentee") | ||
public ResponseEntity<?> createReportMentee(Authentication authentication, | ||
@RequestBody ReportDto request) throws Exception { | ||
ReportDto response = reportService.createReportMentee(request, getUserNameByAuthentication(authentication)); | ||
return ResponseEntity.status(HttpStatus.CREATED).body(response); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.soongsil.CoffeeChat.dto; | ||
|
||
import com.soongsil.CoffeeChat.entity.Report; | ||
import com.soongsil.CoffeeChat.enums.ReportReason; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Builder | ||
@Getter | ||
public class ReportDto { | ||
//private Long reporterId; | ||
private Long reportedUserId; | ||
private ReportReason reason; | ||
private String additionalDetails; | ||
|
||
public static ReportDto from(Report report){ | ||
return ReportDto.builder() | ||
.reportedUserId(report.getReportedUserId()) | ||
.reason(report.getReason()) | ||
.additionalDetails(report.getAdditionalDetails()) | ||
.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.soongsil.CoffeeChat.entity; | ||
|
||
import com.soongsil.CoffeeChat.dto.ReportDto; | ||
import com.soongsil.CoffeeChat.enums.ReportReason; | ||
import com.soongsil.CoffeeChat.enums.ReportStatus; | ||
import jakarta.persistence.*; | ||
import lombok.*; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Entity | ||
@Getter | ||
@Setter | ||
@Table | ||
@NoArgsConstructor | ||
@Builder | ||
@AllArgsConstructor | ||
public class Report { | ||
@Id @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
private Long reporterId; | ||
|
||
// ID of the person being reported (신고 받은 사람 ID, Long 타입) | ||
private Long reportedUserId; | ||
|
||
// Reason for the report (e.g., abusive language, spam, inappropriate content, etc.) | ||
private ReportReason reason; | ||
|
||
// Additional explanation provided by the reporter | ||
private String additionalDetails; | ||
|
||
// Date and time when the report was created | ||
private LocalDateTime reportedAt; | ||
|
||
// Status of the report (e.g., PENDING, REVIEWED, ACTION_TAKEN) | ||
private ReportStatus status; | ||
|
||
public static Report from(ReportDto dto, Long reporterId){ | ||
return Report.builder() | ||
.reporterId(reporterId) | ||
.reportedUserId(dto.getReportedUserId()) | ||
.reason(dto.getReason()) | ||
.additionalDetails(dto.getAdditionalDetails()) | ||
.reportedAt(LocalDateTime.now()) | ||
.status(ReportStatus.PENDING) | ||
.build(); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/soongsil/CoffeeChat/enums/ReportReason.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.soongsil.CoffeeChat.enums; | ||
|
||
public enum ReportReason { | ||
ABUSIVE_LANGUAGE, | ||
SPAM, | ||
INAPPROPRIATE_CONTENT, | ||
PRIVACY_VIOLATION, | ||
OTHER | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/soongsil/CoffeeChat/enums/ReportStatus.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.soongsil.CoffeeChat.enums; | ||
|
||
public enum ReportStatus { | ||
PENDING, | ||
REVIEWED, | ||
ACTION_TAKEN | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
src/main/java/com/soongsil/CoffeeChat/repository/ReportRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.soongsil.CoffeeChat.repository; | ||
|
||
import com.soongsil.CoffeeChat.entity.Report; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface ReportRepository extends JpaRepository<Report, Long> { | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/com/soongsil/CoffeeChat/service/ReportService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.soongsil.CoffeeChat.service; | ||
|
||
import com.soongsil.CoffeeChat.dto.ReportDto; | ||
import com.soongsil.CoffeeChat.entity.Report; | ||
import com.soongsil.CoffeeChat.entity.User; | ||
import com.soongsil.CoffeeChat.repository.ReportRepository; | ||
import com.soongsil.CoffeeChat.repository.User.UserRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.Optional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class ReportService { | ||
private final ReportRepository reportRepository; | ||
private final UserRepository userRepository; | ||
|
||
public ReportDto createReportMentor(ReportDto request, String username) throws Exception { | ||
Optional<User> user=userRepository.findByUsername(username); | ||
if (user.isPresent()){ | ||
return ReportDto.from(reportRepository.save(Report.from(request, user.get().getId()))); | ||
} | ||
else throw new Exception(); | ||
} | ||
|
||
public ReportDto createReportMentee(ReportDto request, String username) throws Exception { | ||
Optional<User> user=userRepository.findByUsername(username); | ||
if (user.isPresent()){ | ||
return ReportDto.from(reportRepository.save(Report.from(request, user.get().getId()))); | ||
} | ||
else throw new Exception(); | ||
} | ||
} |