Skip to content

Commit 25a7ada

Browse files
committed
[feat/#94] 진행중인 문항제출 생성 api 구현
1 parent 5905789 commit 25a7ada

File tree

3 files changed

+81
-0
lines changed

3 files changed

+81
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.moplus.moplus_server.client.submit.controller;
2+
3+
import com.moplus.moplus_server.client.submit.dto.request.ProblemSubmitCreateRequest;
4+
import com.moplus.moplus_server.client.submit.service.ClientSubmitService;
5+
import io.swagger.v3.oas.annotations.Operation;
6+
import io.swagger.v3.oas.annotations.tags.Tag;
7+
import lombok.RequiredArgsConstructor;
8+
import org.springframework.http.ResponseEntity;
9+
import org.springframework.web.bind.annotation.PostMapping;
10+
import org.springframework.web.bind.annotation.RequestBody;
11+
import org.springframework.web.bind.annotation.RequestMapping;
12+
import org.springframework.web.bind.annotation.RestController;
13+
14+
@Tag(name = "클라이언트 제출", description = "클라이언트 제출 관련 API")
15+
@RestController
16+
@RequestMapping("/api/v1/client")
17+
@RequiredArgsConstructor
18+
public class ClientSubmitController {
19+
20+
private final ClientSubmitService clientSubmitService;
21+
22+
@PostMapping("problemSubmit")
23+
@Operation(summary = "문항 제출 데이터 생성", description = "문항 제출을 '진행중'으로 생성합니다.")
24+
public ResponseEntity<Void> createProblemSubmit(
25+
@RequestBody ProblemSubmitCreateRequest request
26+
) {
27+
clientSubmitService.createProblemSubmit(request);
28+
return ResponseEntity.ok(null);
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.moplus.moplus_server.client.submit.dto.request;
2+
3+
import com.moplus.moplus_server.client.submit.domain.ProblemSubmit;
4+
import com.moplus.moplus_server.client.submit.domain.ProblemSubmitStatus;
5+
import jakarta.validation.constraints.NotNull;
6+
7+
public record ProblemSubmitCreateRequest (
8+
@NotNull(message = "발행 ID는 필수입니다.")
9+
Long publishId,
10+
@NotNull(message = "문항 ID는 필수입니다.")
11+
Long problemId
12+
){
13+
public ProblemSubmit toEntity(Long memberId) {
14+
return ProblemSubmit.builder()
15+
.memberId(memberId)
16+
.publishId(this.publishId)
17+
.problemId(this.problemId)
18+
.status(ProblemSubmitStatus.IN_PROGRESS)
19+
.build();
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.moplus.moplus_server.client.submit.service;
2+
3+
4+
import com.moplus.moplus_server.client.submit.domain.ProblemSubmit;
5+
import com.moplus.moplus_server.client.submit.dto.request.ProblemSubmitCreateRequest;
6+
import com.moplus.moplus_server.client.submit.repository.ProblemSubmitRepository;
7+
import java.util.Optional;
8+
import lombok.RequiredArgsConstructor;
9+
import org.springframework.stereotype.Service;
10+
import org.springframework.transaction.annotation.Transactional;
11+
12+
@Service
13+
@RequiredArgsConstructor
14+
public class ClientSubmitService {
15+
16+
private final ProblemSubmitRepository problemSubmitRepository;
17+
18+
@Transactional
19+
public void createProblemSubmit(ProblemSubmitCreateRequest request) {
20+
21+
Long memberId = 1L;
22+
// 제출이력이 없을때만 생성
23+
Optional<ProblemSubmit> existingProblemSubmit = problemSubmitRepository.findByMemberIdAndPublishIdAndProblemId(memberId,
24+
request.publishId(), request.problemId());
25+
if (existingProblemSubmit.isEmpty()) {
26+
ProblemSubmit problemSubmit = request.toEntity(memberId);
27+
problemSubmitRepository.save(problemSubmit);
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)