Skip to content

Commit

Permalink
Merge pull request #1 from 403project/develop
Browse files Browse the repository at this point in the history
feat: repositories & user service
  • Loading branch information
ldw3097 authored Mar 29, 2024
2 parents 9bfabb8 + e272622 commit 6522785
Show file tree
Hide file tree
Showing 26 changed files with 339 additions and 20 deletions.
9 changes: 7 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,19 @@ configurations {
}
}

jar {
// 기본 Jar 태스크를 비활성화합니다.
enabled = false
}

repositories {
mavenCentral()
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
// implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'
// implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.session:spring-session-core'
Expand All @@ -40,7 +45,7 @@ dependencies {
runtimeOnly 'org.postgresql:postgresql'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
// testImplementation 'org.springframework.security:spring-security-test'
testImplementation 'org.springframework.security:spring-security-test'
}

tasks.named('test') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,20 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

@SpringBootApplication
@SpringBootApplication(exclude = SecurityAutoConfiguration.class)
public class ByulbyulpollApplication {

public static void main(String[] args) {
SpringApplication.run(ByulbyulpollApplication.class, args);
}

@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package byulbyul.byulbyulpoll.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import byulbyul.byulbyulpoll.controller.dto.MemberLoginDto;
import byulbyul.byulbyulpoll.controller.dto.MemberRequestDto;
import byulbyul.byulbyulpoll.controller.dto.MessageDto;
import byulbyul.byulbyulpoll.service.MemberService;
import jakarta.servlet.http.HttpSession;
import lombok.RequiredArgsConstructor;

@RestController("users")
@RequiredArgsConstructor
public class MemberController {

private final MemberService memberService;

@GetMapping("/unique-email")
public MessageDto isUniqueEmail(@RequestParam String email) {
MessageDto response = new MessageDto();
try {
memberService.isValidEmail(email);
response.setSuccess(true);
} catch (IllegalArgumentException e) {
response.setSuccess(false);
response.setMessage(e.getMessage());

}
return response;
}

@GetMapping("/unique-nickname")
public MessageDto isUniqueNickname(@RequestParam String nickname) {
MessageDto response = new MessageDto();
try {
memberService.isValidNickname(nickname);
response.setSuccess(true);
} catch (IllegalArgumentException e) {
response.setSuccess(false);
response.setMessage(e.getMessage());
}
return response;
}

@PostMapping("/sign-up")
public MessageDto signUp(@RequestBody MemberRequestDto memberRequestDto) {
MessageDto response = new MessageDto();
try {
memberService.signUp(memberRequestDto.toDto());
response.setSuccess(true);
response.setMessage("회원가입에 성공했습니다.");
} catch (IllegalArgumentException e) {
response.setSuccess(false);
response.setMessage(e.getMessage());
}
return response;
}

@PostMapping("/login")
public MessageDto login(@RequestBody MemberLoginDto memberLoginDto, HttpSession session) {
MessageDto response = new MessageDto();
try {
memberService.login(memberLoginDto.getEmail(), memberLoginDto.getPassword(), session);
response.setSuccess(true);
response.setMessage("로그인에 성공했습니다.");
} catch (IllegalArgumentException e) {
response.setSuccess(false);
response.setMessage(e.getMessage());
}
return response;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package byulbyul.byulbyulpoll.controller.dto;

import lombok.Data;

@Data
public class MemberLoginDto {
private final String email;
private final String password;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package byulbyul.byulbyulpoll.controller.dto;

import byulbyul.byulbyulpoll.service.dto.MemberDto;
import lombok.AllArgsConstructor;
import lombok.Data;

@Data
@AllArgsConstructor
public class MemberRequestDto {
private String email;
private String password;
private String nickname;
private String gender;
private Integer birthYear;
private String occupation;

public MemberDto toDto() {
return new MemberDto(email, password, nickname, gender, birthYear, occupation);
}
}
12 changes: 12 additions & 0 deletions src/main/java/byulbyul/byulbyulpoll/controller/dto/MessageDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package byulbyul.byulbyulpoll.controller.dto;

import com.fasterxml.jackson.annotation.JsonInclude;

import lombok.Data;

@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class MessageDto {
private boolean success;
private String message;
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package byulbyul.byulbyulpoll.endpoint;
package byulbyul.byulbyulpoll.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class helloworld {

@GetMapping("/")
public String home(){
public String home() {

return "Hello world!";
}
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/byulbyul/byulbyulpoll/entity/Like.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
import lombok.Getter;
import lombok.Setter;

import java.util.Optional;

@Entity
@Getter @Setter
@Getter
@Setter
public class Like {

@Id
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/byulbyul/byulbyulpoll/entity/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@

import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Entity
@Getter @Setter
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class Member {

@Id
Expand All @@ -21,4 +26,5 @@ public class Member {
private Integer birthYear;

private String occupation;

}
2 changes: 2 additions & 0 deletions src/main/java/byulbyul/byulbyulpoll/entity/Project.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ public class Project {

@OneToMany(mappedBy = "project", cascade = CascadeType.ALL)
private List<ProjectImage> projectImageList;

private int upvote;
}
5 changes: 3 additions & 2 deletions src/main/java/byulbyul/byulbyulpoll/entity/ProjectImage.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
import lombok.Setter;

@Entity
@Getter @Setter
@Getter
@Setter
public class ProjectImage {
@Id
private long id;

@ManyToOne
@ManyToOne(fetch = FetchType.LAZY)
private Project project;

private int imageOrder;
Expand Down
17 changes: 10 additions & 7 deletions src/main/java/byulbyul/byulbyulpoll/entity/Vote.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
package byulbyul.byulbyulpoll.entity;


import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.Id;
import jakarta.persistence.OneToOne;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;

@Entity
@Getter @Setter
@Getter
@Setter
public class Vote {
@Id
private long id;

@OneToOne(fetch = FetchType.LAZY)
@ManyToOne
private Project project;

private boolean isMember;
Expand All @@ -25,4 +22,10 @@ public class Vote {
@OneToOne(fetch = FetchType.LAZY)
private NonMember nonMember;

private Integer ageType;

private String gender;

private String occupation;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package byulbyul.byulbyulpoll.repository;

import byulbyul.byulbyulpoll.entity.Comment;
import org.springframework.data.jpa.repository.JpaRepository;

public interface CommentRepository extends JpaRepository<Comment, Long> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package byulbyul.byulbyulpoll.repository;

import byulbyul.byulbyulpoll.entity.Like;
import org.springframework.data.jpa.repository.JpaRepository;

public interface LikeRepository extends JpaRepository<Like, Long> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package byulbyul.byulbyulpoll.repository;

import byulbyul.byulbyulpoll.entity.Member;

import java.util.Optional;

import org.springframework.data.jpa.repository.JpaRepository;

public interface MemberRepository extends JpaRepository<Member, String> {

boolean existsByEmail(String email);

boolean existsByNickname(String nickname);

Optional<Member> findByEmail(String email);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package byulbyul.byulbyulpoll.repository;

import byulbyul.byulbyulpoll.entity.NonMember;
import org.springframework.data.jpa.repository.JpaRepository;

public interface NonMemberRepository extends JpaRepository<NonMember, String> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package byulbyul.byulbyulpoll.repository;

import byulbyul.byulbyulpoll.entity.Poll;
import org.springframework.data.jpa.repository.JpaRepository;

public interface PollRepository extends JpaRepository<Poll, Long> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package byulbyul.byulbyulpoll.repository;

import byulbyul.byulbyulpoll.entity.ProjectImage;
import org.springframework.data.jpa.repository.JpaRepository;

public interface ProjectImageRepository extends JpaRepository<ProjectImage, Long> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package byulbyul.byulbyulpoll.repository;

import byulbyul.byulbyulpoll.entity.Project;
import org.springframework.data.jpa.repository.JpaRepository;

public interface ProjectRepository extends JpaRepository<Project, Long> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package byulbyul.byulbyulpoll.repository;

import byulbyul.byulbyulpoll.entity.Tag;
import org.springframework.data.jpa.repository.JpaRepository;

public interface TagRepository extends JpaRepository<Tag, Long> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package byulbyul.byulbyulpoll.repository;

import byulbyul.byulbyulpoll.entity.Vote;
import org.springframework.data.jpa.repository.JpaRepository;

public interface VoteRepository extends JpaRepository<Vote, Long> {
}
Loading

0 comments on commit 6522785

Please sign in to comment.