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] Notice/EventNotice 관련 API 개발 #56

Merged
merged 60 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
6616d1f
feat: Add Notice,EventNotice entity Superbuilder, setter for update
shj1081 Jul 19, 2024
61384a0
feat: Implement NoticeDto Inner Static class
shj1081 Jul 19, 2024
594614c
feat: Implement NoticeRepository
shj1081 Jul 19, 2024
e656cec
feat: Implement NoticeService interface, NoticeServiceImpl
shj1081 Jul 19, 2024
26899e9
feat: Implement NoticeController
shj1081 Jul 19, 2024
725f236
fix: @NoArgsConstructor(access = PROTECTED) for entities
shj1081 Jul 21, 2024
5b25582
fix: change url, dto (request) field, add validation
shj1081 Jul 21, 2024
9eb641e
fix: remove service interface
shj1081 Jul 21, 2024
ac0f515
fix: change exception to bad request exception
shj1081 Jul 21, 2024
9fa7335
feat: implement getNoticeList api, minor renaming controller parameter
shj1081 Jul 22, 2024
4608864
fix: move @Transactional annotation
shj1081 Jul 22, 2024
f448282
fix: remove @Data annotation
shj1081 Jul 22, 2024
5d037e0
refactor: refactor package structure
shj1081 Jul 22, 2024
f129ccf
Merge pull request #12 from SystemConsultantGroup/feat/9-notice-event…
shj1081 Jul 22, 2024
5c39a76
fix: split response, request dto
shj1081 Jul 22, 2024
33f0271
fix: Use static factory method instead of builder pattern
shj1081 Jul 22, 2024
1762fd4
feat: change put/post to return entity value, change update logic (us…
shj1081 Jul 22, 2024
b937045
feat: Implement increasing hitCount when getNotice
shj1081 Jul 22, 2024
40ae1cf
fix: change protect constructor of BaseNoticeEntity to use annotation
shj1081 Jul 23, 2024
895293a
fix: Revise static factory method to use `from`
shj1081 Jul 23, 2024
f6a5a9e
[FEAT] Global Exception, Test, Restdocs 설정 (#17)
yesjuhee Jul 23, 2024
14c8291
feat: Implement RestDocs, base test code for NoticeController, change…
shj1081 Jul 23, 2024
74af5dc
fix: Add cascade option in Notice Entity
shj1081 Jul 23, 2024
46ad2c6
fix: Revise parameter naming for pathvariable annotaion
shj1081 Jul 23, 2024
7684e3f
fix: Fix wrong service method description
shj1081 Jul 23, 2024
ce41a5b
feat: change updateNotice, increaseHitCount to use entity method
shj1081 Jul 24, 2024
e5110dd
feat: Implement attached files handling, add NoticeListElementResponse
yesjuhee Jul 23, 2024
94f561f
refactor: rename DTOs
shj1081 Jul 26, 2024
71ecc30
fix: Revise Notice/EventNotice entity to not inherit BaseNoticeEntity
shj1081 Jul 26, 2024
6fe0af2
feat: Implement Test code/RestDocs for NoticeController
shj1081 Jul 26, 2024
f7a55c2
cherry-pick: revised custom exception code #21
yesjuhee Jul 25, 2024
dd6efef
feat: add custom exceptions for notice, notnull annotation for fileId…
shj1081 Jul 26, 2024
b3967e4
refactor: rename NoticeResponse fileReponses field to files
shj1081 Jul 28, 2024
7e63761
fix: revise NoticeService to work with request with no fileIds field
shj1081 Jul 28, 2024
2146258
fix: refine controllerTest code for restDocs
shj1081 Jul 28, 2024
1a8c230
fix: add pageable parameter in controllerTest
shj1081 Jul 28, 2024
c4738d9
refactor: remove unnecessary annotation
shj1081 Jul 29, 2024
3e184a6
Merge pull request #18 from SystemConsultantGroup/feat/9-notice-event…
shj1081 Jul 30, 2024
18e9935
feat: duplicate notice api for eventNotice api
shj1081 Jul 29, 2024
0ff083a
refactor: reformat (clean) code
shj1081 Jul 29, 2024
c02987d
fix: change exception code number to prevent conflict
shj1081 Jul 30, 2024
9bd81b6
feat: implement fixed notices prioritization
shj1081 Aug 6, 2024
431f0f5
refactor: change :path to {path} in adoc
shj1081 Aug 6, 2024
fa9c6c9
refactor: refactor adoc files
shj1081 Aug 6, 2024
0325dfa
refactor: remove debugging line for getNoticeList
shj1081 Aug 6, 2024
43c0309
feat: new logic for updateNotice file handling (using Cascade=ALL)
shj1081 Aug 7, 2024
b57d41b
Merge pull request #36 from SystemConsultantGroup/feat/9-notice-event…
shj1081 Aug 7, 2024
24230f8
cherrypick: auth commit from develop branch
jcy0308 Aug 3, 2024
90da4cc
refactor: move domain package location
shj1081 Aug 7, 2024
0d0bdd0
feat: duplicate eventNotice getList, update code from Notice
shj1081 Aug 7, 2024
7a263f7
refactor: remove unused import statement
shj1081 Aug 7, 2024
84a7e16
feat: auth user (admin) for create, update, delete
shj1081 Aug 7, 2024
fbb1335
feat: revise test code for auth user
shj1081 Aug 7, 2024
f98fa24
fix: Typo correction
shj1081 Aug 8, 2024
6b86975
fix: add application-local.yml for CI
shj1081 Aug 8, 2024
b7f647a
chore: remove unnecessary comments
shj1081 Aug 8, 2024
5019ed6
refactor: move notice/eventNotice controller test package
shj1081 Aug 8, 2024
bfebf4e
Merge pull request #52 from SystemConsultantGroup/feat/9-notice-event…
shj1081 Aug 8, 2024
0f93472
fix: handle merge conflict
shj1081 Aug 9, 2024
7c61320
Merge pull request #57 from SystemConsultantGroup/feat/9-notice-event…
shj1081 Aug 9, 2024
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
32 changes: 32 additions & 0 deletions src/docs/asciidoc/eventNotice.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
== 이벤트 공지 사항 API
:source-highlighter: highlightjs

=== 이벤트 공지 사항 생성 (POST /eventNotices)

====
operation::event-notice-controller-test/create-event-notice[snippets="http-request,request-fields,http-response,response-fields"]
====

=== 이벤트 공지 사항 리스트 조회 (GET /eventNotices)

====
operation::event-notice-controller-test/get-event-notice-list[snippets="query-parameters,http-request,http-response,response-fields"]
====

=== 이벤트 공지 사항 조회 (GET /eventNotices/{eventNoticeId})

====
operation::event-notice-controller-test/get-event-notice[snippets="path-parameters,http-request,http-response,response-fields"]
====

=== 이벤트 공지 사항 수정 (PUT /eventNotices/{eventNoticeId})

====
operation::event-notice-controller-test/update-event-notice[snippets="path-parameters,http-request,request-fields,http-response,response-fields"]
====

=== 이벤트 공지 사항 삭제 (DELETE /eventNotices/{eventNoticeId})

====
operation::event-notice-controller-test/delete-event-notice[snippets="path-parameters,http-request,http-response"]
====
6 changes: 3 additions & 3 deletions src/docs/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@

include::jobInterview.adoc[]
include::talk.adoc[]
include::auth-controller-test.adoc[]
// include::eventPeriod.adoc[] 컨트롤러별로 주석 지우고 문서 추가

include::notice.adoc[]
include::eventNotice.adoc[]
include::auth-controller-test.adoc[]
32 changes: 32 additions & 0 deletions src/docs/asciidoc/notice.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
== 공지 사항 API
:source-highlighter: highlightjs

=== 공지 사항 생성 (POST /notices)

====
operation::notice-controller-test/create-notice[snippets="http-request,request-fields,http-response,response-fields"]
====

=== 공지 사항 리스트 조회 (GET /notices)

====
operation::notice-controller-test/get-notice-list[snippets="query-parameters,http-request,http-response,response-fields"]
====

=== 공지 사항 조회 (GET /notices/{noticeId})

====
operation::notice-controller-test/get-notice[snippets="path-parameters,http-request,http-response,response-fields"]
====

=== 공지 사항 수정 (PUT /notices/{noticeId})

====
operation::notice-controller-test/update-notice[snippets="path-parameters,http-request,request-fields,http-response,response-fields"]
====

=== 공지 사항 삭제 (DELETE /notices/{noticeId})

====
operation::notice-controller-test/delete-notice[snippets="path-parameters,http-request,http-response"]
====
9 changes: 4 additions & 5 deletions src/main/java/com/scg/stop/StopApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

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

@SpringBootApplication
public class StopApplication {

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

}
}
42 changes: 0 additions & 42 deletions src/main/java/com/scg/stop/domain/event/domain/EventNotice.java

This file was deleted.

29 changes: 16 additions & 13 deletions src/main/java/com/scg/stop/domain/file/domain/File.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
package com.scg.stop.domain.file.domain;

import static jakarta.persistence.FetchType.LAZY;
import static jakarta.persistence.GenerationType.IDENTITY;
import static lombok.AccessLevel.PROTECTED;

import com.scg.stop.domain.event.domain.EventNotice;
import com.scg.stop.domain.gallery.domain.Gallery;
import com.scg.stop.domain.notice.domain.Notice;
import com.scg.stop.event.domain.EventNotice;
import com.scg.stop.global.domain.BaseTimeEntity;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import com.scg.stop.notice.domain.Notice;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.NoArgsConstructor;

import static jakarta.persistence.FetchType.LAZY;
import static jakarta.persistence.GenerationType.IDENTITY;
import static lombok.AccessLevel.PROTECTED;

@Entity
@Getter
@NoArgsConstructor(access = PROTECTED)
Expand Down Expand Up @@ -46,4 +41,12 @@ public class File extends BaseTimeEntity {
@ManyToOne(fetch = LAZY)
@JoinColumn(name = "gallery_id")
private Gallery gallery;
}

public void setNotice(Notice notice) {
this.notice = notice;
}

public void setEventNotice(EventNotice eventNotice) {
this.eventNotice = eventNotice;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.scg.stop.domain.file.dto.response;

import static lombok.AccessLevel.PRIVATE;

import com.scg.stop.domain.file.domain.File;
import java.time.LocalDateTime;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor(access = PRIVATE)
@AllArgsConstructor
public class FileResponse {

private Long id;
private String uuid;
private String name;
private String mimeType;
private LocalDateTime createdAt;
private LocalDateTime updatedAt;

public static FileResponse from(File file) {
return new FileResponse(
file.getId(),
file.getUuid(),
file.getName(),
file.getMimeType(),
file.getCreatedAt(),
file.getUpdatedAt()
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.scg.stop.domain.file.repository;

import com.scg.stop.domain.file.domain.File;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

public interface FileRepository extends JpaRepository<File, Long> {

List<File> findByIdIn(List<Long> ids);
}
42 changes: 0 additions & 42 deletions src/main/java/com/scg/stop/domain/notice/domain/Notice.java
Original file line number Diff line number Diff line change
@@ -1,42 +0,0 @@
package com.scg.stop.domain.notice.domain;

import static jakarta.persistence.FetchType.LAZY;
import static jakarta.persistence.GenerationType.IDENTITY;
import static lombok.AccessLevel.PROTECTED;

import com.scg.stop.domain.file.domain.File;
import com.scg.stop.global.domain.BaseTimeEntity;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import java.util.ArrayList;
import java.util.List;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@Getter
@NoArgsConstructor(access = PROTECTED)
public class Notice extends BaseTimeEntity {

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

@Column(nullable = false)
private String title;

@Column(nullable = false, columnDefinition = "TEXT")
private String content;

@Column(nullable = false)
private Integer hitCount = 0;

@Column(nullable = false, columnDefinition = "TINYINT(1)")
private boolean isFixed;

@OneToMany(fetch = LAZY, mappedBy = "notice")
private List<File> files = new ArrayList<>();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.scg.stop.event.controller;


import com.scg.stop.auth.annotation.AuthUser;
import com.scg.stop.event.dto.request.EventNoticeRequest;
import com.scg.stop.event.dto.response.EventNoticeListElementResponse;
import com.scg.stop.event.dto.response.EventNoticeResponse;
import com.scg.stop.event.service.EventNoticeService;
import com.scg.stop.user.domain.AccessType;
import com.scg.stop.user.domain.User;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RequiredArgsConstructor
@RequestMapping("/eventNotices")
@RestController
public class EventNoticeController {

private final EventNoticeService eventNoticeService;

// Create a new eventNotice
@PostMapping
public ResponseEntity<EventNoticeResponse> createEventNotice(
@RequestBody @Valid EventNoticeRequest createEventNoticeDto,
@AuthUser(accessType = {AccessType.ADMIN}) User user) {
return ResponseEntity.status(HttpStatus.CREATED).body(eventNoticeService.createEventNotice(createEventNoticeDto));
}

// Get a list of eventNotices
@GetMapping
public ResponseEntity<Page<EventNoticeListElementResponse>> getEventNoticeList(
@RequestParam(value = "title", required = false) String title,
@PageableDefault(page = 0, size = 10) Pageable pageable) {
Page<EventNoticeListElementResponse> eventNoticeList = eventNoticeService.getEventNoticeList(title, pageable);
return ResponseEntity.status(HttpStatus.OK).body(eventNoticeList);
}

// Get a corresponding eventNotice
@GetMapping("/{eventNoticeId}")
public ResponseEntity<EventNoticeResponse> getEventNotice(
@PathVariable("eventNoticeId") Long eventNoticeId) {
EventNoticeResponse eventNotice = eventNoticeService.getEventNotice(eventNoticeId);
return ResponseEntity.status(HttpStatus.OK).body(eventNotice);
}

// Update a corresponding eventNotice
@PutMapping("/{eventNoticeId}")
public ResponseEntity<EventNoticeResponse> updateEventNotice(
@PathVariable("eventNoticeId") Long eventNoticeId,
@RequestBody @Valid EventNoticeRequest updateEventNoticeDto,
@AuthUser(accessType = {AccessType.ADMIN}) User user) {
return ResponseEntity.status(HttpStatus.OK).body(eventNoticeService.updateEventNotice(eventNoticeId, updateEventNoticeDto));
}

// Delete a corresponding eventNotice
@DeleteMapping("/{eventNoticeId}")
public ResponseEntity<Long> deleteEventNotice(
@PathVariable("eventNoticeId") Long eventNoticeId,
@AuthUser(accessType = {AccessType.ADMIN}) User user) {
eventNoticeService.deleteEventNotice(eventNoticeId);
return ResponseEntity.noContent().build();
}
}
Loading
Loading