Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import dev.codehouse.backend.global.response.ApiResponseFactory;
import dev.codehouse.backend.global.response.ResponseCode;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

Expand Down Expand Up @@ -40,13 +39,13 @@ public ResponseEntity<ApiResponse<UserPointResponse>> adjustPoint(@RequestBody U
}

@PostMapping("/problem")
public ResponseEntity<ApiResponse<Void>> register(@RequestBody ProblemRequest request) {
public ResponseEntity<ApiResponse<Void>> register(@RequestBody AdminProblemRequest request) {
problemService.saveProblem(request);
return ApiResponseFactory.success(ResponseCode.PROBLEM_REGISTERED);
}

@GetMapping("/problem/{day}")
public ResponseEntity<ApiResponse<List<ProblemResponse>>> getByDay(@PathVariable String day) {
public ResponseEntity<ApiResponse<List<AdminProblemResponse>>> getByDay(@PathVariable String day) {
return ApiResponseFactory.success(ResponseCode.PROBLEM_FOUND, problemService.getProblems(day));
}

Expand All @@ -57,7 +56,7 @@ public ResponseEntity<ApiResponse<Void>> deleteProblem(@PathVariable String numb
}

@GetMapping("/problem")
public ResponseEntity<ApiResponse<List<ProblemResponse>>> getAllProblemsPaged(@RequestParam(defaultValue = "0") int page) {
public ResponseEntity<ApiResponse<List<AdminProblemResponse>>> getAllProblemsPaged(@RequestParam(defaultValue = "0") int page) {
// return ApiResponseFactory.success(ResponseCode.PROBLEM_FOUND, problemService.getAllProblemsPaged(page));
return ApiResponseFactory.success(ResponseCode.PROBLEM_FOUND, problemService.getAllProblems());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.codehouse.backend.admin.entity;
package dev.codehouse.backend.admin.domain;

import lombok.AllArgsConstructor;
import lombok.Builder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

import lombok.Getter;

import java.time.LocalDateTime;

@Getter
public class ProblemRequest {
public class AdminProblemRequest {
private String title;
private String problemNumber;
private String url;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package dev.codehouse.backend.admin.dto;

import dev.codehouse.backend.problem.entity.Problem;
import dev.codehouse.backend.problem.domain.Problem;
import lombok.AllArgsConstructor;
import lombok.Getter;

@AllArgsConstructor
@Getter
public class ProblemResponse {
public class AdminProblemResponse {
private String title;
private String problemNumber;
private String url;
private String difficulty;
private int point;
private String day;

public static ProblemResponse from(Problem problem) {
return new ProblemResponse(
public static AdminProblemResponse from(Problem problem) {
return new AdminProblemResponse(
problem.getTitle(),
problem.getProblemNumber(),
problem.getUrl(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package dev.codehouse.backend.admin.dto;

import dev.codehouse.backend.admin.entity.Notice;
import dev.codehouse.backend.admin.domain.Notice;
import lombok.AllArgsConstructor;
import lombok.Getter;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package dev.codehouse.backend.admin.repository;

import dev.codehouse.backend.admin.entity.Notice;
import dev.codehouse.backend.admin.domain.Notice;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import dev.codehouse.backend.admin.dto.NoticeRequest;
import dev.codehouse.backend.admin.dto.NoticeResponse;
import dev.codehouse.backend.admin.entity.Notice;
import dev.codehouse.backend.admin.domain.Notice;
import dev.codehouse.backend.admin.repository.NoticeRepository;
import dev.codehouse.backend.global.exception.AdminException;
import dev.codehouse.backend.global.response.ResponseCode;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package dev.codehouse.backend.admin.service;

import dev.codehouse.backend.admin.dto.ProblemRequest;
import dev.codehouse.backend.admin.dto.ProblemResponse;
import dev.codehouse.backend.problem.entity.Problem;
import dev.codehouse.backend.admin.repository.ProblemRepository;
import dev.codehouse.backend.admin.dto.AdminProblemRequest;
import dev.codehouse.backend.admin.dto.AdminProblemResponse;
import dev.codehouse.backend.problem.domain.Problem;
import dev.codehouse.backend.problem.repository.ProblemRepository;
import dev.codehouse.backend.global.exception.AdminException;
import dev.codehouse.backend.global.response.ResponseCode;
import lombok.RequiredArgsConstructor;
Expand All @@ -19,7 +19,7 @@ public class AdminProblemService {
private final ProblemRepository problemRepository;

//문제 등록
public void saveProblem(ProblemRequest dto) {
public void saveProblem(AdminProblemRequest dto) {
if (problemRepository.findByProblemNumber(dto.getProblemNumber()).isPresent()) {
throw new AdminException(ResponseCode.PROBLEM_ALREADY_EXISTS);
}
Expand All @@ -36,17 +36,17 @@ public void deleteProblem(String problemNumber) {
}

//날짜로 문제 조회
public List<ProblemResponse> getProblems(String day) {
public List<AdminProblemResponse> getProblems(String day) {
List<Problem> problems = problemRepository.findByDay(day);
return problems.stream()
.map(ProblemResponse::from)
.map(AdminProblemResponse::from)
.toList();
}

public List<ProblemResponse> getAllProblems() {
public List<AdminProblemResponse> getAllProblems() {
List<Problem> problems = problemRepository.findAll();
return problems.stream()
.map(ProblemResponse::from)
.map(AdminProblemResponse::from)
.toList();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
.requestMatchers(HttpMethod.GET, "/api/admin/notice").permitAll()
.requestMatchers(
"/api/auth/**",
"/api/user/toprank/**",
"/api/user/ranking/**",
"/api/chat/**",
"/ws/**"
).permitAll()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package dev.codehouse.backend.global.exception;

import dev.codehouse.backend.global.response.ResponseCode;

public class ExternalApiException extends BaseException {
public ExternalApiException(ResponseCode code) {
super(code);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package dev.codehouse.backend.global.exception;

import dev.codehouse.backend.global.response.ResponseCode;

public class ProblemException extends BaseException {
public ProblemException(ResponseCode code) {
super(code);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public enum ResponseCode {
INVALID_REQUEST(HttpStatus.BAD_REQUEST, "요청 형식이 올바르지 않습니다."),
DUPLICATE_USERNAME(HttpStatus.BAD_REQUEST, "이미 존재하는 사용자입니다"),
INVALID_PASSWORD(HttpStatus.BAD_REQUEST,"비밀번호가 일치하지 않습니다"),
PROBLEM_NOT_SOLVED(HttpStatus.BAD_REQUEST, "문제를 아직 해결하지 않았습니다."),
PROBLEM_NOT_TODAY(HttpStatus.BAD_REQUEST, "오늘의 문제가 아닙니다."),
//401 Unauthorized
USER_NOT_FOUND(HttpStatus.UNAUTHORIZED, "존재하지 않는 아이디입니다."),

Expand All @@ -21,6 +23,9 @@ public enum ResponseCode {
PROBLEM_NOT_FOUND(HttpStatus.NOT_FOUND, "해당 문제가 존재하지 않습니다."),
CLASS_NOT_FOUND(HttpStatus.NOT_FOUND, "회차 정보가 올바르지 않습니다"),

//409 Conflict
PROBLEM_ALREADY_SOLVED(HttpStatus.CONFLICT, "이미 해결한 문제입니다."),

//500 Internal Server Error
DATABASE_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "데이터베이스 오류가 발생했습니다"),
EXTERNAL_API_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "외부 API 호출 중 오류가 발생했습니다."),
Expand All @@ -39,6 +44,7 @@ public enum ResponseCode {
USER_FOUND(HttpStatus.OK, "유저 조회 성공"),
RANK_FOUND(HttpStatus.OK, "랭킹 조회 성공"),
HISTORY_FOUND(HttpStatus.OK, "정산내역 조회 성공"),
PROBLEM_SOLVED(HttpStatus.OK, "문제 해결 및 포인트 적립 완료"),

//201
NOTICE_CREATED(HttpStatus.CREATED, "초기 공지사항이 생성되었습니다."),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,36 @@
package dev.codehouse.backend.problem.controller;

import dev.codehouse.backend.global.response.ApiResponse;
import dev.codehouse.backend.global.response.ApiResponseFactory;
import dev.codehouse.backend.global.response.ResponseCode;
import dev.codehouse.backend.problem.dto.ProblemResponse;
import dev.codehouse.backend.problem.dto.ProblemSubmitRequest;
import dev.codehouse.backend.problem.service.ProblemCheckService;
import dev.codehouse.backend.problem.service.ProblemFindService;
import dev.codehouse.backend.problem.service.ProblemSubmitService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/solvedCheck")
@RequestMapping("/api/problem")
@RequiredArgsConstructor
public class ProblemController {
private final ProblemCheckService problemCheckService;

@GetMapping("/check")
public boolean checkSolved(
@RequestParam("user") String userId,
@RequestParam("problem") int problemId) {
return problemCheckService.hasUserSolvedProblem(userId, problemId);
private final ProblemSubmitService problemSubmitService;
private final ProblemFindService problemFindService;

@PostMapping("/check")
public ResponseEntity<ApiResponse<Void>> submitProblems(@RequestBody ProblemSubmitRequest request, Authentication authentication) {
problemSubmitService.submitSolvedProblem(authentication.getName(), request.getProblemNumber(), request.getPoint());
return ApiResponseFactory.success(ResponseCode.PROBLEM_SOLVED);
}

@GetMapping("/list")
public List<Integer> getProblemList(
@RequestParam("user") String userId,
@RequestParam(value = "size", defaultValue = "20") int size) {
return problemCheckService.getProblemList(userId, size);
@GetMapping("/{today}")
public ResponseEntity<ApiResponse<List<ProblemResponse>>> getProblems(@PathVariable String today, Authentication authentication) {
return ApiResponseFactory.success(ResponseCode.PROBLEM_FOUND, problemFindService.getProblems(today, authentication.getName()));
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.codehouse.backend.problem.entity;
package dev.codehouse.backend.problem.domain;

import lombok.AllArgsConstructor;
import lombok.Builder;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package dev.codehouse.backend.problem.dto;

import dev.codehouse.backend.problem.domain.Problem;
import lombok.AllArgsConstructor;
import lombok.Getter;

@AllArgsConstructor
@Getter
public class ProblemResponse {
private String title;
private String problemNumber;
private String url;
private String difficulty;
private int points;
private boolean solved;

public static ProblemResponse from(Problem problem, boolean solved) {
return new ProblemResponse(
problem.getTitle(),
problem.getProblemNumber(),
problem.getUrl(),
problem.getDifficulty(),
problem.getPoint(),
solved
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package dev.codehouse.backend.problem.dto;

import lombok.Getter;

@Getter
public class ProblemSubmitRequest {

private String problemNumber;
private int point;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package dev.codehouse.backend.admin.repository;
package dev.codehouse.backend.problem.repository;

import dev.codehouse.backend.problem.entity.Problem;
import dev.codehouse.backend.problem.domain.Problem;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;

Expand Down
Loading