Skip to content
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
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ dependencies {
//db
implementation 'mysql:mysql-connector-java'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'

//jwt
implementation group: 'io.jsonwebtoken', name: 'jjwt-api', version: '0.11.5'
runtimeOnly group: 'io.jsonwebtoken', name: 'jjwt-impl', version: '0.11.5'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
@AllArgsConstructor
public class BaseException extends Exception {
private BaseResponseStatus status;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ public BaseResponse(BaseResponseStatus status) {
this.message = status.getMessage();
this.code = status.getCode();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,21 @@
@Getter
public enum BaseResponseStatus {
/**
* 1000: 요청 성공
* 200: 요청 성공
*/
SUCCESS(true, 1000, "요청에 성공하였습니다."),
SUCCESS(true, 200, "요청에 성공하였습니다."),

/**
* 2000: Request 오류
* 400: Request 오류
*/
// [POST] /plans
// [POST] /plans / records
POST_PLAN_EMPTY_USER(false, 400, "계획을 실천할 사용자를 입력해주세요"),
POST_PLAN_EMPTY_FRIEND(false, 400, "함께할 친구를 입력해주세요"),
POST_PLAN_WRONG_FRIEND(false, 400, "친구로 입력한 사용자가 존재하지 않습니다."),
POST_PLAN_EMPTY_CONTENT(false, 400, "계획의 내용을 입력해주세요."),
POST_PLAN_EMPTY_DATE(false, 400, "날짜를 입력해주세요."),
GET_PLAN_EMPTY_ID(false, 400, "계획 식별자를 입력해주세요."),
GET_PLAN_WRONG_ID(false, 400, "계획 식별자를 0이상의 수로 입력해주세요."),
GET_PLAN_EMPTY_DATE(false, 400, "날짜를 입력해주세요."),
PUT_PLAN_EMPTY_ID(false, 400, "계획 식별자를 입력해주세요."),
PUT_PLAN_WRONG_ID(false, 400, "존재하지 않는 계획 식별자입니다."),
Expand All @@ -31,20 +33,26 @@ public enum BaseResponseStatus {
PUT_MILEAGE_EMPTY_COUNT(false, 400, "추가할 마일리지를 입력해주세요."),
PUT_MILEAGE_WRONG_COUNT(false, 400, "마일리지는 1 이상의 수로 입력해주세요."),

POST_RECORD_EMPTY_IMGURL(false, 400, "기록의 이미지를 업로드해주세요."),

POST_RECORD_EMPTY_CONTENT(false, 400, "기록의 내용을 입력해주세요"),

POST_RECORD_EMPTY_SATISFACTION(false, 400, "만족도를 입력해주세요."),

/**
* 3000: Response 오류
* 400: Response 오류
*/
RESPONSE_ERROR(false, 3000, "값을 불러오는데 실패하였습니다."),
RESPONSE_ERROR(false, 400, "값을 불러오는데 실패하였습니다."),

/**
* 4000: Database 오류
* 400: Database 오류
*/
DATABASE_ERROR(false, 4000, "데이터베이스 연결에 실패하였습니다."),
DATABASE_ERROR(false, 400, "데이터베이스 연결에 실패하였습니다."),

/**
* 5000: Server 오류
* 400: Server 오류
*/
SERVER_ERROR(false, 5000, "서버 연결에 실패하였습니다."),
SERVER_ERROR(false, 400, "서버 연결에 실패하였습니다."),

;

Expand All @@ -57,4 +65,5 @@ private BaseResponseStatus(boolean isSuccess, int code, String message) {
this.code = code;
this.message = message;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,14 @@

import com.example.UnderTheSea_Server.config.BaseException;
import com.example.UnderTheSea_Server.config.BaseResponse;
import com.example.UnderTheSea_Server.config.BaseResponseStatus;
import com.example.UnderTheSea_Server.domain.User;
import com.example.UnderTheSea_Server.jwt.JwtAuthenticationFilter;
import com.example.UnderTheSea_Server.model.*;
import com.example.UnderTheSea_Server.service.PlanService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;

import java.net.http.HttpHeaders;
import java.time.LocalDate;

import static com.example.UnderTheSea_Server.config.BaseResponseStatus.*;
Expand Down Expand Up @@ -57,11 +53,11 @@ public BaseResponse<PostPlanRes> createPlan(@RequestBody PostPlanReq postPlanReq
/**
* Get Plan API
* [GET] /plans
* @return BaseResponse<GetPlanRes>
* @return BaseResponse<GetPlansRes>
*/
//@ResponseBody
@GetMapping("/plans")
public BaseResponse<GetPlanRes> selectPlans(@RequestParam("date") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate date) {
public BaseResponse<GetPlansRes> selectPlans(@RequestParam("date") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate date) {
if(date == null){
return new BaseResponse<>(GET_PLAN_EMPTY_DATE);
}
Expand All @@ -70,7 +66,34 @@ public BaseResponse<GetPlanRes> selectPlans(@RequestParam("date") @DateTimeForma
//System.out.println(SecurityContextHolder.getContext().getAuthentication().getPrincipal().getClass());
User userByJwt = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();

GetPlanRes getPlanRes = planService.selectPlans(userByJwt, date);
GetPlansRes getPlansRes = planService.selectPlans(userByJwt, date);
return new BaseResponse<>(getPlansRes);
} catch(BaseException exception){
return new BaseResponse<>((exception.getStatus()));
}
}

/**
* Get Plan API
* [GET] /plans
* @return BaseResponse<GetPlanRes>
*/
//@ResponseBody
@GetMapping("/plan")
public BaseResponse<GetPlanRes> selectPlan(@RequestParam("plan_id") Long plan_id) {
if(plan_id == null){
return new BaseResponse<>(GET_PLAN_EMPTY_ID);
}

if(plan_id < 0){
return new BaseResponse<>(GET_PLAN_WRONG_ID);
}

try{
//System.out.println(SecurityContextHolder.getContext().getAuthentication().getPrincipal().getClass());
User userByJwt = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();

GetPlanRes getPlanRes = planService.selectPlan(userByJwt, plan_id);
return new BaseResponse<>(getPlanRes);
} catch(BaseException exception){
return new BaseResponse<>((exception.getStatus()));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.example.UnderTheSea_Server.controller;


import com.example.UnderTheSea_Server.config.BaseException;
import com.example.UnderTheSea_Server.config.BaseResponse;
import com.example.UnderTheSea_Server.domain.User;
import com.example.UnderTheSea_Server.model.PostRecordReq;
import com.example.UnderTheSea_Server.model.PostRecordRes;
import com.example.UnderTheSea_Server.service.RecordService;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import com.example.UnderTheSea_Server.jwt.JwtService;
import org.springframework.web.bind.annotation.RestController;

import static com.example.UnderTheSea_Server.config.BaseResponseStatus.*;
@RestController
@RequiredArgsConstructor
public class RecordController {

private final RecordService recordService;
private final JwtService jwtService;


//@ResponseBody
@PostMapping("/records")
public BaseResponse<PostRecordRes> createRecord(@RequestBody PostRecordReq postRecordReq) {
if(postRecordReq.img_url == null){
return new BaseResponse<>(POST_RECORD_EMPTY_IMGURL);
}
if(postRecordReq.content.isEmpty()){
return new BaseResponse<>(POST_RECORD_EMPTY_CONTENT);
}
if(postRecordReq.satisfaction == null){
return new BaseResponse<>(POST_RECORD_EMPTY_SATISFACTION);
}

try{
User userByJwt = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
Long userIdByJwt = userByJwt.getUserId();

PostRecordRes postRecordRes = recordService.createRecord(postRecordReq, userByJwt);
return new BaseResponse<>(postRecordRes);
} catch(BaseException exception){
return new BaseResponse<>((exception.getStatus()));
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
public class Plan {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long plan_id;
@JoinColumn(name = "plan_id")
private Long planId;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
Expand Down
23 changes: 17 additions & 6 deletions src/main/java/com/example/UnderTheSea_Server/domain/Record.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,39 @@
package com.example.UnderTheSea_Server.domain;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.*;
import org.hibernate.annotations.ColumnDefault;


import javax.persistence.*;
import java.time.LocalDate;
import java.util.Date;

@Entity
@Builder
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Table(name = "Record")
public class Record {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long record_id;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
@JsonIgnore
private User user;

@Column(nullable = true)
private String content;

@Enumerated(EnumType.STRING)
@ColumnDefault("'UNSATISFIED'")
private RecordSatisfaction satisfaction;
@Column(nullable = true)
private Integer satisfaction;

@Column(nullable = false)
private LocalDate date;

@Enumerated(EnumType.STRING)
@ColumnDefault("'ACTIVE'")
Expand All @@ -39,4 +49,5 @@ public class Record {
@Temporal(value = TemporalType.TIMESTAMP)
@Column(nullable = false)
private Date updated_at;

}

This file was deleted.

10 changes: 8 additions & 2 deletions src/main/java/com/example/UnderTheSea_Server/domain/User.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package com.example.UnderTheSea_Server.domain;

import io.swagger.annotations.Contact;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import io.swagger.annotations.Contact;
import lombok.*;
import org.hibernate.annotations.ColumnDefault;
Expand All @@ -21,7 +26,8 @@
@AllArgsConstructor
@NoArgsConstructor
@Table(name = "User")
public class User implements UserDetails{

public class User implements UserDetails {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "user_id")
Expand Down Expand Up @@ -74,7 +80,6 @@ public User(Long user_id, String email, String nickname, String profileImgUrl, L
@ElementCollection(fetch = FetchType.EAGER)
private List<String> roles = new ArrayList<>();


@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
return this.roles.stream()
Expand Down Expand Up @@ -111,4 +116,5 @@ public boolean isCredentialsNonExpired() {
public boolean isEnabled() {
return true;
}

}
28 changes: 28 additions & 0 deletions src/main/java/com/example/UnderTheSea_Server/dto/RecordDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.example.UnderTheSea_Server.dto;

import com.example.UnderTheSea_Server.domain.Record;
import com.example.UnderTheSea_Server.domain.*;
import org.springframework.stereotype.Repository;

import java.sql.Timestamp;
import java.util.Date;

@Repository
public class RecordDto {
private Timestamp created_at = new Timestamp(new Date().getTime());
private Timestamp updated_at = new Timestamp(new Date().getTime());

public Record insertRecord(String img_url, String content, int satisfaction, User user) {
com.example.UnderTheSea_Server.domain.Record recordEntity = Record.builder()
.img_url(img_url)
.user(user)
.content(content)
.satisfaction(satisfaction)
.status(RecordStatus.ACTIVE)
.created_at(created_at)
.updated_at(updated_at)
.build();
return recordEntity;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;

import java.util.List;

@NoArgsConstructor
@AllArgsConstructor
public class GetPlanRes {
public List<Plan> plans;
public Plan plan;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.example.UnderTheSea_Server.model;

import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;

import java.time.LocalDate;

//달력의 날짜를 누르면 그 날짜에 대한 계획들이 나오는 것
//상세기록도 가져와야해서 더 받아와야할 듯

@NoArgsConstructor
@AllArgsConstructor
public class GetPlansReq {
public LocalDate date;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.example.UnderTheSea_Server.model;

import com.example.UnderTheSea_Server.domain.Plan;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;

import java.util.List;

@NoArgsConstructor
@AllArgsConstructor
public class GetPlansRes {
public List<Plan> plans;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.example.UnderTheSea_Server.model;

/* 프론트>서버 : record 정보 불러오기 / 뭘 집어넣어야할 지 모르겟음..*/

public class GetRecordReq {



}
Loading