-
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.
- Loading branch information
김교휘
authored and
김교휘
committed
Nov 8, 2024
1 parent
a018b17
commit 622c48c
Showing
6 changed files
with
124 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
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(); | ||
} | ||
} |