Skip to content

Commit

Permalink
fix :: conflict 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
ta2ye0n committed Apr 17, 2024
2 parents 6512493 + 5dcc691 commit e2d6c05
Show file tree
Hide file tree
Showing 12 changed files with 173 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/main/java/com/mindway/server/v2/MindWayV2Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
import jakarta.annotation.PostConstruct;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.scheduling.annotation.EnableScheduling;

import java.util.TimeZone;

@EnableScheduling
@EnableJpaAuditing
@SpringBootApplication
public class MindWayV2Application {

@PostConstruct
public void started() {TimeZone.setDefault(TimeZone.getTimeZone("Asia/Seoul"));}

public static void main(String[] args) {
TimeZone.setDefault(TimeZone.getTimeZone("Asia/Seoul"));
SpringApplication.run(MindWayV2Application.class, args);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.mindway.server.v2.domain.notice.converter;


import com.mindway.server.v2.domain.notice.entity.Notice;
import com.mindway.server.v2.domain.notice.presentation.dto.request.NoticeAddRequestDto;
import com.mindway.server.v2.domain.user.entity.User;

public interface NoticeConverter {
Notice toEntity(NoticeAddRequestDto noticeAddRequestDto, User user);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.mindway.server.v2.domain.notice.converter.impl;

import com.mindway.server.v2.domain.notice.converter.NoticeConverter;
import com.mindway.server.v2.domain.notice.entity.Notice;
import com.mindway.server.v2.domain.notice.presentation.dto.request.NoticeAddRequestDto;
import com.mindway.server.v2.domain.user.entity.User;
import org.springframework.stereotype.Component;

@Component
public class NoticeConverterImpl implements NoticeConverter {

public Notice toEntity(NoticeAddRequestDto noticeAddRequestDto, User user) {
return Notice.builder()
.title(noticeAddRequestDto.getTitle())
.content(noticeAddRequestDto.getContent())
.user(user)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.mindway.server.v2.domain.notice.entity;

import com.mindway.server.v2.domain.user.entity.User;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Builder
public class Notice {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

private String title;

private String content;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
private User user;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.mindway.server.v2.domain.notice.exception;

import com.mindway.server.v2.global.exception.ErrorCode;
import com.mindway.server.v2.global.exception.MindWayException;

public class NotAccessStudentException extends MindWayException {
public NotAccessStudentException() {
super(ErrorCode.NOT_ACCESS_STUDENT);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.mindway.server.v2.domain.notice.presentation;

import com.mindway.server.v2.domain.notice.presentation.dto.request.NoticeAddRequestDto;
import com.mindway.server.v2.domain.notice.service.NoticeAddService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v2/notice")
public class NoticeController {

private final NoticeAddService noticeAddService;

@PostMapping
public ResponseEntity<Void> addNotice(@Valid @RequestBody NoticeAddRequestDto noticeAddRequestDto) {
noticeAddService.execute(noticeAddRequestDto);
return ResponseEntity.status(HttpStatus.CREATED).build();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.mindway.server.v2.domain.notice.presentation.dto.request;

import jakarta.validation.constraints.NotNull;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
public class NoticeAddRequestDto {

@NotNull
private String title;
@NotNull
private String content;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.mindway.server.v2.domain.notice.repository;


import com.mindway.server.v2.domain.notice.entity.Notice;
import org.springframework.data.jpa.repository.JpaRepository;

public interface NoticeRepository extends JpaRepository<Notice, Long> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.mindway.server.v2.domain.notice.service;

import com.mindway.server.v2.domain.notice.presentation.dto.request.NoticeAddRequestDto;

public interface NoticeAddService {
void execute(NoticeAddRequestDto noticeAddRequestDto);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.mindway.server.v2.domain.notice.service.impl;

import com.mindway.server.v2.domain.notice.converter.NoticeConverter;
import com.mindway.server.v2.domain.notice.entity.Notice;
import com.mindway.server.v2.domain.notice.exception.NotAccessStudentException;
import com.mindway.server.v2.domain.notice.presentation.dto.request.NoticeAddRequestDto;
import com.mindway.server.v2.domain.notice.repository.NoticeRepository;
import com.mindway.server.v2.domain.notice.service.NoticeAddService;
import com.mindway.server.v2.domain.user.entity.Authority;
import com.mindway.server.v2.domain.user.entity.User;
import com.mindway.server.v2.domain.user.util.UserUtil;
import com.mindway.server.v2.global.annotation.ServiceWithTransaction;
import lombok.RequiredArgsConstructor;

@ServiceWithTransaction
@RequiredArgsConstructor
public class NoticeAddServiceImpl implements NoticeAddService {

private final NoticeConverter noticeConverter;
private final NoticeRepository noticeRepository;
private final UserUtil userUtil;

public void execute(NoticeAddRequestDto noticeAddRequestDto) {
User user = userUtil.getCurrentUser();

if (user.getAuthority() == Authority.ROLE_STUDENT)
throw new NotAccessStudentException();

Notice notice = noticeConverter.toEntity(noticeAddRequestDto, user);

noticeRepository.save(notice);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@
import jakarta.persistence.EntityListeners;
import jakarta.persistence.MappedSuperclass;
import jakarta.persistence.PrePersist;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;

@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
public class BaseEntity {
private ZonedDateTime create_at;

private LocalDateTime createAt;

@PrePersist
public void prePersist() {
this.create_at = ZonedDateTime.now();
protected void onCreate() {
createAt = ZonedDateTime.now(ZoneId.of("Asia/Seoul")).toLocalDateTime();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.mindway.server.v2.global.security.config;

import com.mindway.server.v2.domain.user.entity.Authority;
import com.mindway.server.v2.global.security.filter.JwtFilter;
import com.mindway.server.v2.global.security.handler.JwtAccessDeniedHandler;
import com.mindway.server.v2.global.security.handler.JwtAuthenticationEntryPoint;
Expand Down Expand Up @@ -66,6 +67,9 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
// book
.requestMatchers(HttpMethod.POST, "/api/v2/book").authenticated()

// notice
.requestMatchers(HttpMethod.POST, "/api/v2/notice").hasAnyAuthority(Authority.ROLE_TEACHER.name(), Authority.ROLE_HELPER.name())


.anyRequest().authenticated()
)
Expand Down

0 comments on commit e2d6c05

Please sign in to comment.