Skip to content

Commit

Permalink
Merge pull request #62 from Gamegoo-repo/feature/48
Browse files Browse the repository at this point in the history
[Feat/48] ํšŒ์› ์‹ ๊ณ  API ์ˆ˜์ •.
  • Loading branch information
rimi3226 authored Jul 12, 2024
2 parents abd9d67 + 64f1ecb commit 7c49146
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.gamegoo.dto.report.ReportResponse;
import com.gamegoo.service.report.ReportService;
import com.gamegoo.util.JWTUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -28,7 +29,8 @@ public class ReportController {
private final ReportService reportService;

@PostMapping("")
public ApiResponse<ReportResponse.reportInsertResultDTO> reportInsert(
@Operation(summary = "ํšŒ์› ์‹ ๊ณ  API", description = "๋Œ€์ƒ ํšŒ์›์„ ์‹ ๊ณ ํ•˜๋Š” API ์ž…๋‹ˆ๋‹ค.")
public ApiResponse<ReportResponse.reportInsertResponseDTO> reportInsert(
@RequestBody @Valid ReportRequest.reportInsertDTO request
){
Long memberId = JWTUtil.getCurrentUserId();
Expand All @@ -39,7 +41,7 @@ public ApiResponse<ReportResponse.reportInsertResultDTO> reportInsert(
.map(reportTypeMapping -> reportTypeMapping.getReportType().getId())
.collect(Collectors.toList());

ReportResponse.reportInsertResultDTO result = ReportResponse.reportInsertResultDTO.builder()
ReportResponse.reportInsertResponseDTO result = ReportResponse.reportInsertResponseDTO.builder()
.targetId(report.getTarget().getId())
.reportId(report.getId())
.contents(report.getReportContent())
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/gamegoo/dto/report/ReportRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import lombok.Getter;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.List;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/gamegoo/dto/report/ReportResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class ReportResponse {
@Builder
@NoArgsConstructor
@AllArgsConstructor
public static class reportInsertResultDTO{
public static class reportInsertResponseDTO{
Long reportId;
Long targetId;
List<Long> reportTypeIdList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@
import org.springframework.data.jpa.repository.JpaRepository;

public interface ReportTypeRepository extends JpaRepository<ReportType, Long> {

}
44 changes: 44 additions & 0 deletions src/main/java/com/gamegoo/scripts/ReportTypeInitializer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.gamegoo.scripts;

import com.gamegoo.domain.gamestyle.GameStyle;
import com.gamegoo.domain.report.ReportType;
import com.gamegoo.repository.report.ReportTypeRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
public class ReportTypeInitializer implements ApplicationListener<ApplicationReadyEvent> {

private final ReportTypeRepository reportTypeRepository;

@Override
public void onApplicationEvent(ApplicationReadyEvent event) {
if (isCreateMode(event)) {
initializeReportTypes();
}
}
private boolean isCreateMode(ApplicationReadyEvent event) {
// jpa.hibernate.ddl-auto ๊ฐ’์ด create์ธ์ง€ ํ™•์ธ
String ddlAuto = event.getApplicationContext().getEnvironment().getProperty("spring.jpa.hibernate.ddl-auto");
return "create".equalsIgnoreCase(ddlAuto);
}

private void initializeReportTypes() {
String[] types = {
"์ŠคํŒธ ํ™๋ณด/๋„๋ฐฐ๊ธ€",
"๋ถˆ๋ฒ• ์ •๋ณด ํฌํ•จ",
"์„ฑํฌ๋กฑ ๋ฐœ์–ธ",
"์š•์„ค/ ํ˜์˜ค/ ์ฐจ๋ณ„์  ํ‘œํ˜„",
"๊ฐœ์ธ ์ •๋ณด ๋…ธ์ถœ",
"๋ถˆ์พŒํ•œ ํ‘œํ˜„"
};

for (String type : types) {
ReportType reportType = ReportType.builder().reportTypeContent(type).build();
reportTypeRepository.save(reportType);
}
}
}
4 changes: 1 addition & 3 deletions src/main/java/com/gamegoo/service/report/ReportService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import com.gamegoo.apiPayload.code.status.ErrorStatus;
import com.gamegoo.apiPayload.exception.handler.MemberHandler;
import com.gamegoo.apiPayload.exception.handler.ReportHandler;
import com.gamegoo.apiPayload.exception.handler.TempHandler;
import com.gamegoo.apiPayload.exception.handler.ReportHandler;
import com.gamegoo.domain.Member;
import com.gamegoo.domain.report.Report;
import com.gamegoo.domain.report.ReportType;
Expand All @@ -19,8 +19,6 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
Expand Down

0 comments on commit 7c49146

Please sign in to comment.