Skip to content

Commit

Permalink
Merge pull request #8 from UniD-Hackathon-Team4/feature/#3/subscribe
Browse files Browse the repository at this point in the history
[feat] #2 공동구매
  • Loading branch information
kyungminlee-12 authored Nov 6, 2022
2 parents 5dd31f9 + a698ef9 commit 44e2eaf
Show file tree
Hide file tree
Showing 16 changed files with 268 additions and 48 deletions.
2 changes: 2 additions & 0 deletions src/main/java/com/example/DayClassBack/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;

@EnableJpaAuditing
@SpringBootApplication
@ComponentScan
public class Application {

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.DayClassBack.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
Expand All @@ -10,6 +11,7 @@

@Configuration
@EnableWebSecurity
// @ComponentScan(basePackages = "com.example.DayClassBack")
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.example.DayClassBack.controller;

import com.example.DayClassBack.dto.Response;
import com.example.DayClassBack.dto.request.PartyRequestDto;
import com.example.DayClassBack.enums.WriteType;
import com.example.DayClassBack.service.Helper;
import com.example.DayClassBack.service.PartyService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.Errors;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RequiredArgsConstructor
@RequestMapping("/api/homebody/party")
@RestController
public class PartyController {

private final PartyService partyService;
private final Response response;

@PostMapping("/gather")
public ResponseEntity<?> writeGather(@Validated PartyRequestDto.WriteGather write, Errors errors) {
// validation check
if (errors.hasErrors()) {
return response.invalidFields(Helper.refineErrors(errors));
}
write.setWriteType(WriteType.Gather);
write.set_completed(true);

return partyService.writeGather(write);
}

@PostMapping("/rental")
public ResponseEntity<?> writeRental(@Validated PartyRequestDto.WriteRental write, Errors errors) {
// validation check
if (errors.hasErrors()) {
return response.invalidFields(Helper.refineErrors(errors));
}
write.setWriteType(WriteType.Rental);
write.set_completed(true);
return partyService.writeRental(write);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,44 +1,110 @@
package com.example.DayClassBack.dto.request;

import com.example.DayClassBack.entity.Users;
import com.example.DayClassBack.enums.Ott;
import com.example.DayClassBack.enums.WriteType;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
// import javax.validation.constraints.Pattern;
import java.time.LocalDate;
import java.time.LocalDateTime;

public class PartyRequestDto {

@Getter
@Setter
public static class Write {
public static class WriteGather {

@NotEmpty(message = "title은 필수 입력값입니다.")
@NotNull(message = "필수 입력값입니다.")
private Long user_id;
// private Users users;

// @NotEmpty(message = "필수 입력값입니다.")
// private Type type;

@NotNull(message = "필수 입력값입니다.") // @NotEmpty 사용 시 error
private int number_of_people; // https://sjparkk-dev1og.tistory.com/m/145

@NotNull(message = "필수 입력값입니다.")
private int cost;

@NotNull(message = "ott는 필수 입력값입니다.")
private Ott ott;

// @NotEmpty(message = "필수 입력값입니다.")
// private boolean is_completed;

@NotNull(message = "title은 필수 입력값입니다.")
// @Pattern(regexp = "^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+.[A-Za-z]{2,6}$", message = "이메일 형식에 맞지 않습니다.")
private String title;

@NotEmpty(message = "content는 필수 입력값입니다.")
// @NotEmpty(message = "content는 필수 입력값입니다.")
// @Pattern(regexp = "^(?=.*[A-Za-z])(?=.*\\d)(?=.*[~!@#$%^&*()+|=])[A-Za-z\\d~!@#$%^&*()+|=]{8,16}$", message = "비밀번호는 8~16자 영문 대 소문자, 숫자, 특수문자를 사용하세요.")
private String content;
// private String content;

@NotNull (message = "start_date은 필수 입력값입니다.")
@DateTimeFormat(pattern = "yyyy.MM.dd")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy.MM.dd", timezone = "Asia/Seoul")
private LocalDate start_date;

// @NotNull (message = "start_date은 필수 입력값입니다.")
@DateTimeFormat(pattern = "yyyy.MM.dd")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy.MM.dd", timezone = "Asia/Seoul")
private LocalDate end_date;

private WriteType writeType;

private boolean is_completed;

//type.setWriteType(WriteType.Gather);
}

@Getter
@Setter
public static class WriteRental {

@NotEmpty(message = "필수 입력값입니다.")
private int number_of_people;
@NotNull(message = "필수 입력값입니다.")
private Users users;

@NotEmpty(message = "필수 입력값입니다.")
private LocalDateTime start_date;
// @NotEmpty(message = "필수 입력값입니다.")
// private Type type;

@NotEmpty(message = "필수 입력값입니다.")
private LocalDateTime end_date;
// @NotEmpty(message = "필수 입력값입니다.")
// private int number_of_people;

@NotEmpty(message = "필수 입력값입니다.")
@NotNull(message = "필수 입력값입니다.")
private int cost;

@NotEmpty(message = "ott는 필수 입력값입니다.")
@NotNull(message = "ott는 필수 입력값입니다.")
private Ott ott;

@NotEmpty(message = "o필수 입력값입니다.")
// @NotEmpty(message = "필수 입력값입니다.")
// private boolean is_completed;

@NotNull(message = "title은 필수 입력값입니다.")
// @Pattern(regexp = "^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+.[A-Za-z]{2,6}$", message = "이메일 형식에 맞지 않습니다.")
private String title;

// @NotEmpty(message = "content는 필수 입력값입니다.")
// @Pattern(regexp = "^(?=.*[A-Za-z])(?=.*\\d)(?=.*[~!@#$%^&*()+|=])[A-Za-z\\d~!@#$%^&*()+|=]{8,16}$", message = "비밀번호는 8~16자 영문 대 소문자, 숫자, 특수문자를 사용하세요.")
// private String content;

//@NotNull (message = "start_date은 필수 입력값입니다.")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy.MM.dd", timezone = "Asia/Seoul")
private LocalDate start_date;

// @NotNull (message = "start_date은 필수 입력값입니다.")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy.MM.dd", timezone = "Asia/Seoul")
private LocalDate end_date;

private WriteType writeType;
private boolean is_completed;


}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;

public class UserRequestDto {
Expand All @@ -13,27 +14,31 @@ public class UserRequestDto {
@Setter
public static class SignUp {

@NotEmpty(message = "이메일은 필수 입력값입니다.")
@NotNull(message = "이메일은 필수 입력값입니다.")
@Pattern(regexp = "^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+.[A-Za-z]{2,6}$", message = "이메일 형식에 맞지 않습니다.")
private String email;

@NotEmpty(message = "비밀번호는 필수 입력값입니다.")
@NotNull(message = "비밀번호는 필수 입력값입니다.")
@Pattern(regexp = "^(?=.*[A-Za-z])(?=.*\\d)(?=.*[~!@#$%^&*()+|=])[A-Za-z\\d~!@#$%^&*()+|=]{8,16}$", message = "비밀번호는 8~16자 영문 대 소문자, 숫자, 특수문자를 사용하세요.")
private String password;

@NotEmpty(message = "username은 필수 입력값입니다.")
@NotNull(message = "username은 필수 입력값입니다.")
@Pattern(regexp = "^[A-Za-z0-9._%+-]{2,16}$", message = "username은 2~16자 영문 대 소문자, 숫자를 사용하세요.")
private String username;

@NotNull(message = "contact은 필수 입력값입니다.")
//@Pattern(regexp = "^[0-9]{2,3}+-[0-9]{4,5}+-[0-9]{4,5}$", message = "contact 000-0000-0000 형식으로 입력하세요.")
private String contact;
}

@Getter
@Setter
public static class Login {
@NotEmpty(message = "이메일은 필수 입력값입니다.")
@NotNull(message = "이메일은 필수 입력값입니다.")
@Pattern(regexp = "^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+.[A-Za-z]{2,6}$", message = "이메일 형식에 맞지 않습니다.")
private String email;

@NotEmpty(message = "비밀번호는 필수 입력값입니다.")
@NotNull(message = "비밀번호는 필수 입력값입니다.")
private String password;

public UsernamePasswordAuthenticationToken toAuthentication() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.example.DayClassBack.dto.response;

import com.example.DayClassBack.enums.Type;
import com.example.DayClassBack.enums.WriteType;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -17,7 +17,7 @@ public static class PartyWriteInfo {
private String title;
private String content;

private Type type;
private WriteType type;

private String refreshToken;
private Long refreshTokenExpirationTime;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package com.example.DayClassBack.dto.response;

import com.example.DayClassBack.entity.Users;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;

public class UserResponseDto {

public UserResponseDto(Users user) {
}

@Builder
@Getter
@AllArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class Participate extends BaseTime {

@ManyToOne (targetEntity =Party.class) // (mappedBy ="Party", cascade=CascadeType.ALL, orphanRemoval=true) // Many = Participate, Users = Party
@JoinColumn(name="party_id") // foreign key (partyId) references Party (id)
private List<Party> party;
private Party party;

@Column(nullable=false)
private boolean is_selected;
Expand Down
26 changes: 16 additions & 10 deletions src/main/java/com/example/DayClassBack/entity/Party.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.example.DayClassBack.entity;

import com.example.DayClassBack.enums.Ott;
import com.example.DayClassBack.enums.Type;
import com.example.DayClassBack.enums.WriteType;
import lombok.*;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.*;
import java.time.LocalDate;
import java.time.LocalDateTime;
import javax.validation.constraints.NotNull;

@Builder
@NoArgsConstructor
Expand Down Expand Up @@ -34,19 +36,23 @@ public class Party extends BaseTime {
private LocalDateTime updated_at;
*/

@Column(nullable = false)
@Column
@Enumerated(EnumType.STRING) // enum의 이름으로 지정
private Type type;
private WriteType writeType;

@Column(nullable = false)
@NotNull
@Column
private int number_of_people;

@Column(nullable = false)
private LocalDateTime start_date;
@Column
@DateTimeFormat(pattern = "yyyy.MM.dd")
private LocalDate start_date;

@Column
private LocalDateTime end_date;
@DateTimeFormat(pattern = "yyyy.MM.dd")
private LocalDate end_date;

@NotNull
@Column(nullable = false)
private int cost;

Expand All @@ -60,7 +66,7 @@ public class Party extends BaseTime {
@Column(nullable = false)
private String title;

@Column(nullable = false)
private String contents;
// @Column(nullable = false)
// private String contents;

}
3 changes: 3 additions & 0 deletions src/main/java/com/example/DayClassBack/entity/Users.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public class Users extends BaseTime implements UserDetails {
@Column(nullable = false)
private String username;

@Column(nullable = false)
private String contact;

// @CreationTimestamp
// private Timestamp create_date;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.example.DayClassBack.enums;

public enum Type {
public enum WriteType {
Gather, // 모집
Rental // 대여
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package com.example.DayClassBack.repository;

import com.example.DayClassBack.entity.Party;
import com.example.DayClassBack.entity.Users;
import org.apache.catalina.User;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.Optional;

public interface PartyRepository extends JpaRepository<Party, Long> {
Optional<Party> findById(Long id);
}
Loading

0 comments on commit 44e2eaf

Please sign in to comment.