Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat : add post grade #16

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Binary file not shown.
Binary file not shown.
Binary file modified Backend/haruject/.gradle/7.5.1/fileHashes/fileHashes.bin
Binary file not shown.
Binary file modified Backend/haruject/.gradle/7.5.1/fileHashes/fileHashes.lock
Binary file not shown.
Binary file modified Backend/haruject/.gradle/7.5.1/fileHashes/resourceHashesCache.bin
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ public enum BaseResponseStatus {
INVALID_JWT(false, 2002, "유효하지 않은 JWT입니다."),
INVALID_USER_JWT(false,2003,"권한이 없는 유저의 접근입니다."),

GRADE_IS_EMPTY(false, 2004, "평점을 입력해주세요."),
RATE_IS_EMPTY(false, 2005, "평가를 선택해주세요."),




Expand All @@ -46,7 +49,7 @@ public enum BaseResponseStatus {
DATABASE_ERROR(false, 4000, "데이터베이스 연결에 실패하였습니다."),
SERVER_ERROR(false, 4001, "서버와의 연결에 실패하였습니다."),

POST_ISEMPTY(false, 4002, "불러올 데이터가 없습니다.");
POST_IS_EMPTY(false, 4002, "불러올 데이터가 없습니다.");



Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.umc.haruject.src.grade;



import com.umc.haruject.config.BaseException;
import com.umc.haruject.config.BaseResponse;
import com.umc.haruject.config.BaseResponseStatus;
import com.umc.haruject.src.grade.model.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/grade")
public class GradeController {
final Logger logger = LoggerFactory.getLogger(this.getClass());

@Autowired
private final GradeProvider gradeProvider;

@Autowired
private final GradeService gradeService;

public GradeController(GradeProvider gradeProvider, GradeService gradeService) {
this.gradeProvider = gradeProvider;
this.gradeService = gradeService;
}

/*
평점 등록
*/
@ResponseBody
@PostMapping("")
public BaseResponse<PostGradeRes> createGrade(@RequestBody PostGradeReq postGradeReq){
try {
if(postGradeReq.getGrade() < 1){
return new BaseResponse<>(BaseResponseStatus.GRADE_IS_EMPTY);
}

if(postGradeReq.getTime().length() < 1){
return new BaseResponse<>(BaseResponseStatus.RATE_IS_EMPTY);
}

if(postGradeReq.getCommunication().length() < 1){
return new BaseResponse<>(BaseResponseStatus.RATE_IS_EMPTY);
}

if(postGradeReq.getSkill().length() < 1){
return new BaseResponse<>(BaseResponseStatus.RATE_IS_EMPTY);
}

PostGradeRes postGradeRes = gradeService.createGrade(postGradeReq.getGraderIdx(), postGradeReq);
return new BaseResponse<>(postGradeRes);
} catch (BaseException exception) {
return new BaseResponse<>(exception.getStatus());
}
}




}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.umc.haruject.src.grade;

import com.umc.haruject.src.home.model.GetHomeRes;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import javax.sql.DataSource;
import java.util.List;


@Repository
public class GradeDao {
private JdbcTemplate jdbcTemplate;

@Autowired
public void setDataSource(DataSource dataSource) {
this.jdbcTemplate = new JdbcTemplate(dataSource);}

/*
유저 평점 등록
*/
public int createGrade(int graderIdx, int gradeeIdx, int grade, String time, String communication, String skill) {
String createGradeQuery = "INSERT INTO Grade(graderIdx, gradeeIdx, grade, time, communication, skill) VALUES (?, ?, ?, ?, ?, ?);";
Object[] createGradeParams = new Object[]{graderIdx, gradeeIdx, grade, time, communication, skill};
this.jdbcTemplate.update(createGradeQuery, createGradeParams);

String lastInsertIdxQuery = "select last_insert_id()";
return this.jdbcTemplate.queryForObject(lastInsertIdxQuery, int.class);
}



}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.umc.haruject.src.grade;

import com.umc.haruject.config.BaseException;
import com.umc.haruject.src.home.HomeDao;
import com.umc.haruject.src.home.model.GetHomeRes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.List;

import static com.umc.haruject.config.BaseResponseStatus.DATABASE_ERROR;

@Service
public class GradeProvider {
private final HomeDao homeDao;

final Logger logger = LoggerFactory.getLogger(this.getClass());
public GradeProvider(HomeDao homeDao){
this.homeDao = homeDao;
}


public List<GetHomeRes> getHome() throws BaseException {
try{
List<GetHomeRes> getHomeRes = homeDao.selectPost();
return getHomeRes;
}
catch (Exception exception) {
//System.out.println(exception);
throw new BaseException(DATABASE_ERROR);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.umc.haruject.src.grade;

import com.umc.haruject.config.BaseException;
import com.umc.haruject.src.grade.model.PostGradeReq;
import com.umc.haruject.src.grade.model.PostGradeRes;
import com.umc.haruject.src.home.HomeDao;
import com.umc.haruject.src.home.HomeProvider;
import org.springframework.stereotype.Service;

import static com.umc.haruject.config.BaseResponseStatus.DATABASE_ERROR;


@Service
public class GradeService {
private final GradeDao gradeDao;
private final GradeProvider gradeProvider;

public GradeService(GradeDao gradeDao, GradeProvider gradeProvider) {
this.gradeDao = gradeDao;
this.gradeProvider = gradeProvider;
}

/*
평점 등록
*/
public PostGradeRes createGrade(int graderIdx, PostGradeReq postGradeReq) throws BaseException {

try {
int idx = gradeDao.createGrade(postGradeReq.getGraderIdx(), postGradeReq.getGradeeIdx(), postGradeReq.getGrade(),
postGradeReq.getTime(), postGradeReq.getCommunication(), postGradeReq.getSkill());
return new PostGradeRes(idx);

} catch (Exception exception) {
System.out.println(exception);
throw new BaseException(DATABASE_ERROR);
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.umc.haruject.src.grade.model;


import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;

import java.util.List;

@Getter
@Setter
@AllArgsConstructor
public class PostGradeReq {
private int graderIdx;
private int gradeeIdx;
private int grade;
private String time;
private String communication;
private String skill;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.umc.haruject.src.grade.model;


import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
@AllArgsConstructor
public class PostGradeRes {
private int idx;

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public class HomeDao {
private JdbcTemplate jdbcTemplate;

@Autowired
public void setDataSource(DataSource dataSource) {this.jdbcTemplate = new JdbcTemplate(dataSource);}
public void setDataSource(DataSource dataSource) {
this.jdbcTemplate = new JdbcTemplate(dataSource);}

/*
홈 화면 (게시글 목록 조회)
Expand Down