Skip to content

Commit

Permalink
Merge pull request #102 from goelsonali/api-create-bookclub-program
Browse files Browse the repository at this point in the history
Api create bookclub program
  • Loading branch information
goelsonali authored Aug 9, 2024
2 parents 569340f + 72825f0 commit 5a32d9f
Show file tree
Hide file tree
Showing 22 changed files with 761 additions and 30 deletions.
35 changes: 35 additions & 0 deletions src/main/java/com/wcc/platform/controller/ProgrammeController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.wcc.platform.controller;

import com.wcc.platform.domain.cms.attributes.ProgramType;
import com.wcc.platform.domain.cms.pages.programme.ProgrammePage;
import com.wcc.platform.service.ProgrammeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

/** Rest controller for all the programme apis. */
@RestController
@Tag(name = "APIs relevant Programme pages")
public class ProgrammeController {

private final ProgrammeService service;

@Autowired
public ProgrammeController(final ProgrammeService programmeService) {
this.service = programmeService;
}

@GetMapping("/api/cms/v1/programme")
@Operation(summary = "API to retrieve programme page")
@ResponseStatus(HttpStatus.OK)
public ResponseEntity<ProgrammePage> getProgramme(
@RequestParam(name = "type") final ProgramType programmeType) {
return ResponseEntity.ok(service.getProgramme(programmeType));
}
}
11 changes: 6 additions & 5 deletions src/main/java/com/wcc/platform/domain/cms/ApiResourcesFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

/** Create custom api configurations. */
public enum ApiResourcesFile {
TEAM("teamPage.json"),
MENTORSHIP("mentorshipPage.json"),
FOOTER("footerPage.json"),
COLLABORATOR("collaboratorPage.json"),
CODE_OF_CONDUCT("codeOfConductPage.json"),
EVENTS("eventsPage.json");
COLLABORATOR("collaboratorPage.json"),
EVENTS("eventsPage.json"),
FOOTER("footerPage.json"),
MENTORSHIP("mentorshipPage.json"),
TEAM("teamPage.json"),
PROG_BOOK_CLUB("bookClubPage.json");

private final String fileName;

Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/wcc/platform/domain/cms/attributes/Card.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.wcc.platform.domain.cms.attributes;

/**
* Basic card details for a page or section.
*
* @param title of the card
* @param subtitle on the card
* @param description shortened description
* @param link link for any external or internal resource
*/
public record Card(String title, String subtitle, String description, SimpleLink link) {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.wcc.platform.domain.cms.pages.programme;

import com.wcc.platform.domain.cms.attributes.Contact;
import com.wcc.platform.domain.cms.pages.Page;
import com.wcc.platform.domain.platform.EventSection;
import com.wcc.platform.domain.platform.Programme;
import java.util.List;

/**
* BookClub programme details.
*
* @param page basic information of the page
* @param contact social network contact information
* @param programmeDetails programme details section
* @param eventSection event details section
*/
public record ProgrammePage(
Page page,
Contact contact,
List<Programme> programmeDetails,
List<EventSection> eventSection) {}
// TODO Add resources section
33 changes: 15 additions & 18 deletions src/main/java/com/wcc/platform/domain/platform/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import lombok.Builder;
import lombok.Data;

/** Event class with all the relevant attributes for an event. */
@Data
@Builder
public class Event {
Expand All @@ -21,28 +22,26 @@ public class Event {
private String endDate;
private ProgramType topics;
private List<Image> images;
private String speaker;
private SimpleLink speakerProfile;
private String host;
private SimpleLink hostProfile;
private SimpleLink eventLink;
private List<EventResource> eventResources;

/** Event builder. */
@SuppressWarnings("PMD.ExcessiveParameterList")
public Event(
UUID id,
String title,
String description,
EventType eventType,
String startDate,
String endDate,
ProgramType topics,
List<Image> images,
String speaker,
SimpleLink speakerProfile,
String host,
SimpleLink hostProfile,
SimpleLink eventLink,
List<EventResource> eventResources) {
final UUID id,
final String title,
final String description,
final EventType eventType,
final String startDate,
final String endDate,
final ProgramType topics,
final List<Image> images,
final SimpleLink speakerProfile,
final SimpleLink hostProfile,
final SimpleLink eventLink,
final List<EventResource> eventResources) {
this.id = id;
this.title = title;
this.description = description;
Expand All @@ -51,9 +50,7 @@ public Event(
this.endDate = endDate;
this.topics = topics;
this.images = images;
this.speaker = speaker;
this.speakerProfile = speakerProfile;
this.host = host;
this.hostProfile = hostProfile;
this.eventLink = eventLink;
this.eventResources = eventResources;
Expand Down
32 changes: 32 additions & 0 deletions src/main/java/com/wcc/platform/domain/platform/EventSection.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.wcc.platform.domain.platform;

import com.wcc.platform.domain.cms.attributes.SimpleLink;
import java.util.List;
import lombok.Builder;
import lombok.Data;

/** EventSection representing list of events {@link Event}. */
@Data
@Builder
public class EventSection {
private String title;
private SimpleLink link;
private List<Event> events;

/**
* Builder for the EventSection.
*
* @param title like - "Upcoming Events" or "Past Events"
* @param link link to the Events page
* @param events list of events to show
*/
public EventSection(final String title, final SimpleLink link, final List<Event> events) {
this.title = title;
this.link = link;
this.events = events;
}

public EventSection() {
// Necessary constructor for jackson.
}
}
34 changes: 34 additions & 0 deletions src/main/java/com/wcc/platform/domain/platform/Programme.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.wcc.platform.domain.platform;

import com.wcc.platform.domain.cms.attributes.Card;
import lombok.Builder;
import lombok.Data;

/** Programme class representing the structure of any programme section of a programme page. */
@Data
@Builder
public class Programme {

private String title;

private String description;

private Card card;

/**
* Programme Builder.
*
* @param title like - heading of the programme
* @param description details co-relating the title
* @param card if any details to be represented in a card
*/
public Programme(final String title, final String description, final Card card) {
this.title = title;
this.description = description;
this.card = card;
}

public Programme() {
// Necessary constructor for jackson.
}
}
1 change: 1 addition & 0 deletions src/main/java/com/wcc/platform/service/CmsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.springframework.stereotype.Service;

/** CMS service responsible for simple pages. */
@SuppressWarnings("PMD.TooManyStaticImports")
@Service
public class CmsService {
private final ObjectMapper objectMapper;
Expand Down
41 changes: 41 additions & 0 deletions src/main/java/com/wcc/platform/service/ProgrammeService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.wcc.platform.service;

import static com.wcc.platform.domain.cms.ApiResourcesFile.PROG_BOOK_CLUB;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.wcc.platform.domain.cms.attributes.ProgramType;
import com.wcc.platform.domain.cms.pages.programme.ProgrammePage;
import com.wcc.platform.domain.exceptions.PlatformInternalException;
import com.wcc.platform.utils.FileUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/** Programme Service. */
@Service
public class ProgrammeService {

private final ObjectMapper objectMapper;

@Autowired
public ProgrammeService(final ObjectMapper objectMapper) {
this.objectMapper = objectMapper;
}

/**
* API to fetch details about different type of programmes.
*
* @return Programme Page json response
*/
public ProgrammePage getProgramme(final ProgramType programType) {
try {
String data = null;
if (ProgramType.BOOK_CLUB.equals(programType)) {
data = FileUtil.readFileAsString(PROG_BOOK_CLUB.getFileName());
}
return objectMapper.readValue(data, ProgrammePage.class);
} catch (JsonProcessingException e) {
throw new PlatformInternalException(e.getMessage(), e);
}
}
}
82 changes: 82 additions & 0 deletions src/main/resources/bookClubPage.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{
"page": {
"title": "WCC Book Club",
"subtitle": "",
"description": "What sets our book club apart are the lively conversations, valuable insights and an opportunity to connect with like-minded individuals. The books we read are selected by the community, offering a diverse selection of tech books and essential soft skills topics.The book club meets monthly to share views, exchange ideas, and inspire personal and professional growth."
},
"contact": {
"title": "Join us in our Study Group Slack channel",
"links": [
{
"type": "SLACK",
"link": "http://shortlink_to_slack.com/#prog_book_club"
}
]
},
"programmeDetails": [
{
"title": "How It Works",
"description": "Every month we vote for a book to read, and at the end of the month we review the book together in our bookclub. In order to participate join us n slack.",
"card": null
},
{
"title": "Benefits of Joining",
"description": "Dedication, networking and always knowing what is happening in tech market.",
"card": null
},
{
"title": "What We Are Reading",
"description": "",
"card": {
"title": "The Pragmatic Programmer From Journeyman to Master",
"subtitle": "Andrew Hunt & David Thomas",
"description": "Essential guide for creating working and maintainable code amidst the complexities of modern software development.",
"link": {
"label": "View Book On GoodReads",
"uri": "http://goodread/book_link"
}
}
}
],
"eventSection": [
{
"title": "Upcoming events",
"link": {
"label": "View past events",
"uri": "/eventsPage_link"
},
"events": [
{
"topics": "BOOK_CLUB",
"startDate": "THU, MAY 30, 2024, 8:00 PM CEST",
"endDate": "THU, MAY 30, 2024, 9.30 CEST",
"title": "BOOK MONTH AUG",
"description": "Book description",
"hostProfile": {
"label": "Jane Doe",
"uri": "https://linkedIn/host"
},
"eventLink": {
"label": "Go to Meetup Event",
"uri": "https://meetup.com/event1"
}
},
{
"topics": "BOOK_CLUB",
"startDate": "THU, MAY 30, 2024, 8:00 PM CEST",
"endDate": "THU, MAY 30, 2024, 9.30 CEST",
"title": "BOOK MONTH SEP",
"description": "Book description",
"speakerProfile": {
"label": "Jane Doe",
"uri": "https://linkedIn/host"
},
"eventLink": {
"label": "Go to Meetup Event",
"uri": "https://meetup.com/event1"
}
}
]
}
]
}
2 changes: 0 additions & 2 deletions src/main/resources/eventsPage.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,10 @@
"startDate": "THU, MAY 30, 2024, 8:00 PM CEST",
"endDate": "THU, MAY 30, 2024, 9.30 CEST",
"title": "Book Club: The Pragmatic Programmer",
"speaker": "Jane Doe",
"speakerProfile": {
"label": "John Doe",
"uri": "https://meetup.com/event1"
},
"host": null,
"hostProfile": null,
"description": "Join us for a discussion of this essential guide to writing clear and maintainable code!",
"images": [
Expand Down
Loading

0 comments on commit 5a32d9f

Please sign in to comment.